Esempio n. 1
0
    private static DDS.TypeCode type_w_sequence_get_typecode(
        DDS.TypeCodeFactory tcf)
    {
        DDS.StructMemberSeq members = new DDS.StructMemberSeq();

        try {
            DDS.TypeCode sequence_tc = sequence_get_typecode(tcf);
            if (sequence_tc == null)
            {
                Console.WriteLine("Error to create sequence_get_typecode");
                return(null);
            }
            /* We create the typeCode for struct which contains the sequence */
            DDS.TypeCode tc = tcf.create_struct_tc("TypeWithSequence",
                                                   members);

            tc.add_member(sequence_member_name, DDS.TypeCode.MEMBER_ID_INVALID,
                          sequence_tc, DDS.TypeCode.NONKEY_MEMBER);

            return(tc);
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return(null);
        }
    }
    private static DDS.TypeCode create_type_code(DDS.TypeCodeFactory tcf)
    {
        DDS.UnionMemberSeq members = new DDS.UnionMemberSeq();

        /* First, we create the typeCode for a union */

        /* Default-member index refers to which member of the union
         * will be the default one. In this example index = 1 refers
         * to the the member 'aLong'. Take into account that index
         * starts in 0 */
        try {
            DDS.TypeCode unionTC = tcf.create_union_tc("Foo",
                                                       DDS.ExtensibilityKind.MUTABLE_EXTENSIBILITY,
                                                       DDS.TypeCode.TC_LONG,
                                                       1,        /* default-member index */
                                                       members); /* For now, it does not have any member */

            /* Case 1 will be a short named aShort */
            unionTC.add_member("aShort", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                               DDS.TypeCode.TC_SHORT, DDS.TypeCode.NONKEY_MEMBER);

            /* Case 2, the default, will be a long named aLong */
            unionTC.add_member("aLong", 2, DDS.TypeCode.TC_LONG,
                               DDS.TypeCode.NONKEY_MEMBER);

            /* Case 3 will be a double named aDouble */
            unionTC.add_member("aDouble", 3, DDS.TypeCode.TC_DOUBLE,
                               DDS.TypeCode.NONKEY_MEMBER);

            return(unionTC);
        } catch (Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return(null);
        }
    }
Esempio n. 3
0
    public static void Main(string[] args)
    {
        DDS.TypeCodeFactory tcf = DDS.TypeCodeFactory.get_instance();

        DDS.TypeCode w_sequence_tc = type_w_sequence_get_typecode(tcf);
        if (w_sequence_tc == null)
        {
            Console.WriteLine("Error to create type_w_sequence_get_typecode");
            return;
        }
        try {
            DDS.DynamicData sample = new DDS.DynamicData(w_sequence_tc,
                                                         DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT);

            Console.WriteLine("***** Writing a sample *****");
            write_data(sample, tcf);

            Console.WriteLine("***** Reading a sample *****");
            read_data(sample, tcf);

            /* Delete the created TC */
            if (w_sequence_tc != null)
            {
                tcf.delete_tc(w_sequence_tc);
            }
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return;
        }
    }
Esempio n. 4
0
    private static DDS.TypeCode sequence_element_get_typecode(
        DDS.TypeCodeFactory tcf)
    {
        DDS.StructMemberSeq members = new DDS.StructMemberSeq();

        try {
            /* First, we create the typeCode for the simple struct */
            DDS.TypeCode tc = tcf.create_struct_tc("SimpleStruct", members);

            tc.add_member("a_member", DDS.TypeCode.MEMBER_ID_INVALID,
                          DDS.TypeCode.TC_LONG, DDS.TypeCode.NONKEY_MEMBER);

            return(tc);
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return(null);
        }
    }
    public static void Main(string[] args)
    {
        try {
            /* Creating the union typeCode */
            DDS.TypeCodeFactory       tcf        = DDS.TypeCodeFactory.get_instance();
            DDS.TypeCode              unionTC    = create_type_code(tcf);
            DDS.DynamicDataMemberInfo info       = new DDS.DynamicDataMemberInfo();
            DDS.DynamicDataProperty_t myProperty =
                DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT;
            short valueTestShort = 0;

            /* Creating a new dynamicData instance based on the union
             * type code */
            DDS.DynamicData data = new DDS.DynamicData(unionTC, myProperty);

            /* If we get the current discriminator, it will be the default one
             * (not the first added) */
            data.get_member_info_by_index(info, 0);

            Console.WriteLine("The member selected is {0}", info.member_name);

            /* When we set a value in one of the members of the union,
             * the discriminator updates automatically to point that member.  */
            data.set_short("aShort", DDS.DynamicData.MEMBER_ID_UNSPECIFIED, 42);

            /* The discriminator should now reflect the new situation */
            data.get_member_info_by_index(info, 0);

            Console.WriteLine("The member selected is {0}", info.member_name);

            /* Getting the value of the target member */
            valueTestShort = data.get_short("aShort",
                                            DDS.DynamicData.MEMBER_ID_UNSPECIFIED);

            Console.WriteLine("The member selected is {0} with value: {1}",
                              info.member_name, valueTestShort);

            return;
        } catch (Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return;
        }
    }
Esempio n. 6
0
    private static DDS.TypeCode sequence_get_typecode(
        DDS.TypeCodeFactory tcf)
    {
        try {
            DDS.TypeCode seq_element_tc = sequence_element_get_typecode(tcf);
            if (seq_element_tc == null)
            {
                Console.WriteLine("Error to create " +
                                  "sequence_element_get_typecode");
                return(null);
            }
            /* We create the typeCode for the sequence */
            DDS.TypeCode tc = tcf.create_sequence_tc(MAX_SEQ_LEN,
                                                     seq_element_tc);

            return(tc);
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return(null);
        }
    }
Esempio n. 7
0
    private static DDS.TypeCode outer_struct_get_type_code(
        DDS.TypeCodeFactory tcf)
    {
        DDS.StructMemberSeq members = new DDS.StructMemberSeq();

        try {
            /* First, we create the typeCode for a struct */
            DDS.TypeCode tc = tcf.create_struct_tc("OuterStruct", members);

            DDS.TypeCode inner_tc = inner_struct_get_type_code(tcf);

            /* Member 1 of outer struct will be a struct of type inner_struct
             * called inner*/
            tc.add_member("inner", DDS.TypeCode.MEMBER_ID_INVALID,
                          inner_tc, DDS.TypeCode.NONKEY_MEMBER);

            return(tc);
        } catch (Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return(null);
        }
    }
Esempio n. 8
0
    /* Called when Custom Filter is created, or when parameters are changed */
    public void compile(ref object compile_data, string expression,
                        DDS.StringSeq parameters, DDS.TypeCode type_code,
                        string type_class_name, object old_compile_data)
    {
        /* We expect an expression of the form "%0 %1 <var>"
         * where %1 = "divides" or "greater-than"
         * and <var> is an integral member of the msg structure.
         *
         * We don't actually check that <var> has the correct typecode,
         * (or even that it exists!). See example Typecodes to see
         * how to work with typecodes.
         *
         * The compile information is a structure including the first filter
         * parameter (%0) and a function pointer to evaluate the sample
         */

        if (expression.StartsWith("%0 %1 ") && expression.Length > 6 &&
            parameters.length > 1)      // Enought parameters?
        {
            long p = Convert.ToInt64(parameters.get_at(0));

            if (String.Compare(parameters.get_at(1), "greater-than") == 0)
            {
                compile_data = new gt_test(p);
                return;
            }
            else if (String.Compare(parameters.get_at(1), "divides") == 0)
            {
                compile_data = new divide_test(p);
                return;
            }
        }

        Console.WriteLine("CustomFilter: Unable to compile expresssion '"
                          + expression + "'");
        Console.WriteLine("              with parameters '" + parameters.get_at(0)
                          + "' '" + parameters.get_at(1) + "'");
        //throw (new DDS.Retcode_BadParameter());
    }
Esempio n. 9
0
    private static DDS.TypeCode inner_struct_get_type_code(
        DDS.TypeCodeFactory tcf)
    {
        DDS.StructMemberSeq members = new DDS.StructMemberSeq();

        /* First, we create the typeCode for a struct */
        try {
            DDS.TypeCode tc = tcf.create_struct_tc("InnerStruct", members);

            /* Member 1 will be a double named x */
            tc.add_member("x", DDS.TypeCode.MEMBER_ID_INVALID,
                          DDS.TypeCode.TC_DOUBLE, DDS.TypeCode.NONKEY_MEMBER);

            /* Member 2 will be a double named y */
            tc.add_member("y", DDS.TypeCode.MEMBER_ID_INVALID,
                          DDS.TypeCode.TC_DOUBLE, DDS.TypeCode.NONKEY_MEMBER);

            return(tc);
        } catch (Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return(null);
        }
    }
Esempio n. 10
0
    public static void Main(string[] args)
    {
        try {
            /* Creating the union typeCode */
            DDS.TypeCodeFactory tcf = DDS.TypeCodeFactory.get_instance();

            /* Creating the typeCode of the inner_struct */
            DDS.TypeCode inner_tc = inner_struct_get_type_code(tcf);

            /* Creating the typeCode of the outer_struct that contains
             * an inner_struct */
            DDS.TypeCode outer_tc = outer_struct_get_type_code(tcf);

            /* Now, we create a dynamicData instance for each type */
            DDS.DynamicData outer_data = new DDS.DynamicData(
                outer_tc, DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT);
            DDS.DynamicData inner_data = new DDS.DynamicData(
                inner_tc, DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT);
            DDS.DynamicData bounded_data = new DDS.DynamicData(
                null, DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT);

            Console.WriteLine(" Connext Dynamic Data Nested Struct Example");
            Console.WriteLine("--------------------------------------------");
            Console.WriteLine(" Data Types");
            Console.WriteLine("------------");

            inner_tc.print_IDL(0);
            outer_tc.print_IDL(0);

            /* Setting the inner data */
            inner_data.set_double("x", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                                  3.14159);
            inner_data.set_double("y", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                                  2.71828);

            Console.WriteLine("\n\n get/set_complex_member API");
            Console.WriteLine("----------------------------");

            /* Using set_complex_member, we copy inner_data values in
             * inner_struct of outer_data */
            Console.WriteLine("Setting the initial values of struct with " +
                              "set_complex_member()");

            outer_data.set_complex_member("inner",
                                          DDS.DynamicData.MEMBER_ID_UNSPECIFIED, inner_data);
            outer_data.print(1);
            inner_data.clear_all_members();

            Console.WriteLine("\n + get_complex_member() called");
            outer_data.get_complex_member(inner_data, "inner",
                                          DDS.DynamicData.MEMBER_ID_UNSPECIFIED);

            Console.WriteLine("\n + inner_data value");
            inner_data.print(1);

            /* get_complex_member made a copy of the inner_struct. If we modify
             * inner_data values, outer_data inner_struct WILL NOT be modified.
             */

            Console.WriteLine("\n + setting new values to inner_data");
            inner_data.set_double("x", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                                  1.00000);
            inner_data.set_double("y", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                                  0.00001);

            /* Current value of outer_data
             * outer:
             * inner:
             *     x: 3.141590
             *     y: 2.718280
             * inner_data:
             *     x: 1.000000
             *     y: 0.000010
             */

            Console.WriteLine("\n + current outer_data value ");
            outer_data.print(1);

            /* Bind/Unbind member API */
            Console.WriteLine("\n\nbind/unbind API");
            Console.WriteLine("-----------------");

            /* Using bind_complex_member, we do not copy inner_struct, but bind
             * it. So, if we modify bounded_data, the inner member inside
             * outer_data WILL also be modified */
            Console.WriteLine("\n + bind complex member called");
            outer_data.bind_complex_member(bounded_data, "inner",
                                           DDS.DynamicData.MEMBER_ID_UNSPECIFIED);

            bounded_data.print(1);
            Console.WriteLine("\n + setting new values to bounded_data");

            bounded_data.set_double("x", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                                    1.00000);
            bounded_data.set_double("y", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                                    0.00001);

            /* Current value of outer data
             * outer:
             * inner:
             *     x: 1.000000
             *     y: 0.000010
             */

            bounded_data.print(1);

            outer_data.unbind_complex_member(bounded_data);
            Console.WriteLine("\n + current outer_data value ");
            outer_data.print(1);

            return;
        } catch (Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return;
        }
    }
