コード例 #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);
        }
コード例 #2
0
        private void initializeDataReader(DDS.DomainParticipant participant)
        {
            DDS.Subscriber subscriber = participant.create_subscriber(
                DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
                null,
                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,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (topic == null)
            {
                throw new ApplicationException("create_topic error");
            }

            _listener = new InstanceDataReaderListener(
                _groupSubject, _keyedSubjectDict, _keySelector, _comparer, _handleKeyDict, _scheduler,
                _externalSubDict);

            DDS.DataReaderQos rQos = new DDS.DataReaderQos();
            participant.get_default_datareader_qos(rQos);
            //Console.WriteLine("LIB CODE DR QOS: " + r_qos.history.kind);
            //Console.WriteLine("LIB CODE DR QOS: " + r_qos.reliability.kind);

            DDS.DataReader reader = subscriber.create_datareader(
                topic,
                rQos, //DDS.Subscriber.DATAREADER_QOS_DEFAULT,
                _listener,
                DDS.StatusMask.STATUS_MASK_ALL);
            if (reader != null)
            {
                return;
            }
            _listener = null;
            throw new ApplicationException("create_datareader error");
        }
コード例 #3
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");
        }
コード例 #4
0
        static void publish(int domain_id, String file_name)
        {
            // --- Create participant --- //

            /* To customize participant QoS, use
             * the configuration file USER_QOS_PROFILES.xml */
            DDS.DomainParticipant participant =
                DDS.DomainParticipantFactory.get_instance().create_participant(
                    domain_id,
                    DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                    null,
                    DDS.StatusMask.STATUS_MASK_NONE);
            if (participant == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_participant error");
            }

            // --- Create publisher --- //

            /* To customize publisher QoS, use
             * the configuration file USER_QOS_PROFILES.xml */
            DDS.Publisher publisher = participant.create_publisher(
                DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (publisher == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_publisher error");
            }

            // --- Create topic --- //

            /* Register type before creating topic */
            System.String type_name = SensorDataTypeSupport.get_type_name();
            try {
                SensorDataTypeSupport.register_type(
                    participant, type_name);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("register_type error {0}", e);
                shutdown(participant);
                throw e;
            }

            /* To customize topic QoS, use
             * the configuration file USER_QOS_PROFILES.xml */
            DDS.Topic topic = participant.create_topic(
                "Raw SensorData",
                type_name,
                DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (topic == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_topic error");
            }

            // --- Create writer --- //

            /* To customize data writer QoS, use
             * the configuration file USER_QOS_PROFILES.xml */
            DDS.DataWriter writer = publisher.create_datawriter(
                topic,
                DDS.Publisher.DATAWRITER_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (writer == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_datawriter error");
            }
            SensorDataDataWriter SensorData_writer =
                (SensorDataDataWriter)writer;

            // --- Write --- //

            /* Create data sample for writing */
            SensorData instance = SensorDataTypeSupport.create_data();

            if (instance == null)
            {
                shutdown(participant);
                throw new ApplicationException(
                          "SensorDataTypeSupport.create_data error");
            }

            /* For a data type that has a key, if the same instance is going to be
             * written multiple times, initialize the key here
             * and register the keyed instance prior to writing */
            DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

            //wait for all data-readers to join before publishing:
            while (!wait_for_readers(writer, no_dr))
            {
            }
            System.Threading.Thread.Sleep(1000);
            Console.WriteLine("datareaders have connected. starting to publish");
            bool myparse = true;

            /* Main loop */
            using (StreamReader sReader = new StreamReader(file_name))
            {
                String line;
                publication_sw.Start();
                start_ticks = publication_sw.ElapsedTicks;
                prev_ticks  = start_ticks;
                int[] ballSensors = { 4, 8, 10, 12 };

                while ((line = sReader.ReadLine()) != null && count < max_samples)
                {
                    try
                    {
                        linesRead++;
                        if (myparse)
                        {
                            int pos = 0;
                            instance.sensor_id = myParseInt32(line, ref pos);
                            //if (ballSensors.Contains(instance.sensor_id))
                            //    continue;
                            instance.ts      = myParseLong(line, ref pos);
                            instance.pos_x   = myParseInt32(line, ref pos);
                            instance.pos_y   = myParseInt32(line, ref pos);
                            instance.pos_z   = myParseInt32(line, ref pos);
                            instance.vel     = myParseInt32(line, ref pos);
                            instance.accel   = myParseInt32(line, ref pos);
                            instance.vel_x   = myParseInt32(line, ref pos);
                            instance.vel_y   = myParseInt32(line, ref pos);
                            instance.vel_z   = myParseInt32(line, ref pos);
                            instance.accel_x = myParseInt32(line, ref pos);
                            instance.accel_y = myParseInt32(line, ref pos);
                            instance.accel_z = myParseInt32(line, ref pos);

                            /*
                             * Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}",
                             *  instance.sensor_id,
                             *  instance.ts,
                             *  instance.pos_x,
                             *  instance.pos_y,
                             *  instance.pos_z,
                             *  instance.vel,
                             *  instance.accel,
                             *  instance.vel_x,
                             *  instance.vel_y,
                             *  instance.vel_z,
                             *  instance.accel_x,
                             *  instance.accel_y,
                             *  instance.accel_z);
                             */
                        }
                        else
                        {
                            String[] fields = line.Split(',');

                            instance.sensor_id = Int32.Parse(fields[0]);
                            if (ballSensors.Contains(instance.sensor_id))
                            {
                                continue;
                            }

                            instance.ts      = Int64.Parse(fields[1]);
                            instance.pos_x   = Int32.Parse(fields[2]);
                            instance.pos_y   = Int32.Parse(fields[3]);
                            instance.pos_z   = Int32.Parse(fields[4]);
                            instance.vel     = Int32.Parse(fields[5]);
                            instance.accel   = Int32.Parse(fields[6]);
                            instance.vel_x   = Int32.Parse(fields[7]);
                            instance.vel_y   = Int32.Parse(fields[8]);
                            instance.vel_z   = Int32.Parse(fields[9]);
                            instance.accel_x = Int32.Parse(fields[10]);
                            instance.accel_y = Int32.Parse(fields[11]);
                            instance.accel_z = Int32.Parse(fields[12]);
                        }
                        count++;
                        SensorData_writer.write(instance, ref instance_handle);
                        if (count % calculation_point == 0)
                        {
                            long curr_ticks = publication_sw.ElapsedTicks;
                            ncalcs++;
                            long lapse_ticks = curr_ticks - prev_ticks;

                            double lapse_msec = (double)lapse_ticks * ns_per_tick / (1000.0 * 1000.0);
                            sum_lapse_msec += lapse_msec;
                            if (lapse_msec < min_lapse)
                            {
                                min_lapse = lapse_msec;
                            }
                            if (lapse_msec > max_lapse)
                            {
                                max_lapse = lapse_msec;
                            }
                            prev_ticks = curr_ticks;

                            Console.WriteLine("Took {0} millisec to send next {1} samples: {2}",
                                              lapse_msec, calculation_point, count);

                            double rate = (double)(calculation_point * 1000L * 1000L * 1000L) / (double)(lapse_ticks * ns_per_tick);
                            if (rate < min_rate)
                            {
                                min_rate = rate;
                            }
                            if (rate > max_rate)
                            {
                                max_rate = rate;
                            }
                            Console.WriteLine("publishing rate:{0} samples/sec", rate);
                        }
                    }
                    catch (DDS.Exception e)
                    {
                        Console.WriteLine("write error {0}", e);
                    }

                    if ((target_rate != 0) && (count % 1000 == 0))
                    {
                        //double calib = 0.7;
                        //if(calibrationDict.ContainsKey(target_rate))
                        //    calib = calibrationDict[target_rate];

                        System.Threading.Thread.Sleep(1000 * 1000 / target_rate * 30 / 100);
                    }
                }
                end_ticks = publication_sw.ElapsedTicks;
                publication_sw.Stop();
            }

            Console.WriteLine("Playback finished.. " + count);
            // --- Shutdown --- //
            double total_time_ms = (end_ticks - start_ticks) * ns_per_tick / 1000 / 1000;
            double rate_pub      = (double)count / total_time_ms;

            Console.WriteLine("Target rate = {0} samples/sec.", target_rate);
            Console.WriteLine("Overall Publication Rate Observed: {0} per sec", rate_pub * 1000);
            Console.WriteLine("total time for playback in seconds: {0}", total_time_ms / 1000);
            Console.WriteLine("lines read = {0}, samples written = {1}", linesRead, count);

            /* Delete data sample */
            try {
                SensorData_writer.dispose(instance, ref instance_handle);
                System.Threading.Thread.Sleep(10000);
                SensorDataTypeSupport.delete_data(instance);
            }
            catch (DDS.Exception e) {
                Console.WriteLine(
                    "SensorDataTypeSupport.delete_data error: {0}", e);
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
            using (StreamWriter file = new StreamWriter("publisher_output.txt"))
            {
                file.WriteLine("Publisher summary statistics:\n");
                file.WriteLine("Sent {0} samples in {1} seconds", count, total_time_ms / 1000);
                file.WriteLine("\nAverage rate of publishing: {0} samples/sec", count / total_time_ms / 1000);
                file.WriteLine("Max publishing rate:{0} samples/sec.", max_rate);
                file.WriteLine("Min publishing rate:{0} samples/sec.", min_rate);

                file.WriteLine("\nAverage time taken to publish 10000 samples: {0} sec", (sum_lapse_msec) / (double)ncalcs);
                file.WriteLine("Max time to publish 10000 samples:{0} sec.", max_lapse);
                file.WriteLine("Min time to publish 10000 samples:{0} sec.", min_lapse);
            }

            /* Delete all entities */
            shutdown(participant);
        }
コード例 #5
0
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher_with_profile(
            "ordered_Library", "ordered_Profile_subscriber_instance",
            null /* listener */, DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }


        /* If you want to change the Publisher's QoS programmatically rather
         * than using the XML file, you will need to add the following lines to
         * your code and comment out the create_publisher call above.
         *
         * In this case, we set the presentation publish mode ordered in the
         * topic.
         */

        /* Get default publisher QoS to customize */

/*        DDS.PublisherQos publisher_qos = new DDS.PublisherQos();
 *      participant.get_default_publisher_qos(publisher_qos);
 *
 *      publisher_qos.presentation.access_scope =
 *          DDS.PresentationQosPolicyAccessScopeKind.TOPIC_PRESENTATION_QOS;
 *      publisher_qos.presentation.ordered_access = true;
 *
 *      // --- Create publisher --- //
 *
 *      DDS.Publisher publisher = participant.create_publisher(
 *      publisher_qos, null, DDS.StatusMask.STATUS_MASK_NONE);
 *      if (publisher == null) {
 *          shutdown(participant);
 *          throw new ApplicationException("create_publisher error");
 *      }
 */
        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = orderedTypeSupport.get_type_name();
        try {
            orderedTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example ordered",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create writer --- //

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        orderedDataWriter ordered_writer =
            (orderedDataWriter)writer;

        /* Start changes for Ordered_Presentation */

        /* Create two instances */
        ordered instance0 = null;
        ordered instance1 = null;

        DDS.InstanceHandle_t handle0 = DDS.InstanceHandle_t.HANDLE_NIL;
        DDS.InstanceHandle_t handle1 = DDS.InstanceHandle_t.HANDLE_NIL;



        // --- Write --- //

        /* Create data sample for writing */
        instance0 = orderedTypeSupport.create_data();
        if (instance0 == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "orderedTypeSupport.create_data error");
        }

        instance1 = orderedTypeSupport.create_data();
        if (instance1 == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "orderedTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        instance0.id = 0;
        instance1.id = 1;

        handle0 = ordered_writer.register_instance(instance0);
        handle1 = ordered_writer.register_instance(instance1);

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            instance0.value = count;
            instance1.value = count;

            Console.WriteLine("writing instance0, value->{0}", instance0.value);
            try {
                ordered_writer.write(instance0, ref handle0);
            } catch (DDS.Exception e) {
                Console.WriteLine("write instance0 error {0}", e);
            }

            Console.WriteLine("writing instance1, value->{0}", instance1.value);
            try {
                ordered_writer.write(instance1, ref handle1);
            } catch (DDS.Exception e) {
                Console.WriteLine("write instance1 error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }


        try {
            ordered_writer.unregister_instance(
                instance0, ref handle0);
        } catch (DDS.Exception e) {
            Console.WriteLine("unregister instance0 error: {0}", e);
        }
        try {
            ordered_writer.unregister_instance(
                instance1, ref handle1);
        } catch (DDS.Exception e) {
            Console.WriteLine("unregister instance1 error: {0}", e);
        }

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            orderedTypeSupport.delete_data(instance0);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "orderedTypeSupport.delete_data0 error: {0}", e);
        }
        try {
            orderedTypeSupport.delete_data(instance1);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "orderedTypeSupport.delete_data1 error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #6
0
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        /* Create ande Delete Inconsistent Topic
         * ---------------------------------------------------------------
         * Here we create an inconsistent topic to trigger the subscriber
         * application's callback.
         * The inconsistent topic is created with the topic name used in
         * the Subscriber application, but with a different data type --
         * the msg data type defined in partitions.idl.
         * Once it is created, we sleep to ensure the applications discover
         * each other and delete the Data Writer and Topic.
         */

        /* First we register the msg type -- we name it
         * inconsistent_topic_type_name to avoid confusion.
         */
        Console.WriteLine("Creating Inconsistent Topic...");

        System.String inconsistent_type_name = msgTypeSupport.get_type_name();
        try
        {
            msgTypeSupport.register_type(participant, inconsistent_type_name);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        DDS.Topic inconsistent_topic = participant.create_topic(
            "Example listeners",
            inconsistent_type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (inconsistent_topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        /* We have to associate a writer to the topic, as Topic information is not
         * actually propagated until the creation of an associated writer.
         */
        DDS.DataWriter inconsistent_writer = publisher.create_datawriter(
            inconsistent_topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (inconsistent_writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        msgDataWriter msg_writer = (msgDataWriter)inconsistent_writer;

        // Sleep to leave time for applications to discover each other
        const System.Int32 sleep_period = 2000; //millseconds

        System.Threading.Thread.Sleep(sleep_period);

        try
        {
            publisher.delete_datawriter(ref inconsistent_writer);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("delete_datawriter error {0}", e);
            shutdown(participant);
            return;
        }

        try
        {
            participant.delete_topic(ref inconsistent_topic);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("delete_topic error {0}", e);
            shutdown(participant);
            return;
        }

        Console.WriteLine("... Deleted Inconsistent Topic\n");


        /* Create Consistent Topic
         * -----------------------------------------------------------------
         * Once we have created the inconsistent topic with the wrong type,
         * we create a topic with the right type name -- listeners -- that we
         * will use to publish data.
         */

        /* Register type before creating topic */
        System.String type_name = listenersTypeSupport.get_type_name();
        try
        {
            listenersTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example listeners",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }



        /* We will use the Data Writer Listener defined above to print
         * a message when some of events are triggered in the DataWriter.
         * To do that, first we have to pass the writer_listener and then
         * we have to enable all status in the status mask.
         */
        DataWriterListener writer_listener = new DataWriterListener();

        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            writer_listener /* listener */,
            DDS.StatusMask.STATUS_MASK_ALL /* get all statuses */);
        if (writer == null)
        {
            shutdown(participant);
            writer_listener = null;
            throw new ApplicationException("create_datawriter error");
        }
        listenersDataWriter listeners_writer =
            (listenersDataWriter)writer;

        // --- Write --- //

        /* Create data sample for writing */
        listeners instance = listenersTypeSupport.create_data();

        if (instance == null)
        {
            shutdown(participant);
            writer_listener = null;
            throw new ApplicationException(
                      "listenersTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = listeners_writer.register_instance(instance);
         */

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine("Writing listeners, count {0}", count);

            /* Modify the data to be sent here */
            instance.x = (short)count;

            try
            {
                listeners_writer.write(instance, ref instance_handle);
            }
            catch (DDS.Exception e)
            {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  listeners_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try
        {
            listenersTypeSupport.delete_data(instance);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine(
                "listenersTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
        writer_listener = null;
    }
コード例 #7
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = queryconditionTypeSupport.get_type_name();
        try {
            queryconditionTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example querycondition",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //


        /* 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,
            null,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datareader error");
        }

        /* If you want to change datareader_qos.history programmatically rather
         * than using the XML file, you will need to add the following lines to your
         * code and comment out the create_datareader call above. */

        /*DDS.DataReaderQos reader_qos = new DDS.DataReaderQos();
         * subscriber.get_default_datareader_qos(reader_qos);
         *
         * reader_qos.history.kind = DDS.HistoryQosPolicyKind.KEEP_LAST_HISTORY_QOS;
         * reader_qos.history.depth = 6;
         *
         * DDS.DataReader reader = subscriber.create_datareader(
         *  topic,
         *  reader_qos,
         *  reader_listener,
         *  DDS.StatusMask.STATUS_MASK_ALL);
         * if (reader == null)
         * {
         *  shutdown(participant);
         *  reader_listener = null;
         *  throw new ApplicationException("create_datareader error");
         * } */

        // --- Wait for data --- //

        /* NOTE: There must be single-quotes in the query parameters around
         * any strings!  The single-quotes do NOT go in the query condition
         * itself.
         */
        DDS.QueryCondition query_for_guid2;

        DDS.StringSeq query_parameters = new DDS.StringSeq();
        query_parameters.ensure_length(1, 1);
        query_parameters.set_at(0, "'GUID2'");

        queryconditionDataReader querycondition_reader =
            (queryconditionDataReader)reader;

        query_for_guid2 = querycondition_reader.create_querycondition(
            DDS.SampleStateKind.ANY_SAMPLE_STATE,
            DDS.ViewStateKind.ANY_VIEW_STATE,
            DDS.InstanceStateKind.ALIVE_INSTANCE_STATE,
            "id MATCH %0",
            query_parameters);

        /* Main loop */
        const System.Int32 receive_period = 4000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            System.Threading.Thread.Sleep(receive_period);

            queryconditionSeq data_seq = new queryconditionSeq();
            DDS.SampleInfoSeq info_seq = new DDS.SampleInfoSeq();

            try
            {
                querycondition_reader.read_w_condition(
                    data_seq,
                    info_seq,
                    DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                    query_for_guid2);
            }
            catch (DDS.Retcode_NoData e)
            {
                continue;
            }
            catch (DDS.Exception e)
            {
                shutdown(participant);
                throw e;
            }

            int    len = 0;
            double sum = 0;

            /* Iterate through the samples read using the read_w_condition() method,
             * accessing only the samples of GUID2.  Then, show the number of samples
             * received and, adding the value of x on each of them to calculate the
             * average afterwards. */
            for (int i = 0; i < data_seq.length; ++i)
            {
                if (!info_seq.get_at(i).valid_data)
                {
                    continue;
                }
                len++;
                sum += data_seq.get_at(i).value;
                Console.WriteLine("Guid = {0}\n", data_seq.get_at(i).id);
            }

            if (len > 0)
            {
                Console.WriteLine("Got {0} samples.  Avg = {1}\n", len, sum / len);
            }
            try
            {
                querycondition_reader.return_loan(data_seq, info_seq);
            }
            catch (DDS.Exception e)
            {
                Console.WriteLine("return loan error {0}", e);
            }
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #8
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = deadline_contentfilterTypeSupport.get_type_name();
        try {
            deadline_contentfilterTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example deadline_contentfilter",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //

        //// Start changes for Deadline
        // Set up content filtered topic to show interaction with deadline
        DDS.StringSeq parameters = new DDS.StringSeq(1);
        // need to specify length otherwise create_contentfilteredtopic will
        // throw an unhandled exception error!
        if (parameters.ensure_length(1, 1) == false)
        {
            Console.WriteLine("ensure_length error\n");
        }
        parameters.set_at(0, "2");

        DDS.ContentFilteredTopic cft = participant.create_contentfilteredtopic(
            "ContentFilteredTopic", topic, "code < %0", parameters);

        /* Create a data reader listener */
        deadline_contentfilterListener reader_listener =
            new deadline_contentfilterListener();

        /* To customize the data reader QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataReader reader = subscriber.create_datareader(
            cft,
            DDS.Subscriber.DATAREADER_QOS_DEFAULT,
            reader_listener,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new ApplicationException("create_datareader error");
        }


        /* If you want to change the DataReader's QoS programmatically rather than
         * using the XML file, you will need to add the following lines to your
         * code and comment out the create_datareader call above.
         *
         * In this case, we set the deadline period to 2 seconds to trigger
         * a deadline if the DataWriter does not update often enough, or if
         * the content-filter filters out data so there is no data available
         * with 2 seconds.
         */

        /*
         * DDS.DataReaderQos datareader_qos = new DDS.DataReaderQos();
         * subscriber.get_default_datareader_qos(datareader_qos);
         * if (datareader_qos == null)
         * {
         *  shutdown(participant);
         *  reader_listener = null;
         *  throw new ApplicationException("get_default_datareader_qos error");
         * }
         *
         * // Set deadline QoS to be 2 sec
         * datareader_qos.deadline.period.sec = 2;
         * datareader_qos.deadline.period.nanosec = 0;
         *
         * DDS.DataReader reader = subscriber.create_datareader(
         *  topic,
         *  datareader_qos, //DDS.Subscriber.DATAREADER_QOS_DEFAULT,
         *  reader_listener,
         *  DDS.StatusMask.STATUS_MASK_ALL);
         * if (reader == null)
         * {
         *  shutdown(participant);
         *  reader_listener = null;
         *  throw new ApplicationException("create_datareader error");
         * }
         */

        // --- Wait for data --- //

        /* Main loop */
        const System.Int32 receive_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            // After 10 seconds, change content filter to accept only
            // instance 0

            if (count == 10)
            {
                Console.WriteLine("Starting to filter out instance1\n");
                parameters.set_at(0, "1");
                cft.set_expression_parameters(parameters);
            }
            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }
コード例 #9
0
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        /* If you want to change the type_code_max_serialized_length
         * programmatically (e.g., to 3070) rather than using the XML file, you
         * will need to add the following lines to your code and comment out the
         * create_participant call above. */

        /*
         * DDS.DomainParticipantQos participant_qos =
         *  new DDS.DomainParticipantQos();
         * try {
         *  DDS.DomainParticipantFactory.get_instance().
         *      get_default_participant_qos(participant_qos);
         *
         * } catch (DDS.Exception) {
         *  Console.WriteLine("error in participant_qos");
         * }
         *
         * participant_qos.resource_limits.type_code_max_serialized_length = 3070;
         *
         * try {
         *  DDS.DomainParticipantFactory.get_instance().delete_participant(
         *      ref participant);
         * }
         * catch (DDS.Exception) {
         *  Console.WriteLine("error deleting participant");
         * }
         *
         * participant =
         *  DDS.DomainParticipantFactory.get_instance().create_participant(
         *  domain_id, participant_qos, null, DDS.StatusMask.STATUS_MASK_NONE);
         */

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = msgTypeSupport.get_type_name();
        try {
            msgTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example msg",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create writer --- //

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        msgDataWriter msg_writer =
            (msgDataWriter)writer;

        // --- Write --- //

        /* Create data sample for writing */
        msg instance = msgTypeSupport.create_data();

        if (instance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "msgTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = msg_writer.register_instance(instance);
         */

        /* Main loop */
        const System.Int32 send_period = 4000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine("Writing msg, count {0}", count);

            /* Modify the data to be sent here */
            instance.count = count;

            try {
                msg_writer.write(instance, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  msg_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            msgTypeSupport.delete_data(instance);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "msgTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #10
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* Create participant listener */
        ParticipantListener participant_listener = new ParticipantListener();

        /* We associate the participant_listener to the participant and set the
         * status mask to get all the statuses */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                participant_listener /* listener */,
                DDS.StatusMask.STATUS_MASK_ALL /* get all statuses */);
        if (participant == null)
        {
            shutdown(participant);
            participant_listener = null;
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* Create subscriber listener */
        SubscriberListener subscriber_listener = new SubscriberListener();

        /* Here we associate the subscriber listener to the subscriber and set the
         * status mask to get all the statuses */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            subscriber_listener /* listener */,
            DDS.StatusMask.STATUS_MASK_ALL /* get all statuses */);
        if (subscriber == null)
        {
            shutdown(participant);
            participant_listener = null;
            subscriber_listener  = null;
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = listenersTypeSupport.get_type_name();
        try {
            listenersTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            participant_listener = null;
            subscriber_listener  = null;
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example listeners",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            participant_listener = null;
            subscriber_listener  = null;
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //

        /* Create a data reader listener */
        ReaderListener reader_listener = new ReaderListener();

        /* Create Status mask to listen just LIVELINESS_CHANGED_STATUS and
         * DATA_AVAILABLE_STATUS */
        int liveliness_changed_mask     = (int)DDS.StatusKind.LIVELINESS_CHANGED_STATUS;
        int data_available_changed_mask = (int)DDS.StatusKind.DATA_AVAILABLE_STATUS;

        data_available_changed_mask |= liveliness_changed_mask;
        DDS.StatusMask combined_status_mask = (DDS.StatusMask)data_available_changed_mask;

        /* Here we associate the data reader listener to the reader.
         * We just listen for liveliness changed and data available,
         * since most specific listeners will get called. */
        DDS.DataReader reader = subscriber.create_datareader(
            topic,
            DDS.Subscriber.DATAREADER_QOS_DEFAULT,
            reader_listener,
            combined_status_mask);
        if (reader == null)
        {
            shutdown(participant);
            participant_listener = null;
            subscriber_listener  = null;
            reader_listener      = null;
            throw new ApplicationException("create_datareader error");
        }

        // --- Wait for data --- //

        /* Main loop */
        const System.Int32 receive_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        participant_listener = null;
        subscriber_listener  = null;
        reader_listener      = null;
    }
コード例 #11
0
        private void initialize()
        {
            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");
            }

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

            if (reader == null)
            {
                throw new ApplicationException("create_datareader error");
            }
            status_condition = reader.get_statuscondition();

            try
            {
                int mask =
                    (int)DDS.StatusKind.DATA_AVAILABLE_STATUS |
                    (int)DDS.StatusKind.SUBSCRIPTION_MATCHED_STATUS |
                    (int)DDS.StatusKind.LIVELINESS_CHANGED_STATUS |
                    (int)DDS.StatusKind.SAMPLE_LOST_STATUS |
                    (int)DDS.StatusKind.SAMPLE_REJECTED_STATUS;

                status_condition.set_enabled_statuses((DDS.StatusMask)mask);
            }
            catch (DDS.Exception e)
            {
                throw new ApplicationException("set_enabled_statuses error {0}", e);
            }

            waitset = new DDS.WaitSet();

            try
            {
                waitset.attach_condition(status_condition);
            }
            catch (DDS.Exception e)
            {
                throw new ApplicationException("attach_condition error {0}", e);
            }
        }
コード例 #12
0
ファイル: msg_subscriber.cs プロジェクト: albenq/RTI
    static void subscribe(int domain_id, int sample_count,
                          String participant_auth)
    {
        // --- Create participant --- //

        /* Start changes for programmatically qos */

        /* Get default participant QoS to customize */
        DDS.DomainParticipantQos participant_qos =
            new DDS.DomainParticipantQos();
        DDS.DomainParticipantFactory.get_instance().
        get_default_participant_qos(participant_qos);

        // If you want to change the Participant's QoS programmatically
        // rather than using the XML file, you will need to uncomment the
        // following line.
        //participant_qos.resource_limits.participant_user_data_max_length = 1024;

        // user_data is opaque to DDS
        int len = participant_auth.Length;
        int max =
            participant_qos.resource_limits.participant_user_data_max_length;

        if (len > max)
        {
            Console.WriteLine(
                "error, participant user_data exceeds resource limits");
        }
        else
        {
            /* Byte type is defined to be 8 bits. If chars are not 8 bits
             * on your system, this will not work.
             */
            participant_qos.user_data.value.from_array(
                System.Text.Encoding.ASCII.GetBytes(participant_auth));
        }

        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                participant_qos,
                null,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new Exception("create_participant error");
        }

        /* End changes for programmatically qos */

        /* The participant is disabled by default. We enable it now */
        try {
            participant.enable();
        } catch (DDS.Exception e) {
            Console.WriteLine("failed to enable participant {0}", e);
            shutdown(participant);
            throw e;
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new Exception("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = msgTypeSupport.get_type_name();
        try {
            msgTypeSupport.register_type(participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example msg",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new Exception("create_topic error");
        }

        // --- Create reader --- //

        /* Create a data reader listener */
        msgListener reader_listener = new msgListener();

        /* 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,
            reader_listener,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new Exception("create_datareader error");
        }

        // --- Wait for data --- //

        /* Main loop */
        const int receive_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }
コード例 #13
0
ファイル: cfc_publisher.cs プロジェクト: albenq/RTI
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        /* Start changes for custom_flowcontroller */

        /* If you want to change the Participant's QoS programmatically rather
         * than using the XML file, you will need to add the following lines to
         * your code and comment out the create_participant call above.
         */
        /* Get default participant QoS to customize */

/*        DDS.DomainParticipantQos participant_qos =
 *              new DDS.DomainParticipantQos();
 *
 *      try {
 *          DDS.DomainParticipantFactory.get_instance().
 *              get_default_participant_qos(participant_qos);
 *      } catch (DDS.Exception e) {
 *          Console.WriteLine("get_default_participant_qos error {0}", e);
 *          throw e;
 *      }
 *
 *      // By default, data will be sent via shared memory _and_ UDPv4.  Because
 *      // the flowcontroller limits writes across all interfaces, this halves
 *      // the effective send rate.  To avoid this, we enable only the UDPv4
 *      // transport
 *
 *      participant_qos.transport_builtin.mask =
 *              (int) DDS.TransportBuiltinKind.TRANSPORTBUILTIN_UDPv4;
 *
 *      // To create participant with default QoS,
 *      // use DDS_PARTICIPANT_QOS_DEFAULT instead of participant_qos
 *      DDS.DomainParticipant participant =
 *          DDS.DomainParticipantFactory.get_instance().create_participant(
 *              domain_id,
 *              participant_qos,
 *              null,
 *              DDS.StatusMask.STATUS_MASK_NONE);
 *      if (participant == null) {
 *          shutdown(participant);
 *          throw new ApplicationException("create_participant error");
 *      }
 */
        /* End changes for custom_flow_controller */

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = cfcTypeSupport.get_type_name();
        try {
            cfcTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example cfc",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create writer --- //

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }

        /* Start changes for custom_flowcontroller */

        /* If you want to change the Datawriter's QoS programmatically rather
         * than using the XML file, you will need to add the following lines to
         * your code and comment out the create_datawriter call above.
         *
         * In this case we create the flowcontroller and the neccesary QoS
         * for the datawriter.
         */
/*
 *      DDS.FlowControllerProperty_t custom_fcp =
 *          new DDS.FlowControllerProperty_t();
 *      try {
 *          participant.get_default_flowcontroller_property(custom_fcp);
 *      } catch (DDS.Exception e) {
 *          Console.WriteLine("get_default_flowcontroller_property error {0}",
 *                  e);
 *          shutdown(participant);
 *          throw e;
 *      }
 *
 *      // Don't allow too many tokens to accumulate
 *      custom_fcp.token_bucket.max_tokens =
 *          custom_fcp.token_bucket.tokens_added_per_period = 2;
 *
 *      custom_fcp.token_bucket.tokens_leaked_per_period =
 *          DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED;
 *
 *      //100 ms
 *      custom_fcp.token_bucket.period.sec = 0;
 *      custom_fcp.token_bucket.period.nanosec = 100000000;
 *
 *      // The sample size is 1000, but the minimum bytes_per_token is 1024.
 *      // Furthermore, we want to allow some overhead.
 *      custom_fcp.token_bucket.bytes_per_token = 1024;
 *
 *      // So, in summary, each token can be used to send about one message,
 *      // and we get 2 tokens every 100ms, so this limits transmissions to
 *      // about 20 messages per second.
 *
 *      // Create flowcontroller and set properties
 *      String cfc_name = "custom_flowcontroller";
 *      DDS.FlowController cfc = participant.create_flowcontroller(
 *          cfc_name, custom_fcp);
 *      if (cfc == null) {
 *          shutdown(participant);
 *          throw new ApplicationException("create_flowcontroller error");
 *      }
 *
 *      //Get default datawriter QoS to customize
 *      DDS.DataWriterQos datawriter_qos = new DDS.DataWriterQos();
 *
 *      try {
 *          publisher.get_default_datawriter_qos(datawriter_qos);
 *      } catch (DDS.Exception e) {
 *          Console.WriteLine("get_default_datawriter_qos error {0}", e);
 *          shutdown(participant);
 *          throw e;
 *      }
 *
 *      // As an alternative to increasing h istory depth, we can just
 *      // set the qos to keep all samples
 *      datawriter_qos.history.kind =
 *              DDS.HistoryQosPolicyKind.KEEP_ALL_HISTORY_QOS;
 *
 *      // Set flowcontroller for datawriter
 *      datawriter_qos.publish_mode.kind =
 *          DDS.PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS;
 *      datawriter_qos.publish_mode.flow_controller_name = cfc_name;
 *
 *      // To create a datawriter with default QoS, use
 *      // DDS.Publisher.DATAWRITER_QOS_DEFAULT instead of datawriter_qos
 *      DDS.DataWriter writer = publisher.create_datawriter(
 *         topic,
 *         datawriter_qos,
 *         null,
 *         DDS.StatusMask.STATUS_MASK_NONE);
 *      if (writer == null) {
 *          shutdown(participant);
 *          throw new ApplicationException("create_datawriter error");
 *      }
 *
 */
        // End changes for custom_flowcontroller

        cfcDataWriter cfc_writer =
            (cfcDataWriter)writer;

        // --- Write --- //

        /* Create data sample for writing */
        cfc instance = cfcTypeSupport.create_data();

        if (instance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "cfcTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = cfc_writer.register_instance(instance);
         */
        char[] str = new char[1000];
        for (int i = 0; i < 1000; ++i)
        {
            str[i] = 'a';
        }
        String data = new String(str);

        /* Main loop */
        System.Int32 send_period = 1000; // milliseconds
        for (int count = 0;
             (sample_count == 0) || (count < sample_count); ++count)
        {
            // Changes for custom_flowcontroller
            // Simulate bursty writer
            System.Threading.Thread.Sleep(send_period);
            for (int i = 0; i < 10; ++i)
            {
                int sample = count * 10 + i;
                Console.WriteLine("Writing cfc, sample {0}", sample);
                instance.x   = sample;
                instance.str = data;
                try {
                    cfc_writer.write(instance, ref instance_handle);
                } catch (DDS.Exception e) {
                    Console.WriteLine("write error {0}", e);
                }
            }
        }
        //Console.WriteLine("{0}", instance.str);
        send_period = 4000;
        System.Threading.Thread.Sleep(send_period);

        /*
         * try {
         *  cfc_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            cfcTypeSupport.delete_data(instance);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "cfcTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #14
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name =
            waitset_statuscondTypeSupport.get_type_name();
        try {
            waitset_statuscondTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example waitset_statuscond",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //



        /* 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,
            null,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datareader error");
        }

        // Get narrowed datareader
        waitset_statuscondDataReader waitset_reader =
            (waitset_statuscondDataReader)reader;

        /* Get status conditions
         * ---------------------
         * Each entity may have an attached Status Condition. To modify the
         * statuses we need to get the reader's Status Conditions first.
         */
        DDS.StatusCondition status_condition = reader.get_statuscondition();

        /* Set enabled statuses
         * --------------------
         * Now that we have the Status Condition, we are going to enable the
         * status we are interested in: knowing that data is available
         */
        try
        {
            status_condition.set_enabled_statuses(
                (DDS.StatusMask)DDS.StatusKind.DATA_AVAILABLE_STATUS);
        }
        catch (DDS.Exception e)
        {
            shutdown(participant);
            throw new ApplicationException("set_enabled_statuses error {0}",
                                           e);
        }

        /* Create and attach conditions to the WaitSet
         * -------------------------------------------
         * Finally, we create the WaitSet and attach both the Read Conditions
         * and the Status Condition to it.
         */
        DDS.WaitSet waitset = new DDS.WaitSet();


        /* Attach Status Conditions */
        try
        {
            waitset.attach_condition(status_condition);
        }
        catch (DDS.Exception e)
        {
            shutdown(participant);
            throw new ApplicationException("set_enabled_statuses error {0}",
                                           e);
        }
        // --- Wait for data --- //
        int count = 0;

        DDS.Duration_t timeout;
        timeout.nanosec = (uint)500000000;
        timeout.sec     = 1;

        /* Main loop */
        while (sample_count == 0 || count < sample_count)
        {
            DDS.ConditionSeq active_conditions = new DDS.ConditionSeq();

            // The triggered condition(s) will be placed in active_conditions
            try
            {
                waitset.wait(active_conditions, timeout);
                Console.WriteLine("got {0} active conditions", active_conditions.length);

                for (int i = 0; i < active_conditions.length; ++i)
                {
                    /* In this case, we have only a single condition, but
                     *          if we had multiple, we would need to iterate over
                     *          them and check which one is true.  Leaving the logic
                     *          for the more complex case. */
                    if (active_conditions.get_at(i) == status_condition)
                    {
                        DDS.StatusMask triggeredmask =
                            waitset_reader.get_status_changes();

                        if ((triggeredmask &
                             (DDS.StatusMask)
                             DDS.StatusKind.DATA_AVAILABLE_STATUS) != 0)
                        {
                            /* Current conditions match our conditions to read data, so
                             * we can read data just like we would do in any other
                             * example. */
                            waitset_statuscondSeq data_seq
                                = new waitset_statuscondSeq();
                            DDS.SampleInfoSeq info_seq
                                = new DDS.SampleInfoSeq();

                            try
                            {
                                /* Access data using read(), take(), etc.  If
                                 * you fail to do this the condition will
                                 * remain true, and the WaitSet will wake up
                                 * immediately - causing high CPU usage when it
                                 * does not sleep in the loop */
                                waitset_reader.take(
                                    data_seq,
                                    info_seq,
                                    DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                                    DDS.SampleStateKind.ANY_SAMPLE_STATE,
                                    DDS.ViewStateKind.ANY_VIEW_STATE,
                                    DDS.InstanceStateKind.ANY_INSTANCE_STATE);
                            }
                            catch (DDS.Retcode_NoData e)
                            {
                                shutdown(participant);
                                throw e;
                            }
                            catch (DDS.Exception e)
                            {
                                shutdown(participant);
                                throw e;
                            }

                            /* Iterate over returned data.  Print the data
                             * values if it is not metadata.
                             */
                            System.Int32 data_length = data_seq.length;
                            for (int j = 0; i < data_length; ++i)
                            {
                                if (!info_seq.get_at(j).valid_data)
                                {
                                    Console.WriteLine("Got metadata");
                                    continue;
                                }
                                waitset_statuscondTypeSupport.print_data(data_seq.get_at(j));
                            }

                            try
                            {
                                /* Return the loaned data */
                                waitset_reader.return_loan(data_seq, info_seq);
                            }
                            catch (DDS.Exception e)
                            {
                                Console.WriteLine("return loan error {0}", e);
                            }
                        }
                    }
                }
            }
            catch (DDS.Retcode_Timeout)
            {
                Console.WriteLine("wait timed out");
                count += 2;
                continue;
            }
        }
        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #15
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = keysTypeSupport.get_type_name();
        try
        {
            keysTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example keys",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //

        /* Create a data reader listener */
        keysListener reader_listener =
            new keysListener();

        /* 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,
            reader_listener,
            DDS.StatusMask.STATUS_MASK_ALL);

        /* If you want to set the QoS settings programmatically rather than
         * using the XML, you will need to add the following lines to your code
         * and comment out the create_datareader call above.
         */
        /*
         * DDS.DataReaderQos readerQos = new DDS.DataReaderQos();
         * subscriber.get_default_datareader_qos(readerQos);
         *
         * readerQos.ownership.kind = DDS.OwnershipQosPolicyKind.EXCLUSIVE_OWNERSHIP_QOS;
         *
         * DDS.DataReader reader = subscriber.create_datareader(
         *  topic,
         *  readerQos,
         *  reader_listener,
         *  DDS.StatusMask.STATUS_MASK_ALL);
         */

        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new ApplicationException("create_datareader error");
        }

        // --- Wait for data --- //

        /* Main loop */
        const System.Int32 receive_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            //Console.WriteLine("keys subscriber sleeping for {0} sec...",receive_period / 1000);

            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }
コード例 #16
0
ファイル: hello_world_subscriber.cs プロジェクト: albenq/RTI
    static void subscribe(int domain_id, int sample_count, int drs)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = hello_worldTypeSupport.get_type_name();
        try {
            hello_worldTypeSupport.register_type(
                participant, type_name);
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example hello_world",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //

        /* Create a data reader listener */
        hello_worldListener reader_listener =
            new hello_worldListener();

        DDS.DataReader reader = null;

        /* If you use Durable Reader State, you need to set up several properties.
         * In this example, we have modified them using a QoS XML profile. See
         * further details in USER_QOS_PROFILES.xml.
         */

        if (drs == 1)
        {
            reader = subscriber.create_datareader_with_profile(topic,
                                                               "persistence_example_Library",
                                                               "durable_reader_state_Profile",
                                                               reader_listener, DDS.StatusMask.STATUS_MASK_ALL);
        }
        else
        {
            reader = subscriber.create_datareader_with_profile(topic,
                                                               "persistence_example_Library",
                                                               "persistence_service_Profile",
                                                               reader_listener, DDS.StatusMask.STATUS_MASK_ALL);
        }

        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new ApplicationException("create_datareader error");
        }

        // --- Wait for data --- //

        /* Main loop */
        const System.Int32 receive_period = 4000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine(
                "hello_world subscriber sleeping for {0} sec...",
                receive_period / 1000);

            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }
コード例 #17
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        DDS.SubscriberQos subscriber_qos = new DDS.SubscriberQos();
        participant.get_default_subscriber_qos(subscriber_qos);

        /* If you want to change the Partition name programmatically rather than
         * using the XML, you will need to add the following lines to your code
         * and comment out the create_subscriber() call bellow.
         */

        /*
         * String[] partitions = { "ABC", "X*Z" };
         *
         * subscriber_qos.partition.name.ensure_length(2, 2);
         * subscriber_qos.partition.name.from_array(partitions);
         *
         * DDS.Subscriber subscriber = participant.create_subscriber(
         *  subscriber_qos,
         *  null,
         *  DDS.StatusMask.STATUS_MASK_NONE);
         */

        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = partitionsTypeSupport.get_type_name();
        try
        {
            partitionsTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example partitions",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //

        /* Create a data reader listener */
        partitionsListener reader_listener =
            new partitionsListener();


        /* If you want to change the Datareader QoS programmatically rather than
         * using the XML, you will need to add the following lines to your code
         * and comment out the create_datareader() call bellow.
         */

        /*
         * DDS.DataReaderQos readerQos = new DDS.DataReaderQos();
         * subscriber.get_default_datareader_qos(readerQos);
         *
         * readerQos.reliability.kind = DDS.ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
         * readerQos.history.kind = DDS.HistoryQosPolicyKind.KEEP_ALL_HISTORY_QOS;
         * readerQos.durability.kind = DDS.DurabilityQosPolicyKind.TRANSIENT_LOCAL_DURABILITY_QOS;
         * DDS.DataReader reader = subscriber.create_datareader(
         *  topic,
         *  readerQos,
         *  reader_listener,
         *  DDS.StatusMask.STATUS_MASK_ALL);
         */

        DDS.DataReader reader = subscriber.create_datareader(
            topic,
            DDS.Subscriber.DATAREADER_QOS_DEFAULT,
            reader_listener,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new ApplicationException("create_datareader error");
        }

        // --- Wait for data --- //

        /* Main loop */
        const System.Int32 receive_period = 4000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }
コード例 #18
0
ファイル: ordered_group_publisher.cs プロジェクト: albenq/RTI
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = ordered_groupTypeSupport.get_type_name();
        try {
            ordered_groupTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* Start changes for Ordered Presentation Group example */
        /* TOPICS */

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic1 = participant.create_topic(
            "Topic1",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic1 == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        /* To customize topic QoS, use
         *      the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic2 = participant.create_topic(
            "Topic2",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic2 == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic3 = participant.create_topic(
            "Topic3",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic3 == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        /* DATAWRITERS */

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter writer1 = publisher.create_datawriter(
            topic1,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer1 == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        ordered_groupDataWriter ordered_group_writer1 =
            (ordered_groupDataWriter)writer1;


        DDS.DataWriter writer2 = publisher.create_datawriter(
            topic2,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer2 == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        ordered_groupDataWriter ordered_group_writer2 =
            (ordered_groupDataWriter)writer2;

        DDS.DataWriter writer3 = publisher.create_datawriter(
            topic3,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer3 == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        ordered_groupDataWriter ordered_group_writer3 =
            (ordered_groupDataWriter)writer3;

        // --- Write --- //

        /* Instances */

        ordered_group instance1 = ordered_groupTypeSupport.create_data();

        if (instance1 == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "ordered_groupTypeSupport.create_data error");
        }

        ordered_group instance2 = ordered_groupTypeSupport.create_data();

        if (instance2 == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "ordered_groupTypeSupport.create_data error");
        }
        ordered_group instance3 = ordered_groupTypeSupport.create_data();

        if (instance3 == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "ordered_groupTypeSupport.create_data error");
        }

        /* End changes for Ordered Presentation Example */

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = ordered_group_writer.register_instance(instance);
         */

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine("Writing ordered_group, count {0}", count);

            /* Start changes for Ordered Presentation Example */
            /* Modify the data to be sent here */
            /* Instance 1 */
            instance1.message = "First sample, Topic 1 by DataWriter number 1";
            try {
                ordered_group_writer1.write(instance1, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            instance1.message = "Second sample, Topic 1 by DataWriter number 1";
            try {
                ordered_group_writer1.write(instance1, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            /* Instance 2 */
            instance2.message = "First sample, Topic 2 by DataWriter number 2";
            try {
                ordered_group_writer2.write(instance2, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            instance2.message = "Second sample, Topic 2 by DataWriter number 2";
            try {
                ordered_group_writer2.write(instance2, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            /* Instance 3 */
            instance3.message = "First sample, Topic 3 by DataWriter number 3";
            try {
                ordered_group_writer3.write(instance3, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            instance3.message = "Second sample, Topic 3 by DataWriter number 3";
            try {
                ordered_group_writer3.write(instance3, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  ordered_group_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            ordered_groupTypeSupport.delete_data(instance1);
            ordered_groupTypeSupport.delete_data(instance2);
            ordered_groupTypeSupport.delete_data(instance3);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "ordered_groupTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #19
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = waitsetsTypeSupport.get_type_name();
        try {
            waitsetsTypeSupport.register_type(
                participant, type_name);
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example waitsets",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //

        /* 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,
            null,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datareader error");
        }

        /* If you want to change the DataReader's QoS programmatically rather
         * than using the XML file, you will need to add the following lines to
         * your code and comment out the create_datareader call above.
         *
         * In this case, we reduce the liveliness timeout period to trigger the
         * StatusCondition DDS.StatusKind.LIVELINESS_CHANGED_STATUS
         */
        /*
         * DDS.DataReaderQos datawriter_qos = new DDS.DataReaderQos();
         * try {
         *  subscriber.get_default_datareader_qos(datawriter_qos);
         * } catch (DDS.Exception e) {
         *  Console.WriteLine("get_default_datareader_qos error {0}", e);
         *  shutdown(participant);
         *  throw e;
         * }
         * datawriter_qos.liveliness.lease_duration.sec = 2;
         * datawriter_qos.liveliness.lease_duration.nanosec = 0;
         *
         * reader = subscriber.create_datareader(topic, datawriter_qos,
         *  null, DDS.StatusMask.STATUS_MASK_NONE);
         * if (reader == null) {
         *  shutdown(participant);
         *  throw new ApplicationException("create_datawriter_qos error");
         * }
         */

        /* Create read condition
         * ---------------------
         * Note that the Read Conditions are dependent on both incoming
         * data as well as sample state. Thus, this method has more
         * overhead than adding a DDS.StatusKind.DATA_AVAILABLE_STATUS
         * StatusCondition. We show it here purely for reference
         */
        DDS.ReadCondition read_condition = reader.create_readcondition(
            DDS.SampleStateKind.NOT_READ_SAMPLE_STATE,
            DDS.ViewStateKind.ANY_VIEW_STATE,
            DDS.InstanceStateKind.ANY_INSTANCE_STATE);
        if (read_condition == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_readcondition error");
        }

        /* Get status conditions
         * ---------------------
         * Each entity may have an attached Status Condition. To modify the
         * statuses we need to get the reader's Status Conditions first.
         */

        DDS.StatusCondition status_condition = reader.get_statuscondition();
        if (status_condition.get_entity() == null)
        {
            shutdown(participant);
            throw new ApplicationException("get_statuscondition error");
        }

        /* Set enabled statuses
         * --------------------
         * Now that we have the Status Condition, we are going to enable the
         * statuses we are interested in:
         * DDS.StatusKind.SUBSCRIPTION_MATCHED_STATUS
         * and DDS.StatusKind.LIVELINESS_CHANGED_STATUS.
         */
        try {
            status_condition.set_enabled_statuses(
                DDS.StatusMask.STATUS_MASK_NONE |
                (DDS.StatusMask)DDS.StatusKind.SUBSCRIPTION_MATCHED_STATUS |
                (DDS.StatusMask)DDS.StatusKind.LIVELINESS_CHANGED_STATUS);
        } catch (DDS.Exception e) {
            Console.WriteLine("set_enabled_statuses error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* Create and attach conditions to the WaitSet
         * -------------------------------------------
         * Finally, we create the WaitSet and attach both the Read Conditions
         * and the Status Condition to it.
         */
        DDS.WaitSet waitset = new DDS.WaitSet();

        /* Attach Read Conditions */
        try {
            waitset.attach_condition(read_condition);
        } catch (DDS.Exception e) {
            Console.WriteLine("attach_read_condition error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* Attach Status Conditions */
        try {
            waitset.attach_condition(status_condition);
        } catch (DDS.Exception e) {
            Console.WriteLine("attach_status_condition error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* Narrow the reader into your specific data type */
        waitsetsDataReader waitsets_reader =
            (waitsetsDataReader)reader;


        /* Main loop */
        for (int count = 0; (sample_count == 0) || (count < sample_count);
             ++count)
        {
            DDS.ConditionSeq active_conditions_seq = new DDS.ConditionSeq();
            DDS.Duration_t   timeout;
            timeout.nanosec = (uint)500000000;
            timeout.sec     = 1;

            /* wait() blocks execution of the thread until one or more attached
             * Conditions become true, or until a user-specified timeout expires
             */
            try {
                waitset.wait(active_conditions_seq, timeout);
            } catch (DDS.Retcode_Timeout) {
                Console.WriteLine("Wait timed out!! No conditions were " +
                                  "triggered.");
                continue;
            } catch (DDS.Exception e) {
                Console.WriteLine("wait error {0}", e);
                break;
            }

            /* Get the number of active conditions */
            int active_conditions = active_conditions_seq.length;
            Console.WriteLine("Got {0} active conditions", active_conditions);

            for (int i = 0; i < active_conditions; i++)
            {
                /* Now we compare the current condition with the Status
                 * Conditions and the Read Conditions previously defined. If
                 * they match, we print the condition that was triggered.*/

                /* Compare with Status Conditions */
                if (active_conditions_seq.get_at(i) == status_condition)
                {
                    /* Get the status changes so we can check which status
                     * condition triggered. */
                    DDS.StatusMask triggeredmask =
                        waitsets_reader.get_status_changes();

                    /* Liveliness changed */
                    DDS.StatusMask test = triggeredmask &
                                          (DDS.StatusMask)DDS.StatusKind.
                                          LIVELINESS_CHANGED_STATUS;
                    if (test != DDS.StatusMask.STATUS_MASK_NONE)
                    {
                        DDS.LivelinessChangedStatus st =
                            new DDS.LivelinessChangedStatus();
                        waitsets_reader.get_liveliness_changed_status(ref st);
                        Console.WriteLine("Liveliness changed => " +
                                          "Active writers = {0}", st.alive_count);
                    }

                    /* Subscription matched */
                    test = triggeredmask &
                           (DDS.StatusMask)DDS.StatusKind.
                           SUBSCRIPTION_MATCHED_STATUS;
                    if (test != DDS.StatusMask.STATUS_MASK_NONE)
                    {
                        DDS.SubscriptionMatchedStatus st =
                            new DDS.SubscriptionMatchedStatus();
                        waitsets_reader.get_subscription_matched_status(ref st);
                        Console.WriteLine("Subscription matched => " +
                                          "Cumulative matches = {0}", st.total_count);
                    }
                }

                /* Compare with Read Conditions */
                else if (active_conditions_seq.get_at(i) == read_condition)
                {
                    /* Current conditions match our conditions to read data, so
                     * we can read data just like we would do in any other
                     * example. */
                    waitsetsSeq       data_seq = new waitsetsSeq();
                    DDS.SampleInfoSeq info_seq = new DDS.SampleInfoSeq();

                    /* You may want to call take_w_condition() or
                     * read_w_condition() on the Data Reader. This way you will
                     * use the same status masks that were set on the Read
                     * Condition.
                     * This is just a suggestion, you can always use
                     * read() or take() like in any other example.
                     */
                    bool follow = true;
                    while (follow)
                    {
                        try {
                            waitsets_reader.take_w_condition(
                                data_seq, info_seq,
                                DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                                read_condition);

                            for (int j = 0; j < data_seq.length; ++j)
                            {
                                if (!info_seq.get_at(j).valid_data)
                                {
                                    Console.WriteLine("Got metadata");
                                    continue;
                                }
                                waitsetsTypeSupport.print_data(
                                    data_seq.get_at(j));
                            }
                        } catch (DDS.Retcode_NoData) {
                            /* When there isn't data, the subscriber stop to
                             * take samples
                             */
                            follow = false;
                        } finally {
                            waitsets_reader.return_loan(data_seq, info_seq);
                        }
                    }
                }
            }
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #20
0
ファイル: hello_world_publisher.cs プロジェクト: albenq/RTI
    static void publish(int domain_id, int sample_count, int initial_value,
                        int dwh, int sleep)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = hello_worldTypeSupport.get_type_name();
        try {
            hello_worldTypeSupport.register_type(
                participant, type_name);
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example hello_world",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create writer --- //

        /* If you use Durable Writer History, you need to set several
         * properties. These properties are set in the USER_QOS_PROFILE.xml
         * file, "durable_writer_history_Profile" profile. See that file for
         * further details.
         */
        DDS.DataWriter writer = null;
        if (dwh == 1)
        {
            writer = publisher.create_datawriter_with_profile(topic,
                                                              "persistence_example_Library",
                                                              "durable_writer_history_Profile",
                                                              null, DDS.StatusMask.STATUS_MASK_ALL);
        }
        else
        {
            writer = publisher.create_datawriter_with_profile(topic,
                                                              "persistence_example_Library",
                                                              "persistence_service_Profile",
                                                              null, DDS.StatusMask.STATUS_MASK_ALL);
        }
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        hello_worldDataWriter hello_world_writer =
            (hello_worldDataWriter)writer;

        // --- Write --- //

        /* Create data sample for writing */
        hello_world instance = hello_worldTypeSupport.create_data();

        if (instance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "hello_worldTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = hello_world_writer.register_instance(instance);
         */

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds
        const System.Int32 one_sec     = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine("Writing hello_world, count {0}", initial_value);

            /* Modify the data to be sent here */
            instance.data = initial_value;
            initial_value++;

            try {
                hello_world_writer.write(instance, ref instance_handle);
            } catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        while (sleep != 0)
        {
            System.Threading.Thread.Sleep(one_sec);
            sleep--;
        }

        /*
         * try {
         *  hello_world_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            hello_worldTypeSupport.delete_data(instance);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "hello_worldTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #21
0
ファイル: Form1.cs プロジェクト: gec/dds-training
        private void Form1_Load(object sender, EventArgs e)
        {
            participant = DDS.DomainParticipantFactory.get_instance().create_participant(
                0, DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */, DDS.StatusMask.STATUS_MASK_NONE);

            if (participant == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_participant error");
            }

            // --- Create publisher --- //

            /* To customize publisher QoS, use
            the configuration file USER_QOS_PROFILES.xml */
            DDS.Publisher publisher = participant.create_publisher(
                DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (publisher == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_publisher error");
            }
            // --- Create topics --- //

            /* OpenClose */

            /* Register type before creating topic */
            System.String type_name = cow.OpenCloseTypeSupport.get_type_name();
            try
            {
                cow.OpenCloseTypeSupport.register_type(
                    participant, type_name);
            }
            catch (DDS.Exception ex)
            {
                MessageBox.Show("register_type error " + ex.Message);
                shutdown(participant);
                throw ex;
            }

            /* Customize QoS settings */
            DDS.TopicQos topicQos = new DDS.TopicQos();
            participant.get_default_topic_qos(topicQos);
            topicQos.reliability.kind = DDS.ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
            topicQos.durability.kind = DDS.DurabilityQosPolicyKind.TRANSIENT_LOCAL_DURABILITY_QOS;
            DDS.Topic openCloseTopic = participant.create_topic(
                "OpenClose", type_name, topicQos,
                null /* listener */, DDS.StatusMask.STATUS_MASK_NONE);
            if (openCloseTopic == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_topic error");
            }

            // --- Create writer --- //

            /* To customize data writer QoS, use
            the configuration file USER_QOS_PROFILES.xml */
            DDS.DataWriterQos datawriterQos = new DDS.DataWriterQos();
            publisher.get_default_datawriter_qos(datawriterQos);
            publisher.copy_from_topic_qos(datawriterQos, topicQos);
            DDS.DataWriter writer = publisher.create_datawriter(
                openCloseTopic,  datawriterQos,
                null /* listener */, DDS.StatusMask.STATUS_MASK_NONE);
            if (writer == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_datawriter error");
            }
            openCloseWriter = (cow.OpenCloseDataWriter)writer;

            /* SetWatts */

            /* Register type before creating topic */
            type_name = cow.SetWattsTypeSupport.get_type_name();
            try
            {
                cow.SetWattsTypeSupport.register_type(
                    participant, type_name);
            }
            catch (DDS.Exception ex)
            {
                MessageBox.Show("register_type error " + ex.Message);
                shutdown(participant);
                throw ex;
            }

            /* To customize topic QoS, use
            the configuration file USER_QOS_PROFILES.xml */
            DDS.Topic setWattsTopic = participant.create_topic(
                "SetWatts", type_name, topicQos,
                null /* listener */, DDS.StatusMask.STATUS_MASK_NONE);
            if (setWattsTopic == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_topic error");
            }

            // --- Create writer --- //

            /* To customize data writer QoS, use
            the configuration file USER_QOS_PROFILES.xml */
            writer = publisher.create_datawriter(
                setWattsTopic, datawriterQos,
                null /* listener */, DDS.StatusMask.STATUS_MASK_NONE);
            if (writer == null)
            {
                shutdown(participant);
                throw new ApplicationException("create_datawriter error");
            }
            setWattsWriter = (cow.SetWattsDataWriter)writer;
        }
コード例 #22
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");
            }

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

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

            _statusCondition = _reader.get_statuscondition();

            try
            {
                var mask =
                    (int)DDS.StatusKind.DATA_AVAILABLE_STATUS |
                    (int)DDS.StatusKind.SUBSCRIPTION_MATCHED_STATUS |
                    (int)DDS.StatusKind.LIVELINESS_CHANGED_STATUS |
                    (int)DDS.StatusKind.SAMPLE_LOST_STATUS |
                    (int)DDS.StatusKind.SAMPLE_REJECTED_STATUS;

                _statusCondition.set_enabled_statuses((DDS.StatusMask)mask);
            }
            catch (DDS.Exception e)
            {
                throw new ApplicationException("set_enabled_statuses error {0}", e);
            }

            _waitset = new DDS.WaitSet();

            try
            {
                _waitset.attach_condition(_statusCondition);
            }
            catch (DDS.Exception e)
            {
                throw new ApplicationException("attach_condition error {0}", e);
            }
        }
コード例 #23
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = ccfTypeSupport.get_type_name();
        try {
            ccfTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example ccf",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        /* Start changes for Custom Content Filter */
        /* Create and register custom filter */
        custom_filter_type custom_filter = new custom_filter_type();

        try {
            participant.register_contentfilter("CustomFilter", custom_filter);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("write error {0}", e);
        }

        DDS.StringSeq       parameters = new DDS.StringSeq(2);
        DDS.StringWrapper[] param_list = { "2", "divides" };

        parameters.from_array(param_list);

        /* Create content filtered topic */
        DDS.ContentFilteredTopic cft =
            participant.create_contentfilteredtopic_with_filter(
                "ContentFilteredTopic", topic, "%0 %1 x", parameters,
                "CustomFilter"); // custom filter name
        if (cft == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "create_contentfilteredtopic_with_filter error");
        }

        Console.WriteLine("Filter: 2 divides x");

        /* Also note that we pass 'cft' rather than 'topic' to the
         * datareader below
         */

        /* End changes for Custom Contet Filter */

        // --- Create reader --- //

        /* Create a data reader listener */
        ccfListener reader_listener =
            new ccfListener();


        /*
         * NOTE THAT WE USE THE PREVIOUSLY CREATED CUSTOM FILTERED
         * TOPIC TO READ NEW SAMPLES
         */
        /* To customize the data reader QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataReader reader = subscriber.create_datareader(
            cft,
            DDS.Subscriber.DATAREADER_QOS_DEFAULT,
            reader_listener,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new ApplicationException("create_datareader error");
        }

        // --- Wait for data --- //

        /* Main loop */
        const System.Int32 receive_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            if (count == 10)
            {
                Console.WriteLine("changing filter parameters");
                Console.WriteLine("Filter: 15 greater-than x");
                parameters.set_at(0, "15");
                parameters.set_at(1, "greater-than");
                cft.set_expression_parameters(parameters);
            }
            else if (count == 20)
            {
                Console.WriteLine("changing filter parameters");
                Console.WriteLine("Filter: 3 divides x");
                DDS.StringSeq old_parameters = new DDS.StringSeq();
                cft.get_expression_parameters(old_parameters);

                old_parameters.set_at(0, "3");
                old_parameters.set_at(1, "divides");
                cft.set_expression_parameters(old_parameters);
            }

            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = deadline_contentfilterTypeSupport.get_type_name();
        try {
            deadline_contentfilterTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example deadline_contentfilter",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }



        // --- Create writer --- //

        //// Start changes for Deadline

        // Create listener
        deadlineListener writer_listener = new deadlineListener();

        if (writer_listener == null)
        {
            shutdown(participant);
            throw new ApplicationException("listener instantiation error\n");
        }

        /* To customize data writer QoS, use
         * the configuration file NDDS_QOS_PROFILES.xml */
        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            writer_listener, /* listener */
            DDS.StatusMask.STATUS_MASK_ALL);
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }

        /* If you want to change the DataWriter's QoS programmatically rather than
         * using the XML file, you will need to add the following lines to your
         * code and comment out the create_datawriter call above.
         *
         * In this case, we set the deadline period to 2 seconds to trigger
         * a deadline if the DataWriter does not update often enough.
         */
        /*
         *
         * DDS.DataWriterQos datawriter_qos = new DDS.DataWriterQos();
         * try {
         *  publisher.get_default_datawriter_qos(datawriter_qos);
         * }
         * catch(DDS.Exception e) {
         *  Console.WriteLine("get_default_datawriter_qos error\n", e);
         * }
         *
         * // Set deadline QoS to 1.5 sec
         * datawriter_qos.deadline.period.sec = 1;
         * datawriter_qos.deadline.period.nanosec = 500000000; // 500ms
         *
         * // --- Create writer --- //
         *
         * DDS.DataWriter writer = publisher.create_datawriter(
         *  topic,
         *  datawriter_qos, //DDS.Publisher.DATAWRITER_QOS_DEFAULT,
         *  writer_listener,
         *  DDS.StatusMask.STATUS_MASK_ALL);
         * if (writer == null) {
         *  shutdown(participant);
         *  throw new ApplicationException("create_datawriter error");
         * }
         */

        deadline_contentfilterDataWriter deadline_contentfilter_writer =
            (deadline_contentfilterDataWriter)writer;

        /* Create data sample for writing */
        deadline_contentfilter instance0 = deadline_contentfilterTypeSupport.create_data();

        if (instance0 == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "deadline_contentfilterTypeSupport.create_data error");
        }

        deadline_contentfilter instance1 = deadline_contentfilterTypeSupport.create_data();

        if (instance1 == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "deadline_contentfilterTypeSupport.create_data error");
        }

        // Set keys -- we specify 'code' as the key field in the .idl
        instance0.code = 0;
        instance1.code = 1;

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle0 =
            DDS.InstanceHandle_t.HANDLE_NIL;
        DDS.InstanceHandle_t instance_handle1 =
            DDS.InstanceHandle_t.HANDLE_NIL;
        instance_handle0 = deadline_contentfilter_writer.register_instance(instance0);
        instance_handle1 = deadline_contentfilter_writer.register_instance(instance1);

        const System.Int32 send_period = 1000; // milliseconds

        instance0.x = instance0.y = instance1.x = instance1.y = 0;
        int writeTimes = 15;

        /* Main loop */
        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            //Console.WriteLine("Writing deadline, count {0}", count);

            /* Modify the data to be sent here */
            instance0.x++;
            instance0.y++;
            instance1.x++;
            instance1.y++;

            Console.WriteLine("Writing instance0, x = {0}, y = {1}\n",
                              instance0.x, instance0.y);

            try
            {
                deadline_contentfilter_writer.write(instance0, ref instance_handle0);
            }
            catch (DDS.Exception e)
            {
                Console.WriteLine("write error {0}", e);
            }

            if (count < writeTimes)
            {
                Console.WriteLine("Writing instance1, x = {0}, y = {1}\n",
                                  instance1.x, instance1.y);

                try
                {
                    deadline_contentfilter_writer.write(instance1, ref instance_handle1);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("write error {0}", e);
                }
            }
            else if (count == writeTimes)
            {
                Console.WriteLine("Stopping writes to instance1\n");
            }

            System.Threading.Thread.Sleep(send_period);
        }

        // Unregister the instances
        try
        {
            deadline_contentfilter_writer.unregister_instance(instance0, ref instance_handle0);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("unregister instance error: {0}", e);
        }

        try
        {
            deadline_contentfilter_writer.unregister_instance(instance1, ref instance_handle1);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("unregister instance error: {0}", e);
        }

        // --- Shutdown --- //

        /* Delete data sample */
        try
        {
            deadline_contentfilterTypeSupport.delete_data(instance0);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("deadlineTypeSupport.delete_data error: {0}", e);
        }

        try
        {
            deadline_contentfilterTypeSupport.delete_data(instance1);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("deadlineTypeSupport.delete_data error: {0}", e);
        }
        /* Delete all entities */
        shutdown(participant);
    }
コード例 #25
0
ファイル: flights_subscriber.cs プロジェクト: albenq/RTI
        private static void Subscribe(int domainId, int sampleCount)
        {
            // --- Create participant --- //
            DDS.DomainParticipant participant =
                DDS.DomainParticipantFactory.get_instance().create_participant(
                    domainId,
                    DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                    null /* listener */,
                    DDS.StatusMask.STATUS_MASK_NONE);
            if (participant == null)
            {
                Shutdown(participant);
                throw new Exception("create_participant error");
            }

            // --- Create subscriber --- //
            DDS.Subscriber subscriber = participant.create_subscriber(
                DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
            if (subscriber == null)
            {
                Shutdown(participant);
                throw new ApplicationException("create_subscriber error");
            }

            // --- Create topic --- //
            // Register the type before creating the topic.
            string typeName = FlightTypeSupport.get_type_name();

            try {
                FlightTypeSupport.register_type(participant, typeName);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("register_type error {0}", e);
                Shutdown(participant);
                throw e;
            }

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

            // --- Create reader --- //
            DDS.DataReader reader = subscriber.create_datareader(
                topic,
                DDS.Subscriber.DATAREADER_QOS_DEFAULT,
                null,
                DDS.StatusMask.STATUS_MASK_ALL);
            if (reader == null)
            {
                Shutdown(participant);
                throw new ApplicationException("create_datareader error");
            }

            FlightDataReader flightReader = (FlightDataReader)reader;

            // Query for company named 'CompanyA' and for flights in cruise
            // (about 30,000ft). The company parameter will be changed in
            // run-time. NOTE: There must be single-quotes in the query
            // parameters around-any strings! The single-quote do NOT go in the
            // query condition itself.
            DDS.StringSeq queryParameters = new DDS.StringSeq();
            queryParameters.ensure_length(2, 2);
            queryParameters.set_at(0, "'CompanyA'");
            queryParameters.set_at(1, "30000");
            Console.WriteLine(
                "Setting parameters to company: {0} and altitude >= {1}\n",
                queryParameters.get_at(0), queryParameters.get_at(1));

            // Create the query condition with an expession to MATCH the id
            // field in the structure and a numeric comparison.
            DDS.QueryCondition queryCondition =
                reader.create_querycondition(
                    DDS.SampleStateKind.ANY_SAMPLE_STATE,
                    DDS.ViewStateKind.ANY_VIEW_STATE,
                    DDS.InstanceStateKind.ALIVE_INSTANCE_STATE,
                    "company MATCH %0 AND altitude >= %1",
                    queryParameters);

            // --- Wait for data --- //
            const int receivePeriod = 1000; // Milliseconds
            bool      update        = false;

            for (int count = 0;
                 (sampleCount == 0) || (count < sampleCount);
                 count++)
            {
                // Poll for new samples every second.
                System.Threading.Thread.Sleep(receivePeriod);

                // Change the filter parameter after 5 seconds.
                if ((count + 1) % 10 == 5)
                {
                    queryParameters.set_at(0, "'CompanyB'");
                    update = true;
                }
                else if ((count + 1) % 10 == 0)
                {
                    queryParameters.set_at(0, "'CompanyA'");
                    update = true;
                }

                // Set new parameters.
                if (update)
                {
                    Console.WriteLine("Changing parameter to {0}",
                                      queryParameters.get_at(0));
                    queryCondition.set_query_parameters(queryParameters);
                    update = false;
                }

                // Iterate through the samples using read_w_condition.
                FlightSeq         dataSeq = new FlightSeq();
                DDS.SampleInfoSeq infoSeq = new DDS.SampleInfoSeq();
                try {
                    flightReader.read_w_condition(
                        dataSeq,
                        infoSeq,
                        DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                        queryCondition);
                } catch (DDS.Retcode_NoData) {
                    continue;
                } catch (DDS.Exception e) {
                    Shutdown(participant);
                    throw e;
                }

                for (int i = 0; i < dataSeq.length; i++)
                {
                    DDS.SampleInfo info = (DDS.SampleInfo)infoSeq.get_at(i);
                    if (info.valid_data)
                    {
                        Flight flight_info = (Flight)dataSeq.get_at(i);
                        Console.WriteLine(
                            "\t[trackId: {0}, company: {1}, altitude: {2}]\n",
                            flight_info.trackId,
                            flight_info.company,
                            flight_info.altitude);
                    }
                }

                try {
                    flightReader.return_loan(dataSeq, infoSeq);
                } catch (DDS.Exception e) {
                    Console.WriteLine("return loan error {0}", e);
                }
            }

            // Delete all entities
            Shutdown(participant);
        }
コード例 #26
0
    static void publish(int domain_id, int sample_count, Route routeIn, Route.Bus busIn)
    {
        Random random       = new Random();
        int    randomNumber = random.Next(0, 100);

        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String atype_name = AccidentTypeSupport.get_type_name();
        System.String ptype_name = PositionTypeSupport.get_type_name();
        try
        {
            AccidentTypeSupport.register_type(
                participant, atype_name);
            PositionTypeSupport.register_type(
                participant, ptype_name);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic atopic = participant.create_topic(
            "P3464_BHANDERSON: PT/ALR/ACC",
            atype_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        DDS.Topic ptopic = participant.create_topic(
            "P3464_BHANDERSON: PT/POS",
            ptype_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);

        if (atopic == null || ptopic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }


        // --- Create writer --- //

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter awriter = publisher.create_datawriter(
            atopic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        DDS.DataWriter pwriter = publisher.create_datawriter(
            ptopic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);

        if (awriter == null || pwriter == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        AccidentDataWriter Accident_writer =
            (AccidentDataWriter)awriter;
        PositionDataWriter Position_writer =
            (PositionDataWriter)pwriter;
        // --- Write --- //

        /* Create data sample for writing */
        Accident ainstance = AccidentTypeSupport.create_data();
        Position pinstance = PositionTypeSupport.create_data();

        if (ainstance == null || pinstance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "(Accident|Position)TypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = Accident_writer.register_instance(instance);
         */



        int numPasses = 0;
        /* Main loop */
        int send_period = 4000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            if (count % routeIn.numStops == 0)
            {
                numPasses++;
            }
            if (numPasses > 3)
            {
                break;
            }

            Console.WriteLine("Writing Accident|Position, count {0}", count);

            /* Modify the data to be sent here */

            int traffic = random.Next(0, 100);
            if (traffic <= 25) // light 25%
            {
                pinstance.trafficConditions = "light";
                pinstance.timeBetweenStops  = (int)(Math.Ceiling(routeIn.timeBetweenStops * .75));
            }
            else if (traffic <= 50) // heavy 25%
            {
                pinstance.trafficConditions = "heavy";
                pinstance.timeBetweenStops  = (int)(routeIn.timeBetweenStops + Math.Ceiling(routeIn.timeBetweenStops * .25));
            }
            else // normal 50%
            {
                pinstance.trafficConditions = "normal";
                pinstance.timeBetweenStops  = routeIn.timeBetweenStops;
            }

            ainstance.timestamp  = DateTime.Now.ToString();
            ainstance.route      = routeIn.name;
            ainstance.vehicle    = busIn.id;
            ainstance.stopNumber = busIn.stop;

            pinstance.timestamp   = DateTime.Now.ToString();
            pinstance.route       = routeIn.name;
            pinstance.vehicle     = busIn.id;
            pinstance.stopNumber  = busIn.stop;
            pinstance.numStops    = routeIn.numStops;
            pinstance.fillInRatio = random.Next(0, 100);

            int aOccurs = random.Next(0, 100);

            if (aOccurs <= 10)
            {
                try
                {
                    Accident_writer.write(ainstance, ref instance_handle);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("write error {0}", e);
                }
                pinstance.timeBetweenStops += 10;
            }

            send_period = pinstance.timeBetweenStops * 1000; // threads use milliseconds

            busIn.stop = (busIn.stop % routeIn.numStops) + 1;

            try
            {
                Position_writer.write(pinstance, ref instance_handle);
            }
            catch (DDS.Exception e)
            {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  Accident_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try
        {
            AccidentTypeSupport.delete_data(ainstance);
            PositionTypeSupport.delete_data(pinstance);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine(
                "(Accident|Position)TypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #27
0
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = cftTypeSupport.get_type_name();
        try {
            cftTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example cft",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create writer --- //

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }

        /* If you want to set the reliability and history QoS settings
         * programmatically rather than using the XML, you will need to add
         * the following lines to your code and comment out the
         * create_datawriter call above.
         */
        /*
         * DDS.DataWriterQos datawriter_qos = new DDS.DataWriterQos();
         * try {
         *  publisher.get_default_datawriter_qos(datawriter_qos);
         * } catch (DDS.Exception e) {
         *  Console.WriteLine("get_default_datawriter_qos error {0}", e);
         *  shutdown(participant);
         *  throw e;
         * }
         *
         * datawriter_qos.reliability.kind =
         *  DDS.ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
         * datawriter_qos.durability.kind =
         *  DDS.DurabilityQosPolicyKind.TRANSIENT_LOCAL_DURABILITY_QOS;
         * datawriter_qos.history.kind =
         *  DDS.HistoryQosPolicyKind.KEEP_LAST_HISTORY_QOS;
         * datawriter_qos.history.depth = 20;
         *
         * DDS.DataWriter writer = publisher.create_datawriter(
         *  topic, datawriter_qos, null,
         *  DDS.StatusMask.STATUS_MASK_NONE);
         * if (writer == null) {
         *  shutdown(participant);
         *  throw new ApplicationException("create_datawriter error");
         * }
         */

        cftDataWriter cft_writer = (cftDataWriter)writer;

        // --- Write --- //

        /* Create data sample for writing */
        cft instance = cftTypeSupport.create_data();

        if (instance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "cftTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = cft_writer.register_instance(instance);
         */

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            /* Modify the data to be sent here */

            /* Our purpose is to increment x every time we send a sample and to
             * reset the x counter to 0 every time we send 10 samples
             * (x=0,1,..,9). Using the value of count, we can get set x to the
             * appropriate value applying % 10 operation to it.
             */
            instance.count = count;
            instance.x     = count % 10;

            Console.WriteLine("Writing cft, count {0}\tx={1}",
                              instance.count, instance.x);

            try {
                cft_writer.write(instance, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  cft_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            cftTypeSupport.delete_data(instance);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "cftTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #28
0
    static void publish(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* To customize publisher QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = pollTypeSupport.get_type_name();
        try {
            pollTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example poll",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create writer --- //

        /* To customize data writer QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        pollDataWriter poll_writer =
            (pollDataWriter)writer;

        // --- Write --- //

        /* Create data sample for writing */
        poll instance = pollTypeSupport.create_data();

        if (instance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "pollTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = poll_writer.register_instance(instance);
         */

        Random random = new Random();

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine("Writing poll, count {0}", count);

            /* Modify the data to be sent here */
            instance.x = (short)random.Next();

            try {
                poll_writer.write(instance, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  poll_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            pollTypeSupport.delete_data(instance);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "pollTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #29
0
    static void publish(int domain_id, int sample_count)
    {
        /* There are several different approaches for loading QoS profiles from
         * XML files (see Configuring QoS with XML chapter in the RTI Connext
         * Core Libraries and Utilities User's Manual). In this example we
         * illustrate two of them:
         *
         * 1) Creating a file named USER_QOS_PROFILES.xml, which is loaded,
         * automatically by the DomainParticipantFactory. In this case, the file
         * defines a QoS profile named volatile_profile that configures reliable,
         * volatile DataWriters and DataReaders.
         *
         * 2) Adding XML documents to the DomainParticipantFactory using its
         * Profile QoSPolicy (DDS Extension). In this case, we add
         * my_custom_qos_profiles.xml to the url_profile sequence, which stores
         * the URLs of all the XML documents with QoS policies that are loaded
         * by the DomainParticipantFactory aside from the ones that are
         * automatically loaded.
         * my_custom_qos_profiles.xml defines a QoS profile named
         * transient_local_profile that configures reliable, transient local
         * DataWriters and DataReaders.
         */

        /* To load my_custom_qos_profiles.xml, as explained above, we need to
         * modify the  DDSTheParticipantFactory Profile QoSPolicy */

        DDS.DomainParticipantFactoryQos factory_qos =
            new DDS.DomainParticipantFactoryQos();
        DDS.DomainParticipantFactory.get_instance().get_qos(factory_qos);

        /* We are only going to add one XML file to the url_profile sequence,
         * so we ensure a length of 1,1. */
        factory_qos.profile.url_profile.ensure_length(1, 1);

        /* The XML file will be loaded from the working directory. That means,
         * you need to run the example like this:
         * ./objs/<architecture>/profiles_publisher
         * (see README.txt for more information on how to run the example).
         *
         * Note that you can specify the absolute path of the XML QoS file to
         * avoid this problem.
         */

        factory_qos.profile.url_profile.set_at(0,
                                               "file://my_custom_qos_profiles.xml");
        DDS.DomainParticipantFactory.get_instance().set_qos(factory_qos);


        // --- Create participant --- //

        /* Our default Qos profile, volatile_profile, sets the participant name.
         * This is the only participant_qos policy that we change in our
         * example. As this is done in the default QoS profile, we don't need
         * to specify its name, so we can create the participant using the
         * create_participant() method rather than using
         * create_participant_with_profile().  */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create publisher --- //

        /* We haven't changed the publisher_qos in any of QoS profiles we use in
         * this example, so we can just use the create_publisher() method. If
         * you want to load an specific profile in which you may have changed
         * the publisher_qos, use the create_publisher_with_profile() method. */
        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        // --- Create topic --- //

        /* Register type before creating topic */
        System.String type_name = profilesTypeSupport.get_type_name();
        try {
            profilesTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* We haven't changed the topic_qos in any of QoS profiles we use in
         * this example, so we can just use the create_topic() method. If you
         * want to load an specific profile in which you may have changed the
         * topic_qos, use the create_topic_with_profile() method. */
        DDS.Topic topic = participant.create_topic(
            "Example profiles",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create writers --- //

        /* Volatile writer -- As volatile_profile is the default qos profile
        * we don't need to specify the profile we are going to use, we can
        * just call create_datawriter passing DDS_DATAWRITER_QOS_DEFAULT. */
        DDS.DataWriter writer_volatile = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer_volatile == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }

        /* Transient Local writer -- In this case we use
         * create_datawriter_with_profile, because we have to use a profile
         * other than the default one. This profile has been defined in
         * my_custom_qos_profiles.xml, but since we already loaded the XML file
         * we don't need to specify anything else. */

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

        profilesDataWriter profiles_writer_volatile =
            (profilesDataWriter)writer_volatile;

        profilesDataWriter profiles_writer_transient_local =
            (profilesDataWriter)writer_transient_local;

        // --- Write --- //

        /* Create data sample for writing */
        profiles instance = profilesTypeSupport.create_data();

        if (instance == null)
        {
            shutdown(participant);
            throw new ApplicationException(
                      "profilesTypeSupport.create_data error");
        }

        /* For a data type that has a key, if the same instance is going to be
         * written multiple times, initialize the key here
         * and register the keyed instance prior to writing */
        DDS.InstanceHandle_t instance_handle = DDS.InstanceHandle_t.HANDLE_NIL;

        /*
         * instance_handle = profiles_writer.register_instance(instance);
         */

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine("Writing profiles, count {0}", count);

            /* Modify the data to be sent here */
            instance.profile_name = "volatile_profile";
            instance.x            = count;

            Console.WriteLine("Writing profile_name = " + instance.profile_name
                              + "\t x = " + instance.x);
            try {
                profiles_writer_volatile.write(instance, ref instance_handle);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("write volatile error {0}", e);
            }

            instance.profile_name = "transient_local_profile";
            instance.x            = count;

            Console.WriteLine("Writing profile_name = " + instance.profile_name
                              + "\t x = " + instance.x + "\n");

            try
            {
                profiles_writer_transient_local.write(instance,
                                                      ref instance_handle);
            }
            catch (DDS.Exception e)
            {
                Console.WriteLine("write transient local error {0}", e);
            }

            System.Threading.Thread.Sleep(send_period);
        }

        /*
         * try {
         *  profiles_writer.unregister_instance(
         *      instance, ref instance_handle);
         * } catch(DDS.Exception e) {
         *  Console.WriteLine("unregister instance error: {0}", e);
         * }
         */

        // --- Shutdown --- //

        /* Delete data sample */
        try {
            profilesTypeSupport.delete_data(instance);
        } catch (DDS.Exception e) {
            Console.WriteLine(
                "profilesTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
コード例 #30
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        /* If you want to change the DataWriter's QoS programmatically rather than
         * using the XML file, you will need to add the following lines to your
         * code and comment out the create_subscriber call above.
         */

        // Start changes for coherent_presentation
        /* Get default publisher QoS to customize */

/*        DDS.SubscriberQos subscriber_qos = new DDS.SubscriberQos();
 *      participant.get_default_subscriber_qos(subscriber_qos);
 *
 *      subscriber_qos.presentation.access_scope =
 *            DDS.PresentationQosPolicyAccessScopeKind.TOPIC_PRESENTATION_QOS;
 *      subscriber_qos.presentation.coherent_access = true;
 *
 *      DDS.Subscriber subscriber = participant.create_subscriber(
 *          subscriber_qos,
 *          null,
 *          DDS.StatusMask.STATUS_MASK_NONE);
 *      if (subscriber == null) {
 *          shutdown(participant);
 *          throw new ApplicationException("create_subscriber error");
 *      }
 *
 */     // End changes for coherent_presentation

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = coherentTypeSupport.get_type_name();
        try {
            coherentTypeSupport.register_type(
                participant, type_name);
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example coherent",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //

        /* Create a data reader listener */
        coherentListener reader_listener =
            new coherentListener();

        /* 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,
            reader_listener,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new ApplicationException("create_datareader error");
        }

        // Start changes for coherent_presentation

        /* Get default datareader QoS to customize */

/*        DDS.DataReaderQos datareader_qos = new DDS.DataReaderQos();
 *      subscriber.get_default_datareader_qos(datareader_qos);
 *
 *      datareader_qos.reliability.kind =
 *          DDS.ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
 *      datareader_qos.history.depth = 10;
 *
 *      DDS.DataReader reader = subscriber.create_datareader(
 *          topic,
 *          datareader_qos,
 *          reader_listener,
 *          DDS.StatusMask.STATUS_MASK_ALL);
 *      if (reader == null) {
 *          shutdown(participant);
 *          reader_listener = null;
 *          throw new ApplicationException("create_datareader error");
 *      }
 */     // End changes for coherent_presentation

        // --- Wait for data --- //

        /* Main loop */
        const System.Int32 receive_period = 4000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }
コード例 #31
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //

        /* To customize the participant QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);

        /* If you want to change the DomainParticipant's QoS
         * programmatically rather than using the XML file, you will need
         * to add the following lines to your code and comment out the
         * create_participant call above.
         *
         * This example uses a built-in QoS profile to enable
         * monitoring on the DomainParticipant.*/
        /*
         * DDS.DomainParticipant participant = DDS.DomainParticipantFactory.
         *  get_instance().create_participant_with_profile(domain_id,
         *      "BuiltinQosLib", "Generic.Monitoring.Common", null,
         *      DDS.StatusMask.STATUS_MASK_NONE);
         */
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //

        /* To customize the subscriber QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Subscriber subscriber = participant.create_subscriber(
            DDS.DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (subscriber == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_subscriber error");
        }

        // --- Create topic --- //

        /* Register the type before creating the topic */
        System.String type_name = profilesTypeSupport.get_type_name();
        try {
            profilesTypeSupport.register_type(
                participant, type_name);
        }
        catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            shutdown(participant);
            throw e;
        }

        /* To customize the topic QoS, use
         * the configuration file USER_QOS_PROFILES.xml */
        DDS.Topic topic = participant.create_topic(
            "Example profiles",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

        // --- Create reader --- //

        /* Create a data reader listener */
        profilesListener reader_listener =
            new profilesListener();

        /* 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,
            reader_listener,
            DDS.StatusMask.STATUS_MASK_ALL);

        /* If you want to change the DataWriter's QoS programatically rather
         * than using the XML file, you will need to add the following lines to
         * your code and comment out the create_datawriter call above.
         *
         * This example uses a built-in QoS profile to tune the QoS for
         * reliable streaming data. */
        /*
         * DDS.DataReader reader = subscriber.create_datareader_with_profile(
         *  topic, DDS.BuiltinQosProfiles.BUILTIN_QOS_LIB_EXP,
         *  DDS.BuiltinQosProfiles.PROFILE_PATTERN_RELIABLE_STREAMING,
         *  listener, DDS.StatusMask.STATUS_MASK_ALL);
         */
        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new ApplicationException("create_datareader error");
        }

        // --- Wait for data --- //

        /* Main loop */
        const System.Int32 receive_period = 4000; // milliseconds

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine(
                "profiles subscriber sleeping for {0} sec...",
                receive_period / 1000);

            System.Threading.Thread.Sleep(receive_period);
        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }