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;
        }
    static bool checkParticipant(DDS.DomainParticipant participant)
    {
        DDS.DomainParticipantQos participantQos = new DDS.DomainParticipantQos();
        participant.get_qos(participantQos);

        DDS.PropertySeq properties = participantQos.property_qos.value;

        for (int i = 0; i < properties.length; i++)
        {
            if (String.Compare(properties.get_at(i).name,
                "dds.transport.UDPv4.builtin.send_socket_buffer_size") == 0)
            {
                if (String.Compare(properties.get_at(i).value, NEW_SOCKET_BUFFER_SIZE_STRING)
                     != 0)
                {
                    Console.WriteLine("Error, send_socket_buffer_size...not modified");
                    return false;
                }
            }
            if (String.Compare(properties.get_at(i).name,
                "dds.transport.UDPv4.builtin.recv_socket_buffer_size") == 0)
            {
                string value = properties.get_at(i).value;
                if (String.Compare(properties.get_at(i).value, NEW_SOCKET_BUFFER_SIZE_STRING)
                     != 0)
                {
                    Console.WriteLine("Error, recv_socket_buffer_size...not modified");
                    return false;
                }
            }
        }
        return true;
    }
Example #3
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;
        }
Example #4
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 DDS.DomainParticipant createParticipant(int domainId)
    {
        DDS.DomainParticipant participant = null;

        DDS.DomainParticipantQos participantQos =
            new DDS.DomainParticipantQos();

        DDS.DomainParticipantFactory.get_instance()
                .get_default_participant_qos(participantQos);

        DDS.PropertySeq propertySeq =
            participantQos.property_qos.value;
        propertySeq.ensure_length(2, 2);

        /* Set the send socket buffer size */
        DDS.Property_t propertyElement = propertySeq.get_at(0);
        propertyElement.name =
            "dds.transport.UDPv4.builtin.send_socket_buffer_size";
        propertyElement.value = NEW_SOCKET_BUFFER_SIZE_STRING;
        propertyElement.propagate = false;

        /* Set the send socket buffer size */
        propertyElement = propertySeq.get_at(1);
        propertyElement.name =
            "dds.transport.UDPv4.builtin.recv_socket_buffer_size";
        propertyElement.value = NEW_SOCKET_BUFFER_SIZE_STRING;
        propertyElement.propagate = false;

        /* Create the participant */
        participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domainId, participantQos,
                null /* listener */, DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            return null;
        }
        return participant;
    }
Example #6
0
        public override Test.Framework.TestResult Run()
        {
            string expResult = "register_typesupport tests pass";

            DDS.DomainParticipantFactory factory;
            DDS.DomainParticipantQos     participantQosHolder = null;
            DDS.IDomainParticipant       participant;
            mod.tstTypeSupport           typeSupport;
            mod.otherTypeTypeSupport     otherTypeTypeSupport;
            DDS.ReturnCode            rc;
            Test.Framework.TestResult result;
            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.get_instance() did not return a factory (1)";
                return(result);
            }

            if (factory.GetDefaultParticipantQos(ref participantQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "factory.get_default_participant_qos() did not return a qos (2)";
                return(result);
            }
            participant = factory.CreateParticipant(string.Empty, participantQosHolder);//, null, 0);
            if (participant == null)
            {
                result.Result = "factory.create_participant() did not return a participant (2)";
                return(result);
            }
            typeSupport          = new mod.tstTypeSupport();
            otherTypeTypeSupport = new mod.otherTypeTypeSupport();

            rc = typeSupport.RegisterType(participant, "type1");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not register a type (3)";
                return(result);
            }
            rc = typeSupport.RegisterType(participant, "type1");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not register the same type a second time (4)";
                return(result);
            }
            rc = otherTypeTypeSupport.RegisterType(participant, "type2");
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could register a different type (5)";
                return(result);
            }
            rc = otherTypeTypeSupport.RegisterType(participant, "type1");
            if (rc != DDS.ReturnCode.PreconditionNotMet)
            {
                result.Result = "Expected RETCODE_PRECONDITION_NOT_MET but recieved " + rc + " after calling register_type using an already used name for a different type (6)";
                return(result);
            }
            rc = factory.DeleteParticipant(participant);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "could not delete a participant (7)";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
    static void subscribe(int domain_id, int sample_count, 
        String participant_auth, String reader_auth)
    {
        // --- Create participant --- //

        /* Start changes for programmatically qos */

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

        /* Set user_data qos field for participant */

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

        DDS.StringSeq temp = new DDS.StringSeq(0);
        participant_qos.discovery.multicast_receive_addresses = temp;

        // user_data is opaque to DDS, so we include trailing \0 for string
        int len = participant_auth.Length;
        int max =
            participant_qos.resource_limits.participant_user_data_max_length;

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

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

        /* End changes for programmatically qos */

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

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

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

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

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

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

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

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

        /* Start changes for Builtin_Topics */
        /* Set user_data qos field for datareader */
        DDS.DataReaderQos datareader_qos = new DDS.DataReaderQos();
        subscriber.get_default_datareader_qos(datareader_qos);

        /* user_data is opaque to DDS, so we include trailing \0 for string */
        len = reader_auth.Length;
        max = participant_qos.resource_limits.reader_user_data_max_length;

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

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

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

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

           System.Threading.Thread.Sleep(receive_period);

        }

        // --- Shutdown --- //

        /* Delete all entities */
        shutdown(participant);
        reader_listener = null;
    }
