#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);
int run_publisher_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 (publisher == NULL) {
return shutdown_participant(participant, "create_publisher 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_writer == NULL) {
return shutdown_participant(participant, "create_datawriter error", EXIT_FAILURE);
}
HelloWorldDataWriter *typed_writer =
HelloWorldDataWriter::narrow(untyped_writer);
if (typed_writer == NULL) {
return shutdown_participant(participant, "DataWriter narrow error", EXIT_FAILURE);
}
HelloWorld *data = HelloWorldTypeSupport::create_data();
if (data == NULL) {
return shutdown_participant(
participant,
"HelloWorldTypeSupport::create_data error",
EXIT_FAILURE);
}
for (unsigned int samples_written = 0;
!shutdown_requested && samples_written < sample_count;
++samples_written) {
std::cout << "Writing HelloWorld, count " << samples_written
<< std::endl;
std::cerr << "write error " << retcode << std::endl;
}
}
retcode = HelloWorldTypeSupport::delete_data(data);
std::cerr << "HelloWorldTypeSupport::delete_data error " << retcode
<< std::endl;
}
return shutdown_participant(participant, "Shutting down", EXIT_SUCCESS);
}
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_publisher_application(arguments.domain_id, arguments.sample_count);
std::cerr << "finalize_instance error " << retcode << std::endl;
status = EXIT_FAILURE;
}
return status;
}