Ejemplo n.º 1
0
		public DomainParticipantTransportSource(DomainParticipant participant, string senderTopic, string receiverTopic)
		{
			_participant = participant;

			var senderTopicQos = new TopicQos();
			participant.get_default_topic_qos(senderTopicQos);

			var receiverTopicQos = new TopicQos();
			participant.get_default_topic_qos(receiverTopicQos);

			_sender = participant.create_topic(senderTopic, BytesTypeSupport.TYPENAME, senderTopicQos, null, StatusMask.STATUS_MASK_NONE);
			_receiver = participant.create_topic(receiverTopic, BytesTypeSupport.TYPENAME, receiverTopicQos, null, StatusMask.STATUS_MASK_NONE);

			var writerQos = new DataWriterQos();
			//writerQos.publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS;
			writerQos.publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME;

			participant.get_default_datawriter_qos(writerQos);
			
			var readerQos = new DataReaderQos();
			participant.get_default_datareader_qos(readerQos);

			_writer = participant.create_datawriter(_sender, writerQos, null, StatusMask.STATUS_MASK_NONE);
			_reader = participant.create_datareader(_receiver, readerQos, this, StatusMask.STATUS_MASK_ALL);
		}
Ejemplo n.º 2
0
        public ReturnCode GetQos(ref TopicQos qos)
        {
            IntPtr     userQos = IntPtr.Zero;
            ReturnCode result  = DDS.ReturnCode.AlreadyDeleted;

            ReportStack.Start();
            if (this.rlReq_isAlive)
            {
                result = uResultToReturnCode(
                    User.Topic.GetQos(rlReq_UserPeer, ref userQos));
                if (result == ReturnCode.Ok)
                {
                    using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                               new OpenSplice.CustomMarshalers.TopicQosMarshaler(userQos, true))
                    {
                        marshaler.CopyOut(ref qos);
                    }
                }
                else
                {
                    ReportStack.Report(result, "Could not copy TopicQos.");
                }
            }
            ReportStack.Flush(this, result != ReturnCode.Ok);

            return(result);
        }
Ejemplo n.º 3
0
        public ReturnCode SetQos(TopicQos qos)
        {
            ReturnCode result = DDS.ReturnCode.AlreadyDeleted;

            ReportStack.Start();
            if (this.rlReq_isAlive)
            {
                result = QosManager.checkQos(qos);
                if (result == DDS.ReturnCode.Ok)
                {
                    using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                               new OpenSplice.CustomMarshalers.TopicQosMarshaler())
                    {
                        result = marshaler.CopyIn(qos);
                        if (result == ReturnCode.Ok)
                        {
                            result = uResultToReturnCode(
                                User.Topic.SetQos(rlReq_UserPeer, marshaler.UserPtr));
                            if (result != ReturnCode.Ok)
                            {
                                ReportStack.Report(result, "Could not apply TopicQos.");
                            }
                        }
                    }
                }
            }
            ReportStack.Flush(this, result != ReturnCode.Ok);

            return(result);
        }
Ejemplo n.º 4
0
        public DomainParticipantTransportSource(DomainParticipant participant, string senderTopic, string receiverTopic)
        {
            _participant = participant;

            var senderTopicQos = new TopicQos();

            participant.get_default_topic_qos(senderTopicQos);

            var receiverTopicQos = new TopicQos();

            participant.get_default_topic_qos(receiverTopicQos);

            _sender   = participant.create_topic(senderTopic, BytesTypeSupport.TYPENAME, senderTopicQos, null, StatusMask.STATUS_MASK_NONE);
            _receiver = participant.create_topic(receiverTopic, BytesTypeSupport.TYPENAME, receiverTopicQos, null, StatusMask.STATUS_MASK_NONE);

            var writerQos = new DataWriterQos();

            //writerQos.publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS;
            writerQos.publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME;

            participant.get_default_datawriter_qos(writerQos);

            var readerQos = new DataReaderQos();

            participant.get_default_datareader_qos(readerQos);

            _writer = participant.create_datawriter(_sender, writerQos, null, StatusMask.STATUS_MASK_NONE);
            _reader = participant.create_datareader(_receiver, readerQos, this, StatusMask.STATUS_MASK_ALL);
        }
Ejemplo n.º 5
0
        public void TestGetQos()
        {
            // Create a non-default QoS
            TopicQos qos = TestHelper.CreateNonDefaultTopicQos();

            // Create a new Topic using the non-default QoS
            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(_participant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            Topic topic = _participant.CreateTopic(nameof(TestGetQos), typeName, qos);

            Assert.IsNotNull(topic);
            Assert.AreEqual(nameof(TestGetQos), topic.Name);
            Assert.AreEqual(typeName, topic.TypeName);
            Assert.AreEqual(_participant, topic.Participant);

            // Get the QoS and check it
            TopicQos getQos = new TopicQos();

            result = topic.GetQos(getQos);
            Assert.AreEqual(ReturnCode.Ok, result);
            TestHelper.TestNonDefaultTopicQos(getQos);

            // Test GetQos with null parameter
            result = topic.GetQos(null);
            Assert.AreEqual(ReturnCode.BadParameter, result);
        }
Ejemplo n.º 6
0
        public DomainParticipantTransportSource(IDomainParticipant participant, string senderTopic, string receiverTopic)
        {
            _participant = participant;

            var bdt    = new ByteDataTypeSupport();
            var result = bdt.RegisterType(participant, bdt.TypeName);

            if (result != ReturnCode.Ok)
            {
                throw new Exception("Unable to register type: " + result);
            }

            _publisher  = _participant.CreatePublisher();
            _subscriber = _participant.CreateSubscriber();

            var senderTopicQos = new TopicQos();

            participant.GetDefaultTopicQos(ref senderTopicQos);

            var receiverTopicQos = new TopicQos();

            participant.GetDefaultTopicQos(ref receiverTopicQos);

            _senderTopic   = participant.CreateTopic(senderTopic, bdt.TypeName, senderTopicQos);
            _receiverTopic = participant.CreateTopic(receiverTopic, bdt.TypeName, receiverTopicQos);

            _dataWriter       = (ByteDataWriter)_publisher.CreateDataWriter(_senderTopic);
            _dataToSendHandle = _dataWriter.RegisterInstance(_dataToSend);

            var dataReaderQos = new DataReaderQos();

            _subscriber.GetDefaultDataReaderQos(ref dataReaderQos);
            _dataReader = (ByteDataReader)_subscriber.CreateDataReader(_receiverTopic, dataReaderQos, this, StatusKind.Any);
        }
Ejemplo n.º 7
0
		public DomainParticipantTransportSource(IDomainParticipant participant, string senderTopic, string receiverTopic)
		{
			_participant = participant;

			var bdt = new ByteDataTypeSupport();
			var result = bdt.RegisterType(participant, bdt.TypeName);
			if (result != ReturnCode.Ok)
				throw new Exception("Unable to register type: " + result);

			_publisher = _participant.CreatePublisher();
			_subscriber = _participant.CreateSubscriber();

			var senderTopicQos = new TopicQos();
			participant.GetDefaultTopicQos(ref senderTopicQos);

			var receiverTopicQos = new TopicQos();
			participant.GetDefaultTopicQos(ref receiverTopicQos);

			_senderTopic = participant.CreateTopic(senderTopic, bdt.TypeName, senderTopicQos);
			_receiverTopic = participant.CreateTopic(receiverTopic, bdt.TypeName, receiverTopicQos);

			_dataWriter = (ByteDataWriter)_publisher.CreateDataWriter(_senderTopic);
			_dataToSendHandle = _dataWriter.RegisterInstance(_dataToSend);

			var dataReaderQos = new DataReaderQos();
			_subscriber.GetDefaultDataReaderQos(ref dataReaderQos);
			_dataReader = (ByteDataReader)_subscriber.CreateDataReader(_receiverTopic, dataReaderQos, this, StatusKind.Any);
		}
Ejemplo n.º 8
0
        public ReturnCode CopyFromTopicQos(ref DataWriterQos dataWriterQos, TopicQos topicQos)
        {
            ReturnCode result = DDS.ReturnCode.BadParameter;

            ReportStack.Start();
            if (topicQos != null)
            {
                if (dataWriterQos == null)
                {
                    GetDefaultDataWriterQos(ref dataWriterQos);
                }
                dataWriterQos.Durability        = topicQos.Durability;
                dataWriterQos.Deadline          = topicQos.Deadline;
                dataWriterQos.LatencyBudget     = topicQos.LatencyBudget;
                dataWriterQos.Liveliness        = topicQos.Liveliness;
                dataWriterQos.Reliability       = topicQos.Reliability;
                dataWriterQos.DestinationOrder  = topicQos.DestinationOrder;
                dataWriterQos.History           = topicQos.History;
                dataWriterQos.ResourceLimits    = topicQos.ResourceLimits;
                dataWriterQos.TransportPriority = topicQos.TransportPriority;
                dataWriterQos.Lifespan          = topicQos.Lifespan;
                dataWriterQos.Ownership         = topicQos.Ownership;
                result = DDS.ReturnCode.Ok;
            }
            ReportStack.Flush(this, result != ReturnCode.Ok);
            return(result);
        }
Ejemplo n.º 9
0
        public void TestTakeNextInstance()
        {
            ReturnCode        ret;
            DomainParticipant otherParticipant = null;
            Topic             topic            = null;

            try
            {
                List <TopicBuiltinTopicData> data  = new List <TopicBuiltinTopicData>();
                List <SampleInfo>            infos = new List <SampleInfo>();
                ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil);
                Assert.AreEqual(ReturnCode.NoData, ret);
                Assert.AreEqual(0, data.Count);
                Assert.AreEqual(0, infos.Count);

                otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN);
                Assert.IsNotNull(otherParticipant);
                otherParticipant.BindRtpsUdpTransportConfig();

                TestStructTypeSupport support = new TestStructTypeSupport();
                string     typeName           = support.GetTypeName();
                ReturnCode result             = support.RegisterType(otherParticipant, typeName);
                Assert.AreEqual(ReturnCode.Ok, result);

                TopicQos qos = TestHelper.CreateNonDefaultTopicQos();
                topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos);
                Assert.IsNotNull(topic);

                int count = 200;
                ret = ReturnCode.NoData;
                while (ret != ReturnCode.Ok && count > 0)
                {
                    Thread.Sleep(100);
                    ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil);
                    count--;
                }

                Assert.AreEqual(ReturnCode.Ok, ret);
                Assert.AreEqual(1, data.Count);
                Assert.AreEqual(1, infos.Count);
                Assert.AreEqual(typeName, data.First().TypeName);
                Assert.IsNotNull(data.First().Key);
                TestHelper.TestNonDefaultTopicData(data.First());
            }
            finally
            {
                ret = otherParticipant.DeleteTopic(topic);
                Assert.AreEqual(ReturnCode.Ok, ret);
                ret = otherParticipant.DeleteContainedEntities();
                Assert.AreEqual(ReturnCode.Ok, ret);

                ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
                Assert.AreEqual(ReturnCode.Ok, ret);
            }
        }
