Example #1
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;
        }
    }
    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;
        }
    }
Example #3
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;
        }
    }
    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;
        }
    }