コード例 #1
0
        // This gets called when a participant has been discovered
        public override void on_data_available(DDS.DataReader reader)
        {
            DDS.ParticipantBuiltinTopicDataDataReader builtin_reader =
                (DDS.ParticipantBuiltinTopicDataDataReader) reader;
            string participant_data;
            DDS.ParticipantBuiltinTopicData cur_participant_builtin_topic_data;

            try {
                // We only process newly seen participants
                builtin_reader.take(
                    data_seq, info_seq,
                    DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                    DDS.SampleStateKind.ANY_SAMPLE_STATE,
                    DDS.ViewStateKind.NEW_VIEW_STATE,
                    DDS.InstanceStateKind.ANY_INSTANCE_STATE);

                for (int i = 0; i < data_seq.length; ++i) {
                    DDS.SampleInfo info = (DDS.SampleInfo) info_seq.get_at(i);

                    if (info.valid_data) {
                        participant_data = "nil";
                        bool is_auth = false;
                        cur_participant_builtin_topic_data =
                            (DDS.ParticipantBuiltinTopicData)
                                data_seq.get_at(i);

                        // see if there is any participant_data
                        if (cur_participant_builtin_topic_data.
                                user_data.value.length > 0) {

                            participant_data =
                                System.Text.Encoding.ASCII.GetString(
                                cur_participant_builtin_topic_data.
                                    user_data.value.buffer,
                                0,
                                cur_participant_builtin_topic_data.
                                    user_data.value.length);

                            is_auth = (participant_data == auth);
                        }

                        Console.WriteLine(
                            "Built-in Reader: found participant \n\tkey->'" +
                            cur_participant_builtin_topic_data.key.GetHashCode()
                            + "'\n\tuser_data->'" + participant_data + "'");
                        Console.WriteLine(
                            "instance_handle: " + info.instance_handle);

                        if (!is_auth) {
                            Console.WriteLine(
                                "Bad authorization, ignoring participant");
                            DDS.DomainParticipant participant =
                                reader.get_subscriber().get_participant();
                            DDS.InstanceHandle_t temp = info.instance_handle;
                            participant.ignore_participant(ref temp);
                            info.instance_handle = temp;
                        }
                    }
                }
            } catch (DDS.Retcode_NoData) {
                // No data to process
                // This happens when we get announcements from participants we
                // already know about
                return;
            } finally {
                builtin_reader.return_loan(data_seq, info_seq);
            }
        }