예제 #1
0
        public static DDS.TypedDataWriter <T> CreateDataWriter <T>(string topicName,
                                                                   string typeName)
        {
            DDS.DomainParticipant participant = Instance;

            DDS.Publisher publisher = participant.create_publisher(
                DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);

            if (publisher == null)
            {
                throw new ApplicationException("create_publisher 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");
            }

            /* DDS.DataWriterQos dw_qos = new DDS.DataWriterQos();
             * participant.get_default_datawriter_qos(dw_qos);
             * dw_qos.reliability.kind = DDS.ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
             * dw_qos.history.kind = DDS.HistoryQosPolicyKind.KEEP_ALL_HISTORY_QOS;*/
            DDS.DataWriterQos dw_qos = new DDS.DataWriterQos();
            participant.get_default_datawriter_qos(dw_qos);
            //Console.WriteLine("LIB CODE DW QOS: " + dw_qos.history.kind);
            //Console.WriteLine("LIB CODE DW QOS: " + dw_qos.reliability.kind);

            DDS.DataWriter writer = publisher.create_datawriter(
                topic,
                DDS.Publisher.DATAWRITER_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (writer == null)
            {
                throw new ApplicationException("create_datawriter error");
            }

            return((DDS.TypedDataWriter <T>)writer);
        }