The timeflieslikeanarrow sample in the repo shows a way to use a Subject to connect a Win32 message loop to an Observable. The same technique will work for DBus I expect.
Steps:
Create a Subject (which is an Observer and an Observable). Pass the Observer to the event loop and have it call OnNext for each event. Pass the Observable to the clients that wish to subscribe to the events.
Given that threads are involved:
- The OnNext/OnError/OnCompleted methods on the Subject must not be called at the same time. If more than one thread will use the same Subject’s Observer then a mutex must be used to serialize the calls.
- The calls to OnNext/OnError/OnCompleted on subscribers to the Subject’s Observable will be run on the DBus event loop thread. Use an observe_on if they need to be moved to a different thread.
Kirk
|