Exemplo n.º 1
0
        static void Main(string[] args)
        {
            _dpf = DomainParticipantFactory.Instance;
            ErrorHandler.checkHandle(_dpf, "Domain Participant Factory");

            _dp = _dpf.CreateParticipant(Domain);

            //Initialize QOS
            pQos  = new PublisherQos();
            dwQos = new DataWriterQos();

            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 Publisher QOS and Set Partition Name
            _dp.GetDefaultPublisherQos(ref pQos);
            pQos.Partition.Name    = new String[1];
            pQos.Partition.Name[0] = PartitionName;

            //Create Subscriber for FDMDATA Topic
            Publisher = _dp.CreatePublisher(pQos);
            ErrorHandler.checkHandle(Publisher, "Cannot Create FDMDATA Publisher");

            //Get Data Writer QOS and Set History Depth
            Publisher.GetDefaultDataWriterQos(ref dwQos);
            ErrorHandler.checkHandle(dwQos, "Cannot get Data Writer Qos");
            dwQos.History.Depth    = 5;
            dwQos.Reliability.Kind = ReliabilityQosPolicyKind.BestEffortReliabilityQos;


            //Create DataReader for FDMDATA Topic
            parentWriter = Publisher.CreateDataWriter(fdmDataTopic, dwQos);
            ErrorHandler.checkHandle(parentWriter, "Cannot Create FDMDATA Data Writer");

            //Narrow abstract parentWriter into its typed representative
            fdmDataWriter = parentWriter as FDMDataWriter;
            ErrorHandler.checkHandle(fdmDataWriter, "Cannot Narrow FDMDATA Data Writer");

            fdmData = new FDM();
            while (true)
            {
                StartPublish();
                Console.WriteLine("Publishing data! ");
                Thread.Sleep(10);
            }
        }
Exemplo n.º 2
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());
            }
        }
Exemplo n.º 3
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);
        }