private void ProcessData(Condition _) { Console.WriteLine("---- Data available ----\n"); using (subscriber.BeginAccess()) // Begin coherent access { // Get the list of readers with samples that have not been read yet var readers = subscriber.GetDataReaders(SampleState.NotRead); // Iterate through the returned readers list and take their samples foreach (AnyDataReader reader in readers) { var topicName = reader.TopicDescription.Name; // We're reading the data polymorphically as objects, since // we're only calling the ToString() method. To read the // concrete type, cast down each reader, for example: // if (reader is DataReader<Alarm> alarmReader) { ... } using (LoanedSamples <object> samples = reader.TakeUntyped()) { foreach (LoanedSample <object> sample in samples) { PrintCoheretSetInfo(sample.Info); Console.WriteLine(topicName + " {\n" + sample + "}\n"); } } } } // end coherent access }
private void OnNewParticipant(AnyDataReader _) { // Take all the data about new participants using LoanedSamples <ParticipantBuiltinTopicData> samples = participantReader .Select() .WithState(ViewState.New.And(InstanceState.Alive)) .Take(); foreach (var sample in samples) { if (!sample.Info.ValidData) { continue; } Console.WriteLine($"Discovered participant: {sample.Data}"); if (!IsAuthorized(sample.Data.UserData)) { // Disallow communication with participants that don't // provide the correct password participant.IgnoreParticipant(sample.Info.InstanceHandle); Console.WriteLine(" * Authorization DENIED"); } else { Console.WriteLine(" * Authorization OK"); } } }
private void OnNewSubscription(AnyDataReader _) { // Take all the data about new subscriptions using LoanedSamples <SubscriptionBuiltinTopicData> samples = subscriptionReader .Select() .WithState(ViewState.New.And(InstanceState.Alive)) .Take(); foreach (var sample in samples) { if (!sample.Info.ValidData) { continue; } Console.WriteLine($"Discovered subscription: {sample.Data}"); } }