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); } }
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); } }
/// <summary> /// Get the right configuration for the module /// Should be managed in setting window /// </summary> /// <param name="cm"></param> /// <returns></returns> private CommonConfiguration Configuration(CommunicationModule cm) { CommonConfiguration conf = null; switch (cm.TransportType) { case TransportEnum.OPEN_DDS: OpenDDSConfiguration oddsConfiguration = new OpenDDSConfiguration() { OpenDDSArgs = new OpenDDSConfiguration.OpenDDSArgsConfiguration() { DCPSConfigFile = "dds_tcp_conf.ini", DCPSTransportDebugLevel = 10, }, DCPSInfoRepo = new OpenDDSConfiguration.DCPSInfoRepoConfiguration() { Autostart = StartServer, ORBEndpoint = "iiop://localhost:12345", } }; OpenDDSChannelConfiguration oddsChannelConf = new OpenDDSChannelConfiguration(oddsConfiguration) { TopicQos = new TopicQosConfiguration() { TopicDataQosPolicy = new TopicDataQosPolicyConfiguration() { Value = new byte[] { 100, 23 } }, DurabilityQosPolicy = new DurabilityQosPolicyConfiguration() { Kind = DurabilityQosPolicyConfiguration.DurabilityQosPolicyKind.PERSISTENT_DURABILITY_QOS }, DurabilityServiceQosPolicy = new DurabilityServiceQosPolicyConfiguration() { HistoryDepth = 100, Kind = DurabilityServiceQosPolicyConfiguration.HistoryQosPolicyKind.KEEP_ALL_HISTORY_QOS, }, ReliabilityQosPolicy = new ReliabilityQosPolicyConfiguration() { Kind = ReliabilityQosPolicyConfiguration.ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS } }, SubscriberQos = new SubscriberQosConfiguration() { EntityFactoryQosPolicy = new EntityFactoryQosPolicyConfiguration() { AutoenableCreatedEntities = true }, } }; conf = oddsChannelConf; break; case TransportEnum.KAFKA: KafkaConfiguration kConfiguration = new KafkaConfiguration() { }; KafkaChannelConfiguration kChannelConfiguration = new KafkaChannelConfiguration(kConfiguration) { AutoOffsetReset = (cm.ChannelName == "users") ? AutoOffsetResetType.beginning : AutoOffsetResetType.latest, InitialOffset = (cm.ChannelName == "users") ? InitialOffsetTypes.Beginning : InitialOffsetTypes.Stored, ClientId = "chat" + cm.ChannelName + cm.Id.ToString(), GroupId = "chatGrp" + cm.Id.ToString(), BootstrapBrokers = "206.189.214.143:9093", }; conf = kChannelConfiguration; break; } return(conf); }