Ejemplo n.º 10
0
        public static TopicQos CreateNonDefaultTopicQos()
        {
            TopicQos qos = new TopicQos();

            qos.Deadline.Period = new Duration
            {
                Seconds     = 5,
                NanoSeconds = 0
            };
            qos.DestinationOrder.Kind                   = DestinationOrderQosPolicyKind.BySourceTimestampDestinationOrderQos;
            qos.Durability.Kind                         = DurabilityQosPolicyKind.TransientLocalDurabilityQos;
            qos.DurabilityService.HistoryDepth          = 5;
            qos.DurabilityService.HistoryKind           = HistoryQosPolicyKind.KeepAllHistoryQos;
            qos.DurabilityService.MaxInstances          = 5;
            qos.DurabilityService.MaxSamples            = 5;
            qos.DurabilityService.MaxSamplesPerInstance = 5;
            qos.DurabilityService.ServiceCleanupDelay   = new Duration {
                Seconds = 5, NanoSeconds = 5
            };
            qos.History.Depth          = 5;
            qos.History.Kind           = HistoryQosPolicyKind.KeepAllHistoryQos;
            qos.LatencyBudget.Duration = new Duration
            {
                Seconds     = 5,
                NanoSeconds = 5
            };
            qos.Lifespan.Duration = new Duration
            {
                Seconds     = 5,
                NanoSeconds = 5
            };
            qos.Liveliness.Kind          = LivelinessQosPolicyKind.ManualByParticipantLivelinessQos;
            qos.Liveliness.LeaseDuration = new Duration
            {
                Seconds     = 5,
                NanoSeconds = 5
            };
            qos.Ownership.Kind              = OwnershipQosPolicyKind.ExclusiveOwnershipQos;
            qos.Reliability.Kind            = ReliabilityQosPolicyKind.ReliableReliabilityQos;
            qos.Reliability.MaxBlockingTime = new Duration
            {
                Seconds     = 5,
                NanoSeconds = 5
            };
            qos.ResourceLimits.MaxInstances          = 5;
            qos.ResourceLimits.MaxSamples            = 5;
            qos.ResourceLimits.MaxSamplesPerInstance = 5;
            qos.TopicData.Value = new List <byte> {
                0x5
            };
            qos.TransportPriority.Value = 5;

            return(qos);
        }
Ejemplo n.º 11
0
        GetTopicQos(
            ref TopicQos topicQos,
            string id)
        {
            NamedTopicQos tQos      = new NamedTopicQos();
            GCHandle      qosHandle = GCHandle.Alloc(tQos, GCHandleType.Normal);
            ReturnCode    result    = OpenSplice.Common.QosProvider.GetTopicQos(GapiPeer, id, GCHandle.ToIntPtr(qosHandle));

            topicQos = tQos.TopicQos;
            qosHandle.Free();
            return(result);
        }
Ejemplo n.º 12
0
        public void TestLookupInstance()
        {
            ReturnCode        ret;
            DomainParticipant otherParticipant = null;
            Topic             topic            = null;

            try
            {
                TopicBuiltinTopicData data = default;
                SampleInfo            info = new SampleInfo();

                otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN);
                Assert.IsNotNull(otherParticipant);
                otherParticipant.BindRtpsUdpTransportConfig();

                TestStructTypeSupport support = new TestStructTypeSupport();
                string     typeName           = support.GetTypeName();
                ReturnCode result             = support.RegisterType(otherParticipant, typeName);
                Assert.AreEqual(ReturnCode.Ok, result);

                TopicQos qos = TestHelper.CreateNonDefaultTopicQos();
                topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos);
                Assert.IsNotNull(topic);

                int count = 200;
                ret = ReturnCode.NoData;
                while (ret != ReturnCode.Ok && count > 0)
                {
                    Thread.Sleep(100);
                    ret = _dr.ReadNextSample(ref data, info);
                    count--;
                }

                Assert.AreEqual(ReturnCode.Ok, ret);
                Assert.AreEqual(typeName, data.TypeName);
                Assert.IsNotNull(data.Key);
                TestHelper.TestNonDefaultTopicData(data);

                // Lookup for an existing instance
                var handle = _dr.LookupInstance(data);
                Assert.AreNotEqual(InstanceHandle.HandleNil, handle);
            }
            finally
            {
                ret = otherParticipant.DeleteTopic(topic);
                Assert.AreEqual(ReturnCode.Ok, ret);
                ret = otherParticipant.DeleteContainedEntities();
                Assert.AreEqual(ReturnCode.Ok, ret);

                ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
                Assert.AreEqual(ReturnCode.Ok, ret);
            }
        }
        public void TestReadInstance()
        {
            List <TopicBuiltinTopicData> data  = new List <TopicBuiltinTopicData>();
            List <SampleInfo>            infos = new List <SampleInfo>();
            ReturnCode ret = _dr.Read(data, infos);

            Assert.AreEqual(ReturnCode.NoData, ret);
            Assert.AreEqual(0, data.Count);
            Assert.AreEqual(0, infos.Count);

            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindTcpTransportConfig();

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            TopicQos qos   = TestHelper.CreateNonDefaultTopicQos();
            var      topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos);

            Assert.IsNotNull(topic);

            Thread.Sleep(500);

            ret = _dr.ReadNextInstance(data, infos, InstanceHandle.HandleNil);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);

            var handle = infos.First().InstanceHandle;

            data  = new List <TopicBuiltinTopicData>();
            infos = new List <SampleInfo>();

            ret = _dr.ReadInstance(data, infos, handle);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);
            Assert.AreEqual(typeName, data.First().TypeName);
            Assert.IsNotNull(data.First().Key);
            TestHelper.TestNonDefaultTopicData(data.First());

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
        public void TestGetKeyValue()
        {
            // Call GetKeyValue with HandleNil
            TopicBuiltinTopicData data = default;
            SampleInfo            info = new SampleInfo();
            ReturnCode            ret  = _dr.GetKeyValue(ref data, InstanceHandle.HandleNil);

            Assert.AreEqual(ReturnCode.BadParameter, ret);

            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindTcpTransportConfig();

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            TopicQos qos   = TestHelper.CreateNonDefaultTopicQos();
            var      topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos);

            Assert.IsNotNull(topic);

            Thread.Sleep(500);

            // Get the for an existing instance
            ret = _dr.ReadNextSample(ref data, info);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(typeName, data.TypeName);
            Assert.IsNotNull(data.Key);
            TestHelper.TestNonDefaultTopicData(data);

            TopicBuiltinTopicData aux = default;

            ret = _dr.GetKeyValue(ref aux, info.InstanceHandle);
            Assert.AreEqual(ReturnCode.Ok, ret);
            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(data.Key.Value[i], aux.Key.Value[i]);
            }

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
        private void ApplyQos(TopicQos defaultTopicQos, AdapterTopicQos adapterRequiredQos)
        {
            if (defaultTopicQos == null)
            {
                throw new ArgumentNullException("defaultTopicQos");
            }

            if (adapterRequiredQos == null)
            {
                throw new ArgumentNullException("adapterRequiredQos");
            }

            defaultTopicQos.Durability.Kind  = adapterRequiredQos.PersistenceType.ConvertPersistence();
            defaultTopicQos.Reliability.Kind = adapterRequiredQos.MessageReliabilityType.ConvertReliability();
        }
Ejemplo n.º 16
0
 public static void TestNonDefaultTopicQos(TopicQos qos)
 {
     Assert.IsNotNull(qos);
     Assert.IsNotNull(qos.Deadline);
     Assert.IsNotNull(qos.DestinationOrder);
     Assert.IsNotNull(qos.Durability);
     Assert.IsNotNull(qos.DurabilityService);
     Assert.IsNotNull(qos.History);
     Assert.IsNotNull(qos.LatencyBudget);
     Assert.IsNotNull(qos.Lifespan);
     Assert.IsNotNull(qos.Liveliness);
     Assert.IsNotNull(qos.Ownership);
     Assert.IsNotNull(qos.Reliability);
     Assert.IsNotNull(qos.ResourceLimits);
     Assert.IsNotNull(qos.TopicData);
     Assert.IsNotNull(qos.TransportPriority);
     Assert.AreEqual(5, qos.Deadline.Period.Seconds);
     Assert.AreEqual(Duration.ZeroNanoseconds, qos.Deadline.Period.NanoSeconds);
     Assert.AreEqual(DestinationOrderQosPolicyKind.BySourceTimestampDestinationOrderQos, qos.DestinationOrder.Kind);
     Assert.AreEqual(DurabilityQosPolicyKind.TransientLocalDurabilityQos, qos.Durability.Kind);
     Assert.AreEqual(HistoryQosPolicyKind.KeepAllHistoryQos, qos.DurabilityService.HistoryKind);
     Assert.AreEqual(5, qos.DurabilityService.HistoryDepth);
     Assert.AreEqual(5, qos.DurabilityService.MaxInstances);
     Assert.AreEqual(5, qos.DurabilityService.MaxSamples);
     Assert.AreEqual(5, qos.DurabilityService.MaxSamplesPerInstance);
     Assert.IsNotNull(qos.DurabilityService.ServiceCleanupDelay);
     Assert.AreEqual(5, qos.DurabilityService.ServiceCleanupDelay.Seconds);
     Assert.AreEqual((uint)5, qos.DurabilityService.ServiceCleanupDelay.NanoSeconds);
     Assert.AreEqual(HistoryQosPolicyKind.KeepAllHistoryQos, qos.History.Kind);
     Assert.AreEqual(5, qos.History.Depth);
     Assert.AreEqual(5, qos.LatencyBudget.Duration.Seconds);
     Assert.AreEqual((uint)5, qos.LatencyBudget.Duration.NanoSeconds);
     Assert.AreEqual(5, qos.Lifespan.Duration.Seconds);
     Assert.AreEqual((uint)5, qos.Lifespan.Duration.NanoSeconds);
     Assert.AreEqual(LivelinessQosPolicyKind.ManualByParticipantLivelinessQos, qos.Liveliness.Kind);
     Assert.AreEqual(5, qos.Liveliness.LeaseDuration.Seconds);
     Assert.AreEqual((uint)5, qos.Liveliness.LeaseDuration.NanoSeconds);
     Assert.AreEqual(OwnershipQosPolicyKind.ExclusiveOwnershipQos, qos.Ownership.Kind);
     Assert.AreEqual(ReliabilityQosPolicyKind.ReliableReliabilityQos, qos.Reliability.Kind);
     Assert.AreEqual(5, qos.Reliability.MaxBlockingTime.Seconds);
     Assert.AreEqual((uint)5, qos.Reliability.MaxBlockingTime.NanoSeconds);
     Assert.AreEqual(5, qos.ResourceLimits.MaxInstances);
     Assert.AreEqual(5, qos.ResourceLimits.MaxSamples);
     Assert.AreEqual(5, qos.ResourceLimits.MaxSamplesPerInstance);
     Assert.AreEqual(1, qos.TopicData.Value.Count());
     Assert.AreEqual(0x5, qos.TopicData.Value.First());
     Assert.AreEqual(5, qos.TransportPriority.Value);
 }
Ejemplo n.º 17
0
        public ReturnCode GetQos(ref TopicQos qos)
        {
            ReturnCode result;
            
            using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler = 
                    new OpenSplice.CustomMarshalers.TopicQosMarshaler())
            {
                result = Gapi.Topic.get_qos(GapiPeer, marshaler.GapiPtr);
                if (result == ReturnCode.Ok)
                {
                    marshaler.CopyOut(ref qos);
                }
            }

            return result;
        }
Ejemplo n.º 18
0
        public ReturnCode SetQos(TopicQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.TopicQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == DDS.ReturnCode.Ok)
                {
                    result = Gapi.Topic.set_qos(GapiPeer, marshaler.GapiPtr);
                }
            }

            return(result);
        }
Ejemplo n.º 19
0
        public ReturnCode GetQos(ref TopicQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.TopicQosMarshaler())
            {
                result = Gapi.Topic.get_qos(GapiPeer, marshaler.GapiPtr);
                if (result == ReturnCode.Ok)
                {
                    marshaler.CopyOut(ref qos);
                }
            }

            return(result);
        }
Ejemplo n.º 20
0
        public ReturnCode SetDefaultTopicQos(TopicQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.TopicQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == ReturnCode.Ok)
                {
                    result = Gapi.DomainParticipant.set_default_topic_qos(
                        GapiPeer,
                        marshaler.GapiPtr);
                }
            }

            return(result);
        }
