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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
        void InternalActivate()
        {
            lock (CriticalSection)
            {
                if (Status.Status == StatusEnum.CONNECTED ||
                    Status.Status == StatusEnum.COMMUNICATING ||
                    Status.Status == StatusEnum.COMMUNICATION_ERROR ||
                    Status.Status == StatusEnum.INITIALIZED ||
                    Status.Status == StatusEnum.COMMUNICATION_ERROR
                    )
                {
                    return;
                }
                OPERATION_RESULT Res = new OPERATION_RESULT();
                //dataDistribution = new SmartDataDistribution();

                dataDistribution.LoggingEvent += DataDistribution_LoggingEvent;
                try
                {
                    if (Status.Status == StatusEnum.UNDEFINED)
                    {
                        Res = dataDistribution.Initialize(Configuration);
                    }
                    Status = new ExtendedStatus {
                        Status = StatusEnum.INITIALIZED, Description = "INITIALIZED"
                    };
                    if (Res.Failed)
                    {
                        Status = new ExtendedStatus
                        {
                            Status      = StatusEnum.ERROR,
                            Description = "Initialization error"
                        };
                    }
                    Res = dataDistribution.Start(uint.MaxValue);
                    if (Res.Failed)
                    {
                        Status = new ExtendedStatus
                        {
                            Status      = StatusEnum.ERROR,
                            Description = "Start error"
                        };
                    }

                    Channel = dataDistribution.CreateSmartChannel <SmartDataDistributionChannel>(ChannelName, Configuration);
                    Channel.DataAvailable    += Channel_DataAvailable;
                    Channel.ConditionOrError += Channel_ConditionOrError;
                    Res = Channel.StartChannel(uint.MaxValue);
                    if (Res.Succeeded)
                    {
                        Status = new ExtendedStatus
                        {
                            Status      = StatusEnum.CONNECTED,
                            Description = "Channel connection OK"
                        };
                    }
                    if (Res.Failed)
                    {
                        Status = new ExtendedStatus
                        {
                            Status      = StatusEnum.ERROR,
                            Description = "Channel Start error"
                        };
                    }
                    Channel.SeekChannel(0);
                }
                catch (Exception ex)
                {
                    Status = new ExtendedStatus
                    {
                        Status      = StatusEnum.ERROR,
                        Description = ex.Message
                    };
                }
            }
        }