Example #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);
 }
Example #2
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;
 }
Example #3
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;
 }
		public override void on_data_available(DataReader reader)
		{
			var bytes = new Bytes();
			var info = new SampleInfo();

			reader.take_next_sample_untyped(bytes, info);

			if (bytes.value != null)
			{
				var args = new DataReceivedArgs
				{
					Data = new ArraySegment<byte>(bytes.value, bytes.offset, bytes.length),
					SessionID = info.instance_handle
				};
				Received.Invoke(this, args);
			}
		}
Example #5
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;
        }
Example #6
0
        // This gets called when a new subscriber has been discovered
        public override void on_data_available(DDS.DataReader reader)
        {
            DDS.SubscriptionBuiltinTopicDataDataReader builtin_reader =
                (DDS.SubscriptionBuiltinTopicDataDataReader)reader;
            DDS.SubscriptionBuiltinTopicData
                cur_subscription_builtin_topic_data;

            try {
                //We only process newly seen subscribers
                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)
                    {
                        cur_subscription_builtin_topic_data =
                            (DDS.SubscriptionBuiltinTopicData)
                            data_seq.get_at(i);

                        Console.WriteLine("Built-in Reader: found subscriber");
                        Console.WriteLine("\tparticipant_key->'" +
                                          cur_subscription_builtin_topic_data.
                                          participant_key.GetHashCode() + "'\n\tkey-> '" +
                                          cur_subscription_builtin_topic_data.
                                          key.GetHashCode());
                        Console.WriteLine(
                            "instance_handle: " + info.instance_handle);
                    }
                }
            } catch (DDS.Retcode_NoData) {
                // No data to process
                return;
            } finally {
                builtin_reader.return_loan(data_seq, info_seq);
            }
        }
		public ReturnCode Take(out ByteData data, out SampleInfo info)
		{
			data = new ByteData();
			object dataObjs = data;
			info = new SampleInfo();
			return FooDataReader.TakeNextSample(this, ref dataObjs, ref info);
		}
Example #8
0
	    private bool checkReceivedInstanceSample (tst[] data, SampleInfo[] info, int len)
	    {
	        SampleData sampleData = null;
	        bool noError = true;
	
	        for ( int i = 0; noError && (i < len); i++ ) {
	            int x = data[i].long_1;
	
	            if ( x < MAX_INSTANCE ) {
	                if ( instanceDataList[x].expected != null) {
	                    foreach (SampleData index in instanceDataList[x].expected) {
	                        if (sampleCompare(index.data, data[i]) == C_EQ) {
	                            sampleData = index;
	                            break;
	                        }
	                    }
	                    if ( sampleData != null) {
	                        sampleData.seen = true;
	                        noError = checkSampleInfo(info[i], sampleData);
	                    } else {
	                        noError = false;
	                    }
	                } else {
	                    noError = false;
	                }
	            } else {
	                noError = false;
	            }
	        }
	
	        if ( noError ) {
	            noError = allSamplesReceived();
	        }
	
	        return noError;
	    }
Example #9
0
	    private bool checkSampleInfo (SampleInfo info, SampleData reference)
	    {
	        bool equal = true;
	
	        if ( info.SampleState != reference.SampleState ) {
	            Console.Write(string.Format("                : " + 
	                   "received info.SampleState = {0}   " +
	                   "expected reference.SampleState = {1}\n",
	                   info.SampleState,
	                   reference.SampleState));
	            tfw.TestMessage(TestMessage.Note,
	                         "SampleInfo: SampleState incorrect");
	            equal = false;
	        }
	        if ( info.ViewState != reference.ViewState ) {
	            Console.Write(string.Format("                : " +
	                   "received info.ViewState = {0}   " +
	                   "expected reference.ViewState = {1}\n",
	                   info.ViewState,
	                   reference.ViewState));
	            tfw.TestMessage(TestMessage.Note,
	                         "SampleInfo: ViewState incorrect");
	            equal = false;
	        }
	        if ( info.InstanceState != reference.InstanceState ) {
	            Console.Write(string.Format("                : " +
	                   "received info.InstanceState = {0}   " +
	                   "expected reference.InstanceState = {1}\n",
	                   info.InstanceState,
	                   reference.InstanceState));
	            tfw.TestMessage(TestMessage.Note,
	                         "SampleInfo: InstanceState incorrect");
	            equal = false;
	        }
	        if ( info.DisposedGenerationCount != reference.DisposedGenerationCount ) {
	            Console.Write(string.Format("                : " + 
	                   "received info.DisposedGenerationCount = {0} " +
	                   "expected reference.DisposedGenerationCount = {1}\n",
	                   info.DisposedGenerationCount,
	                   reference.DisposedGenerationCount));
	            tfw.TestMessage(TestMessage.Note,
	                         "SampleInfo: DisposedGenerationCount incorrect");
	            equal = false;
	        }
	        if ( info.NoWritersGenerationCount != reference.NoWritersGenerationCount ) {
	            Console.Write(string.Format("                : " +
	                   "received info.NoWritersGenerationCount = {0} " +
	                   "expected reference.NoWritersGenerationCount = {1}\n",
	                   info.NoWritersGenerationCount,
	                   reference.NoWritersGenerationCount));
	            tfw.TestMessage(TestMessage.Note,
	                         "SampleInfo: NoWritersGenerationCount incorrect");
	            equal = false;
	        }
	        if ( info.SampleRank != reference.SampleRank ) {
	            Console.Write(string.Format("                : " +
	                   "received info.SampleRank = {0}   " +
	                   "expected reference.SampleRank = {1}\n",
	                   info.SampleRank,
	                   reference.SampleRank));
	            tfw.TestMessage(TestMessage.Note, "SampleInfo: SampleRank incorrect");
	            equal = false;
	        }
	        if ( info.GenerationRank != reference.GenerationRank ) {
	            Console.Write(string.Format("                : " +
	                   "received info.GenerationRank = {0}   " +
	                   "expected reference.GenerationRank = {1}\n",
	                   info.GenerationRank,
	                   reference.GenerationRank));
	            tfw.TestMessage(TestMessage.Note,
	                         "SampleInfo: GenerationRank incorrect");
	            equal = false;
	        }
	        if ( info.AbsoluteGenerationRank != reference.AbsoluteGenerationRank ) {
	            Console.Write(string.Format("                : " +
	                   "received info.AbsoluteGenerationRank = {0} " +
	                   "expected reference.AbsoluteGenerationRank = {1}\n",
	                   info.AbsoluteGenerationRank,
	                   reference.AbsoluteGenerationRank));
	            tfw.TestMessage(TestMessage.Note,
	                         "SampleInfo: AbsoluteGenerationRank incorrect");
	            equal = false;
	        }
	        if (timeCompare(info.SourceTimestamp, info.ReceptionTimestamp) == C_GT) {
	            Console.Write(string.Format("                : " +
	                   "received info.SourceTimestamp = {0}.{1:D9} " +
	                   "received info.ReceptionTimestamp = {2}.{3:D9})\n",
	                   info.SourceTimestamp.Sec, info.SourceTimestamp.NanoSec,
	                   info.ReceptionTimestamp.Sec, info.ReceptionTimestamp.NanoSec));
	            tfw.TestMessage(TestMessage.Note,
	                         "SampleInfo: SourceTimestamp > ReceptionTimestamp");
	            equal = false;
	        }
	        
	        return equal;
	    }
Example #10
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);
            }
        }