1
+ //
2
+ // (c) 2024 Copyright, Real-Time Innovations, Inc. All rights reserved.
3
+ //
4
+ // RTI grants Licensee a license to use, modify, compile, and create derivative
5
+ // works of the Software. Licensee has the right to distribute object form
6
+ // only for use with RTI products. The Software is provided "as is", with no
7
+ // warranty of any type, including any warranty for fitness for any purpose.
8
+ // RTI is under no obligation to maintain or support the Software. RTI shall
9
+ // not be liable for any incidental or consequential damages arising out of the
10
+ // use or inability to use the software.
11
+ //
12
+
13
+ using System ;
14
+ using System . Collections . Generic ;
15
+ using System . Threading ;
16
+ using System . Threading . Tasks ;
17
+ using Rti . Dds . Core ;
18
+ using Rti . Dds . Domain ;
19
+ using Rti . Dds . Subscription ;
20
+ using Rti . Dds . Topics ;
21
+
22
+ namespace HomeAutomation
23
+ {
24
+ public class SubscriberUpdateFilter
25
+ {
26
+ public static async Task MonitorSensors ( )
27
+ {
28
+ using DomainParticipant participant =
29
+ DomainParticipantFactory . Instance . CreateParticipant ( domainId : 0 ) ;
30
+
31
+ Topic < DeviceStatus > topic =
32
+ participant . CreateTopic < DeviceStatus > ( "WindowStatus" ) ;
33
+
34
+ List < String > parameters = new List < String > ( ) ;
35
+ parameters . Add ( "'LivingRoom'" ) ;
36
+
37
+ ContentFilteredTopic < DeviceStatus > contentFilteredTopic =
38
+ participant . CreateContentFilteredTopic < DeviceStatus > (
39
+ "FilterRoomAndOpenWindows" ,
40
+ topic ,
41
+ new Filter ( "is_open = true and room_name = %0" , parameters ) ) ;
42
+
43
+ DataReader < DeviceStatus > reader =
44
+ participant . ImplicitSubscriber . CreateDataReader ( contentFilteredTopic ) ;
45
+
46
+ parameters [ 0 ] = "'Kitchen'" ;
47
+ contentFilteredTopic . FilterParameters = parameters ;
48
+
49
+ await foreach ( var data in reader . TakeAsync ( ) . ValidData ( ) )
50
+ {
51
+ Console . WriteLine ( $ "WARNING: { data . sensor_name } in { data . room_name } is open!") ;
52
+ }
53
+ }
54
+ }
55
+ }
0 commit comments