Example #8
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(string.Empty, 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);
            }
            listener   = new test.sacs.MyDataReaderListener();
            datareader = (mod.tstDataReader)subscriber.CreateDataReader(topic, dqosHolder, listener,
                                                                        DDS.StatusKind.Any ^ DDS.StatusKind.DataOnReaders);
            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);
            }
            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);
            }
            listener.Reset();

            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);
            }
            try
            {
                System.Threading.Thread.Sleep(3000);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e);
            }
            if (!listener.onDataAvailableCalled)
            {
                result.Result = "on_data_available does not work properly.";
                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);
            }
            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 (2).";
                this.Cleanup(factory, participant);
                return(result);
            }

            rc = datareader.SetListener(listener, 0);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Listener could not be attached.";
                this.Cleanup(factory, participant);
                return(result);
            }
            rc = datareader.SetListener(null, 0);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Listener could not be detached.";
                this.Cleanup(factory, participant);
                return(result);
            }
            rc = subscriber.DeleteDataReader(datareader);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "Delete datareader failed.";
                this.Cleanup(factory, participant);
                return(result);
            }
            listener.Reset();
            dqosHolder.Durability.Kind = DDS.DurabilityQosPolicyKind.TransientDurabilityQos;
            datareader = (mod.tstDataReader)subscriber.CreateDataReader(topic, dqosHolder, listener,
                                                                        DDS.StatusKind.Any ^ DDS.StatusKind.DataOnReaders);
            try
            {
                System.Threading.Thread.Sleep(3000);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e);
            }
            listener.Reset();
            datawriter = (mod.tstDataWriter)publisher.CreateDataWriter(topic, wqosHolder);//, null, 0);
            try
            {
                System.Threading.Thread.Sleep(3000);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e);
            }
            if (!listener.onRequestedIncompatibleQosCalled)
            {
                result.Result = "on_requested_incompatible_qos 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);
        }
