internal ReturnCode init(DomainParticipant participant, string name, SubscriberQos qos)
        {
            ReturnCode result;

            MyDomainId = participant.MyDomainId;

            using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.SubscriberQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == ReturnCode.Ok)
                {
                    IntPtr uSubscriber = User.Subscriber.New(participant.rlReq_UserPeer, name, marshaler.UserPtr);
                    if (uSubscriber != IntPtr.Zero)
                    {
                        result = base.init(uSubscriber);
                    }
                    else
                    {
                        result = DDS.ReturnCode.Error;
                    }
                }
            }

            if (result == ReturnCode.Ok)
            {
                this.participant = participant;
            }

            return(result);
        }
        public ReturnCode SetQos(SubscriberQos qos)
        {
            ReturnCode result = DDS.ReturnCode.AlreadyDeleted;

            ReportStack.Start();
            if (this.rlReq_isAlive)
            {
                result = QosManager.checkQos(qos);
                if (result == DDS.ReturnCode.Ok)
                {
                    using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                               new OpenSplice.CustomMarshalers.SubscriberQosMarshaler())
                    {
                        result = marshaler.CopyIn(qos);
                        if (result == ReturnCode.Ok)
                        {
                            result = uResultToReturnCode(
                                User.Subscriber.SetQos(rlReq_UserPeer, marshaler.UserPtr));
                            if (result != ReturnCode.Ok)
                            {
                                ReportStack.Report(result, "Could not apply SubscriberQos.");
                            }
                        }
                        else
                        {
                            ReportStack.Report(result, "Could not copy SubscriberQos.");
                        }
                    }
                }
            }
            ReportStack.Flush(this, result != ReturnCode.Ok);
            return(result);
        }
Esempio n. 3
0
        public ISubscriber CreateSubscriber(SubscriberQos qos, ISubscriberListener listener, StatusKind mask)
        {
            ISubscriber subscriber = null;

            using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.SubscriberQosMarshaler())
            {
                if (marshaler.CopyIn(qos) == ReturnCode.Ok)
                {
                    if (listener != null)
                    {
                        OpenSplice.Gapi.gapi_subscriberListener gapiListener;
                        SubscriberListenerHelper listenerHelper = new SubscriberListenerHelper();
                        listenerHelper.Listener = listener;
                        listenerHelper.CreateListener(out gapiListener);
                        using (SubscriberListenerMarshaler listenerMarshaler =
                                   new SubscriberListenerMarshaler(ref gapiListener))
                        {
                            IntPtr gapiPtr = Gapi.DomainParticipant.create_subscriber(
                                GapiPeer,
                                marshaler.GapiPtr,
                                listenerMarshaler.GapiPtr,
                                mask);
                            if (gapiPtr != IntPtr.Zero)
                            {
                                subscriber = new Subscriber(gapiPtr, listenerHelper);
                            }
                        }
                    }
                    else
                    {
                        // Invoke the corresponding gapi function.
                        IntPtr gapiPtr = Gapi.DomainParticipant.create_subscriber(
                            GapiPeer,
                            marshaler.GapiPtr,
                            IntPtr.Zero,
                            mask);
                        if (gapiPtr != IntPtr.Zero)
                        {
                            subscriber = new Subscriber(gapiPtr);
                        }
                    }
                }
            }

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

            return(subscriber);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            _dpf = DomainParticipantFactory.Instance;
            ErrorHandler.checkHandle(_dpf, "Domain Participant Factory");

            _dp = _dpf.CreateParticipant(Domain);

            //Initialize QOS
            sQos  = new SubscriberQos();
            drQos = new DataReaderQos();

            fdmDataType = new FDMTypeSupport();
            string     FDMDATATypeName = fdmDataType.TypeName;
            ReturnCode status          = fdmDataType.RegisterType(_dp, FDMDATATypeName);

            ErrorHandler.checkStatus(status, "FDMDATA: Cannot Register Type");

            //Create FDMDATA Topic
            fdmDataTopic = _dp.FindTopic("FDMDATA", Duration.FromMilliseconds(1000));
            if (fdmDataTopic == null)
            {
                fdmDataTopic = _dp.CreateTopic("FDMDATA", FDMDATATypeName);
            }
            ErrorHandler.checkHandle(fdmDataTopic, "Cannot Create Topic FDMDATA");

            //Get Subscriber QOS and Set Partition Name
            _dp.GetDefaultSubscriberQos(ref sQos);
            sQos.Partition.Name    = new String[1];
            sQos.Partition.Name[0] = PartitionName;

            //Create Subscriber for FDMDATA Topic
            Subscriber = _dp.CreateSubscriber(sQos);
            ErrorHandler.checkHandle(Subscriber, "Cannot Create FDMDATA Subscriber");

            //Get Data Reader QOS and Set History Depth
            Subscriber.GetDefaultDataReaderQos(ref drQos);
            ErrorHandler.checkHandle(drQos, "Cannot get Data Reader Qos");
            drQos.History.Depth    = 5;
            drQos.Reliability.Kind = ReliabilityQosPolicyKind.BestEffortReliabilityQos;

            //Create DataReader for FDMDATA Topic
            parentReader = Subscriber.CreateDataReader(fdmDataTopic, drQos);
            ErrorHandler.checkHandle(parentReader, "Cannot Create FDMDATA Data Reader");

            //Narrow abstract parentReader into its typed representative
            fdmDataReader = parentReader as FDMDataReader;
            ErrorHandler.checkHandle(fdmDataReader, "Cannot Narrow FDMDATA Data Reader");
            // drQos.Durability.Kind = DurabilityQosPolicyKind.TransientLocalDurabilityQos;

            fdmData = new FDM();
            //Rececieve Loop
            while (true)
            {
                StartReceive();

                Console.WriteLine("abc: " + fdmData.aa.ToString());
            }
        }
