示例#1
0
 /* Called to handle relevant data samples */
 public void handle_data(keysDataReader keys_reader,
                         DDS.SampleInfo info,
                         keys msg)
 {
     Console.WriteLine("code: {0}, x: {1}, y: {2}",
                       msg.code, msg.x, msg.y);
 }
示例#2
0
 public void instance_disposed(keysDataReader keys_reader,
                               DDS.SampleInfo info,
                               keys msg)
 {
     Console.WriteLine("Instance disposed; code = {0}", msg.code);
     states[msg.code] = Instance_State.disposed;
 }
示例#3
0
 public void instance_lost_writers(keysDataReader keys_reader,
                                   DDS.SampleInfo info,
                                   keys msg)
 {
     Console.WriteLine("Instance has no writers; code = {0}", msg.code);
     states[msg.code] = Instance_State.no_writers;
 }
示例#4
0
        /* These are not called by DDS.   on_data_available() calls
         * the appropriate function when it gets updates about
         * an instances' status
         */
        public void new_instance_found(keysDataReader keys_reader,
                                       DDS.SampleInfo info,
                                       keys msg)
        {
            /* There are really three cases here:
             * 1.) truly new instance
             * 2.) instance lost all writers, but now we're getting data again
             * 3.) instance was disposed, but a new one has been created
             *
             * We distinguish these cases by examining generation counts, BUT
             * note that if the instance resources have been reclaimed, the
             * generation counts may be reset to 0.
             *
             * Instances are eligible for resource cleanup if there are no
             * active writers and all samples have been taken.  To reliably
             * determine which case a 'new' instance falls into, the application
             * must store state information on a per-instance basis.
             *
             * Note that this example assumes that state changes only occur via
             * explicit register_instance(), unregister_instance() and dispose()
             * calls from the datawriter.  In reality, these changes could also
             * occur due to lost liveliness or missed deadlines, so those
             * listeners would also need to update the instance state.
             */

            switch (states[msg.code])
            {
            case Instance_State.inactive:
                Console.WriteLine("New instance found; code = {0}", msg.code);
                break;

            case Instance_State.active:
                /* An active instance should never be interpreted as new */
                Console.WriteLine("Error, 'new' already-active instance found; code = {0}", msg.code);
                break;

            case Instance_State.no_writers:
                Console.WriteLine("Found writer for instance; code = {0}", msg.code);
                break;

            case Instance_State.disposed:
                Console.WriteLine("Found reborn instance; code = {0}", msg.code);
                break;
            }
            states[msg.code] = Instance_State.active;
        }
        /* These are not called by DDS.   on_data_available() calls
        the appropriate function when it gets updates about
        an instances' status
        */
        public void new_instance_found(keysDataReader keys_reader,
                                       DDS.SampleInfo info,
                                       keys msg)
        {
            /* There are really three cases here:
               1.) truly new instance
               2.) instance lost all writers, but now we're getting data again
               3.) instance was disposed, but a new one has been created

               We distinguish these cases by examining generation counts, BUT
               note that if the instance resources have been reclaimed, the
               generation counts may be reset to 0.

               Instances are eligible for resource cleanup if there are no
               active writers and all samples have been taken.  To reliably
               determine which case a 'new' instance falls into, the application
               must store state information on a per-instance basis.

               Note that this example assumes that state changes only occur via
               explicit register_instance(), unregister_instance() and dispose()
               calls from the datawriter.  In reality, these changes could also
               occur due to lost liveliness or missed deadlines, so those
               listeners would also need to update the instance state.
             */

            switch (states[msg.code])
            {
                case Instance_State.inactive:
                    Console.WriteLine("New instance found; code = {0}", msg.code);
                    break;
                case Instance_State.active:
                    /* An active instance should never be interpreted as new */
                    Console.WriteLine("Error, 'new' already-active instance found; code = {0}", msg.code);
                    break;
                case Instance_State.no_writers:
                    Console.WriteLine("Found writer for instance; code = {0}", msg.code);
                    break;
                case Instance_State.disposed:
                    Console.WriteLine("Found reborn instance; code = {0}", msg.code);
                    break;
            }
            states[msg.code] = Instance_State.active;
        }
 public void instance_lost_writers(keysDataReader keys_reader,
                                   DDS.SampleInfo info,
                                   keys msg)
 {
     Console.WriteLine("Instance has no writers; code = {0}", msg.code);
     states[msg.code] = Instance_State.no_writers;
 }
 public void instance_disposed(keysDataReader keys_reader,
                               DDS.SampleInfo info,
                               keys msg)
 {
     Console.WriteLine("Instance disposed; code = {0}", msg.code);
     states[msg.code] = Instance_State.disposed;
 }
 /* Called to handle relevant data samples */
 public void handle_data(keysDataReader keys_reader,
                         DDS.SampleInfo info,
                         keys msg)
 {
     Console.WriteLine("code: {0}, x: {1}, y: {2}",
                        msg.code, msg.x, msg.y);
 }
示例#9
0
        /**** Start changes for Advanced_Keys ****/

        public override void on_data_available(DDS.DataReader reader)
        {
            keysDataReader keys_reader =
                (keysDataReader)reader;

            //// Start changes for Advanced_Keys

            while (true)
            {
                /* Given DDS_HANDLE_NIL as a parameter, take_next_instance returns
                 * a sequence containing samples from only the next (in a well-determined
                 * but unspecified order) un-taken instance.
                 */

                try
                {
                    keys_reader.take_next_instance(
                        data_seq,
                        info_seq,
                        DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                        ref DDS.InstanceHandle_t.HANDLE_NIL,
                        DDS.SampleStateKind.ANY_SAMPLE_STATE,
                        DDS.ViewStateKind.ANY_VIEW_STATE,
                        DDS.InstanceStateKind.ANY_INSTANCE_STATE);
                }
                catch (DDS.Retcode_NoData)
                {
                    break;
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("take error {0}", e);
                    return;
                }

                System.Int32 data_length = data_seq.length;
                /* We process all the obtained samples for a particular instance */
                for (int i = 0; i < data_length; ++i)
                {
                    /* We first check if the sample includes valid data */
                    if (info_seq.get_at(i).valid_data)
                    {
                        if (info_seq.get_at(i).view_state == DDS.ViewStateKind.NEW_VIEW_STATE)
                        {
                            new_instance_found(keys_reader, info_seq.get_at(i), data_seq.get_at(i));
                        }

                        /* We check if the obtained samples are associated to one
                         * of the instances of interest.
                         * Since take_next_instance gives sequences of the same instance,
                         * we only need to test this for the first sample obtained.
                         */
                        if (i == 0 && !key_is_relevant(data_seq.get_at(i)))
                        {
                            break;
                        }

                        handle_data(keys_reader, info_seq.get_at(i), data_seq.get_at(i));
                    }
                    else
                    {
                        /* Since there is not valid data, it may include metadata */
                        keys dummy = null;;

                        dummy = keysTypeSupport.create_data();
                        if (dummy == null)
                        {
                            throw new ApplicationException(
                                      "keysTypeSupport.create_data error");
                        }

                        DDS.InstanceHandle_t handle = info_seq.get_at(i).instance_handle;

                        try
                        {
                            keys_reader.get_key_value(dummy, ref handle);
                        }
                        catch (DDS.Exception e)
                        {
                            Console.WriteLine(" get_key_value error {0}", e);
                        }

                        /* Here we print a message and change the instance state
                         * if the instance state is ALIVE_NO_WRITERS or ALIVE_DISPOSED */
                        if (info_seq.get_at(i).instance_state == DDS.InstanceStateKind.NOT_ALIVE_NO_WRITERS_INSTANCE_STATE)
                        {
                            instance_lost_writers(keys_reader, info_seq.get_at(i), dummy);
                        }
                        else if (info_seq.get_at(i).instance_state == DDS.InstanceStateKind.NOT_ALIVE_DISPOSED_INSTANCE_STATE)
                        {
                            instance_disposed(keys_reader, info_seq.get_at(i), dummy);
                        }
                    }
                }

                try
                {
                    keys_reader.return_loan(data_seq, info_seq);
                }
                catch (DDS.Exception e)
                {
                    Console.WriteLine("return loan error {0}", e);
                }
            }
        }
示例#10
0
        public override void on_data_available(DDS.DataReader reader)
        {
            keysDataReader keys_reader =
                (keysDataReader)reader;

            try {
                keys_reader.take(
                    data_seq,
                    info_seq,
                    DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                    DDS.SampleStateKind.ANY_SAMPLE_STATE,
                    DDS.ViewStateKind.ANY_VIEW_STATE,
                    DDS.InstanceStateKind.ANY_INSTANCE_STATE);
            }
            catch (DDS.Retcode_NoData) {
                return;
            }
            catch (DDS.Exception e) {
                Console.WriteLine("take error {0}", e);
                return;
            }

            System.Int32 data_length = data_seq.length;
            for (int i = 0; i < data_length; ++i)
            {
                /* Start changes for Keyed_Data */
                /* We first check if the sample includes valid data */
                if (info_seq.get_at(i).valid_data)
                {
                    if (info_seq.get_at(i).view_state ==
                        DDS.ViewStateKind.NEW_VIEW_STATE)
                    {
                        Console.WriteLine("Found new instance; code = {0}",
                                          data_seq.get_at(i).code);
                    }

                    Console.WriteLine("Instance {0}: x: {1}, y: {2}",
                                      data_seq.get_at(i).code, data_seq.get_at(i).x,
                                      data_seq.get_at(i).y);
                }
                else
                {
                    /* Since there is not valid data, it may include metadata */
                    keys dummy = new keys();
                    try
                    {
                        DDS.InstanceHandle_t temp =
                            info_seq.get_at(i).instance_handle;
                        keys_reader.get_key_value(dummy, ref temp);
                    }
                    catch (DDS.Exception e)
                    {
                        Console.WriteLine("get_key_value error {0}", e);
                    }

                    /* Here we print a message if the instance state is ALIVE_NO_WRITERS or ALIVE_DISPOSED */
                    if (info_seq.get_at(i).instance_state ==
                        DDS.InstanceStateKind.NOT_ALIVE_NO_WRITERS_INSTANCE_STATE)
                    {
                        Console.WriteLine("Instance {0} has no writers",
                                          dummy.code);
                    }
                    else if (info_seq.get_at(i).instance_state ==
                             DDS.InstanceStateKind.NOT_ALIVE_DISPOSED_INSTANCE_STATE)
                    {
                        Console.WriteLine("Instance {0} disposed",
                                          dummy.code);
                    }
                }
                /* End changes for Keyed_Data */
            }

            try {
                keys_reader.return_loan(data_seq, info_seq);
            }
            catch (DDS.Exception e) {
                Console.WriteLine("return loan error {0}", e);
            }
        }