|
DUECA/DUSIME
|
Base class for monitoring a channel. More...
#include <ChannelWatcher.hxx>
Public Member Functions | |
| ChannelWatcher (const NameSet &channelname, bool poll=false) | |
| Constructor. | |
| virtual | ~ChannelWatcher () |
| Destructor. | |
| virtual void | entryAdded (const ChannelEntryInfo &i) |
| Callback, is called when a new entry is added. | |
| virtual void | entryRemoved (const ChannelEntryInfo &i) |
| Callback, is called when an entry is invalidated. | |
| bool | checkChange (ChannelEntryInfo &i) |
| Check whether changes have occurred, use only when polling. | |
| const NameSet & | getChannelName () const |
| Read back the channel name. | |
Protected Member Functions | |
| void | disableWatcher () |
| Disable the watcher, call in derived destructor. | |
Friends | |
| class | UnifiedChannel |
| The channel can call a pair of protected functions. | |
Base class for monitoring a channel.
To monitor the creation and deletion of entries in a channel, either derive from this class and reimplement the ChannelWatcher::entryAdded and ChannelWatcher::entryRemoved methods, or select polling mode and regularly call the checkChange function.
Note that you have to be careful about threading issues. The callbacks are performed in the prio 0 thread, if your module performs other activities in other threads, make sure that use of your module's data is done in a thread-safe manner (either use StateGuard to implement mutex functionality, use AsyncList for single-producer, single-consumer thread-safe communication, or use atomic variables).
Another alternative is polling the ChannelWatcher. It is safe to call the checkChange function from any thread.
| dueca::ChannelWatcher::ChannelWatcher | ( | const NameSet & | channelname, |
| bool | poll = false ) |
Constructor.
| channelname | Name for the channel to be watched. |
| poll | Polling mode. In polling mode, checkChange is functional, otherwise, entryAdded and entryRemoved callbacks should be overriden and used. |
|
inlinevirtual |
Callback, is called when a new entry is added.
The passed ChannelEntryInfo object was created with the channel entry lock active, but invocation of this call is delayed to a point where the entry lock is no longer active; note that there may therefore be a slight chance that the promised entry has been removed again in the meantime, so if you attempt to create a reading token, there is a small possibility that you encounter a pathetic situation where this fails.
| i | Set of information about any newly created entry. |
|
inlinevirtual |
Callback, is called when an entry is invalidated.
| i | Set of information about any disappearing entry. |
| bool dueca::ChannelWatcher::checkChange | ( | ChannelEntryInfo & | i | ) |
Check whether changes have occurred, use only when polling.
| i | Filled with the change data |