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;
        }
    }
Example #2
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;
        }
    }
    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;
        }
    }
    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;
        }
    }
Example #5
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;
        }
    }
Example #6
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;
    }
Example #7
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;
        }
    }
    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;
    }
    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;
        }
    }
    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;
        }
    }
Example #11
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);
    }