Ejemplo n.º 21
0
 public static void TestDefaultTopicQos(TopicQos qos)
 {
     Assert.IsNotNull(qos.Deadline);
     Assert.IsNotNull(qos.DestinationOrder);
     Assert.IsNotNull(qos.Durability);
     Assert.IsNotNull(qos.DurabilityService);
     Assert.IsNotNull(qos.History);
     Assert.IsNotNull(qos.LatencyBudget);
     Assert.IsNotNull(qos.Lifespan);
     Assert.IsNotNull(qos.Liveliness);
     Assert.IsNotNull(qos.Ownership);
     Assert.IsNotNull(qos.Reliability);
     Assert.IsNotNull(qos.ResourceLimits);
     Assert.IsNotNull(qos.TopicData);
     Assert.IsNotNull(qos.TransportPriority);
     Assert.AreEqual(Duration.InfiniteSeconds, qos.Deadline.Period.Seconds);
     Assert.AreEqual(Duration.InfiniteNanoseconds, qos.Deadline.Period.NanoSeconds);
     Assert.AreEqual(DestinationOrderQosPolicyKind.ByReceptionTimestampDestinationOrderQos, qos.DestinationOrder.Kind);
     Assert.AreEqual(DurabilityQosPolicyKind.VolatileDurabilityQos, qos.Durability.Kind);
     Assert.AreEqual(HistoryQosPolicyKind.KeepLastHistoryQos, qos.DurabilityService.HistoryKind);
     Assert.AreEqual(1, qos.DurabilityService.HistoryDepth);
     Assert.AreEqual(ResourceLimitsQosPolicy.LengthUnlimited, qos.DurabilityService.MaxInstances);
     Assert.AreEqual(ResourceLimitsQosPolicy.LengthUnlimited, qos.DurabilityService.MaxSamples);
     Assert.AreEqual(ResourceLimitsQosPolicy.LengthUnlimited, qos.DurabilityService.MaxSamplesPerInstance);
     Assert.AreEqual(HistoryQosPolicyKind.KeepLastHistoryQos, qos.History.Kind);
     Assert.AreEqual(1, qos.History.Depth);
     Assert.AreEqual(Duration.ZeroSeconds, qos.LatencyBudget.Duration.Seconds);
     Assert.AreEqual(Duration.ZeroNanoseconds, qos.LatencyBudget.Duration.NanoSeconds);
     Assert.AreEqual(Duration.InfiniteSeconds, qos.Lifespan.Duration.Seconds);
     Assert.AreEqual(Duration.InfiniteNanoseconds, qos.Lifespan.Duration.NanoSeconds);
     Assert.AreEqual(LivelinessQosPolicyKind.AutomaticLivelinessQos, qos.Liveliness.Kind);
     Assert.AreEqual(Duration.InfiniteSeconds, qos.Liveliness.LeaseDuration.Seconds);
     Assert.AreEqual(Duration.InfiniteNanoseconds, qos.Liveliness.LeaseDuration.NanoSeconds);
     Assert.AreEqual(OwnershipQosPolicyKind.SharedOwnershipQos, qos.Ownership.Kind);
     Assert.AreEqual(ReliabilityQosPolicyKind.BestEffortReliabilityQos, qos.Reliability.Kind);
     Assert.AreEqual(Duration.InfiniteSeconds, qos.Reliability.MaxBlockingTime.Seconds);
     Assert.AreEqual(Duration.InfiniteNanoseconds, qos.Reliability.MaxBlockingTime.NanoSeconds);
     Assert.AreEqual(ResourceLimitsQosPolicy.LengthUnlimited, qos.ResourceLimits.MaxInstances);
     Assert.AreEqual(ResourceLimitsQosPolicy.LengthUnlimited, qos.ResourceLimits.MaxSamples);
     Assert.AreEqual(ResourceLimitsQosPolicy.LengthUnlimited, qos.ResourceLimits.MaxSamplesPerInstance);
     Assert.AreEqual(0, qos.TopicData.Value.Count());
     Assert.AreEqual(0, qos.TransportPriority.Value);
 }
Ejemplo n.º 22
0
        internal static ReturnCode checkQos(TopicQos o)
        {
            ReturnCode result = DDS.ReturnCode.BadParameter;

            if (o != null)
            {
                int errorCount = 0;
                errorCount += countErrors(o.TopicData);
                errorCount += countErrors(o.Durability);
                errorCount += countErrors(o.DurabilityService);
                errorCount += countErrors(o.Deadline);
                errorCount += countErrors(o.LatencyBudget);
                errorCount += countErrors(o.Liveliness);
                errorCount += countErrors(o.Reliability);
                errorCount += countErrors(o.DestinationOrder);
                errorCount += countErrors(o.History);
                errorCount += countErrors(o.ResourceLimits);
                errorCount += countErrors(o.TransportPriority);
                errorCount += countErrors(o.Lifespan);
                errorCount += countErrors(o.Ownership);
                if (errorCount == 0)
                {
                    result = DDS.ReturnCode.Ok;
                    if ((o.History.Kind == HistoryQosPolicyKind.KeepLastHistoryQos) &&
                        (o.ResourceLimits.MaxSamplesPerInstance != Length.Unlimited) &&
                        (o.History.Depth > o.ResourceLimits.MaxSamplesPerInstance))
                    {
                        ReportStack.Report(result,
                                           "HistoryQosPolicy.depth is greater than " +
                                           "ResourceLimitsQosPolicy.max_samples_per_instance.");
                        result = DDS.ReturnCode.InconsistentPolicy;
                    }
                }
            }
            else
            {
                ReportStack.Report(result,
                                   "TopicQos 'null' is invalid.");
            }
            return(result);
        }
Ejemplo n.º 23
0
        public ReturnCode CopyFromTopicQos(ref DataWriterQos dataWriterQos, TopicQos topicQos)
        {
            ReturnCode result = ReturnCode.Ok;

            if (dataWriterQos == null)
            {
                result = GetDefaultDataWriterQos(ref dataWriterQos);
            }

            if (result == ReturnCode.Ok)
            {
                using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                           new OpenSplice.CustomMarshalers.TopicQosMarshaler())
                {
                    result = marshaler.CopyIn(topicQos);
                    if (result == ReturnCode.Ok)
                    {
                        using (OpenSplice.CustomMarshalers.DataWriterQosMarshaler dataWriterMarshaler =
                                   new OpenSplice.CustomMarshalers.DataWriterQosMarshaler())
                        {
                            result = dataWriterMarshaler.CopyIn(dataWriterQos);
                            if (result == ReturnCode.Ok)
                            {
                                result = Gapi.Publisher.copy_from_topic_qos(
                                    GapiPeer,
                                    dataWriterMarshaler.GapiPtr,
                                    marshaler.GapiPtr);

                                if (result == ReturnCode.Ok)
                                {
                                    dataWriterMarshaler.CopyOut(ref dataWriterQos);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 24
0
        public ReturnCode CopyFromTopicQos(ref DataWriterQos dataWriterQos, TopicQos topicQos)
        {
            ReturnCode result = ReturnCode.Ok;

            if (dataWriterQos == null)
            {
                result = GetDefaultDataWriterQos(ref dataWriterQos);
            }

            if (result == ReturnCode.Ok)
            {
                using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                        new OpenSplice.CustomMarshalers.TopicQosMarshaler())
                {
                    result = marshaler.CopyIn(topicQos);
                    if (result == ReturnCode.Ok)
                    {
                        using (OpenSplice.CustomMarshalers.DataWriterQosMarshaler dataWriterMarshaler =
                                new OpenSplice.CustomMarshalers.DataWriterQosMarshaler())
                        {
                            result = dataWriterMarshaler.CopyIn(dataWriterQos);
                            if (result == ReturnCode.Ok)
                            {
                                result = Gapi.Publisher.copy_from_topic_qos(
                                        GapiPeer,
                                        dataWriterMarshaler.GapiPtr,
                                        marshaler.GapiPtr);

                                if (result == ReturnCode.Ok)
                                {
                                    dataWriterMarshaler.CopyOut(ref dataWriterQos);
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
Ejemplo n.º 25
0
        GetTopicQos(
            ref TopicQos topicQos,
            string id)
        {
            ReportStack.Start();
            NamedTopicQos tQos      = new NamedTopicQos();
            GCHandle      qosHandle = GCHandle.Alloc(tQos, GCHandleType.Normal);
            ReturnCode    result    = qpResultToReturnCode(
                OpenSplice.Common.QosProvider.GetTopicQos(cmnQpPtr, id, GCHandle.ToIntPtr(qosHandle)));

            if (result == ReturnCode.Ok)
            {
                topicQos = tQos.TopicQos;
            }
            else
            {
                ReportStack.Report(result, "Could not copy TopicQos.");
            }
            qosHandle.Free();
            ReportStack.Flush(null, result != ReturnCode.Ok);
            return(result);
        }
        public Topic(string topicName, AdapterTopicQos requiredTopicQoS, TypeSupport clientTypeSupport)
        {
            if (clientTypeSupport == null)
            {
                throw new ArgumentNullException("clientTypeSupport");
            }

            string domain = null;

            // just using the default partition, named after the topic name
            TopicName = topicName;
            TopicType = typeof(T).Name;

            // Create a DomainParticipantFactory and a DomainParticipant
            RegisterDomain(this, domain);

            ErrorHandler.CheckHandle(Participant, "DDS.DomainParticipantFactory.CreateParticipant");

            // Register the required datatype.
            typeSupport = new TopicTypeSupport(clientTypeSupport);
            ReturnCode status = typeSupport.RegisterType(Participant, topicName);

            ErrorHandler.CheckStatus(status, "Topic.TopicMessageTypeSupport.RegisterType");

            TopicQos topicQos = null;

            Participant.GetDefaultTopicQos(ref topicQos);
            ApplyQos(topicQos, requiredTopicQoS);

            TopicQos = topicQos;

            TopicMessageTopic = Participant.CreateTopic(topicName, topicName, topicQos);

            Participant.SetDefaultTopicQos(topicQos);
            if (TopicMessageTopic == null)
            {
                throw new Exception("QoS for topic " + TopicName + " FAILED!, please check QoS!");
            }
        }
        public void TestTakeNextSample()
        {
            TopicBuiltinTopicData data  = default;
            SampleInfo            infos = new SampleInfo();
            ReturnCode            ret   = _dr.TakeNextSample(ref data, infos);

            Assert.AreEqual(ReturnCode.NoData, ret);

            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindTcpTransportConfig();

            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(otherParticipant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

            TopicQos qos   = TestHelper.CreateNonDefaultTopicQos();
            var      topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos);

            Assert.IsNotNull(topic);

            Thread.Sleep(500);

            ret = _dr.TakeNextSample(ref data, infos);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(typeName, data.TypeName);
            Assert.IsNotNull(data.Key);
            TestHelper.TestNonDefaultTopicData(data);

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
Ejemplo n.º 28
0
        public ReturnCode CopyFromTopicQos(ref DataReaderQos dataReaderQos, TopicQos topicQos)
        {
            ReturnCode result = DDS.ReturnCode.BadParameter;

            if (topicQos != null)
            {
                if (dataReaderQos == null)
                {
                    GetDefaultDataReaderQos(ref dataReaderQos);
                }
                dataReaderQos.Durability       = topicQos.Durability;
                dataReaderQos.Deadline         = topicQos.Deadline;
                dataReaderQos.LatencyBudget    = topicQos.LatencyBudget;
                dataReaderQos.Liveliness       = topicQos.Liveliness;
                dataReaderQos.Reliability      = topicQos.Reliability;
                dataReaderQos.DestinationOrder = topicQos.DestinationOrder;
                dataReaderQos.History          = topicQos.History;
                dataReaderQos.ResourceLimits   = topicQos.ResourceLimits;
                dataReaderQos.Ownership        = topicQos.Ownership;
                result = DDS.ReturnCode.Ok;
            }
            return(result);
        }
Ejemplo n.º 29
0
 public ITopic CreateTopic(string topicName, string typeName, TopicQos qos)
 {
     return realParticipant.CreateTopic(topicName, typeName, qos);
 }
Ejemplo n.º 30
0
        /***
         * Operations
         ***/
        public ITopic CreateSimulatedMultitopic(
        string name,
        string type_name,
        string subscription_expression,
        string[] expression_parameters)
        {
            /* Type-specific DDS entities */
            ChatMessageDataReader   chatMessageDR;
            NameServiceDataReader   nameServiceDR;
            NamedMessageDataWriter  namedMessageDW;

            /* Query related stuff */
            IQueryCondition          nameFinder;
            string[]                nameFinderParams;

            /* QosPolicy holders */
            TopicQos          namedMessageQos = new TopicQos();
            SubscriberQos     subQos          = new SubscriberQos();
            PublisherQos      pubQos          = new PublisherQos();

            /* Others */
            IDataReader              parentReader;
            IDataWriter              parentWriter;
            string                  partitionName   = "ChatRoom";
            string                  nameFinderExpr;
            ReturnCode                     status;

            /* Lookup both components that constitute the multi-topic. */
            chatMessageTopic = realParticipant.FindTopic(
            "Chat_ChatMessage", Duration.Infinite);
            ErrorHandler.checkHandle(
            chatMessageTopic,
            "DDS.DomainParticipant.FindTopic (Chat_ChatMessage)");

            nameServiceTopic = realParticipant.FindTopic(
            "Chat_NameService", Duration.Infinite);
            ErrorHandler.checkHandle(
            nameServiceTopic,
            "DDS.DomainParticipant.FindTopic (Chat_NameService)");

            /* Create a ContentFilteredTopic to filter out
               our own ChatMessages. */
            filteredMessageTopic = realParticipant.CreateContentFilteredTopic(
            "Chat_FilteredMessage",
            chatMessageTopic,
            "userID <> %0",
            expression_parameters);
            ErrorHandler.checkHandle(
            filteredMessageTopic,
            "DDS.DomainParticipant.CreateContentFilteredTopic");

            /* Adapt the default SubscriberQos to read from the
               "ChatRoom" Partition. */
            status = realParticipant.GetDefaultSubscriberQos (ref subQos);
            ErrorHandler.checkStatus(
            status, "DDS.DomainParticipant.GetDefaultSubscriberQos");
            subQos.Partition.Name = new string[1];
            subQos.Partition.Name[0] = partitionName;

            /* Create a private Subscriber for the multitopic simulator. */
            multiSub = realParticipant.CreateSubscriber(subQos);
            ErrorHandler.checkHandle(
            multiSub,
            "DDS.DomainParticipant.CreateSubscriber (for multitopic)");

            /* Create a DataReader for the FilteredMessage Topic
               (using the appropriate QoS). */
            DataReaderQos drQos = new DataReaderQos();
            TopicQos topicQos = new TopicQos();
            multiSub.GetDefaultDataReaderQos(ref drQos);
            filteredMessageTopic.RelatedTopic.GetQos(ref topicQos);
            multiSub.CopyFromTopicQos(ref drQos, topicQos);

            parentReader = multiSub.CreateDataReader(filteredMessageTopic, drQos);
            ErrorHandler.checkHandle(
            parentReader, "DDS.Subscriber.create_datareader (ChatMessage)");

            /* Narrow the abstract parent into its typed representative. */
            chatMessageDR = parentReader as ChatMessageDataReader;

            /* Allocate the DataReaderListener Implementation. */
            msgListener = new DataReaderListenerImpl();

            /* Attach the DataReaderListener to the DataReader,
               only enabling the data_available event. */
            status = chatMessageDR.SetListener(msgListener, StatusKind.DataAvailable);
            ErrorHandler.checkStatus(status, "DDS.DataReader_set_listener");

            /* Create a DataReader for the nameService Topic
               (using the appropriate QoS). */
            DataReaderQos nsDrQos = new DataReaderQos();
            TopicQos nsQos = new TopicQos();
            nameServiceTopic.GetQos(ref nsQos);
            multiSub.CopyFromTopicQos(ref nsDrQos, nsQos);

            parentReader = multiSub.CreateDataReader(nameServiceTopic, nsDrQos);
            ErrorHandler.checkHandle(parentReader, "DDS.Subscriber.CreateDatareader (NameService)");

            /* Narrow the abstract parent into its typed representative. */
            nameServiceDR = parentReader as NameServiceDataReader;

            /* Define the SQL expression (using a parameterized value). */
            nameFinderExpr = "userID = %0";

            /* Allocate and assign the query parameters. */
            nameFinderParams = new string[1];
            nameFinderParams[0] = expression_parameters[0];

            /* Create a QueryCondition to only read corresponding
               nameService information by key-value. */
            nameFinder = nameServiceDR.CreateQueryCondition(
            SampleStateKind.Any,
            ViewStateKind.Any,
            InstanceStateKind.Any,
            nameFinderExpr,
            nameFinderParams);
            ErrorHandler.checkHandle(
            nameFinder, "DDS.DataReader.create_querycondition (nameFinder)");

            /* Create the Topic that simulates the multi-topic
               (use Qos from chatMessage).*/
            status = chatMessageTopic.GetQos(ref namedMessageQos);
            ErrorHandler.checkStatus(status, "DDS.Topic.GetQos");

            /* Create the NamedMessage Topic whose samples simulate
               the MultiTopic */
            namedMessageTopic = realParticipant.CreateTopic(
            "Chat_NamedMessage",
            type_name,
            namedMessageQos);
            ErrorHandler.checkHandle(
            namedMessageTopic,
            "DDS.DomainParticipant.CreateTopic (NamedMessage)");

            /* Adapt the default PublisherQos to write into the
               "ChatRoom" Partition. */
            status = realParticipant.GetDefaultPublisherQos(ref pubQos);
            ErrorHandler.checkStatus(
            status, "DDS.DomainParticipant.get_default_publisher_qos");
            pubQos.Partition.Name = new string[1];
            pubQos.Partition.Name[0] = partitionName;

            /* Create a private Publisher for the multitopic simulator. */
            multiPub = realParticipant.CreatePublisher(pubQos);
            ErrorHandler.checkHandle(
            multiPub,
            "DDS.DomainParticipant.create_publisher (for multitopic)");

            DataWriterQos nmDwQos = new DataWriterQos();
            TopicQos nmQos = new TopicQos();
            multiPub.GetDefaultDataWriterQos(ref nmDwQos);
            namedMessageTopic.GetQos(ref nmQos);
            multiPub.CopyFromTopicQos(ref nmDwQos, nmQos);

            /* Create a DataWriter for the multitopic. */
            parentWriter = multiPub.CreateDataWriter(namedMessageTopic, nmDwQos);
            ErrorHandler.checkHandle(
            parentWriter, "DDS.Publisher.CreateDatawriter (NamedMessage)");

            /* Narrow the abstract parent into its typed representative. */
            namedMessageDW = parentWriter as NamedMessageDataWriter;

            /* Store the relevant Entities in our Listener. */
            msgListener.ChatMessageDR = chatMessageDR;
            msgListener.NameServiceDR = nameServiceDR;
            msgListener.NamedMessageDW = namedMessageDW;
            msgListener.NameFinder = nameFinder;
            msgListener.NameFinderParams = nameFinderParams;

            /* Return the simulated Multitopic. */
            return namedMessageTopic;
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            string partitionName = "ChatRoom";
            int    domain        = DDS.DomainId.Default;

            /* Options: MessageBoard [ownID] */
            /* Messages having owner ownID will be ignored */
            string[] parameterList = new string[1];

            if (args.Length > 0)
            {
                parameterList[0] = args[0];
            }
            else
            {
                parameterList[0] = "0";
            }

            /* Create a DomainParticipantFactory and a DomainParticipant
             * (using Default QoS settings. */
            DomainParticipantFactory dpf = DomainParticipantFactory.Instance;

            ErrorHandler.checkHandle(
                dpf, "DDS.DomainParticipantFactory.Instance");

            IDomainParticipant parentDP = dpf.CreateParticipant(
                domain, null, StatusKind.Any);

            ErrorHandler.checkHandle(
                parentDP, "DDS.DomainParticipantFactory.CreateParticipant");

            /* Register the required datatype for ChatMessage. */
            ChatMessageTypeSupport chatMessageTS = new ChatMessageTypeSupport();
            string     chatMessageTypeName       = chatMessageTS.TypeName;
            ReturnCode status = chatMessageTS.RegisterType(parentDP, chatMessageTypeName);

            ErrorHandler.checkStatus(
                status, "Chat.ChatMessageTypeSupport.RegisterType");

            /* Register the required datatype for NameService. */
            NameServiceTypeSupport nameServiceTS = new NameServiceTypeSupport();

            ErrorHandler.checkHandle(
                nameServiceTS, "new NameServiceTypeSupport");
            string nameServiceTypeName = nameServiceTS.TypeName;

            status = nameServiceTS.RegisterType(parentDP, nameServiceTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.NameServiceTypeSupport.RegisterType");

            /* Register the required datatype for NamedMessage. */
            NamedMessageTypeSupport namedMessageTS = new NamedMessageTypeSupport();

            ErrorHandler.checkHandle(
                namedMessageTS, "new NamedMessageTypeSupport");
            string namedMessageTypeName = namedMessageTS.TypeName;

            status = namedMessageTS.RegisterType(parentDP, namedMessageTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.NamedMessageTypeSupport.RegisterType");

            /* Narrow the normal participant to its extended representative */
            ExtDomainParticipant participant = new ExtDomainParticipant(parentDP);

            /* Initialise QoS variables */
            TopicQos      reliableTopicQos = new TopicQos();
            TopicQos      settingTopicQos  = new TopicQos();
            SubscriberQos subQos           = new SubscriberQos();

            /* Set the ReliabilityQosPolicy to RELIABLE. */
            status = participant.GetDefaultTopicQos(ref reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultTopicQos");
            reliableTopicQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;

            /* Make the tailored QoS the new default. */
            status = participant.SetDefaultTopicQos(reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.SetDefaultTopicQos");

            /* Use the changed policy when defining the ChatMessage topic */
            ITopic chatMessageTopic = participant.CreateTopic(
                "Chat_ChatMessage",
                chatMessageTypeName,
                reliableTopicQos);

            ErrorHandler.checkHandle(
                chatMessageTopic,
                "DDS.DomainParticipant.CreateTopic (ChatMessage)");

            /* Set the DurabilityQosPolicy to TRANSIENT. */
            status = participant.GetDefaultTopicQos(ref settingTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultTopicQos");
            settingTopicQos.Durability.Kind = DurabilityQosPolicyKind.TransientDurabilityQos;

            /* Create the NameService Topic. */
            ITopic nameServiceTopic = participant.CreateTopic(
                "Chat_NameService",
                nameServiceTypeName,
                settingTopicQos);

            ErrorHandler.checkHandle(
                nameServiceTopic,
                "DDS.DomainParticipant.CreateTopic (NameService)");

            /* Create a multitopic that substitutes the userID
             * with its corresponding userName. */
            ITopic namedMessageTopic = participant.CreateSimulatedMultitopic(
                "Chat_NamedMessage",
                namedMessageTypeName,
                "SELECT userID, name AS userName, index, content " +
                "FROM Chat_NameService NATURAL JOIN Chat_ChatMessage " +
                "WHERE userID <> %0",
                parameterList);

            ErrorHandler.checkHandle(
                namedMessageTopic,
                "ExtDomainParticipant.create_simulated_multitopic");

            /* Adapt the default SubscriberQos to read from the "ChatRoom" Partition. */
            status = participant.GetDefaultSubscriberQos(ref subQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultSubscriberQos");
            subQos.Partition.Name    = new string[1];
            subQos.Partition.Name[0] = partitionName;

            /* Create a Subscriber for the MessageBoard application. */
            ISubscriber chatSubscriber = participant.CreateSubscriber(subQos);

            ErrorHandler.checkHandle(
                chatSubscriber, "DDS.DomainParticipant.CreateSubscriber");

            /* Create a DataReader for the NamedMessage Topic
             * (using the appropriate QoS). */
            IDataReader parentReader = chatSubscriber.CreateDataReader(
                namedMessageTopic);

            ErrorHandler.checkHandle(
                parentReader, "DDS.Subscriber.CreateDatareader");

            NamedMessageDataReader chatAdmin = parentReader as NamedMessageDataReader;

            /* Print a message that the MessageBoard has opened. */
            System.Console.WriteLine(
                "MessageBoard has opened: send a ChatMessage " +
                "with userID = -1 to close it....\n");

            bool terminated = false;

            NamedMessage[] messages = null;;
            SampleInfo[]   infos    = null;

            while (!terminated)
            {
                /* Note: using read does not remove the samples from
                 * unregistered instances from the DataReader. This means
                 * that the DataRase would use more and more resources.
                 * That's why we use take here instead. */

                status = chatAdmin.Take(
                    ref messages,
                    ref infos,
                    SampleStateKind.Any,
                    ViewStateKind.Any,
                    InstanceStateKind.Alive);
                ErrorHandler.checkStatus(
                    status, "Chat.NamedMessageDataReader.take");

                foreach (NamedMessage msg in messages)
                {
                    if (msg.userID == TERMINATION_MESSAGE)
                    {
                        System.Console.WriteLine("Termination message received: exiting...");
                        terminated = true;
                    }
                    else
                    {
                        System.Console.WriteLine("{0}: {1}", msg.userName, msg.content);
                    }
                }

                status = chatAdmin.ReturnLoan(ref messages, ref infos);
                ErrorHandler.checkStatus(status, "Chat.ChatMessageDataReader.ReturnLoan");
                System.Threading.Thread.Sleep(100);
            }

            /* Remove the DataReader */
            status = chatSubscriber.DeleteDataReader(chatAdmin);
            ErrorHandler.checkStatus(
                status, "DDS.Subscriber.DeleteDatareader");

            /* Remove the Subscriber. */
            status = participant.DeleteSubscriber(chatSubscriber);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeleteSubscriber");

            /* Remove the Topics. */
            status = participant.DeleteSimulatedMultitopic(namedMessageTopic);
            ErrorHandler.checkStatus(
                status, "DDS.ExtDomainParticipant.DeleteSimulatedMultitopic");

            status = participant.DeleteTopic(nameServiceTopic);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeleteTopic (nameServiceTopic)");

            status = participant.DeleteTopic(chatMessageTopic);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeleteTopic (chatMessageTopic)");

            /* Remove the DomainParticipant. */
            status = dpf.DeleteParticipant(parentDP);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipantFactory.DeleteParticipant");
        }
Ejemplo n.º 32
0
 public ReturnCode GetDefaultTopicQos(ref TopicQos qos)
 {
     return(realParticipant.GetDefaultTopicQos(ref qos));
 }
Ejemplo n.º 33
0
 public ITopic CreateTopic(string topicName, string typeName, TopicQos qos, ITopicListener listener, StatusKind mask)
 {
     return(realParticipant.CreateTopic(topicName, typeName, qos, listener, mask));
 }
Ejemplo n.º 34
0
 public ReturnCode SetDefaultTopicQos(TopicQos qos)
 {
     return realParticipant.SetDefaultTopicQos (qos);
 }
Ejemplo n.º 35
0
        static void Main(string[] args)
        {
            string domain = null;

            /* Create a DomainParticipant */
            DomainParticipantFactory dpf = DomainParticipantFactory.Instance;

            IDomainParticipant participant = dpf.CreateParticipant(
                domain,
                null,
                StatusKind.Any);
            ErrorHandler.checkHandle(
                participant, "DDS.DomainParticipantFactory.CreateParticipant");

            /* Register the required datatype for ChatMessage. */
            ChatMessageTypeSupport chatMessageTS = new ChatMessageTypeSupport();
            string chatMessageTypeName = chatMessageTS.TypeName;
            ReturnCode status = chatMessageTS.RegisterType(
                participant, chatMessageTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.ChatMessageTypeSupport.RegisterType");

            /* Register the required datatype for NameService. */
            NameServiceTypeSupport nameServiceTS = new NameServiceTypeSupport();
            ErrorHandler.checkHandle(
                nameServiceTS, "new NameServiceTypeSupport");
            string nameServiceTypeName = nameServiceTS.TypeName;
            status = nameServiceTS.RegisterType(
                participant, nameServiceTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.NameServiceTypeSupport.RegisterType");

            /* Set the ReliabilityQosPolicy to RELIABLE. */
            TopicQos reliableTopicQos = new TopicQos();
            status = participant.GetDefaultTopicQos(ref reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.get_DefaultTopicQos");
            reliableTopicQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;

            /* Make the tailored QoS the new default. */
            status = participant.SetDefaultTopicQos(reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.SetDefaultTopicQos");

            /* Use the changed policy when defining the ChatMessage topic */
            ITopic chatMessageTopic = participant.CreateTopic(
                "Chat_ChatMessage",
                chatMessageTypeName,
                reliableTopicQos);
            ErrorHandler.checkHandle(
                chatMessageTopic,
                "DDS.DomainParticipant.CreateTopic (ChatMessage)");

            /* Set the DurabilityQosPolicy to TRANSIENT. */
            TopicQos settingTopicQos = new TopicQos();
            status = participant.GetDefaultTopicQos(ref settingTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultTopicQos");
            settingTopicQos.Durability.Kind = DurabilityQosPolicyKind.TransientDurabilityQos;

            /* Create the NameService Topic. */
            ITopic nameServiceTopic = participant.CreateTopic(
                "Chat_NameService",
                nameServiceTypeName,
                settingTopicQos);
            ErrorHandler.checkHandle(
                nameServiceTopic, "DDS.DomainParticipant.CreateTopic");

            /* Adapt the default SubscriberQos to read from the
               "ChatRoom" Partition. */
            SubscriberQos subQos = new SubscriberQos();
            status = participant.GetDefaultSubscriberQos(ref subQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultSubscriberQos");
            subQos.Partition.Name = new string[1];
            subQos.Partition.Name[0] = "ChatRoom";

            /* Create a Subscriber for the UserLoad application. */
            ISubscriber chatSubscriber = participant.CreateSubscriber(subQos);
            ErrorHandler.checkHandle(
                chatSubscriber, "DDS.DomainParticipant.CreateSubscriber");

            /* Create a DataReader for the NameService Topic
               (using the appropriate QoS). */
            DataReaderQos nsQos = null;
            status = chatSubscriber.GetDefaultDataReaderQos(ref nsQos);
            ErrorHandler.checkStatus(
                status, "DDS.Subscriber.GetDefaultDataReaderQos");
            status = chatSubscriber.CopyFromTopicQos(ref nsQos, settingTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.Subscriber.CopyFromTopicQos");
            IDataReader parentReader = chatSubscriber.CreateDataReader(
                nameServiceTopic,
                nsQos,
                null,
                StatusKind.Any);
            ErrorHandler.checkHandle(
                parentReader, "DDS.Subscriber.CreateDatareader (NameService)");

            NameServiceDataReader nameServer = parentReader as NameServiceDataReader;

            /* Adapt the DataReaderQos for the ChatMessageDataReader to
               keep track of all messages. */
            DataReaderQos messageQos = new DataReaderQos();
            status = chatSubscriber.GetDefaultDataReaderQos(ref messageQos);
            ErrorHandler.checkStatus(
                status, "DDS.Subscriber.GetDefaultDataReaderQos");
            status = chatSubscriber.CopyFromTopicQos(
                ref messageQos, reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.Subscriber.CopyFromTopicQos");
            messageQos.History.Kind = HistoryQosPolicyKind.KeepAllHistoryQos;

            /* Create a DataReader for the ChatMessage Topic
               (using the appropriate QoS). */
            parentReader = chatSubscriber.CreateDataReader(
                chatMessageTopic,
                messageQos);
            ErrorHandler.checkHandle(
                parentReader, "DDS.Subscriber.CreateDataReader (ChatMessage)");

            /* Narrow the abstract parent into its typed representative. */
            ChatMessageDataReader loadAdmin = parentReader as ChatMessageDataReader;

            /* Initialize the Query Arguments. */
            string[] parameters = { "0" };

            /* Create a QueryCondition that will contain all messages
               with userID=ownID */
            IQueryCondition singleUser = loadAdmin.CreateQueryCondition("userID=%0", parameters);
            ErrorHandler.checkHandle(singleUser, "DDS.DataReader.CreateQuerycondition");

            /* Create a ReadCondition that will contain new users only */
            IReadCondition newUser = nameServer.CreateReadCondition(SampleStateKind.NotRead, ViewStateKind.New, InstanceStateKind.Alive);
            ErrorHandler.checkHandle(newUser, "DDS.DataReader.create_readcondition");

            /* Obtain a StatusCondition that triggers only when a Writer
               changes Liveliness */
            IStatusCondition leftUser = loadAdmin.StatusCondition;
            ErrorHandler.checkHandle(leftUser, "DDS.DataReader.GetStatusCondition");
            status = leftUser.SetEnabledStatuses(StatusKind.LivelinessChanged);
            ErrorHandler.checkStatus(status, "DDS.StatusCondition.SetEnabledStatuses");

            /* Create a bare guard which will be used to close the room */
            escape = new GuardCondition();

            /* Create a waitset and add the ReadConditions */
            WaitSet userLoadWS = new WaitSet();
            status = userLoadWS.AttachCondition(newUser);
            ErrorHandler.checkStatus(status, "DDS.WaitSet.AttachCondition (newUser)");
            status = userLoadWS.AttachCondition(leftUser);
            ErrorHandler.checkStatus(status, "DDS.WaitSet.AttachCondition (leftUser)");
            status = userLoadWS.AttachCondition(escape);
            ErrorHandler.checkStatus(status, "DDS.WaitSet.AttachCondition (escape)");

            /* Initialize and pre-allocate the GuardList used to obtain
               the triggered Conditions. */
            ICondition[] guardList = new ICondition[3];

            /* Remove all known Users that are not currently active. */
            NameService[] nsMsgs = null;
            SampleInfo[] nsInfos = null;

            status = nameServer.Take(ref nsMsgs,
                ref nsInfos,
                Length.Unlimited,
                SampleStateKind.Any,
                ViewStateKind.Any,
                InstanceStateKind.NotAlive);
            ErrorHandler.checkStatus(
                status, "Chat.NameServiceDataReader.Take");
            status = nameServer.ReturnLoan(ref nsMsgs, ref nsInfos);
            ErrorHandler.checkStatus(
                status, "Chat.NameServiceDataReader.ReturnLoan");

            /* Start the sleeper thread. */
            new Thread(new UserLoad().doWait).Start();

            bool closed = false;

            int prevCount = 0;
            ChatMessage[] msgs = null;
            SampleInfo[] msgInfos = null;

            while (!closed)
            {
                /* Wait until at least one of the Conditions in the
                   waitset triggers. */
                status = userLoadWS.Wait(ref guardList, Duration.Infinite);
                ErrorHandler.checkStatus(status, "DDS.WaitSet.Wait");

                /* Walk over all guards to display information */
                foreach (ICondition guard in guardList)
                {
                    if (guard == newUser)
                    {
                        /* The newUser ReadCondition contains data */
                        status = nameServer.ReadWithCondition(ref nsMsgs, ref nsInfos, newUser);
                        ErrorHandler.checkStatus(status, "Chat.NameServiceDataReader.read_w_condition");

                        foreach (NameService ns in nsMsgs)
                        {
                            Console.WriteLine("New user: "******"Chat.NameServiceDataReader.ReturnLoan");

                    }
                    else if (guard == leftUser)
                    {
                        // Some liveliness has changed (either a DataWriter
                        // joined or a DataWriter left)
                        LivelinessChangedStatus livelinessStatus = new LivelinessChangedStatus() ;
                        status = loadAdmin.GetLivelinessChangedStatus(ref livelinessStatus);
                        ErrorHandler.checkStatus(status, "DDS.DataReader.getLivelinessChangedStatus");
                        if (livelinessStatus.AliveCount < prevCount)
                        {
                            /* A user has left the ChatRoom, since a DataWriter
                               lost its liveliness. Take the effected users
                               so they will not appear in the list later on. */
                            status = nameServer.Take(
                                ref nsMsgs,
                                ref nsInfos,
                                Length.Unlimited,
                                SampleStateKind.Any,
                                ViewStateKind.Any,
                                InstanceStateKind.NotAliveNoWriters);
                            ErrorHandler.checkStatus(status, "Chat.NameServiceDataReader.Take");

                            foreach (NameService nsMsg in nsMsgs)
                            {
                                /* re-apply query arguments */
                                parameters[0] = nsMsg.userID.ToString();
                                status = singleUser.SetQueryParameters(parameters);
                                ErrorHandler.checkStatus(status, "DDS.QueryCondition.SetQueryParameters");

                                /* Read this user's history */
                                status = loadAdmin.TakeWithCondition(
                                    ref msgs,
                                    ref msgInfos,
                                    singleUser);

                                ErrorHandler.checkStatus(
                                    status,
                                    "Chat.ChatMessageDataReader.TakeWithCondition");

                                /* Display the user and his history */
                                Console.WriteLine("Departed user {0} has sent {1} messages ", nsMsg.name, msgs.Length);
                                status = loadAdmin.ReturnLoan(ref msgs, ref msgInfos);
                                ErrorHandler.checkStatus(status, "Chat.ChatMessageDataReader.ReturnLoan");
                            }
                            status = nameServer.ReturnLoan(ref nsMsgs, ref nsInfos);
                            ErrorHandler.checkStatus(status, "Chat.NameServiceDataReader.ReturnLoan");
                        }
                        prevCount = livelinessStatus.AliveCount;

                    }
                    else if (guard == escape)
                    {
                        Console.WriteLine("UserLoad has terminated.");
                        closed = true;
                    }
                    else
                    {
                        //System.Diagnostics.Debug.Fail("Unknown Condition");
                    }
                } /* for */
            } /* while (!closed) */

            /* Remove all Conditions from the WaitSet. */
            status = userLoadWS.DetachCondition(escape);
            ErrorHandler.checkStatus(status, "DDS.WaitSet.DetachCondition (escape)");
            status = userLoadWS.DetachCondition(leftUser);
            ErrorHandler.checkStatus(status, "DDS.WaitSet.DetachCondition (leftUser)");
            status = userLoadWS.DetachCondition(newUser);
            ErrorHandler.checkStatus(status, "DDS.WaitSet.DetachCondition (newUser)");

            /* Free all resources */
            status = participant.DeleteContainedEntities();
            ErrorHandler.checkStatus(status, "DDS.DomainParticipant.DeleteContainedEntities");
            status = dpf.DeleteParticipant(participant);
            ErrorHandler.checkStatus(status, "DDS.DomainParticipantFactory.DeleteParticipant");
        }
Ejemplo n.º 36
0
        public ReturnCode SetQos(TopicQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler = 
                    new OpenSplice.CustomMarshalers.TopicQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == DDS.ReturnCode.Ok)
                {
                    result = Gapi.Topic.set_qos(GapiPeer, marshaler.GapiPtr);
                }
            }

            return result;
        }
Ejemplo n.º 37
0
        public ReturnCode GetDefaultTopicQos(ref TopicQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                    new OpenSplice.CustomMarshalers.TopicQosMarshaler())
            {
                result = Gapi.DomainParticipant.get_default_topic_qos(
                        GapiPeer,
                        marshaler.GapiPtr);

                if (result == ReturnCode.Ok)
                {
                    marshaler.CopyOut(ref qos);
                }
            }

            return result;
        }
Ejemplo n.º 38
0
        public ITopic CreateTopic(
                string topicName,
                string typeName,
                TopicQos qos,
                ITopicListener listener,
                StatusKind mask)
        {
            ITopic topic = null;

            using (OpenSplice.CustomMarshalers.TopicQosMarshaler marshaler =
                    new OpenSplice.CustomMarshalers.TopicQosMarshaler())
            {
                if (marshaler.CopyIn(qos) == ReturnCode.Ok)
                {
                    if (listener != null)
                    {
                        OpenSplice.Gapi.gapi_topicListener gapiListener;
                        TopicListenerHelper listenerHelper = new TopicListenerHelper();
                        listenerHelper.Listener = listener;
                        listenerHelper.CreateListener(out gapiListener);
                        using (TopicListenerMarshaler listenerMarshaler =
                                new TopicListenerMarshaler(ref gapiListener))
                        {
                            IntPtr gapiPtr = Gapi.DomainParticipant.create_topic(
                                    GapiPeer,
                                    topicName,
                                    typeName,
                                    marshaler.GapiPtr,
                                    listenerMarshaler.GapiPtr,
                                    mask);
                            if (gapiPtr != IntPtr.Zero)
                            {
                                topic = new Topic(gapiPtr, listenerHelper);
                            }
                        }
                    }
                    else
                    {
                        // Invoke the corresponding gapi function.
                        IntPtr gapiPtr = Gapi.DomainParticipant.create_topic(
                                GapiPeer,
                                topicName,
                                typeName,
                                marshaler.GapiPtr,
                                IntPtr.Zero,
                                mask);

                        if (gapiPtr != IntPtr.Zero)
                        {
                            topic = new Topic(gapiPtr);
                        }
                    }
                }
            }

            if (topic != null)
            {
                DomainParticipantQos dpQos = null;
                ReturnCode result = GetQos(ref dpQos);
                if (result == ReturnCode.Ok)
                {
                    if (dpQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        topic.Enable();
                    }
                }
            }

            return topic;
        }
Ejemplo n.º 39
0
 public ITopic CreateTopic(string topicName, string typeName, TopicQos qos)
 {
     return CreateTopic(topicName, typeName, qos, null, 0);
 }
Ejemplo n.º 40
0
        static void Main(string[] args)
        {
            string partitionName = "ChatRoom";
            int domain = DDS.DomainId.Default;

            /* Options: MessageBoard [ownID] */
            /* Messages having owner ownID will be ignored */
            string[] parameterList = new string[1];

            if (args.Length > 0)
            {
                parameterList[0] = args[0];
            }
            else
            {
                parameterList[0] = "0";
            }

            /* Create a DomainParticipantFactory and a DomainParticipant
               (using Default QoS settings. */
            DomainParticipantFactory dpf = DomainParticipantFactory.Instance;
            ErrorHandler.checkHandle(
            dpf, "DDS.DomainParticipantFactory.Instance");

            IDomainParticipant parentDP = dpf.CreateParticipant(
            domain, null, StatusKind.Any);
            ErrorHandler.checkHandle(
                parentDP, "DDS.DomainParticipantFactory.CreateParticipant");

            /* Register the required datatype for ChatMessage. */
            ChatMessageTypeSupport chatMessageTS = new ChatMessageTypeSupport();
            string chatMessageTypeName = chatMessageTS.TypeName;
            ReturnCode status = chatMessageTS.RegisterType(parentDP, chatMessageTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.ChatMessageTypeSupport.RegisterType");

            /* Register the required datatype for NameService. */
            NameServiceTypeSupport nameServiceTS = new NameServiceTypeSupport();
            ErrorHandler.checkHandle(
                nameServiceTS, "new NameServiceTypeSupport");
            string nameServiceTypeName = nameServiceTS.TypeName;
            status = nameServiceTS.RegisterType(parentDP, nameServiceTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.NameServiceTypeSupport.RegisterType");

            /* Register the required datatype for NamedMessage. */
            NamedMessageTypeSupport namedMessageTS = new NamedMessageTypeSupport();
            ErrorHandler.checkHandle(
                namedMessageTS, "new NamedMessageTypeSupport");
            string namedMessageTypeName = namedMessageTS.TypeName;
            status = namedMessageTS.RegisterType(parentDP, namedMessageTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.NamedMessageTypeSupport.RegisterType");

            /* Narrow the normal participant to its extended representative */
            ExtDomainParticipant participant = new ExtDomainParticipant(parentDP);

            /* Initialise QoS variables */
            TopicQos reliableTopicQos = new TopicQos();
            TopicQos settingTopicQos = new TopicQos();
            SubscriberQos subQos = new SubscriberQos();

            /* Set the ReliabilityQosPolicy to RELIABLE. */
            status = participant.GetDefaultTopicQos(ref reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultTopicQos");
            reliableTopicQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;

            /* Make the tailored QoS the new default. */
            status = participant.SetDefaultTopicQos (reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.SetDefaultTopicQos");

            /* Use the changed policy when defining the ChatMessage topic */
            ITopic chatMessageTopic = participant.CreateTopic(
                "Chat_ChatMessage",
                chatMessageTypeName,
                reliableTopicQos);
            ErrorHandler.checkHandle(
                chatMessageTopic,
                "DDS.DomainParticipant.CreateTopic (ChatMessage)");

            /* Set the DurabilityQosPolicy to TRANSIENT. */
            status = participant.GetDefaultTopicQos(ref settingTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultTopicQos");
            settingTopicQos.Durability.Kind = DurabilityQosPolicyKind.TransientDurabilityQos;

            /* Create the NameService Topic. */
            ITopic nameServiceTopic = participant.CreateTopic(
                "Chat_NameService",
                nameServiceTypeName,
                settingTopicQos);
            ErrorHandler.checkHandle(
                nameServiceTopic,
                "DDS.DomainParticipant.CreateTopic (NameService)");

            /* Create a multitopic that substitutes the userID
           with its corresponding userName. */
           ITopic namedMessageTopic = participant.CreateSimulatedMultitopic(
                "Chat_NamedMessage",
                namedMessageTypeName,
                "SELECT userID, name AS userName, index, content " +
                    "FROM Chat_NameService NATURAL JOIN Chat_ChatMessage " +
                    "WHERE userID <> %0",
                parameterList);
            ErrorHandler.checkHandle(
                namedMessageTopic,
                "ExtDomainParticipant.create_simulated_multitopic");

            /* Adapt the default SubscriberQos to read from the "ChatRoom" Partition. */
            status = participant.GetDefaultSubscriberQos(ref subQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultSubscriberQos");
            subQos.Partition.Name = new string[1];
            subQos.Partition.Name[0] = partitionName;

            /* Create a Subscriber for the MessageBoard application. */
            ISubscriber chatSubscriber = participant.CreateSubscriber(subQos);
            ErrorHandler.checkHandle(
                chatSubscriber, "DDS.DomainParticipant.CreateSubscriber");

            /* Create a DataReader for the NamedMessage Topic
           (using the appropriate QoS). */
            IDataReader parentReader = chatSubscriber.CreateDataReader(
                namedMessageTopic);
            ErrorHandler.checkHandle(
                parentReader, "DDS.Subscriber.CreateDatareader");

            NamedMessageDataReader chatAdmin = parentReader as NamedMessageDataReader;
            /* Print a message that the MessageBoard has opened. */
            System.Console.WriteLine(
                "MessageBoard has opened: send a ChatMessage " +
                "with userID = -1 to close it....\n");

            bool terminated = false;

            NamedMessage[] messages = null;;
            SampleInfo[] infos = null;

            while (!terminated)
            {
                /* Note: using read does not remove the samples from
               unregistered instances from the DataReader. This means
               that the DataRase would use more and more resources.
               That's why we use take here instead. */

                status = chatAdmin.Take(
                    ref messages,
                    ref infos,
                    SampleStateKind.Any,
                    ViewStateKind.Any,
                    InstanceStateKind.Alive);
                ErrorHandler.checkStatus(
                    status, "Chat.NamedMessageDataReader.take");

                foreach (NamedMessage msg in messages)
                {
                    if (msg.userID == TERMINATION_MESSAGE)
                    {
                        System.Console.WriteLine("Termination message received: exiting...");
                        terminated = true;
                    }
                    else
                    {
                        System.Console.WriteLine("{0}: {1}", msg.userName, msg.content);
                    }
                }

                status = chatAdmin.ReturnLoan(ref messages, ref infos);
                ErrorHandler.checkStatus(status, "Chat.ChatMessageDataReader.ReturnLoan");
                System.Threading.Thread.Sleep(100);
            }

            /* Remove the DataReader */
            status = chatSubscriber.DeleteDataReader(chatAdmin);
            ErrorHandler.checkStatus(
                status, "DDS.Subscriber.DeleteDatareader");

            /* Remove the Subscriber. */
            status = participant.DeleteSubscriber(chatSubscriber);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeleteSubscriber");

            /* Remove the Topics. */
            status = participant.DeleteSimulatedMultitopic(namedMessageTopic);
            ErrorHandler.checkStatus(
                status, "DDS.ExtDomainParticipant.DeleteSimulatedMultitopic");

            status = participant.DeleteTopic(nameServiceTopic);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeleteTopic (nameServiceTopic)");

            status = participant.DeleteTopic(chatMessageTopic);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeleteTopic (chatMessageTopic)");

            /* Remove the DomainParticipant. */
            status = dpf.DeleteParticipant(parentDP);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipantFactory.DeleteParticipant");
        }
Ejemplo n.º 41
0
 public ITopic CreateTopic(string topicName, string typeName, TopicQos qos, ITopicListener listener, StatusKind mask)
 {
     return realParticipant.CreateTopic(topicName, typeName, qos, listener, mask);
 }
Ejemplo n.º 42
0
 public ReturnCode GetDefaultTopicQos(ref TopicQos qos)
 {
     return realParticipant.GetDefaultTopicQos(ref qos);
 }
Ejemplo n.º 43
0
 internal void CopyOut(ref TopicQos to)
 {
     CopyOut(GapiPtr, ref to);
 }
Ejemplo n.º 44
0
 public ITopic CreateTopic(string topicName, string typeName, TopicQos qos)
 {
     return(realParticipant.CreateTopic(topicName, typeName, qos));
 }
Ejemplo n.º 45
0
 internal DDS.ReturnCode CopyIn(TopicQos from)
 {
     cleanupRequired = true;
     return CopyIn(from, GapiPtr);
 }
Ejemplo n.º 46
0
 public ReturnCode SetDefaultTopicQos(TopicQos qos)
 {
     return(realParticipant.SetDefaultTopicQos(qos));
 }
Ejemplo n.º 47
0
 internal static void CopyOut(IntPtr from, ref TopicQos to)
 {
     if (to == null) to = new TopicQos();
     TopicDataQosPolicyMarshaler.CopyOut(from, ref to.TopicData, offset_topic_data);
     DurabilityQosPolicyMarshaler.CopyOut(from, ref to.Durability, offset_durability);
     DurabilityServiceQosPolicyMarshaler.CopyOut(from, ref to.DurabilityService, offset_durability_service);
     DeadlineQosPolicyMarshaler.CopyOut(from, ref to.Deadline, offset_deadline);
     LatencyBudgetQosPolicyMarshaler.CopyOut(from, ref to.LatencyBudget, offset_latency_budget);
     LivelinessQosPolicyMarshaler.CopyOut(from, ref to.Liveliness, offset_liveliness);
     ReliabilityQosPolicyMarshaler.CopyOut(from, ref to.Reliability, offset_reliability);
     DestinationOrderQosPolicyMarshaler.CopyOut(from, ref to.DestinationOrder, offset_destination_order);
     HistoryQosPolicyMarshaler.CopyOut(from, ref to.History, offset_history);
     ResourceLimitsQosPolicyMarshaler.CopyOut(from, ref to.ResourceLimits, offset_resource_limits);
     TransportPriorityQosPolicyMarshaler.CopyOut(from, ref to.TransportPriority, offset_transport_priority);
     LifespanQosPolicyMarshaler.CopyOut(from, ref to.Lifespan, offset_lifespan);
     OwnershipQosPolicyMarshaler.CopyOut(from, ref to.Ownership, offset_ownership);
 }
Ejemplo n.º 48
0
        /***
         * Operations
         ***/
        public ITopic CreateSimulatedMultitopic(
            string name,
            string type_name,
            string subscription_expression,
            string[] expression_parameters)
        {
            /* Type-specific DDS entities */
            ChatMessageDataReader  chatMessageDR;
            NameServiceDataReader  nameServiceDR;
            NamedMessageDataWriter namedMessageDW;

            /* Query related stuff */
            IQueryCondition nameFinder;

            string[] nameFinderParams;

            /* QosPolicy holders */
            TopicQos      namedMessageQos = new TopicQos();
            SubscriberQos subQos          = new SubscriberQos();
            PublisherQos  pubQos          = new PublisherQos();

            /* Others */
            IDataReader parentReader;
            IDataWriter parentWriter;
            string      partitionName = "ChatRoom";
            string      nameFinderExpr;
            ReturnCode  status;

            /* Lookup both components that constitute the multi-topic. */
            chatMessageTopic = realParticipant.FindTopic(
                "Chat_ChatMessage", Duration.Infinite);
            ErrorHandler.checkHandle(
                chatMessageTopic,
                "DDS.DomainParticipant.FindTopic (Chat_ChatMessage)");

            nameServiceTopic = realParticipant.FindTopic(
                "Chat_NameService", Duration.Infinite);
            ErrorHandler.checkHandle(
                nameServiceTopic,
                "DDS.DomainParticipant.FindTopic (Chat_NameService)");

            /* Create a ContentFilteredTopic to filter out
             * our own ChatMessages. */
            filteredMessageTopic = realParticipant.CreateContentFilteredTopic(
                "Chat_FilteredMessage",
                chatMessageTopic,
                "userID <> %0",
                expression_parameters);
            ErrorHandler.checkHandle(
                filteredMessageTopic,
                "DDS.DomainParticipant.CreateContentFilteredTopic");

            /* Adapt the default SubscriberQos to read from the
             * "ChatRoom" Partition. */
            status = realParticipant.GetDefaultSubscriberQos(ref subQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultSubscriberQos");
            subQos.Partition.Name    = new string[1];
            subQos.Partition.Name[0] = partitionName;

            /* Create a private Subscriber for the multitopic simulator. */
            multiSub = realParticipant.CreateSubscriber(subQos);
            ErrorHandler.checkHandle(
                multiSub,
                "DDS.DomainParticipant.CreateSubscriber (for multitopic)");

            /* Create a DataReader for the FilteredMessage Topic
             * (using the appropriate QoS). */
            DataReaderQos drQos    = new DataReaderQos();
            TopicQos      topicQos = new TopicQos();

            multiSub.GetDefaultDataReaderQos(ref drQos);
            filteredMessageTopic.RelatedTopic.GetQos(ref topicQos);
            multiSub.CopyFromTopicQos(ref drQos, topicQos);

            parentReader = multiSub.CreateDataReader(filteredMessageTopic, drQos);
            ErrorHandler.checkHandle(
                parentReader, "DDS.Subscriber.create_datareader (ChatMessage)");

            /* Narrow the abstract parent into its typed representative. */
            chatMessageDR = parentReader as ChatMessageDataReader;

            /* Allocate the DataReaderListener Implementation. */
            msgListener = new DataReaderListenerImpl();

            /* Attach the DataReaderListener to the DataReader,
             * only enabling the data_available event. */
            status = chatMessageDR.SetListener(msgListener, StatusKind.DataAvailable);
            ErrorHandler.checkStatus(status, "DDS.DataReader_set_listener");

            /* Create a DataReader for the nameService Topic
             * (using the appropriate QoS). */
            DataReaderQos nsDrQos = new DataReaderQos();
            TopicQos      nsQos   = new TopicQos();

            nameServiceTopic.GetQos(ref nsQos);
            multiSub.CopyFromTopicQos(ref nsDrQos, nsQos);

            parentReader = multiSub.CreateDataReader(nameServiceTopic, nsDrQos);
            ErrorHandler.checkHandle(parentReader, "DDS.Subscriber.CreateDatareader (NameService)");

            /* Narrow the abstract parent into its typed representative. */
            nameServiceDR = parentReader as NameServiceDataReader;

            /* Define the SQL expression (using a parameterized value). */
            nameFinderExpr = "userID = %0";

            /* Allocate and assign the query parameters. */
            nameFinderParams    = new string[1];
            nameFinderParams[0] = expression_parameters[0];

            /* Create a QueryCondition to only read corresponding
             * nameService information by key-value. */
            nameFinder = nameServiceDR.CreateQueryCondition(
                SampleStateKind.Any,
                ViewStateKind.Any,
                InstanceStateKind.Any,
                nameFinderExpr,
                nameFinderParams);
            ErrorHandler.checkHandle(
                nameFinder, "DDS.DataReader.create_querycondition (nameFinder)");

            /* Create the Topic that simulates the multi-topic
             * (use Qos from chatMessage).*/
            status = chatMessageTopic.GetQos(ref namedMessageQos);
            ErrorHandler.checkStatus(status, "DDS.Topic.GetQos");

            /* Create the NamedMessage Topic whose samples simulate
             * the MultiTopic */
            namedMessageTopic = realParticipant.CreateTopic(
                "Chat_NamedMessage",
                type_name,
                namedMessageQos);
            ErrorHandler.checkHandle(
                namedMessageTopic,
                "DDS.DomainParticipant.CreateTopic (NamedMessage)");

            /* Adapt the default PublisherQos to write into the
             * "ChatRoom" Partition. */
            status = realParticipant.GetDefaultPublisherQos(ref pubQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.get_default_publisher_qos");
            pubQos.Partition.Name    = new string[1];
            pubQos.Partition.Name[0] = partitionName;

            /* Create a private Publisher for the multitopic simulator. */
            multiPub = realParticipant.CreatePublisher(pubQos);
            ErrorHandler.checkHandle(
                multiPub,
                "DDS.DomainParticipant.create_publisher (for multitopic)");

            DataWriterQos nmDwQos = new DataWriterQos();
            TopicQos      nmQos   = new TopicQos();

            multiPub.GetDefaultDataWriterQos(ref nmDwQos);
            namedMessageTopic.GetQos(ref nmQos);
            multiPub.CopyFromTopicQos(ref nmDwQos, nmQos);

            /* Create a DataWriter for the multitopic. */
            parentWriter = multiPub.CreateDataWriter(namedMessageTopic, nmDwQos);
            ErrorHandler.checkHandle(
                parentWriter, "DDS.Publisher.CreateDatawriter (NamedMessage)");

            /* Narrow the abstract parent into its typed representative. */
            namedMessageDW = parentWriter as NamedMessageDataWriter;

            /* Store the relevant Entities in our Listener. */
            msgListener.ChatMessageDR    = chatMessageDR;
            msgListener.NameServiceDR    = nameServiceDR;
            msgListener.NamedMessageDW   = namedMessageDW;
            msgListener.NameFinder       = nameFinder;
            msgListener.NameFinderParams = nameFinderParams;

            /* Return the simulated Multitopic. */
            return(namedMessageTopic);
        }
Ejemplo n.º 49
0
 internal static DDS.ReturnCode CopyIn(TopicQos from, IntPtr to)
 {
     DDS.ReturnCode result;
     if (from != null) {
         result = TopicDataQosPolicyMarshaler.CopyIn(
                 from.TopicData, to, offset_topic_data);
         if (result == DDS.ReturnCode.Ok) {
             result = DurabilityQosPolicyMarshaler.CopyIn(
                     from.Durability, to, offset_durability);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = DurabilityServiceQosPolicyMarshaler.CopyIn(
                     from.DurabilityService, to, offset_durability_service);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = DeadlineQosPolicyMarshaler.CopyIn(
                     from.Deadline, to, offset_deadline);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = LatencyBudgetQosPolicyMarshaler.CopyIn(
                     from.LatencyBudget, to, offset_latency_budget);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = LivelinessQosPolicyMarshaler.CopyIn(
                     from.Liveliness, to, offset_liveliness);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = ReliabilityQosPolicyMarshaler.CopyIn(
                     from.Reliability, to, offset_reliability);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = DestinationOrderQosPolicyMarshaler.CopyIn(
                     from.DestinationOrder, to, offset_destination_order);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = HistoryQosPolicyMarshaler.CopyIn(
                     from.History, to, offset_history);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = ResourceLimitsQosPolicyMarshaler.CopyIn(
                     from.ResourceLimits, to, offset_resource_limits);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = TransportPriorityQosPolicyMarshaler.CopyIn(
                     from.TransportPriority, to, offset_transport_priority);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = LifespanQosPolicyMarshaler.CopyIn(
                     from.Lifespan, to, offset_lifespan);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = OwnershipQosPolicyMarshaler.CopyIn(
                     from.Ownership, to, offset_ownership);
         }
     } else {
         result = DDS.ReturnCode.BadParameter;
         DDS.OpenSplice.OS.Report(
                 DDS.OpenSplice.ReportType.OS_ERROR,
                 "DDS.OpenSplice.CustomMarshalers.TopicQosMarshaler.CopyIn",
                 "DDS/OpenSplice/CustomMarshalers/QosToplevelMarshalers.cs",
                 DDS.ErrorCode.InvalidValue,
                 "TopicQos attribute may not be a null pointer.");
     }
     return result;
 }
Ejemplo n.º 50
0
        static void Main(string[] args)
        {
            int ownID = 1;
            string chatterName = null;
            int domain = DDS.DomainId.Default;
            string partitionName = "ChatRoom";

            /* Options: Chatter [ownID [name]] */
            if (args.Length > 0)
            {
                ownID = int.Parse(args[0]);
                if (args.Length > 1)
                {
                    chatterName = args[1];
                }
            }
                 
            /* Create a DomainParticipantFactory and a DomainParticipant
               (using Default QoS settings. */
            DomainParticipantFactory dpf = DomainParticipantFactory.Instance;
            ErrorHandler.checkHandle(dpf, "DDS.DomainParticipantFactory.Instance");

            IDomainParticipant participant = dpf.CreateParticipant(domain, null, StatusKind.Any);
            ErrorHandler.checkHandle(participant, "DDS.DomainParticipantFactory.CreateParticipant");

            /* Register the required datatype for ChatMessage. */
            ChatMessageTypeSupport chatMessageTS = new ChatMessageTypeSupport();
            string chatMessageTypeName = chatMessageTS.TypeName;
            ReturnCode status = chatMessageTS.RegisterType(
                participant, chatMessageTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.ChatMessageTypeSupport.RegisterType");

            /* Register the required datatype for NameService. */
            NameServiceTypeSupport nameServiceTS = new NameServiceTypeSupport();
            string nameServiceTypeName = nameServiceTS.TypeName;
            status = nameServiceTS.RegisterType(
                participant, nameServiceTypeName);
            ErrorHandler.checkStatus(
                status, "Chat.NameServiceTypeSupport.RegisterType");

            /* Initialise Qos variables */
            TopicQos reliableTopicQos = new TopicQos();
            TopicQos settingTopicQos = new TopicQos();
            PublisherQos pubQos = new PublisherQos();
            DataWriterQos dwQos = new DataWriterQos();
            DataWriterQos nsDwQos = new DataWriterQos();

            /* Set the ReliabilityQosPolicy to RELIABLE. */
            status = participant.GetDefaultTopicQos(ref reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultTopicQos");
            reliableTopicQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;

            /* Make the tailored QoS the new default. */
            status = participant.SetDefaultTopicQos(reliableTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.SetDefaultTopicQos");

            /* Use the changed policy when defining the ChatMessage topic */
            ITopic chatMessageTopic = participant.CreateTopic(
                "Chat_ChatMessage",
                chatMessageTypeName,
                reliableTopicQos);
            ErrorHandler.checkHandle(
                chatMessageTopic,
                "DDS.DomainParticipant.CreateTopic (ChatMessage)");

            /* Set the DurabilityQosPolicy to TRANSIENT. */
            status = participant.GetDefaultTopicQos(ref settingTopicQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultTopicQos");
            settingTopicQos.Durability.Kind = DurabilityQosPolicyKind.TransientDurabilityQos;

            /* Create the NameService Topic. */
            ITopic nameServiceTopic = participant.CreateTopic(
                "Chat_NameService",
                nameServiceTypeName,
                settingTopicQos);
            ErrorHandler.checkHandle(
                nameServiceTopic,
                "DDS.DomainParticipant.CreateTopic (NameService)");

            /* Adapt the default PublisherQos to write into the
               "ChatRoom" Partition. */
            status = participant.GetDefaultPublisherQos(ref pubQos);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.GetDefaultPublisherQos");
            pubQos.Partition.Name = new string[1];
            pubQos.Partition.Name[0] = partitionName;

            /* Create a Publisher for the chatter application. */
            IPublisher chatPublisher = participant.CreatePublisher(pubQos);
            ErrorHandler.checkHandle(
                chatPublisher, "DDS.DomainParticipant.CreatePublisher");

            /* Create a DataWriter for the ChatMessage Topic
               (using the appropriate QoS). */
            chatPublisher.GetDefaultDataWriterQos(ref dwQos);
            status = chatPublisher.CopyFromTopicQos(ref dwQos, reliableTopicQos);
            ErrorHandler.checkStatus(status, "DDS.Publisher.CopyFromTopicQos");

            IDataWriter parentWriter = chatPublisher.CreateDataWriter(chatMessageTopic, dwQos);
            ErrorHandler.checkHandle(
                parentWriter, "DDS.Publisher.CreateDatawriter (chatMessage)");

            /* Narrow the abstract parent into its typed representative. */
            ChatMessageDataWriter talker = parentWriter as ChatMessageDataWriter;
            ErrorHandler.checkHandle(
                talker, "Chat.ChatMessageDataWriter");

            /* Create a DataWriter for the NameService Topic
               (using the appropriate QoS). */
            status = chatPublisher.GetDefaultDataWriterQos(ref nsDwQos);
            ErrorHandler.checkStatus(
                status, "DDS.Publisher.GetDefaultDatawriterQos");
            status = chatPublisher.CopyFromTopicQos(ref nsDwQos, settingTopicQos);
            ErrorHandler.checkStatus(status, "DDS.Publisher.CopyFromTopicQos");

            WriterDataLifecycleQosPolicy writerDataLifecycle = nsDwQos.WriterDataLifecycle;
            writerDataLifecycle.AutodisposeUnregisteredInstances = false;
            IDataWriter nsParentWriter = chatPublisher.CreateDataWriter(nameServiceTopic, nsDwQos);
            ErrorHandler.checkHandle(
                nsParentWriter, "DDS.Publisher.CreateDatawriter (NameService)");

            /* Narrow the abstract parent into its typed representative. */
            NameServiceDataWriter nameServer = nsParentWriter as NameServiceDataWriter;
            ErrorHandler.checkHandle(
                nameServer, "Chat.NameServiceDataWriterHelper");

            /* Initialize the NameServer attributes. */
            NameService ns = new NameService();
            ns.userID = ownID;
            if (chatterName != null)
            {
                ns.name = chatterName;
            }
            else
            {
                ns.name = "Chatter " + ownID;
            }

            /* Write the user-information into the system
               (registering the instance implicitly). */
            status = nameServer.Write(ns);
            ErrorHandler.checkStatus(status, "Chat.ChatMessageDataWriter.Write");

            /* Initialize the chat messages. */
            ChatMessage msg = new ChatMessage();
            msg.userID = ownID;
            msg.index = 0;
            if (ownID == TERMINATION_MESSAGE)
            {
                msg.content = "Termination message.";
            }
            else
            {
                msg.content = "Hi there, I will send you " +
                    NUM_MSG + " more messages.";
            }
            System.Console.WriteLine("Writing message: \"" + msg.content + "\"");

            /* Register a chat message for this user
               (pre-allocating resources for it!!) */
            InstanceHandle userHandle = talker.RegisterInstance(msg);

            /* Write a message using the pre-generated instance handle. */
            status = talker.Write(msg, userHandle);
            ErrorHandler.checkStatus(status, "Chat.ChatMessageDataWriter.Write");

            Thread.Sleep(1000);

            /* Write any number of messages . */
            for (int i = 1; i <= NUM_MSG && ownID != TERMINATION_MESSAGE; i++)
            {
                msg.index = i;
                msg.content = "Message no. " + i;
                Console.WriteLine("Writing message: \"" + msg.content + "\"");
                status = talker.Write(msg, userHandle);
                ErrorHandler.checkStatus(status, "Chat.ChatMessageDataWriter.Write");

                Thread.Sleep(1000); /* do not run so fast! */
            }

            /* Leave the room by disposing and unregistering the message instance */
            status = talker.Dispose(msg, userHandle);
            ErrorHandler.checkStatus(
                status, "Chat.ChatMessageDataWriter.Dispose");
            status = talker.UnregisterInstance(msg, userHandle);
            ErrorHandler.checkStatus(
                status, "Chat.ChatMessageDataWriter.unregister_instance");

            /* Also unregister our name. */
            status = nameServer.UnregisterInstance(ns, InstanceHandle.Nil);
            ErrorHandler.checkStatus(
                status, "Chat.NameServiceDataWriter.unregister_instance");

            /* Remove the DataWriters */
            status = chatPublisher.DeleteDataWriter(talker);
            ErrorHandler.checkStatus(
                status, "DDS.Publisher.DeleteDatawriter (talker)");

            status = chatPublisher.DeleteDataWriter(nameServer);
            ErrorHandler.checkStatus(status,
                "DDS.Publisher.DeleteDatawriter (nameServer)");

            /* Remove the Publisher. */
            status = participant.DeletePublisher(chatPublisher);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeletePublisher");

            /* Remove the Topics. */
            status = participant.DeleteTopic(nameServiceTopic);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeleteTopic (nameServiceTopic)");

            status = participant.DeleteTopic(chatMessageTopic);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipant.DeleteTopic (chatMessageTopic)");

            /* Remove the DomainParticipant. */
            status = dpf.DeleteParticipant(participant);
            ErrorHandler.checkStatus(
                status, "DDS.DomainParticipantFactory.DeleteParticipant");

        }
Ejemplo n.º 51
0
 GetTopicQos (
     ref TopicQos topicQos,
     string id)
 {
     NamedTopicQos tQos = new NamedTopicQos();
     GCHandle qosHandle = GCHandle.Alloc(tQos, GCHandleType.Normal);
     ReturnCode result = OpenSplice.Common.QosProvider.GetTopicQos(GapiPeer, id, GCHandle.ToIntPtr(qosHandle));
     topicQos = tQos.TopicQos;
     qosHandle.Free();
     return result;
 }