#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "HelloWorld.h"
#include "HelloWorldSupport.h"
#include "ndds/ndds_cpp.h"
#include "application.h"
using namespace application;
static int shutdown_participant(
const char *shutdown_message,
int status);
unsigned int process_data(HelloWorldDataReader *typed_reader)
{
HelloWorldSeq data_seq;
unsigned int samples_read = 0;
typed_reader->take(
data_seq,
info_seq,
for (int i = 0; i < data_seq.length(); ++i) {
if (info_seq[i].valid_data) {
std::cout << "Received data" << std::endl;
HelloWorldTypeSupport::print_data(&data_seq[i]);
samples_read++;
} else {
std::cout << "Received instance state notification" << std::endl;
}
}
std::cerr << "return loan error " << retcode << std::endl;
}
return samples_read;
}
int run_subscriber_application(unsigned int domain_id, unsigned int sample_count)
{
domain_id,
NULL ,
if (participant == NULL) {
return shutdown_participant(participant, "create_participant error", EXIT_FAILURE);
}
NULL ,
if (subscriber == NULL) {
return shutdown_participant(participant, "create_subscriber error", EXIT_FAILURE);
}
const char *type_name = HelloWorldTypeSupport::get_type_name();
HelloWorldTypeSupport::register_type(participant, type_name);
return shutdown_participant(participant, "register_type error", EXIT_FAILURE);
}
"Example HelloWorld",
type_name,
NULL ,
if (topic == NULL) {
return shutdown_participant(participant, "create_topic error", EXIT_FAILURE);
}
topic,
NULL,
if (untyped_reader == NULL) {
return shutdown_participant(participant, "create_datareader error", EXIT_FAILURE);
}
HelloWorldDataReader *typed_reader =
HelloWorldDataReader::narrow(untyped_reader);
if (typed_reader == NULL) {
return shutdown_participant(participant, "DataReader narrow error", EXIT_FAILURE);
}
if (read_condition == NULL) {
return shutdown_participant(participant, "create_readcondition error", EXIT_FAILURE);
}
return shutdown_participant(participant, "attach_condition error", EXIT_FAILURE);
}
unsigned int samples_read = 0;
while (!shutdown_requested && samples_read < sample_count) {
retcode = waitset.
wait(active_conditions_seq, wait_timeout);
samples_read += process_data(typed_reader);
} else {
std::cout << "No data after 1 second" << std::endl;
}
}
}
return shutdown_participant(participant, "Shutting down", 0);
}
static int shutdown_participant(
const char *shutdown_message,
int status)
{
std::cout << shutdown_message << std::endl;
if (participant != NULL) {
std::cerr << "delete_contained_entities error" << retcode
<< std::endl;
status = EXIT_FAILURE;
}
std::cerr << "delete_participant error" << retcode << std::endl;
status = EXIT_FAILURE;
}
}
return status;
}
int main(int argc, char *argv[])
{
ApplicationArguments arguments;
parse_arguments(arguments, argc, argv);
if (arguments.parse_result == PARSE_RETURN_EXIT) {
return EXIT_SUCCESS;
} else if (arguments.parse_result == PARSE_RETURN_FAILURE) {
return EXIT_FAILURE;
}
setup_signal_handlers();
int status = run_subscriber_application(arguments.domain_id, arguments.sample_count);
std::cerr << "finalize_instance error" << retcode << std::endl;
status = EXIT_FAILURE;
}
return status;
}