Esempio n. 11
0
    private static void read_data(DDS.DynamicData sample,
                                  DDS.TypeCodeFactory tcf)
    {
        /* Creating typecodes */
        DDS.TypeCode sequence_tc = sequence_get_typecode(tcf);
        if (sequence_tc == null)
        {
            Console.WriteLine("Error to create sequence_get_typecode in " +
                              "reading_data");
            return;
        }

        /* Creating DynamicData */
        DDS.DynamicData seq_member = new DDS.DynamicData(sequence_tc,
                                                         DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT);
        DDS.DynamicData seq_element = new DDS.DynamicData(null,
                                                          DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT);

        DDS.DynamicDataInfo info = new DDS.DynamicDataInfo();

        sample.get_complex_member(seq_member, sequence_member_name,
                                  DDS.DynamicData.MEMBER_ID_UNSPECIFIED);

        /* Now we get the total amount of elements contained in the array
         * by accessing the dynamic data info
         */
        Console.WriteLine("* Getting sequence member info....");
        seq_member.get_info(info);
        Console.WriteLine("* Sequence contains {0} elements",
                          info.member_count);

        for (int i = 0; i < info.member_count; ++i)
        {
            /*
             * The same results can be obtained using
             * bind_complex_member method. The main difference, is that
             * in that case the members are not copied, just referenced
             */

#if (USE_BIND_API)
            try {
                seq_member.bind_complex_member(seq_element, null, i + 1);
            } catch (DDS.Exception e) {
                Console.WriteLine("register_type error {0}", e);
                return;
            }
#else
            try {
                seq_member.get_complex_member(seq_element, null, i + 1);
            } catch (DDS.Exception e) {
                Console.WriteLine("register_type error {0}", e);
                return;
            }
#endif
            long value = seq_element.get_long("a_member",
                                              DDS.DynamicData.MEMBER_ID_UNSPECIFIED);
            Console.WriteLine("Reading sequence element #{0} : ",
                              i + 1);
            seq_element.print(1);

#if (USE_BIND_API)
            try {
                seq_member.unbind_complex_member(seq_element);
            } catch (DDS.Exception e) {
                Console.WriteLine("register_type error {0}", e);
                return;
            }
#endif
        }

        /* Delete the created TC */
        if (sequence_tc != null)
        {
            tcf.delete_tc(sequence_tc);
        }

        return;
    }
Esempio n. 12
0
    private static void write_data(DDS.DynamicData sample,
                                   DDS.TypeCodeFactory tcf)
    {
        /* Creating typecodes */
        DDS.TypeCode sequence_tc = sequence_get_typecode(tcf);
        if (sequence_tc == null)
        {
            Console.WriteLine("Error to create sequence_get_typecode in " +
                              "writing_data");
            return;
        }

        DDS.TypeCode sequence_element_tc = sequence_element_get_typecode(tcf);
        if (sequence_element_tc == null)
        {
            Console.WriteLine("Error to create sequence_element_get_typecode " +
                              "in writing_data");
            return;
        }

        try {
            /* Creating DynamicData */
            DDS.DynamicData seq_member = new DDS.DynamicData(sequence_tc,
                                                             DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT);
            DDS.DynamicData seq_element =
                new DDS.DynamicData(sequence_element_tc,
                                    DDS.DynamicData.DYNAMIC_DATA_PROPERTY_DEFAULT);

            for (int i = 0; i < MAX_SEQ_LEN; ++i)
            {
                /* To access the elements of a sequence it is necessary
                 * to use their id. This parameter allows accessing to every
                 * element of the sequence using a 1-based index.
                 * There are two ways of doing this: bind API and get API.
                 * See the NestedStructExample for further details about the
                 * differences between these two APIs. */

#if (USE_BIND_API)
                seq_member.bind_complex_member(seq_element, null, i + 1);
                seq_element.set_int("a_member",
                                    DDS.DynamicData.MEMBER_ID_UNSPECIFIED, i);
                Console.WriteLine("Writing sequence elemente #{0} : ", i + 1);
                seq_element.print(1);
                seq_member.unbind_complex_member(seq_element);
#else
                seq_element.set_int("a_member",
                                    DDS.DynamicData.MEMBER_ID_UNSPECIFIED, i);
                Console.WriteLine("Writing sequence element #{0}", i + 1);
                seq_element.print(1);
                seq_member.set_complex_member(null, i + 1, seq_element);
#endif
            }

            sample.set_complex_member(sequence_member_name,
                                      DDS.DynamicData.MEMBER_ID_UNSPECIFIED, seq_member);

            /* Delete the created TC */
            if (sequence_element_tc != null)
            {
                tcf.delete_tc(sequence_element_tc);
            }

            if (sequence_tc != null)
            {
                tcf.delete_tc(sequence_tc);
            }

            return;
        } catch (DDS.Exception e) {
            Console.WriteLine("register_type error {0}", e);
            return;
        }
    }
Esempio n. 13
0
    static void subscribe(int domain_id, int sample_count)
    {
        // --- Create participant --- //
        DDS.DomainParticipant participant =
            DDS.DomainParticipantFactory.get_instance().create_participant(
                domain_id,
                DDS.DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
                null /* listener */,
                DDS.StatusMask.STATUS_MASK_NONE);
        if (participant == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_participant error");
        }

        // --- Create subscriber --- //
        DDS.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 DynamicData using TypeCode from Shapes.cxx
         * If you are NOT using a type generated with rtiddsgen, you
         * need to create this TypeCode from scratch.
         */
        DDS.TypeCode type_code = ShapeType.get_typecode();
        if (type_code == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_typecode error");
        }

        /* Create the Dynamic data type support object */
        DDS.DynamicDataTypeSupport type_support =
            new DDS.DynamicDataTypeSupport(type_code,
                                           new DDS.DynamicDataTypeProperty_t());
        if (type_support == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_type_support error");
        }

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

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

        /* Make sure both publisher and subscriber share the same topic name.
         * In the Shapes example: we are subscribing to a Square, wich is the
         * topic name. If you want to publish other shapes (Triangle or Circle),
         * you just need to update the topic name.
         */
        DDS.Topic topic = participant.create_topic(
            "Square",
            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 */
        ShapeTypeListener reader_listener =
            new ShapeTypeListener();

        /* First, we create a generic DataReader for our topic */
        DDS.DataReader reader = subscriber.create_datareader(
            topic,
            DDS.Subscriber.DATAREADER_QOS_DEFAULT,
            reader_listener,
            DDS.StatusMask.STATUS_MASK_ALL);
        if (reader == null)
        {
            shutdown(participant);
            reader_listener = null;
            throw new ApplicationException("create_datareader error");
        }

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

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

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

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

        // --- Shutdown --- //

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

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

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

        DDS.Publisher publisher = participant.create_publisher(
            DDS.DomainParticipant.PUBLISHER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (publisher == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_publisher error");
        }

        /* Create DynamicData using TypeCode from Shapes.cpp
         * If you are NOT using a type generated with rtiddsgen, you
         * need to create this TypeCode from scratch.
         */
        DDS.TypeCode type_code = ShapeType.get_typecode();
        if (type_code == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_typecode error");
        }

        /* Create the Dynamic data type support object */
        DDS.DynamicDataTypeSupport type_support =
            new DDS.DynamicDataTypeSupport(type_code,
                                           new DDS.DynamicDataTypeProperty_t());
        if (type_support == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_type_support error");
        }

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

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

        /* Make sure both publisher and subscriber share the same topic
         * name.
         * In the Shapes example: we are publishing a Square, which is the
         * topic name. If you want to publish other shapes (Triangle or
         * Circle), you just need to update the topic name. */
        DDS.Topic topic = participant.create_topic(
            "Square",
            type_name,
            DDS.DomainParticipant.TOPIC_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (topic == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_topic error");
        }

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

        /* First, we create a generic DataWriter for our topic */
        DDS.DataWriter writer = publisher.create_datawriter(
            topic,
            DDS.Publisher.DATAWRITER_QOS_DEFAULT,
            null /* listener */,
            DDS.StatusMask.STATUS_MASK_NONE);
        if (writer == null)
        {
            shutdown(participant);
            throw new ApplicationException("create_datawriter error");
        }

        /* Then, to use DynamicData, we need to assign the generic
         * DataWriter to a DynamicDataWriter, using a casting. The follow
         * casting should never fail.
         */
        DDS.DynamicDataWriter DynamicData_writer =
            (DDS.DynamicDataWriter)writer;

        // --- Write --- //

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


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

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


        /*** Shape direction variables ***/
        int direction  = 1;  /* 1 means left to right and -1, right to left */
        int x_position = 50; /* 50 is the initial position */

        /* Initialize the DynamicData object */
        data.set_string("color", DDS.DynamicData.MEMBER_ID_UNSPECIFIED, "BLUE");
        data.set_int("x", DDS.DynamicData.MEMBER_ID_UNSPECIFIED, x_position);
        data.set_int("y", DDS.DynamicData.MEMBER_ID_UNSPECIFIED, 100);
        data.set_int("shapesize", DDS.DynamicData.MEMBER_ID_UNSPECIFIED, 30);


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

        for (int count = 0;
             (sample_count == 0) || (count < sample_count);
             ++count)
        {
            Console.WriteLine("Sending shapesize {0}", 30 + (count % 20));
            Console.WriteLine("Sending x position {0}", x_position);

            /* Modify the shapesize from 30 to 50 */
            try {
                data.set_int("shapesize", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                             30 + (count % 20));
            } catch (DDS.Exception e) {
                Console.WriteLine("{0}\nError writing shapesize = {1}",
                                  e, 30 + (count % 20));
            }

            /* Modify the position */
            try {
                data.set_int("x", DDS.DynamicData.MEMBER_ID_UNSPECIFIED,
                             x_position);
            } catch (DDS.Exception e) {
                Console.WriteLine("{0}\nError writing x_position = {1}",
                                  e, x_position);
            }

            /* The x_position will be modified adding or substracting
             * 2 to the previous x_position depending on the direction.
             */
            x_position += (direction * 2);

            /* The x_position will stay between 50 and 150 pixels.
             * When the position is greater than 150 'direction' will be
             * negative (moving to the left) and when it is lower than 50
             * 'direction' will be possitive (moving to the right).
             */
            if (x_position >= 150)
            {
                direction = -1;
            }
            if (x_position <= 50)
            {
                direction = 1;
            }

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

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

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

        // --- Shutdown --- //

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

        /* Delete all entities */
        shutdown(participant);
    }