Esempio n. 5
0
        GetSubscriberQos(
            ref SubscriberQos subscriberQos,
            string id)
        {
            NamedSubscriberQos sQos      = new NamedSubscriberQos();
            GCHandle           qosHandle = GCHandle.Alloc(sQos, GCHandleType.Normal);
            ReturnCode         result    = OpenSplice.Common.QosProvider.GetSubscriberQos(GapiPeer, id, GCHandle.ToIntPtr(qosHandle));

            subscriberQos = sQos.SubscriberQos;
            qosHandle.Free();
            return(result);
        }
Esempio n. 6
0
 public static void TestDefaultSubscriberQos(SubscriberQos qos)
 {
     Assert.IsNotNull(qos.EntityFactory);
     Assert.IsNotNull(qos.GroupData);
     Assert.IsNotNull(qos.Partition);
     Assert.IsNotNull(qos.Presentation);
     Assert.IsTrue(qos.EntityFactory.AutoenableCreatedEntities);
     Assert.IsNotNull(qos.GroupData.Value);
     Assert.AreEqual(0, qos.GroupData.Value.Count());
     Assert.IsNotNull(qos.Partition.Name);
     Assert.AreEqual(0, qos.Partition.Name.Count());
     Assert.IsFalse(qos.Presentation.CoherentAccess);
     Assert.IsFalse(qos.Presentation.OrderedAccess);
     Assert.AreEqual(PresentationQosPolicyAccessScopeKind.InstancePresentationQos, qos.Presentation.AccessScope);
 }
Esempio n. 7
0
        public void TestInitialize()
        {
            _participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN);
            Assert.IsNotNull(_participant);
            _participant.BindRtpsUdpTransportConfig();

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

            Assert.AreEqual(ReturnCode.Ok, result);

            _topic = _participant.CreateTopic(TestContext.TestName, typeName);
            Assert.IsNotNull(_topic);
            Assert.IsNull(_topic.GetListener());
            Assert.AreEqual(TestContext.TestName, _topic.Name);
            Assert.AreEqual(typeName, _topic.TypeName);

            SubscriberQos sQos = new SubscriberQos();

            sQos.EntityFactory.AutoenableCreatedEntities = false;
            sQos.Presentation.OrderedAccess  = true;
            sQos.Presentation.CoherentAccess = true;
            sQos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.InstancePresentationQos;
            _subscriber = _participant.CreateSubscriber(sQos);
            Assert.IsNotNull(_subscriber);

            PublisherQos pQos = new PublisherQos();

            pQos.EntityFactory.AutoenableCreatedEntities = false;
            pQos.Presentation.OrderedAccess  = true;
            pQos.Presentation.CoherentAccess = true;
            pQos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.InstancePresentationQos;
            _publisher = _participant.CreatePublisher(pQos);
            Assert.IsNotNull(_publisher);

            _listener = new MyDataWriterListener();
            _writer   = _publisher.CreateDataWriter(_topic, _listener);
            Assert.IsNotNull(_writer);
            _dataWriter = new TestStructDataWriter(_writer);

            DataReaderQos qos = new DataReaderQos();

            qos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;
            _reader = _subscriber.CreateDataReader(_topic, qos);
            Assert.IsNotNull(_reader);
        }
Esempio n. 8
0
        public static SubscriberQos CreateNonDefaultSubscriberQos()
        {
            SubscriberQos qos = new SubscriberQos();

            qos.EntityFactory.AutoenableCreatedEntities = false;
            qos.GroupData.Value = new List <byte> {
                0x42
            };
            qos.Partition.Name = new List <string> {
                "TestPartition"
            };
            qos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.GroupPresentationQos;
            qos.Presentation.CoherentAccess = true;
            qos.Presentation.OrderedAccess  = true;

            return(qos);
        }
Esempio n. 9
0
        public ReturnCode SetDefaultSubscriberQos(SubscriberQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.SubscriberQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == ReturnCode.Ok)
                {
                    result = Gapi.DomainParticipant.set_default_subscriber_qos(
                        GapiPeer,
                        marshaler.GapiPtr);
                }
            }
            return(result);
        }
Esempio n. 10
0
        public ReturnCode SetQos(SubscriberQos qos)
        {
            DDS.ReturnCode result;

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

            return(result);
        }
Esempio n. 11
0
        public ReturnCode GetQos(ref SubscriberQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.SubscriberQosMarshaler())
            {
                result = OpenSplice.Gapi.Subscriber.get_qos(
                    GapiPeer,
                    marshaler.GapiPtr);

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

            return(result);
        }
Esempio n. 12
0
        public void TestGetQos()
        {
            // Create a non-default QoS and create a subscriber with it
            SubscriberQos qos = TestHelper.CreateNonDefaultSubscriberQos();

            Subscriber subscriber = _participant.CreateSubscriber(qos);

            Assert.IsNotNull(subscriber);

            // Call GetQos and check the values received
            qos = new SubscriberQos();
            ReturnCode result = subscriber.GetQos(qos);

            Assert.AreEqual(ReturnCode.Ok, result);
            TestHelper.TestNonDefaultSubscriberQos(qos);

            // Test GetQos with null parameter
            result = subscriber.GetQos(null);
            Assert.AreEqual(ReturnCode.BadParameter, result);
        }
Esempio n. 13
0
        GetSubscriberQos(
            ref SubscriberQos subscriberQos,
            string id)
        {
            ReportStack.Start();
            NamedSubscriberQos sQos      = new NamedSubscriberQos();
            GCHandle           qosHandle = GCHandle.Alloc(sQos, GCHandleType.Normal);
            ReturnCode         result    = qpResultToReturnCode(
                OpenSplice.Common.QosProvider.GetSubscriberQos(cmnQpPtr, id, GCHandle.ToIntPtr(qosHandle)));

            if (result == ReturnCode.Ok)
            {
                subscriberQos = sQos.SubscriberQos;
            }
            else
            {
                ReportStack.Report(result, "Could not copy subscriberQos.");
            }
            qosHandle.Free();
            ReportStack.Flush(null, result != ReturnCode.Ok);
            return(result);
        }
Esempio n. 14
0
        public ReturnCode GetQos(ref SubscriberQos qos)
        {
            IntPtr     userQos = IntPtr.Zero;
            ReturnCode result  = DDS.ReturnCode.AlreadyDeleted;

            ReportStack.Start();
            if (this.rlReq_isAlive)
            {
                result = uResultToReturnCode(
                    User.Subscriber.GetQos(rlReq_UserPeer, ref userQos));
                if (result == ReturnCode.Ok)
                {
                    using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                               new OpenSplice.CustomMarshalers.SubscriberQosMarshaler(userQos, true))
                    {
                        marshaler.CopyOut(ref qos);
                    }
                }
            }
            ReportStack.Flush(this, result != ReturnCode.Ok);

            return(result);
        }
Esempio n. 15
0
        public Subscriber(Topic <T> topic, string partitionName, AdapterReaderQos desiredQos,
                          DataReaderListener <T> listener, int waitForHistoricalData)
        {
            currentTopic       = topic;
            this.partitionName = partitionName;
            this.listener      = listener;
            IDomainParticipant participant = topic.Participant;
            var subQos = new SubscriberQos();

            ReturnCode status = participant.GetDefaultSubscriberQos(ref subQos);

            ErrorHandler.CheckStatus(
                status, "Subscriber.GetDefaultSubscriberQos (Subscriber)");
            subQos.Partition.Name    = new string[1];
            subQos.Partition.Name[0] = partitionName;

            // Create a Subscriber for the application.
            topicSubscriber = participant.CreateSubscriber(subQos);
            ErrorHandler.CheckHandle(
                topicSubscriber, "Subscriber.CreateSubscriber (Subscriber)");

            CreateDataReader(desiredQos, listener, waitForHistoricalData);
        }
Esempio n. 16
0
        internal static ReturnCode checkQos(SubscriberQos o)
        {
            ReturnCode result = DDS.ReturnCode.BadParameter;

            if (o != null)
            {
                int errorCount = 0;
                errorCount += countErrors(o.Presentation);
                errorCount += countErrors(o.Partition);
                errorCount += countErrors(o.GroupData);
                errorCount += countErrors(o.EntityFactory);
                errorCount += countErrors(o.Share);
                if (errorCount == 0)
                {
                    result = DDS.ReturnCode.Ok;
                }
            }
            else
            {
                ReportStack.Report(result,
                                   "SubscriberQos 'null' is invalid.");
            }
            return(result);
        }
