#ifndef IMPORT_HelloWorld
#include "HelloWorldSupport.h"
#endif
public ref class HelloWorldPublisher {
public:
static void publish(int domain_id, int sample_count);
private:
static void shutdown(
};
int main(array<System::String^>^ argv) {
int domain_id = 0;
if (argv->Length >= 1) {
domain_id = Int32::Parse(argv[0]);
}
int sample_count = 0;
if (argv->Length >= 2) {
sample_count = Int32::Parse(argv[1]);
}
try {
HelloWorldPublisher::publish(
domain_id, sample_count);
}
return -1;
}
return 0;
}
void HelloWorldPublisher::publish(int domain_id, int sample_count) {
domain_id,
nullptr ,
if (participant == nullptr) {
shutdown(participant);
throw gcnew ApplicationException("create_participant error");
}
nullptr ,
if (publisher == nullptr) {
shutdown(participant);
throw gcnew ApplicationException("create_publisher error");
}
System::String^ type_name = HelloWorldTypeSupport::get_type_name();
try {
HelloWorldTypeSupport::register_type(
participant, type_name);
shutdown(participant);
throw e;
}
"Example HelloWorld",
type_name,
nullptr ,
if (topic == nullptr) {
shutdown(participant);
throw gcnew ApplicationException("create_topic error");
}
topic,
nullptr ,
if (writer == nullptr) {
shutdown(participant);
throw gcnew ApplicationException("create_datawriter error");
}
HelloWorldDataWriter^ HelloWorld_writer =
safe_cast<HelloWorldDataWriter^>(writer);
HelloWorld^ instance = HelloWorldTypeSupport::create_data();
if (instance == nullptr) {
shutdown(participant);
throw gcnew ApplicationException(
"HelloWorldTypeSupport::create_data error");
}
const System::Int32 send_period = 4000;
for (int count=0; (sample_count == 0) || (count < sample_count); ++count) {
Console::WriteLine("Writing HelloWorld, count {0}", count);
try {
HelloWorld_writer->write(instance, instance_handle);
}
Console::WriteLine("write error: {0}", e);
}
System::Threading::Thread::Sleep(send_period);
}
try {
HelloWorldTypeSupport::delete_data(instance);
}
Console::WriteLine("HelloWorldTypeSupport::delete_data error: {0}", e);
}
shutdown(participant);
}
void HelloWorldPublisher::shutdown(
if (participant != nullptr) {
}
}