예제 #1
0
            public SnapshotCallback(WaitHandle waitHandle)
            {
                this.waitHandle = waitHandle;
                if (waitHandle == null)
                {
                    throw new ArgumentNullException("waitHandle");
                }

                listener = new DataReaderListener <TDataType>(this, true);
            }
예제 #2
0
            public Callback(AdapterDataCallback <TDataType> clientCallback)
            {
                if (isDisposed)
                {
                    return;
                }

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

                this.clientCallback = clientCallback;
                listener            = new DataReaderListener <TDataType>(this, false);
            }
예제 #3
0
        private void CreateDataReader(AdapterReaderQos desiredQos, DataReaderListener <T> listener,
                                      int waitForHistoricalData)
        {
            if (partitionName.Contains("*"))
            {
                partitionName.Replace("*", string.Empty);
            }

            if (dataReader != null)
            {
                if (listener != null)
                {
                    ReturnCode status = dataReader.SetListener(
                        listener, StatusKind.DataAvailable | StatusKind.SampleLost | StatusKind.SampleRejected);
                    ErrorHandler.CheckStatus(status, "Subscriber.SetListener (CreateDataReader)");
                }
            }
            else
            {
                // Create a DataReader for the Topic
                // (using the appropriate QoS) and attach a listener to the data reader on new data available
                var dataReaderQos = new DataReaderQos();
                topicSubscriber.CopyFromTopicQos(ref dataReaderQos, currentTopic.TopicQos);

                if (desiredQos != null)
                {
                    dataReaderQos.Durability.Kind  = desiredQos.PersistenceType.ConvertPersistence();
                    dataReaderQos.Reliability.Kind = desiredQos.MessageReliabilityType.ConvertReliability();
                }

                dataReader = topicSubscriber.CreateDataReader(
                    currentTopic.TopicMessageTopic,
                    dataReaderQos,
                    listener,
                    StatusKind.DataAvailable);

                ErrorHandler.CheckHandle(
                    dataReader, "Subscriber.CreateDatareader (CreateDataReader)");

                dataReader.WaitForHistoricalData(new Duration(waitForHistoricalData, 0));
            }
        }
예제 #4
0
        public void subscribe()
        {
            listener = new DataReaderListener(demultiplexer);
            DDS.DataReader reader = null;
            if (cftTopic != null)
            {
                reader = subscriber.create_datareader(cftTopic,
                                                      DDS.Subscriber.DATAREADER_QOS_DEFAULT, listener, DDS.StatusMask.STATUS_MASK_ALL);
            }
            else
            {
                reader = subscriber.create_datareader(topic,
                                                      DDS.Subscriber.DATAREADER_QOS_DEFAULT, listener, DDS.StatusMask.STATUS_MASK_ALL);
            }

            if (reader == null)
            {
                listener = null;
                throw new ApplicationException("create_datareader error");
            }
        }
예제 #5
0
        private void initializeDataReader(DDS.DomainParticipant participant)
        {
            DDS.Subscriber subscriber = participant.create_subscriber(
                DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (subscriber == null)
            {
                throw new ApplicationException("create_subscriber error");
            }

            DDS.Topic topic = participant.create_topic(
                _topicName,
                _typeName,
                DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (topic == null)
            {
                throw new ApplicationException("create_topic error");
            }

            _listener = new DataReaderListener(_subject, _scheduler);

            /* To customize the data reader QoS, use
             * the configuration file USER_QOS_PROFILES.xml */
            DDS.DataReader reader = subscriber.create_datareader(
                topic,
                DDS.Subscriber.DATAREADER_QOS_DEFAULT,
                _listener,
                DDS.StatusMask.STATUS_MASK_ALL);

            if (reader != null)
            {
                return;
            }
            _listener = null;
            throw new ApplicationException("create_datareader error");
        }
예제 #6
0
        private void InitializeDDS()
        {
            //string id = usuario.Id;
            string id = "0";

            int.TryParse(id, out domainId);


            // Create the DomainFactory
            factory = DomainParticipantFactory.GetInstance(Bootstrap.CreateInstance());
            // Create the DomainParticipant with reference to the configuration file with the domain ID
            dp = factory.CreateParticipant(domainId);
            // Console.WriteLine("Domain ID = {0} has been created", domainId);
            // Implicitly create TypeSupport and register type:
            tp = dp.CreateTopic <ChatMessage>("Greetings Topic");
            // Create the subscriber
            sub = dp.CreateSubscriber();
            // Create a Listener for the publishing data
            ls = new MyListener(backgroundWorker1, backgroundWorker2, backgroundWorker3, backgroundWorker4, backgroundWorker5,
                                backgroundWorker6);
            ls2 = new MyListener2();
            // Create the DataReader using the topic, politics of QoS for DataReader and implemented listener
            dr = sub.CreateDataReader <ChatMessage>(tp,
                                                    sub.GetDefaultDataReaderQos(),
                                                    ls,
                                                    null);



            // Create the publisher
            pub = dp.CreatePublisher();
            // Create the DataWriter using the topic specified
            //dw = pub.CreateDataWriter(tp);

            dw = pub.CreateDataWriter <ChatMessage>(tp,
                                                    pub.GetDefaultDataWriterQos(),
                                                    ls2,
                                                    null);
        }
예제 #7
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);
        }
예제 #8
0
        public void subscribe()
        {
            DDS.Subscriber subscriber = participant.create_subscriber(
                DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (subscriber == null)
            {
                throw new ApplicationException("create_subscriber error");
            }

            DDS.Topic topic = participant.create_topic(
                topicName,
                typeName,
                DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (topic == null)
            {
                throw new ApplicationException("create_topic error");
            }

            listener = new DataReaderListener(demultiplexer);


            DDS.DataReader reader = subscriber.create_datareader(
                topic,
                DDS.Subscriber.DATAREADER_QOS_DEFAULT,
                listener,
                DDS.StatusMask.STATUS_MASK_ALL);

            if (reader == null)
            {
                listener = null;
                throw new ApplicationException("create_datareader error");
            }
        }