Esempio n. 17
0
        public void TestSetQos()
        {
            // Create a new Subscriber using the default QoS
            Subscriber subscriber = _participant.CreateSubscriber();

            // Get the qos to ensure that is using the default properties
            SubscriberQos qos    = new SubscriberQos();
            ReturnCode    result = subscriber.GetQos(qos);

            Assert.AreEqual(ReturnCode.Ok, result);
            TestHelper.TestDefaultSubscriberQos(qos);

            // Try to change an immutable property
            qos.Presentation.CoherentAccess = true;
            qos.Presentation.OrderedAccess  = true;
            qos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.GroupPresentationQos;
            result = subscriber.SetQos(qos);
            Assert.AreEqual(ReturnCode.ImmutablePolicy, result);

            // Change some mutable properties and check them
            qos = new SubscriberQos();
            qos.EntityFactory.AutoenableCreatedEntities = false;
            qos.GroupData.Value = new List <byte> {
                0x42
            };
            qos.Partition.Name = new List <string> {
                "TestPartition"
            };
            result = subscriber.SetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);

            qos    = new SubscriberQos();
            result = subscriber.GetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.IsNotNull(qos.EntityFactory);
            Assert.IsNotNull(qos.GroupData);
            Assert.IsNotNull(qos.Partition);
            Assert.IsNotNull(qos.Presentation);
            Assert.IsFalse(qos.EntityFactory.AutoenableCreatedEntities);
            Assert.IsNotNull(qos.GroupData.Value);
            Assert.AreEqual(1, qos.GroupData.Value.Count());
            Assert.AreEqual(0x42, qos.GroupData.Value.First());
            Assert.IsNotNull(qos.Partition.Name);
            Assert.AreEqual(1, qos.Partition.Name.Count());
            Assert.AreEqual("TestPartition", qos.Partition.Name.First());
            Assert.IsFalse(qos.Presentation.CoherentAccess);
            Assert.IsFalse(qos.Presentation.OrderedAccess);
            Assert.AreEqual(PresentationQosPolicyAccessScopeKind.InstancePresentationQos, qos.Presentation.AccessScope);

            // Try to set immutable QoS properties before enable the publisher
            DomainParticipantQos pQos = new DomainParticipantQos();

            pQos.EntityFactory.AutoenableCreatedEntities = false;
            result = _participant.SetQos(pQos);
            Assert.AreEqual(ReturnCode.Ok, result);

            Subscriber otherSubscriber = _participant.CreateSubscriber();

            qos = new SubscriberQos();
            qos.EntityFactory.AutoenableCreatedEntities = false;
            qos.GroupData.Value = new List <byte> {
                0x42
            };
            qos.Partition.Name = new List <string> {
                "TestPartition"
            };
            qos.Presentation.CoherentAccess = true;
            qos.Presentation.OrderedAccess  = true;
            qos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.GroupPresentationQos;
            result = otherSubscriber.SetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);

            qos    = new SubscriberQos();
            result = otherSubscriber.GetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.IsNotNull(qos.EntityFactory);
            Assert.IsNotNull(qos.GroupData);
            Assert.IsNotNull(qos.Partition);
            Assert.IsNotNull(qos.Presentation);
            Assert.IsFalse(qos.EntityFactory.AutoenableCreatedEntities);
            Assert.IsNotNull(qos.GroupData.Value);
            Assert.AreEqual(1, qos.GroupData.Value.Count());
            Assert.AreEqual(0x42, qos.GroupData.Value.First());
            Assert.IsNotNull(qos.Partition.Name);
            Assert.AreEqual(1, qos.Partition.Name.Count());
            Assert.AreEqual("TestPartition", qos.Partition.Name.First());
            Assert.IsTrue(qos.Presentation.CoherentAccess);
            Assert.IsTrue(qos.Presentation.OrderedAccess);
            Assert.AreEqual(PresentationQosPolicyAccessScopeKind.GroupPresentationQos, qos.Presentation.AccessScope);

            // Test SetQos with null parameter
            result = subscriber.SetQos(null);
            Assert.AreEqual(ReturnCode.BadParameter, result);
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            int domain = DDS.DomainId.Default;

            /* 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");
        }
Esempio n. 19
0
        public ReturnCode GetDefaultSubscriberQos(ref SubscriberQos qos)
        {
            ReturnCode result;

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

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

            return result;
        }
Esempio n. 20
0
        public ISubscriber CreateSubscriber(SubscriberQos qos, ISubscriberListener listener, StatusKind mask)
        {
            ISubscriber subscriber = null;

            using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                    new OpenSplice.CustomMarshalers.SubscriberQosMarshaler())
            {
                if (marshaler.CopyIn(qos) == ReturnCode.Ok)
                {
                    if (listener != null)
                    {
                        OpenSplice.Gapi.gapi_subscriberListener gapiListener;
                        SubscriberListenerHelper listenerHelper = new SubscriberListenerHelper();
                        listenerHelper.Listener = listener;
                        listenerHelper.CreateListener(out gapiListener);
                        using (SubscriberListenerMarshaler listenerMarshaler =
                                new SubscriberListenerMarshaler(ref gapiListener))
                        {
                            IntPtr gapiPtr = Gapi.DomainParticipant.create_subscriber(
                                    GapiPeer,
                                    marshaler.GapiPtr,
                                    listenerMarshaler.GapiPtr,
                                    mask);
                            if (gapiPtr != IntPtr.Zero)
                            {
                                subscriber = new Subscriber(gapiPtr, listenerHelper);
                            }
                        }
                    }
                    else
                    {
                        // Invoke the corresponding gapi function.
                        IntPtr gapiPtr = Gapi.DomainParticipant.create_subscriber(
                                GapiPeer,
                                marshaler.GapiPtr,
                                IntPtr.Zero,
                                mask);
                        if (gapiPtr != IntPtr.Zero)
                        {
                            subscriber = new Subscriber(gapiPtr);
                        }
                    }
                }
            }

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

            return subscriber;
        }
Esempio n. 21
0
 internal static DDS.ReturnCode CopyIn(SubscriberQos from, IntPtr to)
 {
     DDS.ReturnCode result;
     if (from != null) {
         result = PresentationQosPolicyMarshaler.CopyIn(
                 from.Presentation, to, offset_presentation);
         if (result == DDS.ReturnCode.Ok) {
             result = PartitionQosPolicyMarshaler.CopyIn(
                     from.Partition, to, offset_partition);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = GroupDataQosPolicyMarshaler.CopyIn(
                     from.GroupData, to, offset_group_data);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = EntityFactoryQosPolicyMarshaler.CopyIn(
                     from.EntityFactory, to, offset_entity_factory);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = ShareQosPolicyMarshaler.CopyIn(
                     from.Share, to, offset_share);
         }
     } else {
         result = DDS.ReturnCode.BadParameter;
         DDS.OpenSplice.OS.Report(
                 DDS.OpenSplice.ReportType.OS_ERROR,
                 "DDS.OpenSplice.CustomMarshalers.SubscriberQosMarshaler.CopyIn",
                 "DDS/OpenSplice/CustomMarshalers/QosToplevelMarshalers.cs",
                 DDS.ErrorCode.InvalidValue,
                 "SubscriberQos attribute may not be a null pointer.");
     }
     return result;
 }
Esempio n. 22
0
 internal DDS.ReturnCode CopyIn(SubscriberQos from)
 {
     cleanupRequired = true;
     return CopyIn(from, GapiPtr);
 }
Esempio n. 23
0
 public ISubscriber CreateSubscriber(SubscriberQos qos)
 {
     return realParticipant.CreateSubscriber(qos);
 }
        /// <summary>
        /// Creates a DomainParticipant, Topic, Subscriber and DataReader<Temperature>.
        /// </summary>
        public SubscriberApplication(int domainId, bool useXmlQos = true)
        {
            // Start communicating in a domain, usually one participant per application
            // Load QoS profile from USER_QOS_PROFILES.xml file
            participant = DomainParticipantFactory.Instance.CreateParticipant(domainId);

            // Create the topics
            var alarmTopic       = participant.CreateTopic <Alarm>("Alarm");
            var heartRateTopic   = participant.CreateTopic <HeartRate>("HeartRate");
            var temperatureTopic = participant.CreateTopic <Temperature>("Temperature");

            // Create a subscriber
            SubscriberQos subscriberQos = null;

            if (useXmlQos)
            {
                // Retrieve the Subscriber QoS, from USER_QOS_PROFILES.xml
                subscriberQos = QosProvider.Default.GetSubscriberQos();
            }
            else
            {
                // Set the Subscriber QoS programatically, to the same effect
                subscriberQos = participant.DefaultSubscriberQos
                                .WithPresentation(policy =>
                {
                    policy.AccessScope    = PresentationAccessScopeKind.Group;
                    policy.CoherentAccess = true;
                    policy.OrderedAccess  = true;

                    // Uncomment this line to keep and deliver incomplete
                    // coherent sets to the application
                    // policy.DropIncompleteCoherentSet = false;
                });
            }
            subscriber = participant.CreateSubscriber(subscriberQos);

            // Create a DataReader for each topic
            DataReaderQos readerQos = null;

            if (useXmlQos)
            {
                // Retrieve the DataReader QoS, from USER_QOS_PROFILES.xml
                readerQos = QosProvider.Default.GetDataReaderQos();
            }
            else
            {
                // Set the DataReader QoS programatically, to the same effect
                readerQos = subscriber.DefaultDataReaderQos
                            .WithReliability(policy => policy.Kind = ReliabilityKind.Reliable)
                            .WithHistory(policy => policy.Kind     = HistoryKind.KeepAll);
            }

            alarmReader       = subscriber.CreateDataReader(alarmTopic, readerQos);
            heartRateReader   = subscriber.CreateDataReader(heartRateTopic, readerQos);
            temperatureReader = subscriber.CreateDataReader(temperatureTopic, readerQos);

            // We are monitoring the sample lost status in case an
            // incomplete coherent set is received and dropped (assuming the
            // Presentation.DropIncompleteCoherentSet is true (the default))
            alarmReader.SampleLost       += OnSampleLost;
            heartRateReader.SampleLost   += OnSampleLost;
            temperatureReader.SampleLost += OnSampleLost;
        }
Esempio n. 25
0
        public ReturnCode GetQos(ref SubscriberQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                    new OpenSplice.CustomMarshalers.SubscriberQosMarshaler())
            {
                result = OpenSplice.Gapi.Subscriber.get_qos(
                        GapiPeer,
                        marshaler.GapiPtr);

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

            return result;
        }
Esempio n. 26
0
 internal static void CopyOut(IntPtr from, ref SubscriberQos to)
 {
     if (to == null) to = new SubscriberQos();
     PresentationQosPolicyMarshaler.CopyOut(from, ref to.Presentation, offset_presentation);
     PartitionQosPolicyMarshaler.CopyOut(from, ref to.Partition, offset_partition);
     GroupDataQosPolicyMarshaler.CopyOut(from, ref to.GroupData, offset_group_data);
     EntityFactoryQosPolicyMarshaler.CopyOut(from, ref to.EntityFactory, offset_entity_factory);
     ShareQosPolicyMarshaler.CopyOut(from, ref to.Share, offset_share);
 }
Esempio n. 27
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");
        }
Esempio n. 28
0
        public IDataReader CreateDataReader(
            ITopicDescription topic,
            IDataReaderListener listener,
            StatusKind mask)
        {
            DataReader dataReader = null;

            if (topic != null)
            {
                SacsSuperClass superObj = (SacsSuperClass)topic;

                if (listener != null)
                {
                    OpenSplice.Gapi.gapi_dataReaderListener gapiListener;
                    DataReaderListenerHelper listenerHelper = new DataReaderListenerHelper();
                    listenerHelper.Listener = listener;
                    listenerHelper.CreateListener(out gapiListener);
                    using (DataReaderListenerMarshaler listenerMarshaler =
                               new DataReaderListenerMarshaler(ref gapiListener))
                    {
                        IntPtr gapiPtr = Gapi.Subscriber.create_datareader(
                            GapiPeer,
                            superObj.GapiPeer,
                            IntPtr.Zero,
                            listenerMarshaler.GapiPtr,
                            mask);
                        if (gapiPtr != IntPtr.Zero)
                        {
                            DDS.OpenSplice.DomainParticipant participantImpl;

                            participantImpl = topic.Participant as DDS.OpenSplice.DomainParticipant;
                            TypeSupportFactory tsFactory = participantImpl.GetTypeSupportFactory(topic.TypeName);
                            dataReader = tsFactory.CreateDataReader(gapiPtr);
                            dataReader.SetListener(listenerHelper);
                        }
                    }
                }
                else
                {
                    IntPtr gapiPtr = Gapi.Subscriber.create_datareader(
                        GapiPeer,
                        superObj.GapiPeer,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        StatusKind.Any);
                    if (gapiPtr != IntPtr.Zero)
                    {
                        DDS.OpenSplice.DomainParticipant participantImpl;

                        participantImpl = topic.Participant as DDS.OpenSplice.DomainParticipant;
                        TypeSupportFactory tsFactory = participantImpl.GetTypeSupportFactory(topic.TypeName);
                        dataReader = tsFactory.CreateDataReader(gapiPtr);
                    }
                }
            }

            if (dataReader != null)
            {
                SubscriberQos subQos = null;
                ReturnCode    result = GetQos(ref subQos);
                if (result == ReturnCode.Ok)
                {
                    if (subQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        dataReader.Enable();
                    }
                }
            }

            return(dataReader);
        }
Esempio n. 29
0
 public ReturnCode GetDefaultSubscriberQos(ref SubscriberQos qos)
 {
     return realParticipant.GetDefaultSubscriberQos(ref qos);
 }
Esempio n. 30
0
        public void TestBeginEndAccess()
        {
            // OpenDDS Issue: Coherent sets for PRESENTATION QoS not Currently implemented on RTPS.
            // Just prepare the unit test for the moment.

            // Initialize entities
            TestStructTypeSupport support = new TestStructTypeSupport();
            string     typeName           = support.GetTypeName();
            ReturnCode result             = support.RegisterType(_participant, typeName);

            Assert.AreEqual(ReturnCode.Ok, result);

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

            Assert.IsNotNull(topic);
            Assert.IsNull(topic.GetListener());
            Assert.AreEqual(nameof(TestNotifyDataReaders), topic.Name);
            Assert.AreEqual(typeName, topic.TypeName);

            Topic otherTopic = _participant.CreateTopic("Other" + nameof(TestNotifyDataReaders), typeName);

            Assert.IsNotNull(otherTopic);
            Assert.IsNull(otherTopic.GetListener());
            Assert.AreEqual("Other" + nameof(TestNotifyDataReaders), otherTopic.Name);
            Assert.AreEqual(typeName, otherTopic.TypeName);

            PublisherQos pubQos = new PublisherQos();

            pubQos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.GroupPresentationQos;
            pubQos.Presentation.CoherentAccess = true;
            pubQos.Presentation.OrderedAccess  = true;
            Publisher publisher = _participant.CreatePublisher(pubQos);

            Assert.IsNotNull(publisher);

            DataWriter writer = publisher.CreateDataWriter(topic);

            Assert.IsNotNull(writer);
            TestStructDataWriter dataWriter = new TestStructDataWriter(writer);

            DataWriter otherWriter = publisher.CreateDataWriter(otherTopic);

            Assert.IsNotNull(otherWriter);
            TestStructDataWriter otherDataWriter = new TestStructDataWriter(otherWriter);

            SubscriberQos subQos = new SubscriberQos();

            subQos.Presentation.AccessScope    = PresentationQosPolicyAccessScopeKind.GroupPresentationQos;
            subQos.Presentation.CoherentAccess = true;
            subQos.Presentation.OrderedAccess  = true;
            MySubscriberListener listener = new MySubscriberListener();

            listener.DataOnReaders += (sub) =>
            {
                result = sub.BeginAccess();
                Assert.AreEqual(ReturnCode.Ok, result);

                List <DataReader> list = new List <DataReader>();
                result = sub.GetDataReaders(list);

                // Here we should check that we received two DataReader
                // read the data of each one and confirm tha the group coherent access
                // is working as expected.

                result = sub.EndAccess();
                Assert.AreEqual(ReturnCode.Ok, result);
            };

            Subscriber subscriber = _participant.CreateSubscriber(subQos, listener);

            Assert.IsNotNull(subscriber);

            DataReader reader = subscriber.CreateDataReader(topic);

            Assert.IsNotNull(reader);
            TestStructDataReader dataReader = new TestStructDataReader(reader);

            DataReader otherReader = subscriber.CreateDataReader(otherTopic);

            Assert.IsNotNull(otherReader);
            TestStructDataReader otherDataReader = new TestStructDataReader(otherReader);

            // Call EndAccess without calling first BeginAccess
            result = subscriber.EndAccess();
            Assert.AreEqual(ReturnCode.PreconditionNotMet, result);

            // Publish a samples in both topics
            result = publisher.BeginCoherentChanges();
            Assert.AreEqual(ReturnCode.Ok, result);

            result = dataWriter.Write(new TestStruct
            {
                Id = 1
            });
            Assert.AreEqual(ReturnCode.Ok, result);

            result = otherDataWriter.Write(new TestStruct
            {
                Id = 1
            });
            Assert.AreEqual(ReturnCode.Ok, result);

            result = publisher.EndCoherentChanges();
            Assert.AreEqual(ReturnCode.Ok, result);

            // Give some time to the subscriber to process the messages
            System.Threading.Thread.Sleep(500);
        }
Esempio n. 31
0
 public ISubscriber CreateSubscriber(SubscriberQos qos)
 {
     return(realParticipant.CreateSubscriber(qos));
 }
Esempio n. 32
0
        public ReturnCode SetQos(SubscriberQos qos)
        {
            DDS.ReturnCode result;

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

            return result;
        }
Esempio n. 33
0
 internal void CopyOut(ref SubscriberQos to)
 {
     CopyOut(GapiPtr, ref to);
 }
Esempio n. 34
0
 public ISubscriber CreateSubscriber(SubscriberQos qos)
 {
     return(CreateSubscriber(qos, null, 0));
 }
Esempio n. 35
0
 public ReturnCode SetDefaultSubscriberQos(SubscriberQos qos)
 {
     return(realParticipant.SetDefaultSubscriberQos(qos));
 }
Esempio n. 36
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;
        }
Esempio n. 37
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);
        }
Esempio n. 38
0
 public ISubscriber CreateSubscriber(SubscriberQos qos, ISubscriberListener listener, StatusKind mask)
 {
     return realParticipant.CreateSubscriber(qos, listener, mask);
 }
Esempio n. 39
0
 GetSubscriberQos (
     ref SubscriberQos subscriberQos,
     string id)
 {
     NamedSubscriberQos sQos = new NamedSubscriberQos();
     GCHandle qosHandle = GCHandle.Alloc(sQos, GCHandleType.Normal);
     ReturnCode result = OpenSplice.Common.QosProvider.GetSubscriberQos(GapiPeer, id, GCHandle.ToIntPtr(qosHandle));
     subscriberQos = sQos.SubscriberQos;
     qosHandle.Free();
     return result;
 }
Esempio n. 40
0
 public ReturnCode SetDefaultSubscriberQos(SubscriberQos qos)
 {
     return realParticipant.SetDefaultSubscriberQos (qos);
 }
Esempio n. 41
0
 public ISubscriber CreateSubscriber(SubscriberQos qos)
 {
     return CreateSubscriber(qos, null, 0);
 }
Esempio n. 42
0
 public ISubscriber CreateSubscriber(SubscriberQos qos, ISubscriberListener listener, StatusKind mask)
 {
     return(realParticipant.CreateSubscriber(qos, listener, mask));
 }
Esempio n. 43
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");
        }
Esempio n. 44
0
 public ReturnCode GetDefaultSubscriberQos(ref SubscriberQos qos)
 {
     return(realParticipant.GetDefaultSubscriberQos(ref qos));
 }
Esempio n. 45
0
        public void TestNewSubscriberQos()
        {
            SubscriberQos qos = new SubscriberQos();

            TestHelper.TestDefaultSubscriberQos(qos);
        }
Esempio n. 46
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");
        }
Esempio n. 47
0
        public void Run()
        {
#if DBCallTests
            DDS.Test.DatabaseTests();
#endif

            Console.WriteLine("Press enter to enter...");
            Console.ReadLine();
            Data.DataTest detectionData = new Data.DataTest();
            detectionData.TestId    = 3214;
            detectionData.Emergency = true;
            detectionData.TestStr   = "not really";
            //detectionData.SeqInt[3] = 23;
#if TestMarshaling
            //Tactical.DetectionTypeSupport support = new Tactical.DetectionTypeSupport();
            //Tactical.Detection cachedObj = new Tactical.Detection();
            //support.Copy(cachedObj, detectionData);

            //SampleMarshaler marshaler = SampleMarshalerFactory.CreateMarshaler(detectionData);

            //using (SampleMarshalHelper helper = new SampleMarshalHelper(marshaler))
            //{
            //    DDS.OpenSplice.Gapi.Test.test_detection(helper.GapiPtr);

            //    Tactical.Detection detectionData2 = new Tactical.Detection();
            //    SampleMarshaler marshaler2 = SampleMarshalerFactory.CreateMarshaler(detectionData2);
            //    marshaler2.CopyOut(helper.GapiPtr, 0);
            //}

            //Duration d = new Duration(234, 2343);
            //int sec;
            //uint nanosec;
            //DDS.OpenSplice.Gapi.Test.test_duration(d, out sec, out nanosec);

            //LivelinessChangedStatus status;
            //DDS.OpenSplice.Gapi.Test.get_liveliness_changed_status(out status);

            //Time t = new Time(1, 2);
            //int size = Marshal.SizeOf(t);
            //IntPtr ptr = Marshal.AllocHGlobal(size);
            //Marshal.StructureToPtr(t, ptr, true);
#endif

            //DDS.Test.TestDataReaderQos();
            //DDS.Test.TestTopicQos();

            // Create a DomainParticipantFactory
            DomainParticipantFactory dpf = DomainParticipantFactory.Instance;
            Console.WriteLine("DomainParticipantFactory: " + dpf);

            // Tailor the DomainPartipantFactoryQos;
            DomainParticipantFactoryQos dpfQos = null;
            ReturnCode result = dpf.GetQos(ref dpfQos);
            Console.WriteLine("DomainParticipantFactory.get_qos: {0}", result);
            Console.WriteLine("DomainParticipantFactoryQos.entity_factory.autoenable_created_entities: " + dpfQos.EntityFactory.AutoenableCreatedEntities);

            dpfQos.EntityFactory.AutoenableCreatedEntities = false;
            result = dpf.SetQos(dpfQos);
            Console.WriteLine("DomainParticipantFactory.set_qos: {0}", result);

            // Get the QOS settings for the Factory...  Check values without additional changes
            DomainParticipantFactoryQos dpf2Qos = null;
            result = dpf.GetQos(ref dpf2Qos);
            Console.WriteLine("DomainParticipantFactory.get_qos: {0}", result);
            Console.WriteLine("DomainParticipantFactoryQos.entity_factory.autoenable_created_entities: " + dpf2Qos.EntityFactory.AutoenableCreatedEntities);

            // Create the domainParticipant itself.
            DomainParticipantQos dpQos = new DomainParticipantQos();
            dpQos.UserData.Value = new byte[] { (byte)1, (byte)2, (byte)3 };
            dpQos.EntityFactory.AutoenableCreatedEntities        = true;
            dpQos.ListenerScheduling.SchedulingClass.Kind        = SchedulingClassQosPolicyKind.ScheduleDefault;
            dpQos.ListenerScheduling.SchedulingPriorityKind.Kind = SchedulingPriorityQosPolicyKind.PriorityRelative;
            dpQos.ListenerScheduling.SchedulingPriority          = 0;
            dpQos.WatchdogScheduling.SchedulingClass.Kind        = SchedulingClassQosPolicyKind.ScheduleDefault;
            dpQos.WatchdogScheduling.SchedulingPriorityKind.Kind = SchedulingPriorityQosPolicyKind.PriorityRelative;
            dpQos.WatchdogScheduling.SchedulingPriority          = 4;

            IDomainParticipant dp = dpf.CreateParticipant(null, dpQos);
            Console.Write("DomainParticipant: ");
            Console.WriteLine(dp != null ? "yes" : "no");


            if (dp.ContainsEntity(0))
            {
                Console.WriteLine("contains_entity with nil handle incorrect");
            }
            if (dp.ContainsEntity(100))
            {
                Console.WriteLine("contains_entity with incorrect handle incorrect");
            }

            Time currentTime;
            dp.GetCurrentTime(out currentTime);
            Console.WriteLine("Current Local Time: {0}", currentTime.ToDatetime().ToLocalTime());

            // And look up this DomainParticipant.
            IDomainParticipant dp2 = dpf.LookupParticipant(null);

            DomainParticipantQos dp2Qos = null;

            Console.Write("lookup DomainParticipant: ");
            Console.WriteLine(dp2 != null ? "Success" : "Fail");
            result = dp2.GetQos(ref dp2Qos);
            Console.WriteLine("DomainParticipant.get_qos: {0}", result);
            Console.WriteLine("DomainParticipantQos.entity_factory.autoenable_created_entities: " + dp2Qos.EntityFactory.AutoenableCreatedEntities);

            // Create a new PublisherQos and set some values...
            PublisherQos publisherQos = new PublisherQos();
            publisherQos.EntityFactory.AutoenableCreatedEntities = true;
            publisherQos.Partition.Name = new string[] { "howdy" }; //, "neighbor", "partition" };

            // true not supported in 4.1 ??
            publisherQos.Presentation.OrderedAccess = false;

            // Create the Publisher
            dp.Enable();
            IPublisher publisher = dp.CreatePublisher(publisherQos);
            Console.WriteLine("Create Publisher: {0}", publisher);

            //DataWriterQos dwQos;
            //publisher.GetDefaultDataWriterQos(out dwQos);


            // Create a Detection Type Support and register it's type
            Data.DataTestTypeSupport support = new Data.DataTestTypeSupport();

            string test2 = support.TypeName;
            Console.WriteLine("Register Typesupport");
            result = support.RegisterType(dp, support.TypeName);
            Console.WriteLine("Register Typesupport Result: {0}", result);

            // Create a topic for the Detection type
            TopicQos topicQos = null;
            result = dp.GetDefaultTopicQos(ref topicQos);

            //topicQos.Ownership.Kind = OwnershipQosPolicyKind.ExclusiveOwnershipQos;

            //DDS.Test.TestTopicQos2(ref topicQos);

            // Add a listener to the topic
            ITopic topic = dp.CreateTopic("Data_DataTest", support.TypeName, topicQos,
                                          this, StatusKind.InconsistentTopic);

            topicQos.History.Depth = 5;

            ITopic topic2 = dp.CreateTopic("Data_DataTest", support.TypeName, topicQos);

            //			ErrorCode errorCode;
            //			string msg;
            //			result = ErrorInfo.Update();
            //			result = ErrorInfo.GetCode(out errorCode);
            //			result = ErrorInfo.GetMessage(out msg);

            // Create a DataWriter for the topic
            Data.IDataTestDataWriter dataWriter = publisher.CreateDataWriter(topic) as Data.IDataTestDataWriter;

            // Create a SubscriberQos object and set the partition name
            SubscriberQos subscriberQos = null;
            result = dp.GetDefaultSubscriberQos(ref subscriberQos);
            subscriberQos.Partition.Name = new string[] { "howdy" };

            // Create the subscriber
            ISubscriber sub = dp.CreateSubscriber(subscriberQos);
            // Verify that the subsciber was created...
            if (sub == null)
            {
                Console.WriteLine("Subscriber not created");
                return;
            }

            DDS.DataReaderQos readerQos = null;
            sub.GetDefaultDataReaderQos(ref readerQos);

            //readerQos.SubscriptionKeys.KeyList = new string[] { "test" };
            //readerQos.Durability.Kind = DurabilityQosPolicyKind.TransientDurabilityQos;
            //readerQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;

            // Create a DataReader for the Detection topic
            Data.IDataTestDataReader dataReader = sub.CreateDataReader(topic, readerQos, this, StatusKind.DataAvailable)
                                                  as Data.IDataTestDataReader;

            // Create a filtered detection topic (only read detections that have an id != 4)
            IContentFilteredTopic filteredTopic = dp.CreateContentFilteredTopic("Another", topic, "TestId <> %0", "4");

            string[] testParams = null;
            result = filteredTopic.GetExpressionParameters(ref testParams);
            result = filteredTopic.SetExpressionParameters("hello", "test");
            result = filteredTopic.GetExpressionParameters(ref testParams);

            // Create a DataReader to read the filtered topic
            IDataReader reader2 = sub.CreateDataReader(filteredTopic);

            IQueryCondition queryCondition = dataReader.CreateQueryCondition(
                "TestId = %0",
                "234");

            // just for testing...
            //GC.Collect();

            // WaitSet
            WaitSet waitSet = new WaitSet();

            // either use status conditions...or
            IStatusCondition sc = reader2.StatusCondition;
            sc.SetEnabledStatuses(StatusKind.DataAvailable);
            waitSet.AttachCondition(sc);

            IStatusCondition sc2 = reader2.StatusCondition;

            // read conditions...
            // IReadCondition readCond = reader2.CreateReadCondition();
            // waitSet.AttachCondition(readCond);

            ICondition[] cond = null;
            //waitSet.Wait(ref cond, Duration.Infinite);


            Console.WriteLine("Press enter to write data");
            Console.ReadLine();

            detectionData.SequenceTest = new int[1];// new System.Collections.Generic.List<int>();
            //detectionData.SequenceTest.Add(4);
            detectionData.SequenceTest[0] = 4;

            // Write detection data
            result = dataWriter.Write(detectionData);

            detectionData        = new Data.DataTest();
            detectionData.TestId = 234;
            dataWriter.Write(detectionData, InstanceHandle.Nil);

            detectionData        = new Data.DataTest();
            detectionData.TestId = 235;
            dataWriter.Write(detectionData);

            detectionData        = new Data.DataTest();
            detectionData.TestId = 236;
            dataWriter.Write(detectionData);

            detectionData        = new Data.DataTest();
            detectionData.TestId = 237;
            dataWriter.Write(detectionData);

            Console.WriteLine("Press enter to read data");
            Console.ReadLine();

            // Read the data
            SampleInfo[]    infos      = null;
            Data.DataTest[] dataValues = null;

//            result = dataReader.ReadWithCondition(ref dataValues, ref infos, DDS.Length.Unlimited, queryCondition);

            result = dataReader.Read(ref dataValues, ref infos);
            Console.WriteLine("dataReader: {0}", dataReader);

            if (dataValues != null)
            {
                Console.WriteLine("Number of samples received: {0}", dataValues.Length);
                for (int index = 0; index < dataValues.Length; index++)
                {
                    Console.WriteLine("TestId: {0}, ProviderId: {1}, Emergency: {2}, TestStr: {3}", dataValues[index].TestId,
                                      dataValues[index].ProviderId, dataValues[index].Emergency, dataValues[index].TestStr);
                    Console.WriteLine("info: ValidData: {0},  InstHandle: {1},  PubHandle:{2},  SourceTS: {3}, ArrivalTS: {4}, sample: {5}, view: {6}, instance: {7}",
                                      infos[index].ValidData,
                                      infos[index].InstanceHandle, infos[index].PublicationHandle,
                                      infos[index].SourceTimestamp, infos[index].ArrivalTimestamp,
                                      infos[index].SampleState, infos[index].ViewState, infos[index].InstanceState);
                }
            }
            Console.WriteLine("Press enter to cleanup");
            Console.ReadLine();

            Console.WriteLine("DeleteContainedEntities");
            result = dp.DeleteContainedEntities();

            // If you don't use DeleteContainedEntities then you must delete everything that was created
            //result = sub.DeleteDataReader(dataReader);
            //result = publisher.DeleteDataWriter(dataWriter);

            //result = dp.DeleteTopic(topic);
            //result = dp.DeletePublisher(publisher);

            //result = dp.DeleteSubscriber(sub);

            Console.WriteLine("DeleteParticipant");
            result = dpf.DeleteParticipant(dp);

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }