DUECA/DUSIME
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Friends | List of all members
dueca::ChannelWatcher Class Reference

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 NameSetgetChannelName () 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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ChannelWatcher()

dueca::ChannelWatcher::ChannelWatcher ( const NameSet & channelname,
bool poll = false )

Constructor.

Parameters
channelnameName for the channel to be watched.
pollPolling mode. In polling mode, checkChange is functional, otherwise, entryAdded and entryRemoved callbacks should be overriden and used.

Member Function Documentation

◆ entryAdded()

virtual void dueca::ChannelWatcher::entryAdded ( const ChannelEntryInfo & i)
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.

Parameters
iSet of information about any newly created entry.

◆ entryRemoved()

virtual void dueca::ChannelWatcher::entryRemoved ( const ChannelEntryInfo & i)
inlinevirtual

Callback, is called when an entry is invalidated.

Parameters
iSet of information about any disappearing entry.

◆ checkChange()

bool dueca::ChannelWatcher::checkChange ( ChannelEntryInfo & i)

Check whether changes have occurred, use only when polling.

Parameters
iFilled with the change data
Returns
true if new changes occurred

The documentation for this class was generated from the following file: