Пример #1
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult result;
            DDS.QosProvider qosProvider = null;
            DDS.DomainParticipantQos participantQos =
                test.sacs.QosComparer.defaultDomainParticipantQos;
            DDS.TopicQos topicQos =
                test.sacs.QosComparer.defaultTopicQos;
            DDS.SubscriberQos subscriberQos =
                test.sacs.QosComparer.defaultSubscriberQos;
            DDS.DataReaderQos readerQos =
                test.sacs.QosComparer.defaultDataReaderQos;
            DDS.PublisherQos publisherQos =
                test.sacs.QosComparer.defaultPublisherQos;
            DDS.DataWriterQos writerQos =
                test.sacs.QosComparer.defaultDataWriterQos;

            DDS.DomainParticipantQos xmlParticipantQos = new DDS.DomainParticipantQos ();
            DDS.TopicQos xmlTopicQos = new DDS.TopicQos ();
            DDS.SubscriberQos xmlSubscriberQos = new DDS.SubscriberQos ();
            DDS.DataReaderQos xmlReaderQos = new DDS.DataReaderQos ();
            DDS.PublisherQos xmlPublisherQos = new DDS.PublisherQos ();
            DDS.DataWriterQos xmlWriterQos = new DDS.DataWriterQos ();

            qosProvider = new DDS.QosProvider (this.uri, null);

            if (qosProvider.GetParticipantQos (ref xmlParticipantQos, null) != 0 ||
                qosProvider.GetTopicQos (ref xmlTopicQos, null) != 0 ||
                qosProvider.GetSubscriberQos (ref xmlSubscriberQos, null) != 0 ||
                qosProvider.GetDataReaderQos (ref xmlReaderQos, null) != 0 ||
                qosProvider.GetPublisherQos (ref xmlPublisherQos, null) != 0 ||
                qosProvider.GetDataWriterQos (ref xmlWriterQos, null) != 0)
            {
                result = new Test.Framework.TestResult (
                    "QosProvider should successfully parse XML file",
                    "QosProvider did not parse XML file " + uri,
                    Test.Framework.TestVerdict.Pass,
                    Test.Framework.TestVerdict.Fail);
            } else if (!QosComparer.DomainParticipantQosEquals (xmlParticipantQos, participantQos) ||
                       !QosComparer.TopicQosEquals (xmlTopicQos, topicQos) ||
                       !QosComparer.SubscriberQosEquals (xmlSubscriberQos, subscriberQos) ||
                       !QosComparer.DataReaderQosEquals (xmlReaderQos, readerQos) ||
                       !QosComparer.PublisherQosEquals (xmlPublisherQos, publisherQos) ||
                       !QosComparer.DataWriterQosEquals (xmlWriterQos, writerQos))
            {
                result = new Test.Framework.TestResult (
                    "QosProvider should successfully parse XML file",
                    "QosProvider did not correctly parse XML file " + uri,
                    Test.Framework.TestVerdict.Pass,
                    Test.Framework.TestVerdict.Fail);
            } else {
                result = new Test.Framework.TestResult (
                    "QosProvider should successfully parse XML file",
                    "QosProvider correctly parsed XML file " + uri,
                    Test.Framework.TestVerdict.Pass,
                    Test.Framework.TestVerdict.Pass);
            }

            return result;
        }
Пример #2
0
        public override Test.Framework.TestResult Run()
        {
            DDS.IDataWriter           writer;
            DDS.DataWriterQos         qos;
            DDS.DataWriterQos         qos2;
            DDS.DataWriterQos         holder = null;
            DDS.ReturnCode            rc;
            Test.Framework.TestResult result;
            string expResult = "Writer test succeeded.";

            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict
                                                   .Pass, Test.Framework.TestVerdict.Fail);
            writer = (DDS.IDataWriter) this.ResolveObject("datawriter");
            qos    = (DDS.DataWriterQos) this.ResolveObject("datawriterQos");

            if (writer.GetQos(ref holder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Qos of DataWriter could not be resolved.";
                return(result);
            }
            if (!test.sacs.QosComparer.DataWriterQosEquals(holder, qos))
            {
                result.Result = "Qos of DataWriter does not match provided qos.";
                return(result);
            }
            if (!test.sacs.QosComparer.DataWriterQosEquals(holder, test.sacs.QosComparer.defaultDataWriterQos))
            {
                result.Result = "Qos of DataWriter does not match default qos.";
                return(result);
            }
            qos2 = holder;
            qos2.Deadline.Period         = new DDS.Duration(3, 3);
            qos2.LatencyBudget.Duration  = new DDS.Duration(6, 6);
            qos2.Lifespan.Duration       = new DDS.Duration(9, 9);
            qos2.OwnershipStrength.Value = 22;
            qos2.UserData.Value          = new byte[2];
            qos2.UserData.Value[0]       = 2;
            qos2.UserData.Value[0]       = 4;
            rc = writer.SetQos(qos2);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "New Qos could not be applied.";
                return(result);
            }

            if (writer.GetQos(ref holder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Qos of DataWriter could not be resolved (2).";
                return(result);
            }
            if (!test.sacs.QosComparer.DataWriterQosEquals(holder, qos2))
            {
                result.Result = "Qos of DataWriter does not match provided qos (2).";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #3
0
        public override Test.Framework.TestResult Run()
        {
            DDS.IPublisher    publisher;
            DDS.DataWriterQos dataWriterQos = null;
            DDS.DataWriterQos qosHolder1    = null;
            DDS.DataWriterQos qosHolder2    = null;
            DDS.IDataWriter   writer        = null;
            DDS.ITopic        topic;
            string            expResult = "Default DataWriterQos is used when DATAWRITER_QOS_DEFAULT is specified.";

            Test.Framework.TestResult result;
            DDS.ReturnCode            rc;
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            publisher = (DDS.IPublisher) this.ResolveObject("publisher");
            topic     = (DDS.ITopic) this.ResolveObject("topic");

            if (publisher.GetDefaultDataWriterQos(ref qosHolder1) != DDS.ReturnCode.Ok)
            {
                result.Result = "Could not retrieve default DataWriterQos";
                return(result);
            }
            dataWriterQos = qosHolder1;
            dataWriterQos.History.Kind  = DDS.HistoryQosPolicyKind.KeepAllHistoryQos;
            dataWriterQos.History.Depth = 150;
            publisher.SetDefaultDataWriterQos(dataWriterQos);

            //TODO: JLS, DDS.DataWriterQos.Default does not exist
            writer = publisher.CreateDataWriter(topic, qosHolder1);
            if (writer == null)
            {
                result.Result = "Could not create a DataWriter.";
                return(result);
            }

            if (writer.GetQos(ref qosHolder2) != DDS.ReturnCode.Ok)
            {
                result.Result = "Could not retrieve DataWriter qos";
                return(result);
            }
            if (!test.sacs.QosComparer.DataWriterQosEquals(qosHolder1, qosHolder2))
            {
                result.Result = "Default DataWriterQos is not used when DATAWRITER_QOS_DEFAULT is specified.";
                return(result);
            }
            rc = publisher.DeleteDataWriter(writer);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Could not delete a DataWriter (RETCODE = " + rc + ").";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Tests the initial default DataWriterQos and the getting and setting
        /// of the default DataWriterQos in the Publisher.
        /// </summary>
        /// <remarks>
        /// Tests the initial default DataWriterQos and the getting and setting
        /// of the default DataWriterQos in the Publisher.
        /// </remarks>
        public override Test.Framework.TestResult Run()
        {
            DDS.IPublisher    publisher;
            DDS.DataWriterQos qos       = null;
            string            expResult = "DataWriterQos test succeeded";

            Test.Framework.TestResult result;
            DDS.ReturnCode            rc;
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            publisher = (DDS.IPublisher) this.ResolveObject("publisher");

            if (publisher.GetDefaultDataWriterQos(ref qos) != DDS.ReturnCode.Ok)
            {
                result.Result = "Failed to get the default datawriter qos (1)";
                return(result);
            }
            if (!test.sacs.QosComparer.DataWriterQosEquals(qos, test.sacs.QosComparer.defaultDataWriterQos
                                                           ))
            {
                result.Result = "The default DataWriterQos != default (2)";
                return(result);
            }
            qos.Deadline.Period.NanoSec = DDS.Duration.InfiniteNanoSec + 1;
            rc = publisher.SetDefaultDataWriterQos(qos);
            if (rc != DDS.ReturnCode.BadParameter)
            {
                result.Result = "Received return code " + rc + " but expected RETCODE_BAD_PARAMETER (3)";
                return(result);
            }

            if (publisher.GetDefaultDataWriterQos(ref qos) != DDS.ReturnCode.Ok)
            {
                result.Result = "Failed to get the default datawriter qos (4)";
                return(result);
            }
            if (!test.sacs.QosComparer.DataWriterQosEquals(qos, test.sacs.QosComparer.defaultDataWriterQos))
            {
                result.Result = "The default DataWriterQos != default (4)";
                return(result);
            }
            qos.History.Depth = 8;
            qos.ResourceLimits.MaxSamplesPerInstance = 2;
            rc = publisher.SetDefaultDataWriterQos(qos);
            if (rc != DDS.ReturnCode.InconsistentPolicy)
            {
                result.Result = "Received return code " + rc + " but expected RETCODE_INCONSISTENT_POLICY (5)";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
        public override Test.Framework.TestResult Run()
        {
            DDS.TopicQos      tQos  = null;
            DDS.DataWriterQos dwQos = null;
            DDS.ReturnCode    rc;
            string            expResult = "Initialization success";

            Test.Framework.TestResult result = new Test.Framework.TestResult(
                expResult,
                string.Empty,
                Test.Framework.TestVerdict.Pass,
                Test.Framework.TestVerdict.Fail);

            bce.typeSupport2 = new mod.embeddedStructTypeTypeSupport();
            rc = bce.typeSupport2.RegisterType(bce.participant, "embeddedStructType");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Typesupport could not be registered.";
                return(result);
            }
            rc = bce.participant.GetDefaultTopicQos(ref tQos);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Default TopicQos could not be resolved.";
                return(result);
            }
            bce.topic2 = bce.participant.CreateTopic("embeddedStruct", "embeddedStructType", tQos);
            if (bce.topic2 == null)
            {
                result.Result = "Topic could not be created.";
                return(result);
            }
            rc = bce.publisher.GetDefaultDataWriterQos(ref dwQos);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataWriterQos could not be resolved.";
                return(result);
            }
            bce.datawriter2 = (mod.embeddedStructTypeDataWriter)bce.publisher.CreateDataWriter(bce.topic2, dwQos);
            if (bce.datawriter2 == null)
            {
                result.Result = "DataWriter could not be created.";
                return(result);
            }

            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #6
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);
        }
Пример #7
0
    public static void Main(string[] args)
    {
        DDS.QosProvider   provider = null;
        DDS.DataReaderQos drQos    = new DDS.DataReaderQos();
        DDS.DataWriterQos dwQos    = new DDS.DataWriterQos();
        DDS.DataWriterQos dwBarQos = new DDS.DataWriterQos();
        DDS.ReturnCode    result;

        provider = new DDS.QosProvider("file://path/to/file.xml", "FooQosProfile");
        if (provider != null)
        {
            // As default QoS profile is "FooQosProfile", requesting
            // "TransientKeepLast" in this case is equivalent to requesting
            // "::FooQosProfile::TransientKeepLast".
            result = provider.GetDataReaderQos(ref drQos, "TransientKeepLast");
            if (result != 0)
            {
                Console.WriteLine("Unable to resolve ReaderQos.");
                System.Environment.Exit(1);
            }
            // As default QoS profile is "FooQosProfile", requesting
            // "Transient" would have been equivalent to requesting
            // "::FooQosProfile::Transient".
            result = provider.GetDataWriterQos(ref dwQos, "::FooQosProfile::Transient");
            if (result != 0)
            {
                Console.WriteLine("Unable to resolve WriterQos.");
                System.Environment.Exit(1);
            }
            // As default QoS profile is "FooQosProfile" it is necessary
            // to use the fully-qualified name to get access to QoS-ses from
            // the "BarQosProfile".
            result = provider.GetDataWriterQos(ref dwQos, "::BarQosProfile::Persistent");
            if (result != 0)
            {
                Console.WriteLine("Unable to resolve WriterQos.");
                System.Environment.Exit(1);
            }
        }
        else
        {
            Console.WriteLine("Initialization of QosProvider failed.");
        }
    }
Пример #8
0
        public override Test.Framework.TestResult Run()
        {
            DDS.IDomainParticipant    participant;
            DDS.ReturnCode            retCode;
            DDS.ITopic                topic;
            DDS.TopicQos              tQos;
            DDS.IPublisher            pub;
            Foo.TestDataWriter        testDW;
            DDS.DataWriterQos         dwQos = new DDS.DataWriterQos();
            Test.Framework.TestResult result;
            string expResult = "Successfully written a sample.";

            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            participant = (DDS.IDomainParticipant) this.ResolveObject("participant");
            topic       = (DDS.ITopic) this.ResolveObject("topic");
            tQos        = (DDS.TopicQos) this.ResolveObject("topicQos");
            pub         = participant.CreatePublisher();
            if (pub == null)
            {
                result.Result = "participant.create_publisher failed.";
                return(result);
            }
            retCode = pub.GetDefaultDataWriterQos(ref dwQos);
            if (retCode != DDS.ReturnCode.Ok)
            {
                result.Result = "publisher.get_default_datawriter_qos failed.";
                return(result);
            }
            testDW = (Foo.TestDataWriter)pub.CreateDataWriter(topic, dwQos);
            if (testDW == null)
            {
                result.Result = "publisher.create_datawriter failed.";
                return(result);
            }



            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #9
0
        public override Test.Framework.TestResult Run()
        {
            DDS.IPublisher    publisher;
            DDS.DataWriterQos dataWriterQos = null;
            DDS.DataWriterQos qosHolder1    = null;
            DDS.ITopic        topic;
            string            expResult = "copy_from_topic_qos rejects TOPIC_QOS_DEFAULT with correct code.";

            Test.Framework.TestResult result;
            DDS.ReturnCode            rc = DDS.ReturnCode.Error;
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            publisher = (DDS.IPublisher) this.ResolveObject("publisher");
            topic     = (DDS.ITopic) this.ResolveObject("topic");

            if (publisher.GetDefaultDataWriterQos(ref qosHolder1) != DDS.ReturnCode.Ok)
            {
                result.Result = "Could not retrieve default DataWriterQos";
                return(result);
            }
            dataWriterQos = qosHolder1;
            dataWriterQos.History.Kind  = DDS.HistoryQosPolicyKind.KeepAllHistoryQos;
            dataWriterQos.History.Depth = 150;

            // TODO: JLS, Verify the intent of this BadParameter test.
            DDS.TopicQos defaultTopicQos = null;
            rc = publisher.CopyFromTopicQos(ref qosHolder1, defaultTopicQos);
            if (rc != DDS.ReturnCode.BadParameter)
            {
                result.Result = "copy_from_topic_qos returns wrong code (RETCODE = " + rc + ").";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #10
0
        /*
         * P I N G
         */
        public void run(String[] args)
        {
            System.Console.WriteLine("starting PING");
            DDS.ICondition[] conditionList = null;
            DDS.IWaitSet w;

            DDS.DomainParticipantQos dpQos;
            DDS.TopicQos tQos;
            DDS.PublisherQos pQos;
            DDS.DataWriterQos dwQos;
            DDS.SubscriberQos sQos;
            DDS.DataReaderQos drQos;

            DDS.Duration wait_timeout = new DDS.Duration(3, 0);

            DDS.ReturnCode result;
            Boolean finish_flag = false;
            Boolean timeout_flag = false;
            Boolean terminate = false;

            int imax = 1;
            int i;
            uint block;
            int nof_cycles = 100;
            int nof_blocks = 20;

            /**
             * Command Line argument processing
             */
            if (args.Length != 0)
            {
                if (args.Length != 5)
                {
                    System.Console.WriteLine("Invalid.....");
                    System.Console.WriteLine("Usage: ping blocks blocksize topic_id WRITE_PARTITION READ_PARTITION ");
                    Environment.Exit(1);
                }
                nof_blocks = int.Parse(args[0]);
                nof_cycles = int.Parse(args[1]);
                topic_id = args[2][0];
                write_partition = args[3];
                read_partition = args[4];
            }

            /*
             * Create WaitSet
             */

            w = new DDS.WaitSet();

            /*
             * Initialize Qos variables
             */
            dpQos = new DDS.DomainParticipantQos();
            tQos = new DDS.TopicQos();
            pQos = new DDS.PublisherQos();
            dwQos = new DDS.DataWriterQos();
            sQos = new DDS.SubscriberQos();
            drQos = new DDS.DataReaderQos();

            /*
             * Create participant
             */
            dpf = DDS.DomainParticipantFactory.Instance;
            dpf.GetDefaultParticipantQos(ref dpQos);

            ErrorHandler.checkHandle(dpf, "DDS.DomainParticipantFactory.Instance");

            dp = dpf.CreateParticipant(myDomain, dpQos);
            if (dp == null)
            {
                System.Console.WriteLine("PING: ERROR - Splice Daemon not running");
                return;
            }

            /*
              * Create PING publisher
              */
            dp.GetDefaultPublisherQos(ref pQos);
            pQos.Partition.Name = new String[1];
            pQos.Partition.Name[0] = write_partition;
            p = dp.CreatePublisher(pQos);

            /*
             * Create PONG subscriber
             */
            dp.GetDefaultSubscriberQos(ref sQos);
            sQos.Partition.Name = new String[1];
            sQos.Partition.Name[0] = read_partition;
            s = dp.CreateSubscriber(sQos);

            /*
             * Get default DataReader and DataWriter QoS settings
             */
            p.GetDefaultDataWriterQos(ref dwQos);
            s.GetDefaultDataReaderQos(ref drQos);

            /*
             * Get default Topic Qos settings
             */
            dp.GetDefaultTopicQos(ref tQos);

            /*match data reader/writer qos with topic qos*/
            p.CopyFromTopicQos(ref dwQos, tQos);
            s.CopyFromTopicQos(ref drQos, tQos);

            /*
             * PP_min_msg
             */
            /* Create Topic */
            PP_min_dt = new pingpong.PP_min_msgTypeSupport();
            PP_min_dt.RegisterType(dp, "pingpong::PP_min_msg");
            PP_min_topic = dp.CreateTopic("PP_min_topic", "pingpong::PP_min_msg", tQos);

            /* Create datawriter */
            PP_min_writer = p.CreateDataWriter(PP_min_topic, dwQos) as pingpong.PP_min_msgDataWriter;

            /* Create datareader */
            PP_min_reader = s.CreateDataReader(PP_min_topic, drQos) as pingpong.PP_min_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_min_sc = PP_min_reader.StatusCondition;
            PP_min_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);

            result = w.AttachCondition(PP_min_sc);
            ErrorHandler.checkStatus(result, "attach condition pp_min_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_seq_msg
             */
            /* Create Topic */
            PP_seq_dt = new pingpong.PP_seq_msgTypeSupport();
            PP_seq_dt.RegisterType(dp, "pingpong::PP_seq_msg");
            PP_seq_topic = dp.CreateTopic("PP_seq_topic", "pingpong::PP_seq_msg", tQos);

            /* Create datawriter */
            PP_seq_writer = p.CreateDataWriter(PP_seq_topic, dwQos) as pingpong.PP_seq_msgDataWriter;

            /* Create datareader */
            PP_seq_reader = s.CreateDataReader(PP_seq_topic, drQos) as pingpong.PP_seq_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_seq_sc = PP_seq_reader.StatusCondition;
            PP_seq_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);

            result = w.AttachCondition(PP_seq_sc);
            ErrorHandler.checkStatus(result, "attach condition pp_seq_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_string_msg
             */

            /* Create Topic */
            PP_string_dt = new pingpong.PP_string_msgTypeSupport();
            PP_string_dt.RegisterType(dp, "pingpong::PP_string_msg");
            PP_string_topic = dp.CreateTopic("PP_string_topic", "pingpong::PP_string_msg", tQos);

            /* Create datawriter */
            PP_string_writer = p.CreateDataWriter(PP_string_topic, dwQos) as pingpong.PP_string_msgDataWriter;

            /* Create datareader */
            PP_string_reader = s.CreateDataReader(PP_string_topic, drQos) as pingpong.PP_string_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_string_sc = PP_string_reader.StatusCondition;
            PP_string_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);

            result = w.AttachCondition(PP_string_sc);
            ErrorHandler.checkStatus(result, "attach condition pp_string_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_fixed_msg
             */

            /* Create Topic */
            PP_fixed_dt = new pingpong.PP_fixed_msgTypeSupport();
            PP_fixed_dt.RegisterType(dp, "pingpong::PP_fixed_msg");

            PP_fixed_topic = dp.CreateTopic("PP_fixed_topic", "pingpong::PP_fixed_msg", tQos);

            /* Create datawriter */
            PP_fixed_writer = p.CreateDataWriter(PP_fixed_topic, dwQos) as pingpong.PP_fixed_msgDataWriter;

            /* Create datareader */
            PP_fixed_reader = s.CreateDataReader(PP_fixed_topic, drQos) as pingpong.PP_fixed_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_fixed_sc = PP_fixed_reader.StatusCondition;
            PP_fixed_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_fixed_sc);
            ErrorHandler.checkStatus(result, "attach condition pp_fixed_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_array_msg
             */

            /* Create Topic */
            PP_array_dt = new pingpong.PP_array_msgTypeSupport();
            PP_array_dt.RegisterType(dp, "pingpong::PP_array_msg");
            PP_array_topic = dp.CreateTopic("PP_array_topic", "pingpong::PP_array_msg", tQos);

            /* Create datawriter */
            PP_array_writer = p.CreateDataWriter(PP_array_topic, dwQos) as pingpong.PP_array_msgDataWriter;

            /* Create datareader */
            PP_array_reader = s.CreateDataReader(PP_array_topic, drQos) as pingpong.PP_array_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_array_sc = PP_array_reader.StatusCondition;
            PP_array_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);

            result = w.AttachCondition(PP_array_sc);

            ErrorHandler.checkStatus(result, "attach condition pp_array_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_quit_msg
             */

            /* Create Topic */
            PP_quit_dt = new pingpong.PP_quit_msgTypeSupport();
            PP_quit_dt.RegisterType(dp, "pingpong::PP_quit_msg");
            PP_quit_topic = dp.CreateTopic("PP_quit_topic", "pingpong::PP_quit_msg", tQos);

            /* Create datawriter */
            PP_quit_writer = p.CreateDataWriter(PP_quit_topic, dwQos) as pingpong.PP_quit_msgDataWriter;

            for (block = 0; block < nof_blocks; block++)
            {
                while (!finish_flag)
                {
                    /*
                     * Send Initial message
                     */
                    timeout_flag = false;

                    switch (topic_id)
                    {
                        case 'm':
                            {
                                /* System.Console.WriteLine ("PING: sending initial ping_min"); */
                                pingpong.PP_min_msg PPdata = new pingpong.PP_min_msg();
                                PPdata.count = 0;
                                PPdata.block = block;
                                preWriteTime.timeGet();
                                result = PP_min_writer.Write(PPdata);
                                postWriteTime.timeGet();
                            }
                            break;
                        case 'q':
                            {
                                /* System.Console.WriteLine ("PING: sending initial ping_seq"); */
                                pingpong.PP_seq_msg PPdata = new pingpong.PP_seq_msg();
                                PPdata.count = 0;
                                PPdata.block = block;
                                preWriteTime.timeGet();
                                result = PP_seq_writer.Write(PPdata);
                                postWriteTime.timeGet();
                            }
                            break;
                        case 's':
                            {
                                //System.Console.WriteLine ("PING: sending initial ping_string");
                                pingpong.PP_string_msg PPdata = new pingpong.PP_string_msg();
                                PPdata.count = 0;
                                PPdata.block = block;
                                PPdata.a_string = "a_string " + block.ToString();
                                preWriteTime.timeGet();
                                result = PP_string_writer.Write(PPdata);
                                ErrorHandler.checkStatus(result, "writing PPData in case S");
                                postWriteTime.timeGet();
                            }
                            break;
                        case 'f':
                            {
                                /* System.Console.WriteLine ("PING: sending initial ping_fixed"); */
                                pingpong.PP_fixed_msg PPdata = new pingpong.PP_fixed_msg();
                                PPdata.count = 0;
                                PPdata.block = block;
                                preWriteTime.timeGet();
                                result = PP_fixed_writer
                                        .Write(PPdata);
                                postWriteTime.timeGet();
                            }
                            break;
                        case 'a':
                            {
                                /* System.Console.WriteLine ("PING: sending initial ping_array"); */
                                pingpong.PP_array_msg PPdata = new pingpong.PP_array_msg();
                                PPdata.count = 0;
                                PPdata.block = block;
                                PPdata.str_arr_char = new char[10];
                                PPdata.str_arr_octet = new byte[10];
                                PPdata.str_arr_short = new short[10];
                                PPdata.str_arr_ushort = new ushort[10];
                                PPdata.str_arr_long = new int[10];
                                PPdata.str_arr_ulong = new uint[10];
                                PPdata.str_arr_longlong = new long[10];
                                PPdata.str_arr_ulonglong = new ulong[10];
                                PPdata.str_arr_float = new float[10];
                                PPdata.str_arr_double = new double[10];
                                PPdata.str_arr_boolean = new Boolean[11];
                                preWriteTime.timeGet();
                                result = PP_array_writer
                                        .Write(PPdata);
                                postWriteTime.timeGet();
                            }
                            break;
                        case 't':
                            {
                                /* System.Console.WriteLine ("PING: sending initial ping_quit"); */
                                pingpong.PP_quit_msg PPdata = new pingpong.PP_quit_msg();
                                PPdata.quit = true;
                                terminate = true;
                                finish_flag = true;
                                preWriteTime.timeGet();
                                result = PP_quit_writer.Write(PPdata);
                                postWriteTime.timeGet();
                            }
                            break;
                        default:
                            System.Console.WriteLine("Invalid topic-id");
                            return;
                    }

                    if (!terminate)
                    {
                        roundTripTime.set(preWriteTime.get());
                        write_access.add_stats(postWriteTime.sub(preWriteTime));

                        /*
                         * Wait for response, calculate timing, and send another
                         * data if not ready
                         */
                        while (!(timeout_flag || finish_flag))
                        {
                            result = w.Wait(ref conditionList, wait_timeout);
                            //ErrorHandler.checkStatus(result, "wait did not work condition list is probably null!");
                            if (conditionList != null)
                            {
                                imax = conditionList.Length;
                                if (imax != 0)
                                {
                                    for (i = 0; i < imax; i++)
                                    {
                                        if (conditionList[i] == PP_min_sc)
                                        {
                                            finish_flag = PP_min_handler(nof_cycles);
                                        }
                                        else if (conditionList[i] == PP_seq_sc)
                                        {
                                            finish_flag = PP_seq_handler(nof_cycles);
                                        }
                                        else if (conditionList[i] == PP_string_sc)
                                        {
                                            finish_flag = PP_string_handler(nof_cycles);
                                        }
                                        else if (conditionList[i] == PP_fixed_sc)
                                        {
                                            finish_flag = PP_fixed_handler(nof_cycles);
                                        }
                                        else if (conditionList[i] == PP_array_sc)
                                        {
                                            finish_flag = PP_array_handler(nof_cycles);
                                        }
                                        else
                                        {
                                            System.Console.WriteLine("PING: unexpected condition triggered: "
                                                            + conditionList[i]);
                                        }
                                    }
                                }
                                else
                                {
                                    System.Console.WriteLine("PING: TIMEOUT - message lost (1)");
                                    timeout_flag = true;
                                }
                            }
                            else
                            {
                                System.Console.WriteLine("PING: TIMEOUT - message lost (2)");
                                timeout_flag = true;
                            }
                        }
                    }
                }
                if (!terminate)
                {
                    finish_flag = false;
                    if (block == 0)
                    {
                        System.Console.WriteLine("# PING PONG measurements (in us)");
                        System.Console.WriteLine("# Executed at: ");
                        System.Console.WriteLine("#           Roundtrip time [us]             Write-access time [us]          Read-access time [us]");
                        System.Console.WriteLine("# Block     Count   mean    min    max      Count   mean    min    max      Count   mean    min    max");
                    }

                    System.Console.WriteLine(String.Format("{0,-6} {1, 10} {2, 6} {3, 6} {4, 6} {5, 10} {6, 6} {7, 6} {8, 6} {9, 10} {10, 6} {11, 6} {12, 6}",
                        block,roundtrip.count,roundtrip.average,roundtrip.min, roundtrip.max,write_access.count,
                        write_access.average,write_access.min, write_access.max, read_access.count, read_access.average,
                        read_access.min, read_access.max));
                    Console.Out.Flush();
                    write_access.init_stats();
                    read_access.init_stats();
                    roundtrip.init_stats();
                }
            }
            result = s.DeleteDataReader(PP_min_reader);
            result = p.DeleteDataWriter(PP_min_writer);
            result = s.DeleteDataReader(PP_seq_reader);
            result = p.DeleteDataWriter(PP_seq_writer);
            result = s.DeleteDataReader(PP_string_reader);
            result = p.DeleteDataWriter(PP_string_writer);
            result = s.DeleteDataReader(PP_fixed_reader);
            result = p.DeleteDataWriter(PP_fixed_writer);
            result = s.DeleteDataReader(PP_array_reader);
            result = p.DeleteDataWriter(PP_array_writer);
            result = p.DeleteDataWriter(PP_quit_writer);
            result = dp.DeleteSubscriber(s);
            result = dp.DeletePublisher(p);
            result = dp.DeleteTopic(PP_min_topic);
            result = dp.DeleteTopic(PP_seq_topic);
            result = dp.DeleteTopic(PP_string_topic);
            result = dp.DeleteTopic(PP_fixed_topic);
            result = dp.DeleteTopic(PP_array_topic);
            result = dp.DeleteTopic(PP_quit_topic);
            result = dpf.DeleteParticipant(dp);

            return;
        }
Пример #11
0
        public override Test.Framework.TestResult Run(Test.Framework.TestCase testCase)
        {
            DDS.DomainParticipantFactory factory;
            DDS.IDomainParticipant       participant;
            DDS.DomainParticipantQos     pqos   = null;
            DDS.SubscriberQos            subQos = null;
            DDS.ISubscriber           subscriber;
            DDS.PublisherQos          pubQos = null;
            DDS.IPublisher            publisher;
            mod.tstTypeSupport        typeSupport;
            DDS.TopicQos              tQos = null;
            DDS.ITopic                topic;
            DDS.DataReaderQos         drQos = null;
            mod.tstDataReader         datareader;
            DDS.DataWriterQos         dwQos = null;
            mod.tstDataWriter         datawriter;
            Test.Framework.TestResult result;
            DDS.ReturnCode            rc;
            result = new Test.Framework.TestResult("Initialization success", string.Empty, Test.Framework.TestVerdict
                                                   .Pass, Test.Framework.TestVerdict.Fail);
            factory = DDS.DomainParticipantFactory.Instance;
            if (factory == null)
            {
                result.Result = "DomainParticipantFactory could not be initialized.";
                return(result);
            }

            if (factory.GetDefaultParticipantQos(ref pqos) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DomainParticipantQos could not be resolved.";
                return(result);
            }
            participant = factory.CreateParticipant(DDS.DomainId.Default, pqos);//, null, 0);
            if (participant == null)
            {
                result.Result = "Creation of DomainParticipant failed.";
                return(result);
            }

            if (participant.GetDefaultSubscriberQos(ref subQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default SubscriberQos could not be resolved.";
                return(result);
            }
            subscriber = participant.CreateSubscriber(subQos);//, null, 0);
            if (subscriber == null)
            {
                result.Result = "Subscriber could not be created.";
                return(result);
            }
            typeSupport = new mod.tstTypeSupport();
            rc          = typeSupport.RegisterType(participant, "tstType");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Typesupport could not be registered.";
                return(result);
            }

            if (participant.GetDefaultTopicQos(ref tQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default TopicQos could not be resolved.";
                return(result);
            }

            topic = participant.CreateTopic("tst", "tstType", tQos);//, null, 0);
            if (topic == null)
            {
                result.Result = "Topic could not be created.";
                return(result);
            }
            if (participant.GetDefaultPublisherQos(ref pubQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default PublisherQos could not be resolved.";
                return(result);
            }
            publisher = participant.CreatePublisher(pubQos);//, null, 0);
            if (publisher == null)
            {
                result.Result = "Publisher could not be created.";
                return(result);
            }

            if (subscriber.GetDefaultDataReaderQos(ref drQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataReaderQos could not be resolved.";
                return(result);
            }
            datareader = (mod.tstDataReader)subscriber.CreateDataReader(topic, drQos);//, null, 0);
            if (datareader == null)
            {
                result.Result = "DataReader could not be created.";
                return(result);
            }

            if (publisher.GetDefaultDataWriterQos(ref dwQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataWriterQos could not be resolved.";
                return(result);
            }
            datawriter = (mod.tstDataWriter)publisher.CreateDataWriter(topic, dwQos);//, null, 0);

            testCase.RegisterObject("factory", factory);
            testCase.RegisterObject("participantQos", pqos);
            testCase.RegisterObject("participant", participant);
            testCase.RegisterObject("topic", topic);
            testCase.RegisterObject("topicQos", tQos);
            testCase.RegisterObject("subscriber", subscriber);
            testCase.RegisterObject("subscriberQos", subQos);
            testCase.RegisterObject("datareader", datareader);
            testCase.RegisterObject("datareaderQos", drQos);
            testCase.RegisterObject("publisher", publisher);
            testCase.RegisterObject("publisherQos", pubQos);
            testCase.RegisterObject("datawriter", datawriter);
            testCase.RegisterObject("datawriterQos", dwQos);
            result.Result  = "Initialization success.";
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #12
0
        public void run(String[] args)
        {
            String myDomain = null;
            DDS.DomainParticipantFactory dpf;
            DDS.IDomainParticipant dp;
            DDS.IPublisher p;
            DDS.ISubscriber s;

            pingpong.PP_min_msgDataWriter PP_min_writer;
            pingpong.PP_seq_msgDataWriter PP_seq_writer;
            pingpong.PP_string_msgDataWriter PP_string_writer;
            pingpong.PP_fixed_msgDataWriter PP_fixed_writer;
            pingpong.PP_array_msgDataWriter PP_array_writer;

            pingpong.PP_min_msgDataReader PP_min_reader;
            pingpong.PP_seq_msgDataReader PP_seq_reader;
            pingpong.PP_string_msgDataReader PP_string_reader;
            pingpong.PP_fixed_msgDataReader PP_fixed_reader;
            pingpong.PP_array_msgDataReader PP_array_reader;
            pingpong.PP_quit_msgDataReader PP_quit_reader;

            pingpong.PP_min_msgTypeSupport PP_min_dt;
            pingpong.PP_seq_msgTypeSupport PP_seq_dt;
            pingpong.PP_string_msgTypeSupport PP_string_dt;
            pingpong.PP_fixed_msgTypeSupport PP_fixed_dt;
            pingpong.PP_array_msgTypeSupport PP_array_dt;
            pingpong.PP_quit_msgTypeSupport PP_quit_dt;

            pingpong.PP_min_msg[] PP_min_dataList = null;
            pingpong.PP_seq_msg[] PP_seq_dataList = null;
            pingpong.PP_string_msg[] PP_string_dataList = null;
            pingpong.PP_fixed_msg[] PP_fixed_dataList = null;
            pingpong.PP_array_msg[] PP_array_dataList = null;
            pingpong.PP_quit_msg[] PP_quit_dataList = null;

            DDS.IStatusCondition PP_min_sc;
            DDS.IStatusCondition PP_seq_sc;
            DDS.IStatusCondition PP_string_sc;
            DDS.IStatusCondition PP_fixed_sc;
            DDS.IStatusCondition PP_array_sc;
            DDS.IStatusCondition PP_quit_sc;

            DDS.ITopic PP_min_topic;
            DDS.ITopic PP_seq_topic;
            DDS.ITopic PP_string_topic;
            DDS.ITopic PP_fixed_topic;
            DDS.ITopic PP_array_topic;
            DDS.ITopic PP_quit_topic;

            DDS.ICondition[] conditionList = null;
            DDS.SampleInfo[] infoList = null;
            DDS.IWaitSet w;

            DDS.DomainParticipantQos dpQos;
            DDS.TopicQos tQos;
            DDS.PublisherQos pQos;
            DDS.DataWriterQos dwQos;
            DDS.SubscriberQos sQos;
            DDS.DataReaderQos drQos;

            Boolean terminate = false;

            DDS.ReturnCode result;
            int i;
            int imax;
            int j;
            int jmax;

            /*
             * Evaluate cmdline arguments
             */

            if (args.Length != 0)
            {
                if (args.Length != 2)
                {
                    System.Console.WriteLine("Invalid.....");
                    System.Console.WriteLine("Usage: pong [READ_PARTITION WRITE_PARTITION]");
                    Environment.Exit(1);
                }
                read_partition = args[0];
                write_partition = args[1];
            }

            /*
             * Create WaitSet
             */
            w = new DDS.WaitSet();
            /*
             * Initialize Qos variables
             */
            dpQos = new DDS.DomainParticipantQos();
            tQos = new DDS.TopicQos();
            pQos = new DDS.PublisherQos();
            dwQos = new DDS.DataWriterQos();
            sQos = new DDS.SubscriberQos();
            drQos = new DDS.DataReaderQos();

            /*
             * Create participant
             */
            dpf = DDS.DomainParticipantFactory.Instance;
            dpf.GetDefaultParticipantQos(ref dpQos);
            dp = dpf.CreateParticipant(myDomain, dpQos, null, DDS.StatusKind.Any);
            if (dp == null)
            {
                System.Console.WriteLine("PING: ERROR - Splice Daemon not running");
                return;
            }

            /*
             * Create PONG publisher
             */
            dp.GetDefaultPublisherQos(ref pQos);
            pQos.Partition.Name = new String[1];
            pQos.Partition.Name[0] = write_partition;
            p = dp.CreatePublisher(pQos);

            /*
             * Create PING subscriber
             */
            dp.GetDefaultSubscriberQos(ref sQos);
            sQos.Partition.Name = new String[1];
            sQos.Partition.Name[0] = read_partition;
            s = dp.CreateSubscriber(sQos);
            /*
             * Get default DataReader and DataWriter QoS settings
             */
            p.GetDefaultDataWriterQos(ref dwQos);
            s.GetDefaultDataReaderQos(ref drQos);

            /*
             * Get default Topic Qos settings
             */
            dp.GetDefaultTopicQos(ref tQos);

            /* match data reader/writer qos with topic qos */
            p.CopyFromTopicQos(ref dwQos, tQos);
            s.CopyFromTopicQos(ref drQos, tQos);

            /*
             * PP_min_msg
             */

            /* Create Topic */
            PP_min_dt = new pingpong.PP_min_msgTypeSupport();
            PP_min_dt.RegisterType(dp, "pingpong::PP_min_msg");
            PP_min_topic = dp.CreateTopic("PP_min_topic", "pingpong::PP_min_msg", tQos);

            /* Create datawriter */
            PP_min_writer = p.CreateDataWriter(PP_min_topic, dwQos) as pingpong.PP_min_msgDataWriter;

            /* Create datareader */
            PP_min_reader = s.CreateDataReader(PP_min_topic, drQos) as pingpong.PP_min_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_min_sc = PP_min_reader.StatusCondition;
            PP_min_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_min_sc);
            // assert(result == RETCODE_OK.value);

            /*
             * PP_seq_msg
             */

            /*  Create Topic */
            PP_seq_dt = new pingpong.PP_seq_msgTypeSupport();
            PP_seq_dt.RegisterType(dp, "pingpong::PP_seq_msg");
            PP_seq_topic = dp.CreateTopic("PP_seq_topic", "pingpong::PP_seq_msg", tQos);

            /* Create datawriter */
            PP_seq_writer = p.CreateDataWriter(PP_seq_topic, dwQos) as pingpong.PP_seq_msgDataWriter;

            /* Create datareader */
            PP_seq_reader = s.CreateDataReader(PP_seq_topic, drQos) as pingpong.PP_seq_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_seq_sc = PP_seq_reader.StatusCondition;
            PP_seq_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_seq_sc);
            //assert(result == RETCODE_OK.value);

            /*
             * PP_string_msg
             */

            /*  Create Topic */
            PP_string_dt = new pingpong.PP_string_msgTypeSupport();
            PP_string_dt.RegisterType(dp, "pingpong::PP_string_msg");
            PP_string_topic = dp.CreateTopic("PP_string_topic", "pingpong::PP_string_msg", tQos);

            /* Create datawriter */
            PP_string_writer = p.CreateDataWriter(PP_string_topic, dwQos) as pingpong.PP_string_msgDataWriter;

            /* Create datareader */
            PP_string_reader = s.CreateDataReader(PP_string_topic,drQos) as pingpong.PP_string_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_string_sc = PP_string_reader.StatusCondition;
            PP_string_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_string_sc);
            //assert(result == RETCODE_OK.value);

            /*
             * PP_fixed_msg
             */

            /*  Create Topic */
            PP_fixed_dt = new pingpong.PP_fixed_msgTypeSupport();
            PP_fixed_dt.RegisterType(dp, "pingpong::PP_fixed_msg");
            PP_fixed_topic = dp.CreateTopic("PP_fixed_topic", "pingpong::PP_fixed_msg", tQos);

            /* Create datawriter */
            PP_fixed_writer = p.CreateDataWriter(PP_fixed_topic, dwQos) as pingpong.PP_fixed_msgDataWriter;

            /* Create datareader */
            PP_fixed_reader = s.CreateDataReader(PP_fixed_topic, drQos) as pingpong.PP_fixed_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_fixed_sc = PP_fixed_reader.StatusCondition;
            PP_fixed_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_fixed_sc);
            //assert(result == RETCODE_OK.value);

            /*
             * PP_array_msg
             */

            /*  Create Topic */
            PP_array_dt = new pingpong.PP_array_msgTypeSupport();
            PP_array_dt.RegisterType(dp, "pingpong::PP_array_msg");
            PP_array_topic = dp.CreateTopic("PP_array_topic", "pingpong::PP_array_msg", tQos);

            /* Create datawriter */
            PP_array_writer = p.CreateDataWriter(PP_array_topic, dwQos) as pingpong.PP_array_msgDataWriter;

            /* Create datareader */
            PP_array_reader = s.CreateDataReader(PP_array_topic, drQos) as pingpong.PP_array_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_array_sc = PP_array_reader.StatusCondition;
            PP_array_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_array_sc);
            //assert(result == RETCODE_OK.value);

            /*
             * PP_quit_msg
             */

            /*  Create Topic */
            PP_quit_dt = new pingpong.PP_quit_msgTypeSupport();
            PP_quit_dt.RegisterType(dp, "pingpong::PP_quit_msg");
            PP_quit_topic = dp.CreateTopic("PP_quit_topic", "pingpong::PP_quit_msg", tQos);

            /* Create datareader */
            PP_quit_reader = s.CreateDataReader(PP_quit_topic, drQos) as pingpong.PP_quit_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_quit_sc = PP_quit_reader.StatusCondition;
            PP_quit_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_quit_sc);
            //assert(result == RETCODE_OK.value);

            while (!terminate)
            {
                DDS.Duration wait_timeout = new DDS.Duration(DDS.Duration.InfiniteSec, DDS.Duration.InfiniteSec);

                result = w.Wait(ref conditionList, wait_timeout);
                ErrorHandler.checkStatus(result, "wait did not succeeed");

                if (result == DDS.ReturnCode.AlreadyDeleted)
                {
                    terminate = true;
                    continue;
                }
                if (conditionList != null)
                {
                    imax = conditionList.Length;
                    for (i = 0; i < imax; i++)
                    {
                        if (conditionList[i] == PP_min_sc)
                        {
                            result = PP_min_reader.Take(ref PP_min_dataList, ref infoList,
                                          DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_min_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_min_writer.Write(PP_min_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_min_reader.ReturnLoan(ref PP_min_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_min triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_seq_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_seq arrived"); */
                            result = PP_seq_reader.Take(ref PP_seq_dataList, ref infoList,
                                         DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_seq_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_seq_writer.Write(PP_seq_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_seq_reader.ReturnLoan(ref PP_seq_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_seq triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_string_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_string arrived"); */
                            result = PP_string_reader.Take(ref PP_string_dataList, ref infoList,
                                         DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_string_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_string_writer.Write(PP_string_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_string_reader.ReturnLoan(ref PP_string_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_string triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_fixed_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_fixed arrived"); */
                            result = PP_fixed_reader.Take(ref PP_fixed_dataList, ref infoList,
                                         DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_fixed_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_fixed_writer.Write(PP_fixed_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_fixed_reader.ReturnLoan(ref PP_fixed_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_fixed triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_array_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_array arrived"); */
                            result = PP_array_reader.Take(ref PP_array_dataList, ref infoList,
                                         DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_array_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_array_writer.Write(PP_array_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_array_reader.ReturnLoan(ref PP_array_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_array triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_quit_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_quit arrived"); */
                            result = PP_quit_reader.Take(ref PP_quit_dataList, ref infoList,
                                         DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_quit_dataList.Length;
                            if (jmax != 0)
                            {
                                result = PP_quit_reader.ReturnLoan(ref PP_quit_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_quit triggered, but no data available");
                            }
                            terminate = true;
                        }
                        else
                        {
                            System.Console.WriteLine("PONG: unknown condition triggered: " + conditionList[i]);
                        }
                    }
                }
                else
                {
                    System.Console.WriteLine("PONG: unknown condition triggered");
                }
            }

            result = s.DeleteDataReader(PP_min_reader);
            result = p.DeleteDataWriter(PP_min_writer);
            result = s.DeleteDataReader(PP_seq_reader);
            result = p.DeleteDataWriter(PP_seq_writer);
            result = s.DeleteDataReader(PP_string_reader);
            result = p.DeleteDataWriter(PP_string_writer);
            result = s.DeleteDataReader(PP_fixed_reader);
            result = p.DeleteDataWriter(PP_fixed_writer);
            result = s.DeleteDataReader(PP_array_reader);
            result = p.DeleteDataWriter(PP_array_writer);
            result = s.DeleteDataReader(PP_quit_reader);
            result = dp.DeleteSubscriber(s);
            result = dp.DeletePublisher(p);
            result = dp.DeleteTopic(PP_min_topic);
            result = dp.DeleteTopic(PP_seq_topic);
            result = dp.DeleteTopic(PP_string_topic);
            result = dp.DeleteTopic(PP_fixed_topic);
            result = dp.DeleteTopic(PP_array_topic);
            result = dp.DeleteTopic(PP_quit_topic);
            result = dpf.DeleteParticipant(dp);

            return;
        }
    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 = 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 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 writer --- //

        /* We are going to load different QoS profiles for the two DWs */
        DDS.DataWriterQos writerQos = new DDS.DataWriterQos();

        /* 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);
        DDS.DomainParticipantFactory.get_instance().get_datawriter_qos_from_profile(writerQos, "keys_Library", "keys_Profile_dw2");

        /* If you want to set the writer_data_lifecycle 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
        * and get_datawriter_qos_from_profile calls above.
        */

        /*
        publisher.get_default_datawriter_qos(writerQos);

        writerQos.writer_data_lifecycle.autodispose_unregistered_instances = false;
        writerQos.ownership.kind = DDS.OwnershipQosPolicyKind.EXCLUSIVE_OWNERSHIP_QOS;
        writerQos.ownership_strength.value = 10;

        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            writerQos,
            null,
            DDS.StatusMask.STATUS_MASK_NONE);

        writerQos.ownership_strength.value = 5;
        */

        DDS.DataWriter writer2 = publisher.create_datawriter(
            topic,
            writerQos,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);

        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        keysDataWriter keys_writer = (keysDataWriter)writer;

        if (writer2 == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        keysDataWriter keys_writer2 = (keysDataWriter)writer2;

        // --- Write --- //

        /* Creates three instances */
        keys[] instance = new keys[3] { null, null, null };

        /* Create data sample for writing */
        instance[0] = keysTypeSupport.create_data();
        instance[1] = keysTypeSupport.create_data();
        instance[2] = keysTypeSupport.create_data();
        if ((instance[0] == null)
                       ||
            (instance[1] == null)
                       ||
            (instance[2] == null)
            )
        {
            shutdown(participant);
            throw new ApplicationException(
                "keysTypeSupport.create_data error");
        }

        /* RTI Connext could examine the key fields each time it needs to determine
        * which data-instance is being modified.
        * However, for performance and semantic reasons, it is better
        * for your application to declare all the data-instances it intends to
        * modify prior to actually writing any samples. This is known as registration.
        */

        /* In order to register the instances, we must set their associated keys first */
        instance[0].code = 0;
        instance[1].code = 1;
        instance[2].code = 2;

        /* 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[] handle = new DDS.InstanceHandle_t[3];

        Console.WriteLine("----DW1 registering instance handle", instance[0].code);
        handle[0] = keys_writer.register_instance(instance[0]);

        // Init coordinates
        instance[0].x = 1;
        instance[1].x = 1;
        instance[2].x = 1;

        int[] active = new int[] { 1, 0, 0 }; // Only send active keys.

        /* Make variables for the instance for the second datawriter to use.
        Note that it actually refers to the same logical instance, but
        because we're running both datawriters in the same thread, we
        to create separate variables so they don't clobber each other.
        */

        keys instance_dw2 = null;

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

        /* instance_dw2 and instance[1] have the same key, and thus
           will write to the same instance (ins1).
         */
        instance_dw2.code = instance[1].code;
        instance_dw2.x = 2;
        DDS.InstanceHandle_t handle_dw2 = keys_writer2.register_instance(instance_dw2);
        int active_dw2 = 1;

        /* Main loop */
        const System.Int32 send_period = 1000; // milliseconds
        for (int count = 0; (sample_count == 0) || (count < sample_count); ++count)
        {
            System.Threading.Thread.Sleep(send_period);

            /* Modify the data to be sent here */
            instance[0].y = count;
            instance[1].y = count + 1000;
            instance[2].y = count + 2000;

            instance_dw2.y = -count - 1000;

            /* We control two datawriters via a state machine here rather than
               introducing separate threads.
            */
            /* Control first DataWriter */
            switch (count)
            {
                case 4:
                    { /* Start sending the second (ins1) and third instances (ins2) */
                        Console.WriteLine("----DW1 registering instance {0}", instance[1].code);
                        Console.WriteLine("----DW1 registering instance {0}", instance[2].code);
                        handle[1] = keys_writer.register_instance(instance[1]);
                        handle[2] = keys_writer.register_instance(instance[2]);
                        active[1] = 1;
                        active[2] = 1;
                    } break;
                case 8:
                    { /* Dispose the second instance (ins1) */
                        Console.WriteLine("----DW1 disposing instance {0}", instance[1].code);
                        try
                        {
                            keys_writer.dispose(instance[1], ref handle[1]);
                        }
                        catch (DDS.Exception e)
                        {
                            Console.WriteLine("dispose instance error: {0}", e);
                            return;
                        }

                        active[1] = 0;
                    } break;
                case 10:
                    { /* Unregister the second instance (ins1) */
                        Console.WriteLine("----DW1 unregistering instance {0}", instance[1].code);
                        try
                        {
                            keys_writer.unregister_instance(instance[1], ref handle[1]);
                        }
                        catch (DDS.Exception e)
                        {
                            Console.WriteLine("unregister instance error: {0}", e);
                            return;
                        }

                        active[1] = 0;
                    } break;
                case 12:
                    { /* Unregister the third instance (ins2) */
                        Console.WriteLine("----DW1 unregistering instance {0}", instance[2].code);

                        try
                        {
                            keys_writer.unregister_instance(instance[2], ref handle[2]);
                        }
                        catch (DDS.Exception e)
                        {
                            Console.WriteLine("unregister instance error: {0}", e);
                            return;
                        }

                        active[2] = 0;

                        /* Re-register the second instance (ins1) */
                        Console.WriteLine("----DW1 re-registering instance {0}", instance[1].code);
                        handle[1] = keys_writer.register_instance(instance[1]);
                        active[1] = 1;
                    } break;
                case 16:
                    { /* Re-register the third instance (ins2) */
                        Console.WriteLine("----DW1 re-registering instance {0}", instance[2].code);
                        handle[2] = keys_writer.register_instance(instance[2]);
                        active[2] = 1;
                    } break;
            }

            for (int i = 0; i < 3; ++i)
            {
                if (active[i] == 1)
                {
                    Console.WriteLine("DW1 write; code: {0}, x: {1}, y: {2}",
                                      instance[i].code, instance[i].x, instance[i].y);

                    try
                    {
                        keys_writer.write(instance[i], ref handle[i]);
                    }
                    catch (DDS.Exception e)
                    {
                        Console.WriteLine("write error {0}", e);
                        return;
                    }

                }
            }

            /* Control second datawriter */
            switch (count)
            {
                case 16:
                    { /* Dispose the instance (ins1).
                       Since it has lower ownership strength, this does nothing */
                        Console.WriteLine("----DW2 disposing instance {0}", instance_dw2.code);
                        try
                        {
                            keys_writer2.dispose(instance_dw2, ref handle_dw2);
                        }
                        catch (DDS.Exception e)
                        {
                            Console.WriteLine("dispose error {0}", e);
                            return;
                        }

                        active_dw2 = 0;
                    } break;
            }

            if (active_dw2 == 1)
            {
                Console.WriteLine("DW2 write; code: {0}, x: {1}, y: {2}",
                       instance_dw2.code, instance_dw2.x, instance_dw2.y);
                try
                {
                    keys_writer2.write(instance_dw2, ref handle_dw2);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("write error {0}", e);
                    return;
                }
            }

        }

        // --- Shutdown --- //

        /* Delete data sample */
        for (int i = 0; i < 3; i++)
        {

            try
            {
                keysTypeSupport.delete_data(instance[i]);
            }
            catch (DDS.Exception e)
            {
                Console.WriteLine(
                    "keysTypeSupport.delete_data error: {0}", e);
            }
        }
        try
        {
            keysTypeSupport.delete_data(instance_dw2);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine(
                "keysTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
Пример #14
0
        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;
        }
Пример #15
0
        public override Test.Framework.TestResult Run()
        {
            DDS.IDomainParticipant participant;
            DDS.IDomainParticipant participant2;
            DDS.IPublisher         publisher;
            DDS.IPublisher         publisher2;
            DDS.PublisherQos       qos = null;
            DDS.IDataWriter        writer;
            DDS.DataWriterQos      dataWriterQosHolder = null;
            DDS.ITopic             topic;
            string expResult = "PublisherQos test succeeded";

            Test.Framework.TestResult result;
            DDS.ReturnCode            rc;
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            participant = (DDS.IDomainParticipant) this.ResolveObject("participant");
            publisher   = (DDS.IPublisher) this.ResolveObject("publisher");
            qos         = (DDS.PublisherQos) this.ResolveObject("publisherQos");
            topic       = (DDS.ITopic) this.ResolveObject("topic");
            rc          = participant.DeletePublisher(publisher);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a publisher (1)";
                return(result);
            }
            qos.Partition.Name = new string[] { "Partition1", "Partition2", "Partition3" };
            publisher2         = participant.CreatePublisher(qos);//, null, 0);
            if (publisher2 == null)
            {
                result.Result = "could not create a publisher (2)";
                return(result);
            }

            publisher2.GetDefaultDataWriterQos(ref dataWriterQosHolder);
            if (topic == null)
            {
                result.Result = "topic == null";
                return(result);
            }
            writer = publisher2.CreateDataWriter(topic, dataWriterQosHolder);//, null, 0);
            if (writer == null)
            {
                result.Result = "could not create a writer (3)";
                return(result);
            }
            rc = participant.DeletePublisher(publisher2);
            if (rc != DDS.ReturnCode.PreconditionNotMet)
            {
                result.Result = "returncode = " + rc + ". Expected returncode 4 (PRECONDITION_NOT_MET) (4).";
                return(result);
            }
            rc = publisher2.DeleteDataWriter(writer);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a datawriter (5)";
                return(result);
            }
            rc = publisher2.DeleteDataWriter(writer);
            if (rc != DDS.ReturnCode.BadParameter)
            {
                result.Result = "expected RETCODE_BAD_PARAMETER but received Retcode " + rc + " after deleting an already deleted datawriter (6)";
                return(result);
            }
            participant2 = publisher2.GetParticipant();
            if (participant != participant2)
            {
                result.Result = "Looked up participant != participant (7)";
                return(result);
            }
            rc = participant.DeletePublisher(publisher2);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a publisher (8)";
                return(result);
            }
            writer = publisher2.CreateDataWriter(topic, dataWriterQosHolder);//, null, 0);
            if (writer != null)
            {
                result.Result = "could create a writer on a deleted publisher (9)";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #16
0
        public void run(String[] args)
        {
            int myDomain = DDS.DomainId.Default;

            DDS.DomainParticipantFactory dpf;
            DDS.IDomainParticipant       dp;
            DDS.IPublisher  p;
            DDS.ISubscriber s;

            pingpong.PP_min_msgDataWriter    PP_min_writer;
            pingpong.PP_seq_msgDataWriter    PP_seq_writer;
            pingpong.PP_string_msgDataWriter PP_string_writer;
            pingpong.PP_fixed_msgDataWriter  PP_fixed_writer;
            pingpong.PP_array_msgDataWriter  PP_array_writer;

            pingpong.PP_min_msgDataReader    PP_min_reader;
            pingpong.PP_seq_msgDataReader    PP_seq_reader;
            pingpong.PP_string_msgDataReader PP_string_reader;
            pingpong.PP_fixed_msgDataReader  PP_fixed_reader;
            pingpong.PP_array_msgDataReader  PP_array_reader;
            pingpong.PP_quit_msgDataReader   PP_quit_reader;

            pingpong.PP_min_msgTypeSupport    PP_min_dt;
            pingpong.PP_seq_msgTypeSupport    PP_seq_dt;
            pingpong.PP_string_msgTypeSupport PP_string_dt;
            pingpong.PP_fixed_msgTypeSupport  PP_fixed_dt;
            pingpong.PP_array_msgTypeSupport  PP_array_dt;
            pingpong.PP_quit_msgTypeSupport   PP_quit_dt;

            pingpong.PP_min_msg[]    PP_min_dataList    = null;
            pingpong.PP_seq_msg[]    PP_seq_dataList    = null;
            pingpong.PP_string_msg[] PP_string_dataList = null;
            pingpong.PP_fixed_msg[]  PP_fixed_dataList  = null;
            pingpong.PP_array_msg[]  PP_array_dataList  = null;
            pingpong.PP_quit_msg[]   PP_quit_dataList   = null;

            DDS.IStatusCondition PP_min_sc;
            DDS.IStatusCondition PP_seq_sc;
            DDS.IStatusCondition PP_string_sc;
            DDS.IStatusCondition PP_fixed_sc;
            DDS.IStatusCondition PP_array_sc;
            DDS.IStatusCondition PP_quit_sc;

            DDS.ITopic PP_min_topic;
            DDS.ITopic PP_seq_topic;
            DDS.ITopic PP_string_topic;
            DDS.ITopic PP_fixed_topic;
            DDS.ITopic PP_array_topic;
            DDS.ITopic PP_quit_topic;

            DDS.ICondition[] conditionList = null;
            DDS.SampleInfo[] infoList      = null;
            DDS.IWaitSet     w;

            DDS.DomainParticipantQos dpQos;
            DDS.TopicQos             tQos;
            DDS.PublisherQos         pQos;
            DDS.DataWriterQos        dwQos;
            DDS.SubscriberQos        sQos;
            DDS.DataReaderQos        drQos;

            Boolean terminate = false;

            DDS.ReturnCode result;
            int            i;
            int            imax;
            int            j;
            int            jmax;

            /*
             * Evaluate cmdline arguments
             */

            if (args.Length != 0)
            {
                if (args.Length != 2)
                {
                    System.Console.WriteLine("Invalid.....");
                    System.Console.WriteLine("Usage: pong [READ_PARTITION WRITE_PARTITION]");
                    Environment.Exit(1);
                }
                read_partition  = args[0];
                write_partition = args[1];
            }

            /*
             * Create WaitSet
             */
            w = new DDS.WaitSet();

            /*
             * Initialize Qos variables
             */
            dpQos = new DDS.DomainParticipantQos();
            tQos  = new DDS.TopicQos();
            pQos  = new DDS.PublisherQos();
            dwQos = new DDS.DataWriterQos();
            sQos  = new DDS.SubscriberQos();
            drQos = new DDS.DataReaderQos();

            /*
             * Create participant
             */
            dpf = DDS.DomainParticipantFactory.Instance;
            dpf.GetDefaultParticipantQos(ref dpQos);
            dp = dpf.CreateParticipant(myDomain, dpQos, null, DDS.StatusKind.Any);
            if (dp == null)
            {
                System.Console.WriteLine("PING: ERROR - Splice Daemon not running");
                return;
            }

            /*
             * Create PONG publisher
             */
            dp.GetDefaultPublisherQos(ref pQos);
            pQos.Partition.Name    = new String[1];
            pQos.Partition.Name[0] = write_partition;
            p = dp.CreatePublisher(pQos);

            /*
             * Create PING subscriber
             */
            dp.GetDefaultSubscriberQos(ref sQos);
            sQos.Partition.Name    = new String[1];
            sQos.Partition.Name[0] = read_partition;
            s = dp.CreateSubscriber(sQos);

            /*
             * Get default DataReader and DataWriter QoS settings
             */
            p.GetDefaultDataWriterQos(ref dwQos);
            s.GetDefaultDataReaderQos(ref drQos);

            /*
             * Get default Topic Qos settings
             */
            dp.GetDefaultTopicQos(ref tQos);


            /* match data reader/writer qos with topic qos */
            p.CopyFromTopicQos(ref dwQos, tQos);
            s.CopyFromTopicQos(ref drQos, tQos);

            /*
             * PP_min_msg
             */

            /* Create Topic */
            PP_min_dt = new pingpong.PP_min_msgTypeSupport();
            PP_min_dt.RegisterType(dp, "pingpong::PP_min_msg");
            PP_min_topic = dp.CreateTopic("PP_min_topic", "pingpong::PP_min_msg", tQos);


            /* Create datawriter */
            PP_min_writer = p.CreateDataWriter(PP_min_topic, dwQos) as pingpong.PP_min_msgDataWriter;

            /* Create datareader */
            PP_min_reader = s.CreateDataReader(PP_min_topic, drQos) as pingpong.PP_min_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_min_sc = PP_min_reader.StatusCondition;
            PP_min_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_min_sc);
            // assert(result == RETCODE_OK.value);

            /*
             * PP_seq_msg
             */

            /*  Create Topic */
            PP_seq_dt = new pingpong.PP_seq_msgTypeSupport();
            PP_seq_dt.RegisterType(dp, "pingpong::PP_seq_msg");
            PP_seq_topic = dp.CreateTopic("PP_seq_topic", "pingpong::PP_seq_msg", tQos);

            /* Create datawriter */
            PP_seq_writer = p.CreateDataWriter(PP_seq_topic, dwQos) as pingpong.PP_seq_msgDataWriter;

            /* Create datareader */
            PP_seq_reader = s.CreateDataReader(PP_seq_topic, drQos) as pingpong.PP_seq_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_seq_sc = PP_seq_reader.StatusCondition;
            PP_seq_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_seq_sc);
            //assert(result == RETCODE_OK.value);

            /*
             * PP_string_msg
             */

            /*  Create Topic */
            PP_string_dt = new pingpong.PP_string_msgTypeSupport();
            PP_string_dt.RegisterType(dp, "pingpong::PP_string_msg");
            PP_string_topic = dp.CreateTopic("PP_string_topic", "pingpong::PP_string_msg", tQos);

            /* Create datawriter */
            PP_string_writer = p.CreateDataWriter(PP_string_topic, dwQos) as pingpong.PP_string_msgDataWriter;

            /* Create datareader */
            PP_string_reader = s.CreateDataReader(PP_string_topic, drQos) as pingpong.PP_string_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_string_sc = PP_string_reader.StatusCondition;
            PP_string_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_string_sc);
            //assert(result == RETCODE_OK.value);

            /*
             * PP_fixed_msg
             */

            /*  Create Topic */
            PP_fixed_dt = new pingpong.PP_fixed_msgTypeSupport();
            PP_fixed_dt.RegisterType(dp, "pingpong::PP_fixed_msg");
            PP_fixed_topic = dp.CreateTopic("PP_fixed_topic", "pingpong::PP_fixed_msg", tQos);

            /* Create datawriter */
            PP_fixed_writer = p.CreateDataWriter(PP_fixed_topic, dwQos) as pingpong.PP_fixed_msgDataWriter;

            /* Create datareader */
            PP_fixed_reader = s.CreateDataReader(PP_fixed_topic, drQos) as pingpong.PP_fixed_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_fixed_sc = PP_fixed_reader.StatusCondition;
            PP_fixed_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_fixed_sc);
            //assert(result == RETCODE_OK.value);

            /*
             * PP_array_msg
             */

            /*  Create Topic */
            PP_array_dt = new pingpong.PP_array_msgTypeSupport();
            PP_array_dt.RegisterType(dp, "pingpong::PP_array_msg");
            PP_array_topic = dp.CreateTopic("PP_array_topic", "pingpong::PP_array_msg", tQos);

            /* Create datawriter */
            PP_array_writer = p.CreateDataWriter(PP_array_topic, dwQos) as pingpong.PP_array_msgDataWriter;

            /* Create datareader */
            PP_array_reader = s.CreateDataReader(PP_array_topic, drQos) as pingpong.PP_array_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_array_sc = PP_array_reader.StatusCondition;
            PP_array_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_array_sc);
            //assert(result == RETCODE_OK.value);

            /*
             * PP_quit_msg
             */

            /*  Create Topic */
            PP_quit_dt = new pingpong.PP_quit_msgTypeSupport();
            PP_quit_dt.RegisterType(dp, "pingpong::PP_quit_msg");
            PP_quit_topic = dp.CreateTopic("PP_quit_topic", "pingpong::PP_quit_msg", tQos);

            /* Create datareader */
            PP_quit_reader = s.CreateDataReader(PP_quit_topic, drQos) as pingpong.PP_quit_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_quit_sc = PP_quit_reader.StatusCondition;
            PP_quit_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_quit_sc);
            //assert(result == RETCODE_OK.value);

            while (!terminate)
            {
                DDS.Duration wait_timeout = new DDS.Duration(DDS.Duration.InfiniteSec, DDS.Duration.InfiniteSec);


                result = w.Wait(ref conditionList, wait_timeout);
                ErrorHandler.checkStatus(result, "wait did not succeeed");

                if (result == DDS.ReturnCode.AlreadyDeleted)
                {
                    terminate = true;
                    continue;
                }
                if (conditionList != null)
                {
                    imax = conditionList.Length;
                    for (i = 0; i < imax; i++)
                    {
                        if (conditionList[i] == PP_min_sc)
                        {
                            result = PP_min_reader.Take(ref PP_min_dataList, ref infoList,
                                                        DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_min_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_min_writer.Write(PP_min_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_min_reader.ReturnLoan(ref PP_min_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_min triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_seq_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_seq arrived"); */
                            result = PP_seq_reader.Take(ref PP_seq_dataList, ref infoList,
                                                        DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_seq_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_seq_writer.Write(PP_seq_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_seq_reader.ReturnLoan(ref PP_seq_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_seq triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_string_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_string arrived"); */
                            result = PP_string_reader.Take(ref PP_string_dataList, ref infoList,
                                                           DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_string_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_string_writer.Write(PP_string_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_string_reader.ReturnLoan(ref PP_string_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_string triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_fixed_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_fixed arrived"); */
                            result = PP_fixed_reader.Take(ref PP_fixed_dataList, ref infoList,
                                                          DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_fixed_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_fixed_writer.Write(PP_fixed_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_fixed_reader.ReturnLoan(ref PP_fixed_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_fixed triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_array_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_array arrived"); */
                            result = PP_array_reader.Take(ref PP_array_dataList, ref infoList,
                                                          DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_array_dataList.Length;
                            if (jmax != 0)
                            {
                                for (j = 0; j < jmax; j++)
                                {
                                    if (infoList[j].ValidData)
                                    {
                                        result = PP_array_writer.Write(PP_array_dataList[j], DDS.InstanceHandle.Nil);
                                    }
                                }
                                result = PP_array_reader.ReturnLoan(ref PP_array_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_array triggered, but no data available");
                            }
                        }
                        else if (conditionList[i] == PP_quit_sc)
                        {
                            /*  System.Console.WriteLine ("PONG: PING_quit arrived"); */
                            result = PP_quit_reader.Take(ref PP_quit_dataList, ref infoList,
                                                         DDS.SampleStateKind.Any, DDS.ViewStateKind.Any, DDS.InstanceStateKind.Any);
                            jmax = PP_quit_dataList.Length;
                            if (jmax != 0)
                            {
                                result = PP_quit_reader.ReturnLoan(ref PP_quit_dataList, ref infoList);
                            }
                            else
                            {
                                System.Console.WriteLine("PONG: PING_quit triggered, but no data available");
                            }
                            terminate = true;
                        }
                        else
                        {
                            System.Console.WriteLine("PONG: unknown condition triggered: " + conditionList[i]);
                        }
                    }
                }
                else
                {
                    System.Console.WriteLine("PONG: unknown condition triggered");
                }
            }

            result = s.DeleteDataReader(PP_min_reader);
            result = p.DeleteDataWriter(PP_min_writer);
            result = s.DeleteDataReader(PP_seq_reader);
            result = p.DeleteDataWriter(PP_seq_writer);
            result = s.DeleteDataReader(PP_string_reader);
            result = p.DeleteDataWriter(PP_string_writer);
            result = s.DeleteDataReader(PP_fixed_reader);
            result = p.DeleteDataWriter(PP_fixed_writer);
            result = s.DeleteDataReader(PP_array_reader);
            result = p.DeleteDataWriter(PP_array_writer);
            result = s.DeleteDataReader(PP_quit_reader);
            result = dp.DeleteSubscriber(s);
            result = dp.DeletePublisher(p);
            result = dp.DeleteTopic(PP_min_topic);
            result = dp.DeleteTopic(PP_seq_topic);
            result = dp.DeleteTopic(PP_string_topic);
            result = dp.DeleteTopic(PP_fixed_topic);
            result = dp.DeleteTopic(PP_array_topic);
            result = dp.DeleteTopic(PP_quit_topic);
            result = dpf.DeleteParticipant(dp);

            return;
        }
Пример #17
0
        public override Test.Framework.TestResult Run()
        {
            DDS.DomainParticipantQos pqos   = null;
            DDS.PublisherQos         pubQos = null;
            DDS.TopicQos             tQos   = null;
            DDS.DataWriterQos        dwQos  = null;
            DDS.ReturnCode           rc;
            string expResult = "Initialization success";

            Test.Framework.TestResult result = new Test.Framework.TestResult(
                expResult,
                string.Empty,
                Test.Framework.TestVerdict.Pass,
                Test.Framework.TestVerdict.Fail);

            bce.factory = DDS.DomainParticipantFactory.Instance;
            if (bce.factory == null)
            {
                result.Result = "DomainParticipantFactory could not be initialized.";
                return(result);
            }
            rc = bce.factory.GetDefaultParticipantQos(ref pqos);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DomainParticipantQos could not be resolved.";
                return(result);
            }
            bce.participant = bce.factory.CreateParticipant(string.Empty, pqos);
            if (bce.participant == null)
            {
                result.Result = "Creation of DomainParticipant failed.";
                return(result);
            }
            bce.typeSupport = new mod.boundsTypeTypeSupport();
            rc = bce.typeSupport.RegisterType(bce.participant, "boundsType");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Typesupport could not be registered.";
                return(result);
            }
            rc = bce.participant.GetDefaultTopicQos(ref tQos);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Default TopicQos could not be resolved.";
                return(result);
            }
            bce.topic = bce.participant.CreateTopic("bounds", "boundsType", tQos);
            if (bce.topic == null)
            {
                result.Result = "Topic could not be created.";
                return(result);
            }
            rc = bce.participant.GetDefaultPublisherQos(ref pubQos);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Default PublisherQos could not be resolved.";
                return(result);
            }
            bce.publisher = bce.participant.CreatePublisher(pubQos);
            if (bce.publisher == null)
            {
                result.Result = "Publisher could not be created.";
                return(result);
            }
            rc = bce.publisher.GetDefaultDataWriterQos(ref dwQos);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataWriterQos could not be resolved.";
                return(result);
            }
            bce.datawriter = (mod.boundsTypeDataWriter)bce.publisher.CreateDataWriter(bce.topic, dwQos);
            if (bce.datawriter == null)
            {
                result.Result = "DataWriter could not be created.";
                return(result);
            }

            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #18
0
        /// <summary>
        /// Tests the initial default DataWriterQos and the getting and setting
        /// of the default DataWriterQos in the Publisher.
        /// </summary>
        /// <remarks>
        /// Tests the initial default DataWriterQos and the getting and setting
        /// of the default DataWriterQos in the Publisher.
        /// </remarks>
        public override Test.Framework.TestResult Run()
        {
            DDS.IPublisher    publisher;
            DDS.DataWriterQos qosHolder = null;
            DDS.TopicQos      topicQos  = null;
            string            expResult = "copy_from_topic_qos test succeeded";

            Test.Framework.TestResult result;
            DDS.ReturnCode            rc;
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            publisher = (DDS.IPublisher) this.ResolveObject("publisher");
            topicQos  = (DDS.TopicQos) this.ResolveObject("topicQos");

            publisher.GetDefaultDataWriterQos(ref qosHolder);
            rc = publisher.CopyFromTopicQos(ref qosHolder, topicQos);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "copy_from_topic_qos failed.";
                return(result);
            }

            if (!test.sacs.QosComparer.DeadlineQosPolicyEquals(qosHolder.Deadline, topicQos.Deadline))
            {
                result.Result = "deadLineQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.DestinationOrderQosPolicyEquals(qosHolder.DestinationOrder, topicQos.DestinationOrder))
            {
                result.Result = "destinationQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.DurabilityQosPolicyEquals(qosHolder.Durability, topicQos.Durability))
            {
                result.Result = "durabilityQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.HistoryQosPolicyEquals(qosHolder.History, topicQos.History))
            {
                result.Result = "historyQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.LatencyBudgetQosPolicyEquals(qosHolder.LatencyBudget, topicQos.LatencyBudget))
            {
                result.Result = "latencyBudgetQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.LifespanQosPolicyEquals(qosHolder.Lifespan, topicQos.Lifespan))
            {
                result.Result = "lifespanQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.LivelinessQosPolicyEquals(qosHolder.Liveliness, topicQos.Liveliness))
            {
                result.Result = "livelinessQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.ReliabilityQosPolicyEquals(qosHolder.Reliability, topicQos.Reliability))
            {
                result.Result = "reliabilityQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.ResourceLimitsQosPolicyEquals(qosHolder.ResourceLimits, topicQos.ResourceLimits))
            {
                result.Result = "resourceLimitsQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.TransportPriorityQosPolicyEquals(qosHolder.TransportPriority, topicQos.TransportPriority))
            {
                result.Result = "transportPriorityQosPolicy not valid.";
                return(result);
            }
            byte[] bytes = new byte[] { 1, 2, 3 };
            DDS.UserDataQosPolicy udp = new DDS.UserDataQosPolicy();
            udp.Value = bytes;
            qosHolder.UserData.Value = bytes;
            DDS.OwnershipStrengthQosPolicy osp = new DDS.OwnershipStrengthQosPolicy();
            osp.Value = 11;
            qosHolder.OwnershipStrength.Value = 11;
            DDS.WriterDataLifecycleQosPolicy wlp = new DDS.WriterDataLifecycleQosPolicy();
            wlp.AutodisposeUnregisteredInstances = true;
            qosHolder.WriterDataLifecycle.AutodisposeUnregisteredInstances = true;

            DDS.DataWriterQos wqos = qosHolder;
            rc = publisher.CopyFromTopicQos(ref qosHolder, topicQos);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "copy_from_topic_qos failed.";
                return(result);
            }

            if (!test.sacs.QosComparer.UserDataQosPolicyEquals(qosHolder.UserData, udp))
            {
                result.Result = "userDataQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.OwnershipStrengthQosPolicyEquals(qosHolder.OwnershipStrength, osp))
            {
                result.Result = "ownershipStrengthQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.WriterDataLifecycleQosPolicyEquals(qosHolder.WriterDataLifecycle, wlp))
            {
                result.Result = "writerDataLifecycleQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.DeadlineQosPolicyEquals(qosHolder.Deadline, topicQos.Deadline))
            {
                result.Result = "deadLineQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.DestinationOrderQosPolicyEquals(qosHolder.DestinationOrder, topicQos.DestinationOrder))
            {
                result.Result = "destinationQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.DurabilityQosPolicyEquals(qosHolder.Durability, topicQos.Durability))
            {
                result.Result = "durabilityQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.HistoryQosPolicyEquals(qosHolder.History, topicQos.History))
            {
                result.Result = "historyQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.LatencyBudgetQosPolicyEquals(qosHolder.LatencyBudget, topicQos.LatencyBudget))
            {
                result.Result = "latencyBudgetQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.LifespanQosPolicyEquals(qosHolder.Lifespan, topicQos.Lifespan))
            {
                result.Result = "lifespanQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.LivelinessQosPolicyEquals(qosHolder.Liveliness, topicQos.Liveliness))
            {
                result.Result = "livelinessQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.ReliabilityQosPolicyEquals(qosHolder.Reliability, topicQos.Reliability))
            {
                result.Result = "reliabilityQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.ResourceLimitsQosPolicyEquals(qosHolder.ResourceLimits, topicQos.ResourceLimits))
            {
                result.Result = "resourceLimitsQosPolicy not valid.";
                return(result);
            }
            if (!test.sacs.QosComparer.TransportPriorityQosPolicyEquals(qosHolder.TransportPriority, topicQos.TransportPriority))
            {
                result.Result = "transportPriorityQosPolicy not valid.";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #19
0
        public override Test.Framework.TestResult Run()
        {
            DDS.DomainParticipantFactory factory;
            DDS.IDomainParticipant       participant;
            DDS.DomainParticipantQos     pqosHolder     = null;
            DDS.TopicQos                   topQosHolder = null;
            DDS.ITopic                     topic;
            mod.tstTypeSupport             typeSupport = null;
            mod.tstDataReader              datareader;
            test.sacs.MyDataReaderListener listener;
            DDS.ISubscriber                subscriber;
            DDS.SubscriberQos              sqosHolder = null;
            DDS.DataReaderQos              dqosHolder = null;
            DDS.IPublisher                 publisher;
            DDS.PublisherQos               pubQosHolder = null;
            mod.tstDataWriter              datawriter;
            DDS.DataWriterQos              wqosHolder = null;
            Test.Framework.TestResult      result;
            DDS.ReturnCode                 rc;
            string expResult = "DataReaderListener test succeeded.";

            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict
                                                   .Pass, Test.Framework.TestVerdict.Fail);
            factory = DDS.DomainParticipantFactory.Instance;
            if (factory == null)
            {
                result.Result = "DomainParticipantFactory could not be initialized.";
                return(result);
            }

            if (factory.GetDefaultParticipantQos(ref pqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DomainParticipantQos could not be resolved.";
                return(result);
            }
            participant = factory.CreateParticipant(DDS.DomainId.Default, pqosHolder);//, null, 0);
            if (participant == null)
            {
                result.Result = "Creation of DomainParticipant failed.";
                return(result);
            }
            typeSupport = new mod.tstTypeSupport();
            if (typeSupport == null)
            {
                result.Result = "Creation of tstTypeSupport failed.";
                this.Cleanup(factory, participant);
                return(result);
            }
            rc = typeSupport.RegisterType(participant, "my_type");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Register type failed.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (participant.GetDefaultTopicQos(ref topQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default TopicQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            topQosHolder.Durability.Kind = DDS.DurabilityQosPolicyKind.TransientDurabilityQos;
            topic = participant.CreateTopic("my_topic_t", "my_type", topQosHolder);//, null, 0);
            if (topic == null)
            {
                result.Result = "Topic could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (participant.GetDefaultPublisherQos(ref pubQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default PublisherQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            publisher = participant.CreatePublisher(pubQosHolder);//, null, 0);
            if (publisher == null)
            {
                result.Result = "Publisher could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (publisher.GetDefaultDataWriterQos(ref wqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataWriterQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            wqosHolder.Durability.Kind = DDS.DurabilityQosPolicyKind.TransientDurabilityQos;
            datawriter = (mod.tstDataWriter)publisher.CreateDataWriter(topic, wqosHolder);//, null, 0);
            if (datawriter == null)
            {
                result.Result = "DataWriter could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }
            mod.tst t = new mod.tst();
            t.long_1 = 1;
            t.long_2 = 2;
            t.long_3 = 3;

            rc = datawriter.Write(t, DDS.InstanceHandle.Nil);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Data could not be written.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (participant.GetDefaultSubscriberQos(ref sqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default SubscriberQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            subscriber = participant.CreateSubscriber(sqosHolder);//, null, 0);
            if (subscriber == null)
            {
                result.Result = "Subscriber could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (subscriber.GetDefaultDataReaderQos(ref dqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataReaderQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            dqosHolder.Durability.Kind = DDS.DurabilityQosPolicyKind.TransientDurabilityQos;
            listener   = new test.sacs.MyDataReaderListener();
            datareader = (mod.tstDataReader)subscriber.CreateDataReader(topic, dqosHolder, listener, DDS.StatusKind.Any);
            if (datareader == null)
            {
                result.Result = "DataReader could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }
            try
            {
                System.Threading.Thread.Sleep(3000);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e);
            }
            if (!listener.onLivelinessChangedCalled)
            {
                result.Result = "on_liveliness_changed does not work properly.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (!listener.onDataAvailableCalled)
            {
                result.Result = "on_data_available does not work properly.";
                this.Cleanup(factory, participant);
                return(result);
            }
            rc = participant.DeleteContainedEntities();
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Delete contained entities failed.";
                this.Cleanup(factory, participant);
                return(result);
            }
            rc = factory.DeleteParticipant(participant);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Delete DomainParticipant failed.";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #20
0
        /*
         * P I N G
         */

        public void run(String[] args)
        {
            System.Console.WriteLine("starting PING");
            DDS.ICondition[] conditionList = null;
            DDS.IWaitSet     w;

            DDS.DomainParticipantQos dpQos;
            DDS.TopicQos             tQos;
            DDS.PublisherQos         pQos;
            DDS.DataWriterQos        dwQos;
            DDS.SubscriberQos        sQos;
            DDS.DataReaderQos        drQos;

            DDS.Duration wait_timeout = new DDS.Duration(3, 0);

            DDS.ReturnCode result;
            Boolean        finish_flag  = false;
            Boolean        timeout_flag = false;
            Boolean        terminate    = false;

            int  imax = 1;
            int  i;
            uint block;
            int  nof_cycles = 100;
            int  nof_blocks = 20;

            /**
             * Command Line argument processing
             */
            if (args.Length != 0)
            {
                if (args.Length != 5)
                {
                    System.Console.WriteLine("Invalid.....");
                    System.Console.WriteLine("Usage: ping blocks blocksize topic_id WRITE_PARTITION READ_PARTITION ");
                    Environment.Exit(1);
                }
                nof_blocks      = int.Parse(args[0]);
                nof_cycles      = int.Parse(args[1]);
                topic_id        = args[2][0];
                write_partition = args[3];
                read_partition  = args[4];
            }


            /*
             * Create WaitSet
             */

            w = new DDS.WaitSet();

            /*
             * Initialize Qos variables
             */
            dpQos = new DDS.DomainParticipantQos();
            tQos  = new DDS.TopicQos();
            pQos  = new DDS.PublisherQos();
            dwQos = new DDS.DataWriterQos();
            sQos  = new DDS.SubscriberQos();
            drQos = new DDS.DataReaderQos();

            /*
             * Create participant
             */
            dpf = DDS.DomainParticipantFactory.Instance;
            dpf.GetDefaultParticipantQos(ref dpQos);

            ErrorHandler.checkHandle(dpf, "DDS.DomainParticipantFactory.Instance");

            dp = dpf.CreateParticipant(myDomain, dpQos);
            if (dp == null)
            {
                System.Console.WriteLine("PING: ERROR - Splice Daemon not running");
                return;
            }

            /*
             * Create PING publisher
             */
            dp.GetDefaultPublisherQos(ref pQos);
            pQos.Partition.Name    = new String[1];
            pQos.Partition.Name[0] = write_partition;
            p = dp.CreatePublisher(pQos);

            /*
             * Create PONG subscriber
             */
            dp.GetDefaultSubscriberQos(ref sQos);
            sQos.Partition.Name    = new String[1];
            sQos.Partition.Name[0] = read_partition;
            s = dp.CreateSubscriber(sQos);

            /*
             * Get default DataReader and DataWriter QoS settings
             */
            p.GetDefaultDataWriterQos(ref dwQos);
            s.GetDefaultDataReaderQos(ref drQos);

            /*
             * Get default Topic Qos settings
             */
            dp.GetDefaultTopicQos(ref tQos);

            /*match data reader/writer qos with topic qos*/
            p.CopyFromTopicQos(ref dwQos, tQos);
            s.CopyFromTopicQos(ref drQos, tQos);

            /*
             * PP_min_msg
             */
            /* Create Topic */
            PP_min_dt = new pingpong.PP_min_msgTypeSupport();
            PP_min_dt.RegisterType(dp, "pingpong::PP_min_msg");
            PP_min_topic = dp.CreateTopic("PP_min_topic", "pingpong::PP_min_msg", tQos);

            /* Create datawriter */
            PP_min_writer = p.CreateDataWriter(PP_min_topic, dwQos) as pingpong.PP_min_msgDataWriter;

            /* Create datareader */
            PP_min_reader = s.CreateDataReader(PP_min_topic, drQos) as pingpong.PP_min_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_min_sc = PP_min_reader.StatusCondition;
            PP_min_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);

            result = w.AttachCondition(PP_min_sc);
            ErrorHandler.checkStatus(result, "attach condition pp_min_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_seq_msg
             */
            /* Create Topic */
            PP_seq_dt = new pingpong.PP_seq_msgTypeSupport();
            PP_seq_dt.RegisterType(dp, "pingpong::PP_seq_msg");
            PP_seq_topic = dp.CreateTopic("PP_seq_topic", "pingpong::PP_seq_msg", tQos);

            /* Create datawriter */
            PP_seq_writer = p.CreateDataWriter(PP_seq_topic, dwQos) as pingpong.PP_seq_msgDataWriter;

            /* Create datareader */
            PP_seq_reader = s.CreateDataReader(PP_seq_topic, drQos) as pingpong.PP_seq_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_seq_sc = PP_seq_reader.StatusCondition;
            PP_seq_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);

            result = w.AttachCondition(PP_seq_sc);
            ErrorHandler.checkStatus(result, "attach condition pp_seq_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_string_msg
             */

            /* Create Topic */
            PP_string_dt = new pingpong.PP_string_msgTypeSupport();
            PP_string_dt.RegisterType(dp, "pingpong::PP_string_msg");
            PP_string_topic = dp.CreateTopic("PP_string_topic", "pingpong::PP_string_msg", tQos);

            /* Create datawriter */
            PP_string_writer = p.CreateDataWriter(PP_string_topic, dwQos) as pingpong.PP_string_msgDataWriter;

            /* Create datareader */
            PP_string_reader = s.CreateDataReader(PP_string_topic, drQos) as pingpong.PP_string_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_string_sc = PP_string_reader.StatusCondition;
            PP_string_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);

            result = w.AttachCondition(PP_string_sc);
            ErrorHandler.checkStatus(result, "attach condition pp_string_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_fixed_msg
             */

            /* Create Topic */
            PP_fixed_dt = new pingpong.PP_fixed_msgTypeSupport();
            PP_fixed_dt.RegisterType(dp, "pingpong::PP_fixed_msg");

            PP_fixed_topic = dp.CreateTopic("PP_fixed_topic", "pingpong::PP_fixed_msg", tQos);

            /* Create datawriter */
            PP_fixed_writer = p.CreateDataWriter(PP_fixed_topic, dwQos) as pingpong.PP_fixed_msgDataWriter;

            /* Create datareader */
            PP_fixed_reader = s.CreateDataReader(PP_fixed_topic, drQos) as pingpong.PP_fixed_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_fixed_sc = PP_fixed_reader.StatusCondition;
            PP_fixed_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);
            result = w.AttachCondition(PP_fixed_sc);
            ErrorHandler.checkStatus(result, "attach condition pp_fixed_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_array_msg
             */

            /* Create Topic */
            PP_array_dt = new pingpong.PP_array_msgTypeSupport();
            PP_array_dt.RegisterType(dp, "pingpong::PP_array_msg");
            PP_array_topic = dp.CreateTopic("PP_array_topic", "pingpong::PP_array_msg", tQos);


            /* Create datawriter */
            PP_array_writer = p.CreateDataWriter(PP_array_topic, dwQos) as pingpong.PP_array_msgDataWriter;

            /* Create datareader */
            PP_array_reader = s.CreateDataReader(PP_array_topic, drQos) as pingpong.PP_array_msgDataReader;

            /* Add datareader statuscondition to waitset */
            PP_array_sc = PP_array_reader.StatusCondition;
            PP_array_sc.SetEnabledStatuses(DDS.StatusKind.DataAvailable);

            result = w.AttachCondition(PP_array_sc);

            ErrorHandler.checkStatus(result, "attach condition pp_array_reader");
            //assert (result == RETCODE_OK.value);

            /*
             * PP_quit_msg
             */

            /* Create Topic */
            PP_quit_dt = new pingpong.PP_quit_msgTypeSupport();
            PP_quit_dt.RegisterType(dp, "pingpong::PP_quit_msg");
            PP_quit_topic = dp.CreateTopic("PP_quit_topic", "pingpong::PP_quit_msg", tQos);

            /* Create datawriter */
            PP_quit_writer = p.CreateDataWriter(PP_quit_topic, dwQos) as pingpong.PP_quit_msgDataWriter;

            for (block = 0; block < nof_blocks && !terminate; block++)
            {
                while (!finish_flag)
                {
                    /*
                     * Send Initial message
                     */
                    timeout_flag = false;

                    switch (topic_id)
                    {
                    case 'm':
                    {
                        /* System.Console.WriteLine ("PING: sending initial ping_min"); */
                        pingpong.PP_min_msg PPdata = new pingpong.PP_min_msg();
                        PPdata.count = 0;
                        PPdata.block = block;
                        preWriteTime.timeGet();
                        result = PP_min_writer.Write(PPdata);
                        postWriteTime.timeGet();
                    }
                    break;

                    case 'q':
                    {
                        /* System.Console.WriteLine ("PING: sending initial ping_seq"); */
                        pingpong.PP_seq_msg PPdata = new pingpong.PP_seq_msg();
                        PPdata.count = 0;
                        PPdata.block = block;
                        preWriteTime.timeGet();
                        result = PP_seq_writer.Write(PPdata);
                        postWriteTime.timeGet();
                    }
                    break;

                    case 's':
                    {
                        //System.Console.WriteLine ("PING: sending initial ping_string");
                        pingpong.PP_string_msg PPdata = new pingpong.PP_string_msg();
                        PPdata.count    = 0;
                        PPdata.block    = block;
                        PPdata.a_string = "a_string " + block.ToString();
                        preWriteTime.timeGet();
                        result = PP_string_writer.Write(PPdata);
                        ErrorHandler.checkStatus(result, "writing PPData in case S");
                        postWriteTime.timeGet();
                    }
                    break;

                    case 'f':
                    {
                        /* System.Console.WriteLine ("PING: sending initial ping_fixed"); */
                        pingpong.PP_fixed_msg PPdata = new pingpong.PP_fixed_msg();
                        PPdata.count = 0;
                        PPdata.block = block;
                        preWriteTime.timeGet();
                        result = PP_fixed_writer
                                 .Write(PPdata);
                        postWriteTime.timeGet();
                    }
                    break;

                    case 'a':
                    {
                        /* System.Console.WriteLine ("PING: sending initial ping_array"); */
                        pingpong.PP_array_msg PPdata = new pingpong.PP_array_msg();
                        PPdata.count             = 0;
                        PPdata.block             = block;
                        PPdata.str_arr_char      = new char[10];
                        PPdata.str_arr_octet     = new byte[10];
                        PPdata.str_arr_short     = new short[10];
                        PPdata.str_arr_ushort    = new ushort[10];
                        PPdata.str_arr_long      = new int[10];
                        PPdata.str_arr_ulong     = new uint[10];
                        PPdata.str_arr_longlong  = new long[10];
                        PPdata.str_arr_ulonglong = new ulong[10];
                        PPdata.str_arr_float     = new float[10];
                        PPdata.str_arr_double    = new double[10];
                        PPdata.str_arr_boolean   = new Boolean[11];
                        preWriteTime.timeGet();
                        result = PP_array_writer
                                 .Write(PPdata);
                        postWriteTime.timeGet();
                    }
                    break;

                    case 't':
                    {
                        /* System.Console.WriteLine ("PING: sending initial ping_quit"); */
                        pingpong.PP_quit_msg PPdata = new pingpong.PP_quit_msg();
                        PPdata.quit = true;
                        terminate   = true;
                        finish_flag = true;
                        System.Threading.Thread.Sleep(1000);
                        preWriteTime.timeGet();
                        result = PP_quit_writer.Write(PPdata);
                        postWriteTime.timeGet();
                        System.Threading.Thread.Sleep(1000);
                    }
                    break;

                    default:
                        System.Console.WriteLine("Invalid topic-id");
                        return;
                    }

                    if (!terminate)
                    {
                        roundTripTime.set(preWriteTime.get());
                        write_access.add_stats(postWriteTime.sub(preWriteTime));

                        /*
                         * Wait for response, calculate timing, and send another
                         * data if not ready
                         */
                        while (!(timeout_flag || finish_flag))
                        {
                            result = w.Wait(ref conditionList, wait_timeout);
                            if (result == DDS.ReturnCode.Ok || result == DDS.ReturnCode.NoData || result == DDS.ReturnCode.Timeout)
                            {
                                //ErrorHandler.checkStatus(result, "wait did not work condition list is probably null!");
                                if (conditionList != null)
                                {
                                    imax = conditionList.Length;
                                    if (imax != 0)
                                    {
                                        for (i = 0; i < imax; i++)
                                        {
                                            if (conditionList[i] == PP_min_sc)
                                            {
                                                finish_flag = PP_min_handler(nof_cycles);
                                            }
                                            else if (conditionList[i] == PP_seq_sc)
                                            {
                                                finish_flag = PP_seq_handler(nof_cycles);
                                            }
                                            else if (conditionList[i] == PP_string_sc)
                                            {
                                                finish_flag = PP_string_handler(nof_cycles);
                                            }
                                            else if (conditionList[i] == PP_fixed_sc)
                                            {
                                                finish_flag = PP_fixed_handler(nof_cycles);
                                            }
                                            else if (conditionList[i] == PP_array_sc)
                                            {
                                                finish_flag = PP_array_handler(nof_cycles);
                                            }
                                            else
                                            {
                                                System.Console.WriteLine("PING: unexpected condition triggered: "
                                                                         + conditionList[i]);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        System.Console.WriteLine("PING: TIMEOUT - message lost (1)");
                                        timeout_flag = true;
                                    }
                                }
                                else
                                {
                                    System.Console.WriteLine("PING: TIMEOUT - message lost (2)");
                                    timeout_flag = true;
                                }
                            }
                            else
                            {
                                System.Console.WriteLine("PING: Waitset wait failed (code " + result + "), terminating");
                                finish_flag = true;
                                terminate   = true;
                            }
                        }
                    }
                }
                if (!terminate)
                {
                    finish_flag = false;
                    if (block == 0)
                    {
                        System.Console.WriteLine("# PING PONG measurements (in us)");
                        System.Console.WriteLine("# Executed at: ");
                        System.Console.WriteLine("#           Roundtrip time [us]             Write-access time [us]          Read-access time [us]");
                        System.Console.WriteLine("# Block     Count   mean    min    max      Count   mean    min    max      Count   mean    min    max");
                    }

                    System.Console.WriteLine(String.Format("{0,-6} {1, 10} {2, 6} {3, 6} {4, 6} {5, 10} {6, 6} {7, 6} {8, 6} {9, 10} {10, 6} {11, 6} {12, 6}",
                                                           block, roundtrip.count, roundtrip.average, roundtrip.min, roundtrip.max, write_access.count,
                                                           write_access.average, write_access.min, write_access.max, read_access.count, read_access.average,
                                                           read_access.min, read_access.max));
                    Console.Out.Flush();
                    write_access.init_stats();
                    read_access.init_stats();
                    roundtrip.init_stats();
                }
            }
            result = s.DeleteDataReader(PP_min_reader);
            result = p.DeleteDataWriter(PP_min_writer);
            result = s.DeleteDataReader(PP_seq_reader);
            result = p.DeleteDataWriter(PP_seq_writer);
            result = s.DeleteDataReader(PP_string_reader);
            result = p.DeleteDataWriter(PP_string_writer);
            result = s.DeleteDataReader(PP_fixed_reader);
            result = p.DeleteDataWriter(PP_fixed_writer);
            result = s.DeleteDataReader(PP_array_reader);
            result = p.DeleteDataWriter(PP_array_writer);
            result = p.DeleteDataWriter(PP_quit_writer);
            result = dp.DeleteSubscriber(s);
            result = dp.DeletePublisher(p);
            result = dp.DeleteTopic(PP_min_topic);
            result = dp.DeleteTopic(PP_seq_topic);
            result = dp.DeleteTopic(PP_string_topic);
            result = dp.DeleteTopic(PP_fixed_topic);
            result = dp.DeleteTopic(PP_array_topic);
            result = dp.DeleteTopic(PP_quit_topic);
            result = dpf.DeleteParticipant(dp);

            return;
        }
Пример #21
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult result;
            string expResult = "contains_entity returns the correct result";
            DDS.IDomainParticipant participant;
            DDS.DomainParticipantFactory factory;
            DDS.TopicQos tHolder = new DDS.TopicQos();
            DDS.PublisherQos pHolder = new DDS.PublisherQos();
            DDS.SubscriberQos sHolder = new DDS.SubscriberQos();
            DDS.DataWriterQos wHolder = new DDS.DataWriterQos();
            DDS.DataReaderQos rHolder = new DDS.DataReaderQos();
            DDS.ITopic topic;
            DDS.IPublisher publisher;
            DDS.ISubscriber subscriber;
            mod.tstDataWriter writer;
            mod.tstDataReader reader;
            long handle;
            DDS.ReturnCode rc;
            participant = (DDS.IDomainParticipant)this.ResolveObject("participant");
            factory = (DDS.DomainParticipantFactory)this.ResolveObject("factory");
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                Test.Framework.TestVerdict.Fail);
            if (participant.ContainsEntity(0))
            {
                result.Result = "contains_entity with nil handle incorrect";
                return result;
            }
            if (participant.ContainsEntity(100))
            {
                result.Result = "contains_entity with incorrect handle incorrect";
                return result;
            }
            
            handle = participant.InstanceHandle;
            if (handle == DDS.InstanceHandle.Nil)
            {
                result.Result = "get_instance_handle returned 0";
                return result;
            }
            if (participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with own handle incorrect";
                return result;
            }
            mod.tstTypeSupport typeSupport = new mod.tstTypeSupport();
            rc = typeSupport.RegisterType(participant, "type1");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Register type failed.";
                return result;
            }
            participant.GetDefaultTopicQos(ref tHolder);
            topic = participant.CreateTopic("TestTopic", "type1", tHolder);//, null, 0);
            if (topic == null)
            {
                result.Result = "Create Topic failed.";
                return result;
            }
            participant.GetDefaultPublisherQos(ref pHolder);
            publisher = participant.CreatePublisher(pHolder);//, null, 0);
            if (publisher == null)
            {
                result.Result = "Create Publisher failed.";
                return result;
            }
            participant.GetDefaultSubscriberQos(ref sHolder);
            subscriber = participant.CreateSubscriber(sHolder);//, null, 0);
            if (subscriber == null)
            {
                result.Result = "Create Subscriber failed.";
                return result;
            }
            publisher.GetDefaultDataWriterQos(ref wHolder);
            writer = publisher.CreateDataWriter(topic, wHolder) as mod.tstDataWriter;
            if (writer == null)
            {
                result.Result = "Create Writer failed.";
                return result;
            }

            subscriber.GetDefaultDataReaderQos(ref rHolder);
            reader = subscriber.CreateDataReader(topic, rHolder) as mod.tstDataReader;
            if (reader == null)
            {
                result.Result = "Create Reader failed.";
                return result;
            }
            handle = topic.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (topic) returned 0";
                return result;
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with topic handle incorrect";
                return result;
            }
            handle = publisher.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (publisher) returned != 0";
                return result;
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with publisher handle incorrect";
                return result;
            }
            handle = subscriber.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (subscriber) returned != 0";
                return result;
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with subscriber handle incorrect";
                return result;
            }
            handle = writer.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (writer) returned 0";
                return result;
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with writer handle incorrect";
                return result;
            }
            handle = reader.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (reader) returned 0";
                return result;
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with reader handle incorrect";
                return result;
            }
            rc = participant.DeleteContainedEntities();
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "delete_contained_entities failed.";
                return result;
            }
            if (participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity of deleted reader incorrect";
                return result;
            }
            result.Verdict = Test.Framework.TestVerdict.Pass;
            result.Result = expResult;
            return result;
        }
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult result;
            DDS.QosProvider           qosProvider    = null;
            DDS.DomainParticipantQos  participantQos =
                test.sacs.QosComparer.defaultDomainParticipantQos;
            DDS.TopicQos topicQos =
                test.sacs.QosComparer.defaultTopicQos;
            DDS.SubscriberQos subscriberQos =
                test.sacs.QosComparer.defaultSubscriberQos;
            DDS.DataReaderQos readerQos =
                test.sacs.QosComparer.defaultDataReaderQos;
            DDS.PublisherQos publisherQos =
                test.sacs.QosComparer.defaultPublisherQos;
            DDS.DataWriterQos writerQos =
                test.sacs.QosComparer.defaultDataWriterQos;

            DDS.DomainParticipantQos xmlParticipantQos = new DDS.DomainParticipantQos();
            DDS.TopicQos             xmlTopicQos       = new DDS.TopicQos();
            DDS.SubscriberQos        xmlSubscriberQos  = new DDS.SubscriberQos();
            DDS.DataReaderQos        xmlReaderQos      = new DDS.DataReaderQos();
            DDS.PublisherQos         xmlPublisherQos   = new DDS.PublisherQos();
            DDS.DataWriterQos        xmlWriterQos      = new DDS.DataWriterQos();

            qosProvider = new DDS.QosProvider(this.uri, string.Empty);

            if (qosProvider.GetParticipantQos(ref xmlParticipantQos, null) != 0 ||
                qosProvider.GetTopicQos(ref xmlTopicQos, null) != 0 ||
                qosProvider.GetSubscriberQos(ref xmlSubscriberQos, null) != 0 ||
                qosProvider.GetDataReaderQos(ref xmlReaderQos, null) != 0 ||
                qosProvider.GetPublisherQos(ref xmlPublisherQos, null) != 0 ||
                qosProvider.GetDataWriterQos(ref xmlWriterQos, null) != 0)
            {
                result = new Test.Framework.TestResult(
                    "QosProvider should successfully parse XML file",
                    "QosProvider did not parse XML file " + uri,
                    Test.Framework.TestVerdict.Pass,
                    Test.Framework.TestVerdict.Fail);
            }
            else if (!QosComparer.DomainParticipantQosEquals(xmlParticipantQos, participantQos) ||
                     !QosComparer.TopicQosEquals(xmlTopicQos, topicQos) ||
                     !QosComparer.SubscriberQosEquals(xmlSubscriberQos, subscriberQos) ||
                     !QosComparer.DataReaderQosEquals(xmlReaderQos, readerQos) ||
                     !QosComparer.PublisherQosEquals(xmlPublisherQos, publisherQos) ||
                     !QosComparer.DataWriterQosEquals(xmlWriterQos, writerQos))
            {
                result = new Test.Framework.TestResult(
                    "QosProvider should successfully parse XML file",
                    "QosProvider did not correctly parse XML file " + uri,
                    Test.Framework.TestVerdict.Pass,
                    Test.Framework.TestVerdict.Fail);
            }
            else
            {
                result = new Test.Framework.TestResult(
                    "QosProvider should successfully parse XML file",
                    "QosProvider correctly parsed XML file " + uri,
                    Test.Framework.TestVerdict.Pass,
                    Test.Framework.TestVerdict.Pass);
            }

            return(result);
        }
Пример #23
0
        public override Test.Framework.TestResult Run()
        {
            DDS.IDomainParticipant participant;
            DDS.IPublisher         publisher;
            DDS.IPublisher         publisher2;
            DDS.PublisherQos       qos = null;
            DDS.IDataWriter        writer;
            DDS.IDataWriter        writer2;
            DDS.DataWriterQos      dataWriterQosHolder = null;
            DDS.DataWriterQos      dataWriterQos       = null;
            DDS.ITopic             topic;
            DDS.ITopic             topic2;
            DDS.TopicQos           defaultTopicQos = null;
            mod.tstTypeSupport     typeSupport;
            string expResult = "Successful creation and deletion of DataWriters";

            Test.Framework.TestResult result;
            DDS.ReturnCode            rc;
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            participant     = (DDS.IDomainParticipant) this.ResolveObject("participant");
            publisher       = (DDS.IPublisher) this.ResolveObject("publisher");
            qos             = (DDS.PublisherQos) this.ResolveObject("publisherQos");
            topic           = (DDS.ITopic) this.ResolveObject("topic");
            defaultTopicQos = (DDS.TopicQos) this.ResolveObject("topicQos");
            publisher.GetDefaultDataWriterQos(ref dataWriterQosHolder);
            writer = publisher.CreateDataWriter(topic, dataWriterQosHolder);//, null, 0);
            if (writer == null)
            {
                result.Result = "could not create a writer (1).";
                return(result);
            }
            rc = publisher.DeleteDataWriter(writer);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a writer (2).";
                return(result);
            }
            try
            {
                writer = publisher.CreateDataWriter(null, dataWriterQosHolder);//, null, 0);
            }
            catch (System.NullReferenceException)
            {
                writer = null;
            }
            if (writer != null)
            {
                result.Result = "could create a writer with invalid topic (3).";
                return(result);
            }
            typeSupport = new mod.tstTypeSupport();
            if (typeSupport == null)
            {
                result.Result = "Creation of tstTypeSupport failed.";
                return(result);
            }
            rc = typeSupport.RegisterType(participant, "my_other_type");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Register type failed.";
                return(result);
            }
            publisher2 = participant.CreatePublisher(qos);//, null, 0);
            if (publisher2 == null)
            {
                result.Result = "creation of a second publisher failed.";
                return(result);
            }
            topic2 = participant.CreateTopic("my_other_topic", "my_other_type", defaultTopicQos);//, null, 0);
            if (topic2 == null)
            {
                result.Result = "Topic2 could not be created.";
                return(result);
            }
            writer = publisher.CreateDataWriter(topic2, dataWriterQosHolder);//, null, 0);
            if (writer == null)
            {
                result.Result = "could not create a writer with another topic (4).";
                return(result);
            }
            writer2 = publisher.LookupDataWriter("my_other_topic");
            if (writer2 == null)
            {
                result.Result = "could not lookup writer (5).";
                return(result);
            }
            if (writer2 != writer)
            {
                result.Result = "looked-up writer != initial writer (6).";
                return(result);
            }
            writer2 = null;
            writer2 = publisher.LookupDataWriter("unknown_topic_name");
            if (writer2 != null)
            {
                result.Result = "could lookup writer with unknown topic name (7).";
                return(result);
            }
            rc = publisher2.DeleteDataWriter(writer);
            if (rc != DDS.ReturnCode.PreconditionNotMet)
            {
                result.Result = "Expected returncode PRECONDITION_NOT_MET instead of " + rc + " after deleting a writer on wrong publisher (8).";
                return(result);
            }
            rc = publisher.DeleteDataWriter(writer);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a writer (9).";
                return(result);
            }
            rc = participant.DeleteTopic(topic2);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a topic (10).";
                return(result);
            }
            writer = publisher.CreateDataWriter(topic2, dataWriterQosHolder);//, null, 0);
            if (writer != null)
            {
                result.Result = "could create a writer with an already deleted topic (11).";
                return(result);
            }
            dataWriterQos = dataWriterQosHolder;
            dataWriterQos.Durability.Kind = DDS.DurabilityQosPolicyKind.TransientDurabilityQos;
            dataWriterQos.History.Kind    = DDS.HistoryQosPolicyKind.KeepAllHistoryQos;
            writer = publisher.CreateDataWriter(topic, dataWriterQos);//, null, 0);
            if (writer == null)
            {
                result.Result = "could not create a writer with TRANSIENT durabilityQosPolicy (12).";
                return(result);
            }
            rc = publisher.DeleteDataWriter(writer);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a writer (13).";
                return(result);
            }
            dataWriterQos.Durability.Kind = DDS.DurabilityQosPolicyKind.PersistentDurabilityQos;
            writer = publisher.CreateDataWriter(topic, dataWriterQos);//, null, 0);
            if (writer == null)
            {
                result.Result = "could not create a writer with PERSISTENT durabilityQosPolicy (14).";
                return(result);
            }
            rc = publisher.DeleteDataWriter(writer);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a writer (15).";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #24
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 = 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 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 writer --- //

        /* We are going to load different QoS profiles for the two DWs */
        DDS.DataWriterQos writerQos = new DDS.DataWriterQos();

        /* 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);
        DDS.DomainParticipantFactory.get_instance().get_datawriter_qos_from_profile(writerQos, "keys_Library", "keys_Profile_dw2");

        /* If you want to set the writer_data_lifecycle 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
         * and get_datawriter_qos_from_profile calls above.
         */

        /*
         * publisher.get_default_datawriter_qos(writerQos);
         *
         * writerQos.writer_data_lifecycle.autodispose_unregistered_instances = false;
         * writerQos.ownership.kind = DDS.OwnershipQosPolicyKind.EXCLUSIVE_OWNERSHIP_QOS;
         * writerQos.ownership_strength.value = 10;
         *
         * DDS.DataWriter writer = publisher.create_datawriter(
         *  topic,
         *  writerQos,
         *  null,
         *  DDS.StatusMask.STATUS_MASK_NONE);
         *
         * writerQos.ownership_strength.value = 5;
         */

        DDS.DataWriter writer2 = publisher.create_datawriter(
            topic,
            writerQos,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);

        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        keysDataWriter keys_writer = (keysDataWriter)writer;

        if (writer2 == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }
        keysDataWriter keys_writer2 = (keysDataWriter)writer2;

        // --- Write --- //

        /* Creates three instances */
        keys[] instance = new keys[3] {
            null, null, null
        };

        /* Create data sample for writing */
        instance[0] = keysTypeSupport.create_data();
        instance[1] = keysTypeSupport.create_data();
        instance[2] = keysTypeSupport.create_data();
        if ((instance[0] == null)
            ||
            (instance[1] == null)
            ||
            (instance[2] == null)
            )
        {
            shutdown(participant);
            throw new ApplicationException(
                      "keysTypeSupport.create_data error");
        }

        /* RTI Connext could examine the key fields each time it needs to determine
         * which data-instance is being modified.
         * However, for performance and semantic reasons, it is better
         * for your application to declare all the data-instances it intends to
         * modify prior to actually writing any samples. This is known as registration.
         */

        /* In order to register the instances, we must set their associated keys first */
        instance[0].code = 0;
        instance[1].code = 1;
        instance[2].code = 2;

        /* 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[] handle = new DDS.InstanceHandle_t[3];

        Console.WriteLine("----DW1 registering instance handle", instance[0].code);
        handle[0] = keys_writer.register_instance(instance[0]);

        // Init coordinates
        instance[0].x = 1;
        instance[1].x = 1;
        instance[2].x = 1;

        int[] active = new int[] { 1, 0, 0 }; // Only send active keys.

        /* Make variables for the instance for the second datawriter to use.
         * Note that it actually refers to the same logical instance, but
         * because we're running both datawriters in the same thread, we
         * to create separate variables so they don't clobber each other.
         */

        keys instance_dw2 = null;

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

        /* instance_dw2 and instance[1] have the same key, and thus
         * will write to the same instance (ins1).
         */
        instance_dw2.code = instance[1].code;
        instance_dw2.x    = 2;
        DDS.InstanceHandle_t handle_dw2 = keys_writer2.register_instance(instance_dw2);
        int active_dw2 = 1;

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

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

            /* Modify the data to be sent here */
            instance[0].y = count;
            instance[1].y = count + 1000;
            instance[2].y = count + 2000;

            instance_dw2.y = -count - 1000;

            /* We control two datawriters via a state machine here rather than
             * introducing separate threads.
             */
            /* Control first DataWriter */
            switch (count)
            {
            case 4:
            {         /* Start sending the second (ins1) and third instances (ins2) */
                Console.WriteLine("----DW1 registering instance {0}", instance[1].code);
                Console.WriteLine("----DW1 registering instance {0}", instance[2].code);
                handle[1] = keys_writer.register_instance(instance[1]);
                handle[2] = keys_writer.register_instance(instance[2]);
                active[1] = 1;
                active[2] = 1;
            } break;

            case 8:
            {         /* Dispose the second instance (ins1) */
                Console.WriteLine("----DW1 disposing instance {0}", instance[1].code);
                try
                {
                    keys_writer.dispose(instance[1], ref handle[1]);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("dispose instance error: {0}", e);
                    return;
                }

                active[1] = 0;
            } break;

            case 10:
            {         /* Unregister the second instance (ins1) */
                Console.WriteLine("----DW1 unregistering instance {0}", instance[1].code);
                try
                {
                    keys_writer.unregister_instance(instance[1], ref handle[1]);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("unregister instance error: {0}", e);
                    return;
                }

                active[1] = 0;
            } break;

            case 12:
            {         /* Unregister the third instance (ins2) */
                Console.WriteLine("----DW1 unregistering instance {0}", instance[2].code);

                try
                {
                    keys_writer.unregister_instance(instance[2], ref handle[2]);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("unregister instance error: {0}", e);
                    return;
                }

                active[2] = 0;

                /* Re-register the second instance (ins1) */
                Console.WriteLine("----DW1 re-registering instance {0}", instance[1].code);
                handle[1] = keys_writer.register_instance(instance[1]);
                active[1] = 1;
            } break;

            case 16:
            {         /* Re-register the third instance (ins2) */
                Console.WriteLine("----DW1 re-registering instance {0}", instance[2].code);
                handle[2] = keys_writer.register_instance(instance[2]);
                active[2] = 1;
            } break;
            }

            for (int i = 0; i < 3; ++i)
            {
                if (active[i] == 1)
                {
                    Console.WriteLine("DW1 write; code: {0}, x: {1}, y: {2}",
                                      instance[i].code, instance[i].x, instance[i].y);

                    try
                    {
                        keys_writer.write(instance[i], ref handle[i]);
                    }
                    catch (DDS.Exception e)
                    {
                        Console.WriteLine("write error {0}", e);
                        return;
                    }
                }
            }

            /* Control second datawriter */
            switch (count)
            {
            case 16:
            {         /* Dispose the instance (ins1).
                       * Since it has lower ownership strength, this does nothing */
                Console.WriteLine("----DW2 disposing instance {0}", instance_dw2.code);
                try
                {
                    keys_writer2.dispose(instance_dw2, ref handle_dw2);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("dispose error {0}", e);
                    return;
                }

                active_dw2 = 0;
            } break;
            }

            if (active_dw2 == 1)
            {
                Console.WriteLine("DW2 write; code: {0}, x: {1}, y: {2}",
                                  instance_dw2.code, instance_dw2.x, instance_dw2.y);
                try
                {
                    keys_writer2.write(instance_dw2, ref handle_dw2);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("write error {0}", e);
                    return;
                }
            }
        }

        // --- Shutdown --- //

        /* Delete data sample */
        for (int i = 0; i < 3; i++)
        {
            try
            {
                keysTypeSupport.delete_data(instance[i]);
            }
            catch (DDS.Exception e)
            {
                Console.WriteLine(
                    "keysTypeSupport.delete_data error: {0}", e);
            }
        }
        try
        {
            keysTypeSupport.delete_data(instance_dw2);
        }
        catch (DDS.Exception e)
        {
            Console.WriteLine(
                "keysTypeSupport.delete_data error: {0}", e);
        }

        /* Delete all entities */
        shutdown(participant);
    }
Пример #25
0
        public override Test.Framework.TestResult Run(Test.Framework.TestCase testCase)
        {
            string filteredTypeName = "my_filtered_topic";
            string filterExpression = "long_1 < %0";

            //        final String expressionParameters[] = {"1", "2", "3"};
            string[] expressionParameters = new string[] { "1" };
            DDS.IDomainParticipant    participant;
            DDS.ITopic                topic;
            DDS.IContentFilteredTopic filteredTopic;
            DDS.IPublisher            publisher;
            DDS.ISubscriber           subscriber;
            mod.tstDataReader         reader;
            mod.tstDataWriter         writer;
            DDS.PublisherQos          publisherQos  = null;
            DDS.SubscriberQos         subscriberQos = null;
            DDS.DataReaderQos         dataReaderQos = null;
            DDS.DataWriterQos         dataWriterQos = null;
            Test.Framework.TestResult result;
            participant = (DDS.IDomainParticipant)testCase.ResolveObject("participant");
            topic       = (DDS.ITopic)testCase.ResolveObject("topic");
            result      = new Test.Framework.TestResult("Initialization success", string.Empty, Test.Framework.TestVerdict.Pass,
                                                        Test.Framework.TestVerdict.Fail);
            filteredTopic = participant.CreateContentFilteredTopic(filteredTypeName, topic,
                                                                   filterExpression, expressionParameters);
            if (filteredTopic == null)
            {
                result.Result = "participant.create_contentfilteredtopic failed (1).";
                return(result);
            }

            if (participant.GetDefaultPublisherQos(ref publisherQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "participant.get_default_publisher_qos failed (2).";
                return(result);
            }
            publisher = participant.CreatePublisher(publisherQos);//, null, 0);
            if (publisher == null)
            {
                result.Result = "participant.create_publisher failed (3).";
                return(result);
            }

            if (publisher.GetDefaultDataWriterQos(ref dataWriterQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "publisher.get_default_datawriter_qos failed (4).";
                return(result);
            }

            writer = publisher.CreateDataWriter(topic, dataWriterQos) as mod.tstDataWriter;
            if (writer == null)
            {
                result.Result = "could not create a tstDataWriter (5).";
                return(result);
            }

            if (participant.GetDefaultSubscriberQos(ref subscriberQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "participant.get_default_subscriber_qos failed (6).";
                return(result);
            }
            subscriber = participant.CreateSubscriber(subscriberQos);//, null, 0);
            if (subscriber == null)
            {
                result.Result = "participant.create_subscriber failed (7).";
                return(result);
            }

            if (subscriber.GetDefaultDataReaderQos(ref dataReaderQos) != DDS.ReturnCode.Ok)
            {
                result.Result = "subscriber.get_default_datareader_qos failed (8).";
                return(result);
            }

            reader = subscriber.CreateDataReader(filteredTopic, dataReaderQos) as mod.tstDataReader;
            if (reader == null)
            {
                result.Result = "subscriber.create_datareader failed (9).";
                return(result);
            }
            testCase.RegisterObject("filteredTopic", filteredTopic);
            testCase.RegisterObject("publisher", publisher);
            testCase.RegisterObject("subscriber", subscriber);
            testCase.RegisterObject("reader", reader);
            testCase.RegisterObject("dataReaderQos", dataReaderQos);
            testCase.RegisterObject("writer", writer);
            result.Result  = "Initialization success.";
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #26
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult result;
            string expResult = "contains_entity returns the correct result";

            DDS.IDomainParticipant       participant;
            DDS.DomainParticipantFactory factory;
            DDS.TopicQos      tHolder = new DDS.TopicQos();
            DDS.PublisherQos  pHolder = new DDS.PublisherQos();
            DDS.SubscriberQos sHolder = new DDS.SubscriberQos();
            DDS.DataWriterQos wHolder = new DDS.DataWriterQos();
            DDS.DataReaderQos rHolder = new DDS.DataReaderQos();
            DDS.ITopic        topic;
            DDS.IPublisher    publisher;
            DDS.ISubscriber   subscriber;
            mod.tstDataWriter writer;
            mod.tstDataReader reader;
            long handle;

            DDS.ReturnCode rc;
            participant = (DDS.IDomainParticipant) this.ResolveObject("participant");
            factory     = (DDS.DomainParticipantFactory) this.ResolveObject("factory");
            result      = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                        Test.Framework.TestVerdict.Fail);
            if (participant.ContainsEntity(0))
            {
                result.Result = "contains_entity with nil handle incorrect";
                return(result);
            }
            if (participant.ContainsEntity(100))
            {
                result.Result = "contains_entity with incorrect handle incorrect";
                return(result);
            }

            handle = participant.InstanceHandle;
            if (handle == DDS.InstanceHandle.Nil)
            {
                result.Result = "get_instance_handle returned 0";
                return(result);
            }
            if (participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with own handle incorrect";
                return(result);
            }
            mod.tstTypeSupport typeSupport = new mod.tstTypeSupport();
            rc = typeSupport.RegisterType(participant, "type1");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Register type failed.";
                return(result);
            }
            participant.GetDefaultTopicQos(ref tHolder);
            topic = participant.CreateTopic("TestTopic", "type1", tHolder);//, null, 0);
            if (topic == null)
            {
                result.Result = "Create Topic failed.";
                return(result);
            }
            participant.GetDefaultPublisherQos(ref pHolder);
            publisher = participant.CreatePublisher(pHolder);//, null, 0);
            if (publisher == null)
            {
                result.Result = "Create Publisher failed.";
                return(result);
            }
            participant.GetDefaultSubscriberQos(ref sHolder);
            subscriber = participant.CreateSubscriber(sHolder);//, null, 0);
            if (subscriber == null)
            {
                result.Result = "Create Subscriber failed.";
                return(result);
            }
            publisher.GetDefaultDataWriterQos(ref wHolder);
            writer = publisher.CreateDataWriter(topic, wHolder) as mod.tstDataWriter;
            if (writer == null)
            {
                result.Result = "Create Writer failed.";
                return(result);
            }

            subscriber.GetDefaultDataReaderQos(ref rHolder);
            reader = subscriber.CreateDataReader(topic, rHolder) as mod.tstDataReader;
            if (reader == null)
            {
                result.Result = "Create Reader failed.";
                return(result);
            }
            handle = topic.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (topic) returned 0";
                return(result);
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with topic handle incorrect";
                return(result);
            }
            handle = publisher.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (publisher) returned != 0";
                return(result);
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with publisher handle incorrect";
                return(result);
            }
            handle = subscriber.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (subscriber) returned != 0";
                return(result);
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with subscriber handle incorrect";
                return(result);
            }
            handle = writer.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (writer) returned 0";
                return(result);
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with writer handle incorrect";
                return(result);
            }
            handle = reader.InstanceHandle;
            if (handle == 0)
            {
                result.Result = "get_instance_handle (reader) returned 0";
                return(result);
            }
            if (!participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity with reader handle incorrect";
                return(result);
            }
            rc = participant.DeleteContainedEntities();
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "delete_contained_entities failed.";
                return(result);
            }
            if (participant.ContainsEntity(handle))
            {
                result.Result = "contains_entity of deleted reader incorrect";
                return(result);
            }
            result.Verdict = Test.Framework.TestVerdict.Pass;
            result.Result  = expResult;
            return(result);
        }
Пример #27
0
        public override Test.Framework.TestResult Run()
        {
            DDS.DomainParticipantFactory factory;
            DDS.IDomainParticipant       participant;
            DDS.DomainParticipantQos     pqosHolder     = null;
            DDS.TopicQos                   topQosHolder = null;
            DDS.ITopic                     topic;
            mod.tstTypeSupport             typeSupport = null;
            mod.tstDataReader              datareader;
            test.sacs.MyDataReaderListener listener;
            DDS.ISubscriber                subscriber;
            DDS.SubscriberQos              sqosHolder = null;
            DDS.DataReaderQos              dqosHolder = null;
            DDS.IPublisher                 publisher;
            DDS.PublisherQos               pubQosHolder = null;
            mod.tstDataWriter              datawriter;
            DDS.DataWriterQos              wqosHolder = null;
            Test.Framework.TestResult      result;
            DDS.ReturnCode                 rc;
            string expResult = "DataReaderListener test succeeded.";

            semaphores = new Dictionary <DDS.StatusKind, Semaphore>();
            semaphores.Add(DDS.StatusKind.DataAvailable, new Semaphore(0, 1));

            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict
                                                   .Pass, Test.Framework.TestVerdict.Fail);
            factory = DDS.DomainParticipantFactory.Instance;
            if (factory == null)
            {
                result.Result = "DomainParticipantFactory could not be initialized.";
                return(result);
            }

            if (factory.GetDefaultParticipantQos(ref pqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DomainParticipantQos could not be resolved.";
                return(result);
            }
            participant = factory.CreateParticipant(DDS.DomainId.Default, pqosHolder);//, null, 0);
            if (participant == null)
            {
                result.Result = "Creation of DomainParticipant failed.";
                return(result);
            }
            typeSupport = new mod.tstTypeSupport();
            if (typeSupport == null)
            {
                result.Result = "Creation of tstTypeSupport failed.";
                this.Cleanup(factory, participant);
                return(result);
            }
            rc = typeSupport.RegisterType(participant, "my_type");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Register type failed.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (participant.GetDefaultTopicQos(ref topQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default TopicQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            topic = participant.CreateTopic("my_topic", "my_type", topQosHolder);//, null,
            //0);
            if (topic == null)
            {
                result.Result = "Topic could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (participant.GetDefaultSubscriberQos(ref sqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default SubscriberQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            subscriber = participant.CreateSubscriber(sqosHolder);//, null, 0);
            if (subscriber == null)
            {
                result.Result = "Subscriber could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (subscriber.GetDefaultDataReaderQos(ref dqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataReaderQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            datareader = (mod.tstDataReader)subscriber.CreateDataReader(topic, dqosHolder);//, null, 0);
            if (datareader == null)
            {
                result.Result = "DataReader could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (participant.GetDefaultPublisherQos(ref pubQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default PublisherQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            publisher = participant.CreatePublisher(pubQosHolder);//, null, 0);
            if (publisher == null)
            {
                result.Result = "Publisher could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }

            if (publisher.GetDefaultDataWriterQos(ref wqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataWriterQos could not be resolved.";
                this.Cleanup(factory, participant);
                return(result);
            }
            datawriter = (mod.tstDataWriter)publisher.CreateDataWriter(topic, wqosHolder);//, null, 0);
            if (datawriter == null)
            {
                result.Result = "DataWriter could not be created.";
                this.Cleanup(factory, participant);
                return(result);
            }
            listener = new test.sacs.MyDataReaderListener(semaphores);
            rc       = datareader.SetListener(listener, DDS.StatusKind.LivelinessChanged | DDS.StatusKind.DataAvailable);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Set listener failed.";
                return(result);
            }
            mod.tst t = new mod.tst();
            t.long_1 = 1;
            t.long_2 = 2;
            t.long_3 = 3;

            rc = datawriter.Write(t, DDS.InstanceHandle.Nil);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Data could not be written.";
                this.Cleanup(factory, participant);
                return(result);
            }
            if (semaphores[DDS.StatusKind.DataAvailable].WaitOne(10000))
            {
                if (!listener.onDataAvailableCalled)
                {
                    result.Result = "on_data_available does not work properly.";
                    this.Cleanup(factory, participant);
                    return(result);
                }
            }
            else
            {
                result.Result = "on_data_available did not trigger";
                this.Cleanup(factory, participant);
                return(result);
            }
            listener.Reset();
            rc = publisher.DeleteDataWriter(datawriter);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "DataWriter could not be deleted.";
                this.Cleanup(factory, participant);
                return(result);
            }
            rc = participant.DeleteContainedEntities();
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Delete contained entities failed.";
                this.Cleanup(factory, participant);
                return(result);
            }
            rc = factory.DeleteParticipant(participant);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Delete DomainParticipant failed.";
                this.Cleanup(factory, participant);
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Пример #28
0
        public override Test.Framework.TestResult Run(Test.Framework.TestCase testCase)
        {
            DDS.DomainParticipantFactory factory;
            DDS.IDomainParticipant       participant;
            DDS.DomainParticipantQos     pqosHolder   = null;
            DDS.SubscriberQos            subQosHolder = null;
            DDS.DataReaderQos            drQosHolder  = null;
            DDS.ISubscriber           subscriber;
            DDS.PublisherQos          pubQosHolder = null;
            DDS.IPublisher            publisher;
            mod.tstTypeSupport        typeSupport;
            DDS.TopicQos              tQosHolder = null;
            DDS.ITopic                topic;
            DDS.DataWriterQos         dwQosHolder = null;
            mod.tstDataWriter         datawriter;
            Test.Framework.TestResult result;
            DDS.ReturnCode            rc;
            result = new Test.Framework.TestResult("Initialization success", string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            factory = DDS.DomainParticipantFactory.Instance;
            if (factory == null)
            {
                result.Result = "DomainParticipantFactory could not be initialized.";
                return(result);
            }

            if (factory.GetDefaultParticipantQos(ref pqosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DomainParticipantQos could not be resolved.";
                return(result);
            }
            participant = factory.CreateParticipant(string.Empty, pqosHolder);//, null, 0);
            if (participant == null)
            {
                result.Result = "Creation of DomainParticipant failed.";
                return(result);
            }

            if (participant.GetDefaultSubscriberQos(ref subQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default SubscriberQos could not be resolved.";
                return(result);
            }
            subQosHolder.Partition.Name    = new string[1];
            subQosHolder.Partition.Name[0] = "testPartition";
            subscriber = participant.CreateSubscriber(subQosHolder);//, null, 0);
            if (subscriber == null)
            {
                result.Result = "Subscriber could not be created.";
                return(result);
            }
            typeSupport = new mod.tstTypeSupport();
            rc          = typeSupport.RegisterType(participant, "tstType");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Typesupport could not be registered.";
                return(result);
            }

            if (participant.GetDefaultTopicQos(ref tQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default TopicQos could not be resolved.";
                return(result);
            }
            tQosHolder.Durability.Kind  = DDS.DurabilityQosPolicyKind.TransientDurabilityQos;
            tQosHolder.Reliability.Kind = DDS.ReliabilityQosPolicyKind.ReliableReliabilityQos;
            topic = participant.CreateTopic("tst", "tstType", tQosHolder);//, null, 0);
            if (topic == null)
            {
                result.Result = "Topic could not be created.";
                return(result);
            }

            if (participant.GetDefaultPublisherQos(ref pubQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default PublisherQos could not be resolved.";
                return(result);
            }
            pubQosHolder.Partition.Name    = new string[1];
            pubQosHolder.Partition.Name[0] = "testPartition";
            publisher = participant.CreatePublisher(pubQosHolder);//, null, 0);
            if (publisher == null)
            {
                result.Result = "Publisher could not be created.";
                return(result);
            }

            if (publisher.CopyFromTopicQos(ref dwQosHolder, tQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataWriterQos could not be resolved.";
                return(result);
            }
            dwQosHolder.WriterDataLifecycle.AutodisposeUnregisteredInstances = true;
            datawriter = (mod.tstDataWriter)publisher.CreateDataWriter(topic, dwQosHolder);//, null, 0);
            if (datawriter == null)
            {
                result.Result = "DataWriter could not be created.";
                return(result);
            }

            if (subscriber.CopyFromTopicQos(ref drQosHolder, tQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataReaderQos could not be resolved.";
                return(result);
            }
            drQosHolder.Durability.Kind = DDS.DurabilityQosPolicyKind.VolatileDurabilityQos;
            testCase.RegisterObject("factory", factory);
            testCase.RegisterObject("participantQos", pqosHolder);
            testCase.RegisterObject("participant", participant);
            testCase.RegisterObject("topic", topic);
            testCase.RegisterObject("topicQos", tQosHolder);
            testCase.RegisterObject("subscriber", subscriber);
            testCase.RegisterObject("subscriberQos", subQosHolder);
            testCase.RegisterObject("datareaderQos", drQosHolder);
            testCase.RegisterObject("publisher", publisher);
            testCase.RegisterObject("publisherQos", pubQosHolder);
            testCase.RegisterObject("datawriter", datawriter);
            testCase.RegisterObject("datawriterQos", dwQosHolder);
            result.Result  = "Initialization success.";
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }