async Task InternalSendMessage <T>(T message, string key = null) { await Task.Run(() => { if (!(Status.Status == StatusEnum.CONNECTED || Status.Status == StatusEnum.COMMUNICATING || Status.Status == StatusEnum.COMMUNICATION_ERROR)) { throw new Exception("Unable to send messages in status: " + Status.Status); } if (Id == null) { throw new Exception("Id not configured"); } if (!(message is string)) { throw new NotImplementedException("Only string messages are implemented"); } byte[] msg = ASCIIEncoding.ASCII.GetBytes(message as string); string strMessage = message as string; OPERATION_RESULT res = Channel.WriteOnChannel(key, message as string); //OPERATION_RESULT res = Channel.WriteOnChannel(key, msg); if (res.Failed) { Status = new ExtendedStatus { Status = StatusEnum.COMMUNICATION_ERROR, Description = "Error sending message" }; } else { Status = new ExtendedStatus { Status = StatusEnum.COMMUNICATING, Description = "Ok" }; } }); }
static void Main(string[] args) { DDM_CHANNEL_DIRECTION direction = DDM_CHANNEL_DIRECTION.RECEIVER; SmartDataDistribution dataDistribution = new SmartDataDistribution(); dataDistribution.LoggingEvent += DataDistribution_LoggingEvent; OpenDDSConfiguration conf = null; OPERATION_RESULT hRes = OPERATION_RESULT.DDM_NO_ERROR_CONDITION; if (args.Length == 0) { conf = new OpenDDSConfiguration() { OpenDDSArgs = new OpenDDSConfiguration.OpenDDSArgsConfiguration() { DCPSConfigFile = "dds_tcp_conf.ini", DCPSTransportDebugLevel = 10, }, DCPSInfoRepo = new OpenDDSConfiguration.DCPSInfoRepoConfiguration() { Autostart = direction.HasFlag(DDM_CHANNEL_DIRECTION.RECEIVER), // start only on receiver Monitor = true, Resurrect = true, PersistenceFile = "persistance.file", ORBEndpoint = "iiop://localhost:12345", }, DomainParticipantQos = new DomainParticipantQosConfiguration() { EntityFactoryQosPolicy = new EntityFactoryQosPolicyConfiguration() { AutoenableCreatedEntities = true }, PropertyQosPolicy = new PropertyQosPolicyConfiguration() { DDSSEC_PROP_IDENTITY_CA = new PropertyQosPolicyConfiguration.Property("1"), DDSSEC_PROP_IDENTITY_CERT = new PropertyQosPolicyConfiguration.Property("2"), DDSSEC_PROP_IDENTITY_PRIVKEY = new PropertyQosPolicyConfiguration.Property("3"), DDSSEC_PROP_PERM_CA = new PropertyQosPolicyConfiguration.Property("4"), DDSSEC_PROP_PERM_DOC = new PropertyQosPolicyConfiguration.Property("5"), DDSSEC_PROP_PERM_GOV_DOC = new PropertyQosPolicyConfiguration.Property("6", true), } } }; hRes = dataDistribution.Initialize(conf); } else { hRes = dataDistribution.Initialize(args[0]); } if (hRes.Failed) { Console.WriteLine("Error in configuration."); Console.ReadKey(); return; } if (!dataDistribution.Start(uint.MaxValue)) { Console.ReadKey(); return; } OpenDDSChannelConfiguration channelConf = new OpenDDSChannelConfiguration(conf) { TopicQos = new TopicQosConfiguration() { TopicDataQosPolicy = new TopicDataQosPolicyConfiguration() { Value = new byte[] { 100, 23 } }, DurabilityQosPolicy = new DurabilityQosPolicyConfiguration() { Kind = DurabilityQosPolicyConfiguration.DurabilityQosPolicyKind.TRANSIENT_DURABILITY_QOS } }, SubscriberQos = new SubscriberQosConfiguration() { EntityFactoryQosPolicy = new EntityFactoryQosPolicyConfiguration() { AutoenableCreatedEntities = true } } }; SmartDataDistributionChannel testChannel = dataDistribution.CreateSmartChannel <SmartDataDistributionChannel>("test", channelConf); testChannel.DataAvailable += TestChannel_DataAvailable; testChannel.ConditionOrError += TestChannel_ConditionOrError; Console.WriteLine("After CreateSmartChannel...\n"); testChannel.StartChannel(uint.MaxValue); uint counter = 100; int pid = Process.GetCurrentProcess().Id; var str = string.Format("{0:10}", pid); Console.WriteLine("Starting operations...\n"); while (true) { if (direction.HasFlag(DDM_CHANNEL_DIRECTION.TRANSMITTER)) { if (testChannel.WriteOnChannel(str).Succeeded) { str = string.Format("{0:10}", counter++); if ((counter % THRESHOLD) == 0) { string key = string.Format("SendData Reached {0}", counter); testChannel.WriteOnChannel(key, str); Console.WriteLine(key); } } } Thread.Sleep(1000); } }
static void Main(string[] args) { bool transmitter = false; SmartDataDistribution dataDistribution = new SmartDataDistribution(); dataDistribution.LoggingEvent += DataDistribution_LoggingEvent; OpenDDSConfiguration conf = null; HRESULT hRes = HRESULT.S_OK; if (args.Length == 1) { if (args[0] == "t") { transmitter = true; } else { Console.WriteLine("Usage TransmitterReceiver [t]"); Console.WriteLine("Use t for transmitter."); return; } } conf = new OpenDDSConfiguration() { OpenDDSArgs = new OpenDDSConfiguration.OpenDDSArgsConfiguration() { DCPSConfigFile = "dds_tcp_conf.ini", DCPSTransportDebugLevel = 10, }, DCPSInfoRepo = new OpenDDSConfiguration.DCPSInfoRepoConfiguration() { Autostart = !transmitter, ORBEndpoint = "iiop://localhost:12345", } }; hRes = dataDistribution.Initialize(conf); if (hRes.Failed) { Console.WriteLine("Error in configuration."); Console.ReadKey(); return; } hRes = dataDistribution.Start(uint.MaxValue); if (hRes.Failed) { Console.WriteLine("Error in Start."); Console.ReadKey(); return; } SmartDataDistributionChannel testChannel = dataDistribution.CreateSmartChannel <SmartDataDistributionChannel>("testChannel"); testChannel.DataAvailable += TestChannel_DataAvailable; testChannel.ConditionOrError += TestChannel_ConditionOrError; testChannel.StartChannel(uint.MaxValue); int pid = Process.GetCurrentProcess().Id; uint counter = 0; var str = string.Format("Pid: {0} {1:10}", pid, counter); if (transmitter) { Console.WriteLine("Starting sending...\n"); } else { Console.WriteLine("Waiting messages...\n"); } while (true) { if (transmitter) { if (testChannel.WriteOnChannel(str) == HRESULT.S_OK) { str = string.Format("Pid: {0} {1:10}", pid, counter++); if ((counter % THRESHOLD) == 0) { Console.WriteLine("SendData Reached {0}", counter); } } } Thread.Sleep(1000); } }