Exemplo n.º 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;
        }
    }
    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;
        }
    }