Example #9
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.ISubscriber    subscriber;
            DDS.PublisherQos   pubQosHolder = null;
            DDS.IPublisher     publisher;
            mod.tstTypeSupport typeSupport;
            DDS.TopicQos       tQosHolder = null;
            DDS.ITopic         topic;
            DDS.DataReaderQos  drQosHolder = null;
            mod.tstDataReader  datareader;
            //mod.tstDataReader datareader2;
            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);
            }
            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);
            }
            topic = participant.CreateTopic("tst", "tstType", tQosHolder);//, null, 0);
            if (topic == null)
            {
                result.Result = "Topic could not be created.";
                return(result);
            }

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

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

            if (publisher.GetDefaultDataWriterQos(ref dwQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Default DataWriterQos could not be resolved.";
                return(result);
            }

            datawriter = (mod.tstDataWriter)publisher.CreateDataWriter(topic, dwQosHolder);//, null, 0);
            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("datareader", datareader);
            //testCase.RegisterObject("datareader2", datareader2);
            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);
        }
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult  result;
            Test.Framework.TestVerdict expVerdict = Test.Framework.TestVerdict.Pass;
            string expResult = "Get/Set DomainParticipantQos succeeded.";

            DDS.DomainParticipantFactory factory;
            DDS.DomainParticipantQos     pqosHolder  = null;
            DDS.DomainParticipantQos     pqosHolder2 = null;
            DDS.ReturnCode returnCode;
            byte[]         ud;
            factory = DDS.DomainParticipantFactory.Instance;
            if (factory == null)
            {
                result = new Test.Framework.TestResult(expResult, "DomainParticipantFactory could not be initialised."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            returnCode = factory.GetDefaultParticipantQos(ref pqosHolder);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Default DomainParticipantQos could not be resolved."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            pqosHolder.EntityFactory.AutoenableCreatedEntities = true;
            ud    = new byte[1];
            ud[0] = System.Convert.ToByte("4");
            pqosHolder.UserData.Value = ud;
            pqosHolder.WatchdogScheduling.SchedulingClass.Kind        = DDS.SchedulingClassQosPolicyKind.ScheduleRealtime;
            pqosHolder.WatchdogScheduling.SchedulingPriorityKind.Kind = DDS.SchedulingPriorityQosPolicyKind.PriorityAbsolute;
            pqosHolder.WatchdogScheduling.SchedulingPriority          = 10;
            pqosHolder.ListenerScheduling.SchedulingClass.Kind        = DDS.SchedulingClassQosPolicyKind.ScheduleTimesharing;
            pqosHolder.ListenerScheduling.SchedulingPriorityKind.Kind = DDS.SchedulingPriorityQosPolicyKind.PriorityAbsolute;
            pqosHolder.ListenerScheduling.SchedulingPriority          = 20;
            returnCode = factory.SetDefaultParticipantQos(pqosHolder);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Set default participant qos failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            factory.GetDefaultParticipantQos(ref pqosHolder2);
            if (pqosHolder.EntityFactory.AutoenableCreatedEntities != pqosHolder2.EntityFactory.AutoenableCreatedEntities)
            {
                result = new Test.Framework.TestResult(expResult, "Resolved entity_factory policy does not match the applied one."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            if (pqosHolder.UserData.Value.Length != pqosHolder2.UserData.Value.
                Length)
            {
                result = new Test.Framework.TestResult(expResult, "Resolved UserData policy does not match the applied one."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            if (pqosHolder.UserData.Value[0] != pqosHolder2.UserData.Value[0])
            {
                result = new Test.Framework.TestResult(expResult, "Resolved UserData policy does not match the applied one (2)."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            if (pqosHolder.WatchdogScheduling.SchedulingClass.Kind != pqosHolder2.WatchdogScheduling.SchedulingClass.Kind)
            {
                result = new Test.Framework.TestResult(expResult, "Resolved watchdog_scheduling.scheduling_class policy does not match the applied one"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            if (pqosHolder.WatchdogScheduling.SchedulingPriorityKind.Kind != pqosHolder2
                .WatchdogScheduling.SchedulingPriorityKind.Kind)
            {
                result = new Test.Framework.TestResult(expResult, "Resolved watchdog_scheduling.scheduling_priority_kind policy does not match the applied one"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            if (pqosHolder.WatchdogScheduling.SchedulingPriority != pqosHolder2.WatchdogScheduling.SchedulingPriority)
            {
                result = new Test.Framework.TestResult(expResult, "Resolved watchdog_scheduling.SchedulingPriority does not match the applied one"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            if (pqosHolder.ListenerScheduling.SchedulingClass.Kind != pqosHolder2.ListenerScheduling.SchedulingClass.Kind)
            {
                result = new Test.Framework.TestResult(expResult, "Resolved listener_scheduling.scheduling_class policy does not match the applied one"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            if (pqosHolder.ListenerScheduling.SchedulingPriorityKind.Kind != pqosHolder2
                .ListenerScheduling.SchedulingPriorityKind.Kind)
            {
                result = new Test.Framework.TestResult(expResult, "Resolved listener_scheduling.scheduling_priority_kind policy does not match the applied one"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            if (pqosHolder.ListenerScheduling.SchedulingPriority != pqosHolder2.ListenerScheduling.SchedulingPriority)
            {
                result = new Test.Framework.TestResult(expResult, "Resolved listener_scheduling.SchedulingPriority does not match the applied one"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            result = new Test.Framework.TestResult(expResult, expResult, expVerdict, expVerdict
                                                   );
            return(result);
        }
Example #11
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult  result;
            Test.Framework.TestVerdict expVerdict = Test.Framework.TestVerdict.Pass;
            string expResult = "Creating/deleting DomainParticipant succeeded.";

            DDS.DomainParticipantFactory factory;
            DDS.IDomainParticipant       participant;
            DDS.IDomainParticipant       participant2;
            DDS.DomainParticipantQos     pqosHolder = null;
            DDS.ReturnCode returnCode;
            factory = DDS.DomainParticipantFactory.Instance;
            if (factory == null)
            {
                result = new Test.Framework.TestResult(expResult, "DomainParticipantFactory could not be initialised."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            returnCode = factory.GetDefaultParticipantQos(ref pqosHolder);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Default DomainParticipantQos could not be resolved ("
                                                       + returnCode + ").", expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            participant = factory.CreateParticipant(DDS.DomainId.Default, pqosHolder);//, null, 0);
            if (participant == null)
            {
                result = new Test.Framework.TestResult(expResult, "DomainParticipant could not be created."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            participant2 = factory.CreateParticipant(DDS.DomainId.Default, pqosHolder);//, null, 0);
            if (participant2 == null)
            {
                result = new Test.Framework.TestResult(expResult, "DomainParticipant 2 could not be created."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            returnCode = factory.DeleteParticipant(participant);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "DomainParticipant could not be deleted."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            returnCode = factory.DeleteParticipant(participant2);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "DomainParticipant  2 could not be deleted."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            participant2 = factory.CreateParticipant(DDS.DomainId.Default, pqosHolder);//, null, 0);
            if (participant2 == null)
            {
                return(new Test.Framework.TestResult(expResult, "failure creating a DomainParticipant with an empty domainId"
                                                     , expVerdict, Test.Framework.TestVerdict.Fail));
            }
            returnCode = factory.DeleteParticipant(participant2);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                return(new Test.Framework.TestResult(expResult, "erroneous returncode while deleting a participant"
                                                     , expVerdict, Test.Framework.TestVerdict.Fail));
            }
            participant = factory.LookupParticipant(DDS.DomainId.Default);
            if (participant != null)
            {
                return(new Test.Framework.TestResult(expResult, "could still lookup deleted participant"
                                                     , expVerdict, Test.Framework.TestVerdict.Fail));
            }
            returnCode = factory.DeleteParticipant(participant);
            if (returnCode == DDS.ReturnCode.Ok)
            {
                return(new Test.Framework.TestResult(expResult, "could delete a non existing participant"
                                                     , expVerdict, Test.Framework.TestVerdict.Fail));
            }
            result = new Test.Framework.TestResult(expResult, expResult, expVerdict, expVerdict
                                                   );
            return(result);
        }
Example #12
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult  result;
            Test.Framework.TestVerdict expVerdict = Test.Framework.TestVerdict.Pass;
            string expResult = "Default subscriberQos is used when SUBSCRIBER_QOS_DEFAULT is specified.";

            DDS.DomainParticipantFactory factory;
            DDS.IDomainParticipant       participant;
            DDS.DomainParticipantQos     pqosHolder    = null;
            DDS.SubscriberQos            subQosHolder  = null;
            DDS.SubscriberQos            subQosHolder2 = null;
            DDS.ISubscriber sub;
            DDS.ReturnCode  returnCode;
            factory = DDS.DomainParticipantFactory.Instance;
            if (factory == null)
            {
                result = new Test.Framework.TestResult(expResult, "DomainParticipantFactory could not be initialised."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            if (factory.GetDefaultParticipantQos(ref pqosHolder) != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Default DomainParticipantQos could not be resolved."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            participant = factory.CreateParticipant(DDS.DomainId.Default, pqosHolder);//, null, 0);
            if (participant == null)
            {
                result = new Test.Framework.TestResult(expResult, "Creation of DomainParticipant failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            if (participant.GetDefaultSubscriberQos(ref subQosHolder) != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Subscriber qos could not be resolved."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            string[] name = new string[2];
            name[0] = "Subscriber";
            name[1] = "QoS";
            subQosHolder.Partition.Name = name;
            returnCode = participant.SetDefaultSubscriberQos(subQosHolder);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Setting default subscriber QoS failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            sub = participant.CreateSubscriber();
            if (sub == null)
            {
                result = new Test.Framework.TestResult(expResult, "Subscriber could not be created."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            sub.GetQos(ref subQosHolder2);
            if (!subQosHolder.Partition.Name[0].Equals(subQosHolder.Partition.Name
                                                       [0]) || !subQosHolder.Partition.Name[1].Equals(subQosHolder.Partition
                                                                                                      .Name[1]))
            {
                result = new Test.Framework.TestResult(expResult, "Default subscriber QoS is not taken when SUBSCRIBER_QOS_DEFAULT is specified."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            returnCode = participant.DeleteSubscriber(sub);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Deletion of Subscriber failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            returnCode = factory.DeleteParticipant(participant);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Deletion of DomainParticipant failed."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            result = new Test.Framework.TestResult(expResult, expResult, expVerdict, expVerdict
                                                   );
            return(result);
        }
Example #13
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult  result;
            Test.Framework.TestVerdict expVerdict = Test.Framework.TestVerdict.Pass;
            string expResult = "Waitset StatusCondition succeeded.";

            DDS.ICondition[]             holder;
            DDS.ReturnCode               rc;
            DDS.DomainParticipantFactory factory;
            DDS.IDomainParticipant       participant;
            DDS.DomainParticipantQos     qosHolder = null;
            DDS.IStatusCondition         condition;
            DDS.IStatusCondition         condition2;
            DDS.IPublisher               publisher;
            DDS.PublisherQos             pubQosHolder = null;
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict
                                                   .Pass, Test.Framework.TestVerdict.Fail);
            holder = new DDS.ICondition[0];
            DDS.WaitSet waitset = new DDS.WaitSet();
            factory = DDS.DomainParticipantFactory.Instance;
            if (factory == null)
            {
                result.Result = "Factory get_instance failed.";
                return(result);
            }

            if (factory.GetDefaultParticipantQos(ref qosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "get_default_participant_qos failed.";
                return(result);
            }
            participant = factory.CreateParticipant(DDS.DomainId.Default, qosHolder);//, null, 0);
            if (participant == null)
            {
                result.Result = "create_participant failed.";
                return(result);
            }

            if (participant.GetDefaultPublisherQos(ref pubQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "get_default_publisher_qos failed.";
                return(result);
            }
            publisher = participant.CreatePublisher(pubQosHolder);//, null, DDS.StatusKind.Any);
            if (publisher == null)
            {
                result.Result = "create_publisher failed.";
                return(result);
            }
            condition = participant.StatusCondition;
            if (condition == null)
            {
                result.Result = "get_status_condition failed.";
                return(result);
            }
            condition2 = publisher.StatusCondition;
            if (condition2 == null)
            {
                result.Result = "get_status_condition failed.(2)";
                return(result);
            }
            rc = waitset.AttachCondition(condition);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "attach_condition returned RETCODE: " + rc;
                return(result);
            }
            rc = waitset.GetConditions(ref holder);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "get_conditions returned RETCODE: " + rc;
                return(result);
            }
            if (holder.Length != 1)
            {
                result.Result = "get_conditions returned " + holder.Length + " conditions.";
                return(result);
            }
            if (holder[0] != condition)
            {
                result.Result = "get_conditions returned wrong condition.";
                return(result);
            }
            rc = waitset.DetachCondition(condition);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "detach_condition returned RETCODE: " + rc + " (1)";
                return(result);
            }
            rc = waitset.GetConditions(ref holder);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "get_conditions returned RETCODE: " + rc + " (1)";
                return(result);
            }
            if (holder.Length != 0)
            {
                result.Result = "get_conditions returned " + holder.Length + " conditions (1).";
                return(result);
            }
            rc = waitset.AttachCondition(condition);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "attach_condition returned RETCODE: " + rc;
                return(result);
            }
            rc = waitset.AttachCondition(condition2);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "attach_condition returned RETCODE: " + rc;
                return(result);
            }
            rc = waitset.GetConditions(ref holder);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "get_conditions returned RETCODE: " + rc;
                return(result);
            }
            if (holder.Length != 2)
            {
                result.Result = "get_conditions returned " + holder.Length + " conditions.";
                return(result);
            }
            if ((holder[0] != condition) && (holder[1] != condition))
            {
                result.Result = "get_conditions returned wrong conditions(1).";
                return(result);
            }
            if ((holder[0] != condition2) && (holder[1] != condition2))
            {
                result.Result = "get_conditions returned wrong conditions(2).";
                return(result);
            }
            rc = waitset.DetachCondition(condition);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "detach_condition returned RETCODE: " + rc + " (2)";
                return(result);
            }
            rc = waitset.DetachCondition(condition2);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "detach_condition returned RETCODE: " + rc + " (3)";
                return(result);
            }
            rc = participant.DeleteContainedEntities();
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "delete_contained_entities returned RETCODE: " + rc;
                return(result);
            }
            rc = factory.DeleteParticipant(participant);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "delete_participant returned RETCODE: " + rc;
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = expVerdict;
            return(result);
        }
        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.LivelinessChanged, new Semaphore(0, 1));
            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);
            }
            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(semaphores);
            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);
            }
            if (semaphores[DDS.StatusKind.LivelinessChanged].WaitOne(10000))
            {
                if (!listener.onLivelinessChangedCalled)
                {
                    result.Result = "on_liveliness_changed does not work properly.";
                    this.Cleanup(factory, participant);
                    return(result);
                }
            }
            else
            {
                result.Result = "on_liveliness_changed did not trigger";
                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);
            }


            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);
        }
Example #15
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult result;
            string expResult = "DomainParticipant Publisher test succeeded.";

            DDS.PublisherQos             pubQosHolder = null;
            DDS.IPublisher               publisher;
            DDS.IPublisher               publisher2;
            DDS.ReturnCode               returnCode;
            DDS.DomainParticipantQos     qos = null;
            DDS.IDomainParticipant       participant;
            DDS.IDomainParticipant       participant2;
            DDS.DomainParticipantFactory factory;
            factory     = (DDS.DomainParticipantFactory) this.ResolveObject("factory");
            participant = (DDS.IDomainParticipant) this.ResolveObject("participant");
            result      = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                        Test.Framework.TestVerdict.Fail);
            qos = (DDS.DomainParticipantQos) this.ResolveObject("participantQos");

            if (participant.GetDefaultPublisherQos(ref pubQosHolder) != DDS.ReturnCode.Ok)
            {
                result.Result = "Get default PublisherQos failed.";
                return(result);
            }
            publisher = participant.CreatePublisher(pubQosHolder);//, null, 0);
            if (publisher == null)
            {
                result.Result = "Create Publisher failed.";
                return(result);
            }
            publisher2 = participant.CreatePublisher(null, null, 0);
            if (publisher2 != null)
            {
                this.testFramework.TestMessage(Test.Framework.TestMessage.Note, "See scdds213");
                result.ExpectedVerdict = Test.Framework.TestVerdict.Fail;
                result.Result          = "Create Publisher with BAD_PARAM succeeded.";
                participant.DeleteContainedEntities();
                return(result);
            }
            participant2 = factory.CreateParticipant(null, qos);//, null, 0);
            if (participant2 == null)
            {
                result.Result = "Create Participant failed.";
                return(result);
            }
            returnCode = participant2.DeletePublisher(publisher);
            if (returnCode == DDS.ReturnCode.Ok)
            {
                result.Result = "Delete publisher on wrong Participant succeeded.";
                return(result);
            }
            returnCode = factory.DeleteParticipant(participant2);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result.Result = "Delete Participant failed.";
                return(result);
            }
            returnCode = participant.DeletePublisher(publisher);
            if (returnCode != DDS.ReturnCode.Ok)
            {
                result.Result = "Delete Publisher failed.";
                return(result);
            }
            returnCode = participant.DeletePublisher(publisher);
            if (returnCode == DDS.ReturnCode.Ok)
            {
                result.Result = "Delete of already deleted Publisher succeeded.";
                return(result);
            }
            try
            {
                returnCode = participant.DeletePublisher(null);
                if (returnCode == DDS.ReturnCode.Ok)
                {
                    result.Result = "Delete null Publisher succeeded.";
                    return(result);
                }
            }
            catch {}

            result.Verdict = Test.Framework.TestVerdict.Pass;
            result.Result  = expResult;
            return(result);
        }
Example #16
0
        public override Test.Framework.TestResult Run()
        {
            Test.Framework.TestResult  result;
            Test.Framework.TestVerdict expVerdict = Test.Framework.TestVerdict.Pass;
            string expResult = "get_discovered_xxx succeeded.";

            DDS.DomainParticipantFactory dpf;
            DDS.IDomainParticipant       dp1;
            DDS.IDomainParticipant       dp2;
            DDS.IDomainParticipant       dp3;
            DDS.ITopic   topic1;
            DDS.ITopic   topic2;
            DDS.TopicQos tQos;
            tc_get_discovered_xxx.Type1TypeSupport type1_ts;
            bool dp1res = false;
            bool dp2res = false;
            bool dp3res = false;
            bool t1res  = false;
            bool t2res  = false;

            DDS.ReturnCode returnCode;

            DDS.ParticipantBuiltinTopicData participant_data = null;
            DDS.TopicBuiltinTopicData       topic_data       = null;
            DDS.SampleInfo[]         sample_infos            = null;
            DDS.DomainParticipantQos dpQos     = null;
            DDS.InstanceHandle[]     sequence  = null;
            DDS.InstanceHandle[]     sequence1 = null;

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            tQos = new DDS.TopicQos();

            dpf = DDS.DomainParticipantFactory.Instance;
            if (dpf == null)
            {
                result = new Test.Framework.TestResult(expResult, "DomainParticipantFactory could not be initialised."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            result = new Test.Framework.TestResult(expResult, "DomainParticipantFactory could be initialised."
                                                   , expVerdict, Test.Framework.TestVerdict.Pass);

            if (dpf.GetDefaultParticipantQos(ref dpQos) != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "Default DomainParticipantQos could not be resolved."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }


            dpQos.UserData.Value = encoding.GetBytes("dp1");

            dp1 = dpf.CreateParticipant(string.Empty, dpQos, null, 0);
            if (dp1 == null)
            {
                result = new Test.Framework.TestResult(expResult, "Test case failed. Failed to create dp1 participant"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            dpQos.UserData.Value = encoding.GetBytes("dp2");

            dp2 = dpf.CreateParticipant(string.Empty, dpQos, null, 0);
            if (dp2 == null)
            {
                result = new Test.Framework.TestResult(expResult, "Test case failed. Failed to create dp2 participant"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            dpQos.UserData.Value = encoding.GetBytes("dp3");

            dp3 = dpf.CreateParticipant(string.Empty, dpQos, null, 0);
            if (dp3 == null)
            {
                result = new Test.Framework.TestResult(expResult, "Test case failed. Failed to create dp3 participant"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

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

            /* Create Topic */
            type1_ts = new tc_get_discovered_xxx.Type1TypeSupport();
            type1_ts.RegisterType(dp1, "tc_get_discovered_xxx::Type1");
            topic1 = dp1.CreateTopic("Topic1", "tc_get_discovered_xxx::Type1", tQos);

            if (topic1 == null)
            {
                result = new Test.Framework.TestResult(expResult, "Test case failed. Failed to create Topic1"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            topic2 = dp1.CreateTopic("Topic2", "tc_get_discovered_xxx::Type1", tQos);

            if (topic2 == null)
            {
                result = new Test.Framework.TestResult(expResult, "Test case failed. Failed to create Topic2"
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }

            returnCode = dp1.GetDiscoveredParticipants(ref sequence);

            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "get_discovered_participants returned not OK."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            else
            {
                /* the test should find 5 participants:
                 * buildinParticipant
                 * spliced
                 * dp1
                 * dp2
                 * dp3
                 */

                if (sequence.Length != 5)
                {
                    result = new Test.Framework.TestResult(expResult, "get_discovered_participants failed found: " + sequence.Length + " expected 5"
                                                           , expVerdict, Test.Framework.TestVerdict.Fail);
                    return(result);
                }

                /* read from each handle the UserDataQos and check the result against the made participant names*/
                for (int i = 0; i < sequence.Length; i++)
                {
                    returnCode = dp1.GetDiscoveredParticipantData(ref participant_data, sequence[i]);

                    if (returnCode == DDS.ReturnCode.Ok)
                    {
                        if (participant_data.UserData.Value.Length > 0)
                        {
                            if (encoding.GetString(participant_data.UserData.Value).CompareTo("dp1") == 0)
                            {
                                dp1res = true;
                            }
                            else if (encoding.GetString(participant_data.UserData.Value).CompareTo("dp2") == 0)
                            {
                                dp2res = true;
                            }
                            else if (encoding.GetString(participant_data.UserData.Value).CompareTo("dp3") == 0)
                            {
                                dp3res = true;
                            }
                        }
                        // returnCode = dataReader.ReturnLoan(ref data_values, ref sample_infos);
                    }
                    else
                    {
                        result = new Test.Framework.TestResult(
                            expResult, "read instance failed",
                            expVerdict, Test.Framework.TestVerdict.Fail);
                        return(result);
                    }
                }
                if (!dp1res || !dp2res || !dp3res)
                {
                    result = new Test.Framework.TestResult(
                        expResult, "failed to discover all participants",
                        expVerdict, Test.Framework.TestVerdict.Fail);
                    return(result);
                }
            }

            returnCode = dp1.GetDiscoveredTopics(ref sequence1);

            if (returnCode != DDS.ReturnCode.Ok)
            {
                result = new Test.Framework.TestResult(expResult, "get_discovered_topics returned not OK."
                                                       , expVerdict, Test.Framework.TestVerdict.Fail);
                return(result);
            }
            else
            {
                if (sequence1.Length != 9)
                {
                    result = new Test.Framework.TestResult(expResult, "get_discovered_topics failed found: " + sequence1.Length + " expected 9"
                                                           , expVerdict, Test.Framework.TestVerdict.Fail);
                    return(result);
                }

                /* read from each handle the name and check the result against the made topic names*/
                for (int i = 0; i < sequence1.Length; i++)
                {
                    returnCode = dp1.GetDiscoveredTopicData(ref topic_data, sequence1[i]);

                    if (returnCode == DDS.ReturnCode.Ok)
                    {
                        if (topic_data.Name.CompareTo("Topic1") == 0)
                        {
                            t1res = true;
                        }
                        else if (topic_data.Name.CompareTo("Topic2") == 0)
                        {
                            t2res = true;
                        }
                    }
                    else
                    {
                        result = new Test.Framework.TestResult(
                            expResult, "get discovered topic data failed",
                            expVerdict, Test.Framework.TestVerdict.Fail);
                        return(result);
                    }
                }
                if (!t1res || !t2res)
                {
                    result = new Test.Framework.TestResult(
                        expResult, "failed to discover all topics",
                        expVerdict, Test.Framework.TestVerdict.Fail);
                    return(result);
                }

                result = new Test.Framework.TestResult(expResult, expResult, expVerdict, expVerdict);
                return(result);
            }
        }