using System.Collections.Generic;
public class HelloWorldPublisher {
public static void Main(string[] args) {
int domain_id = 0;
if (args.Length >= 1) {
domain_id = Int32.Parse(args[0]);
}
int sample_count = 0;
if (args.Length >= 2) {
sample_count = Int32.Parse(args[1]);
}
try {
HelloWorldPublisher.publish(
domain_id, sample_count);
}
{
Console.WriteLine("error in publisher");
}
}
static void publish(int domain_id, int sample_count) {
domain_id,
null ,
DDS.StatusMask.STATUS_MASK_NONE);
if (participant == null) {
shutdown(participant);
throw new ApplicationException("create_participant error");
}
null ,
DDS.StatusMask.STATUS_MASK_NONE);
if (publisher == null) {
shutdown(participant);
throw new ApplicationException("create_publisher error");
}
System.String type_name = HelloWorldTypeSupport.get_type_name();
try {
HelloWorldTypeSupport.register_type(
participant, type_name);
}
Console.WriteLine("register_type error {0}", e);
shutdown(participant);
throw e;
}
DDS.
Topic topic = participant.create_topic(
"Example HelloWorld",
type_name,
null ,
DDS.StatusMask.STATUS_MASK_NONE);
if (topic == null) {
shutdown(participant);
throw new ApplicationException("create_topic error");
}
topic,
null ,
DDS.StatusMask.STATUS_MASK_NONE);
if (writer == null) {
shutdown(participant);
throw new ApplicationException("create_datawriter error");
}
HelloWorldDataWriter HelloWorld_writer =
(HelloWorldDataWriter)writer;
HelloWorld instance = HelloWorldTypeSupport.create_data();
if (instance == null) {
shutdown(participant);
throw new 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, ref 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);
}
static void shutdown(
if (participant != null) {
participant.delete_contained_entities();
ref participant);
}
}
}