#include <Monitor.h>
Public Member Functions | |
Monitor (int sz=50) | |
Constructor. | |
~Monitor () | |
Destructor. | |
void | push_event (Event *ev) |
Adds a new Event in the buffer. | |
Event * | get_event (int timeout=-1) |
Retrieves the oldest Event from the queue. | |
bool | condition () |
The wait condition. | |
void | set_max_size (unsigned long s) |
Sets the maximum size of the buffer. | |
unsigned long | get_max_size () const |
Returns the current maximum size of the object. | |
bool | full () |
Returs true if the buffer is full. | |
void | clean () |
Empties the buffer. | |
void | start_monitor () |
Starts a new thread. | |
void | stop_monitor () |
Stops the monitor thread started with start_monitor(). | |
Static Public Attributes | |
static Event * | MonitorDie = (Event *)0xD1E00D1E |
This is a magic number that get_event() may return. | |
static Event * | MonitorTimeOut = (Event *)0xD1E00AAA |
This is a magic number that get_event() may return. | |
Private Attributes | |
unsigned long | mxsize |
maximum number of events allowed in the buffer | |
Mutex | mtx |
A mutex used to pop and push the queue. |
The Monitor class implements a buffer of Event objects. It is implemented as a queue in which new events will only be pushed if the current size (number of elements in the queue) is smaller than a specified maximum. The size limit can be set either on the constructor or changed afterwards.
It also derives from Thread and the monitoring of the sampled events should be done in the implementation of the run() method. In that method, the Monitor instance should use get_event() to get the next event in the Event queue. If the queue is empty, get_event() blocks.
get_event() accepts a timeout argument and it will wake up and return MonitorTimeOut instead of a valid pointer. Similarly, it will return MonitorDie when the monitoring should die.
Monitor::Monitor | ( | int | sz = 50 |
) |
Constructor.
sz | maximum size of the buffer |
void Monitor::push_event | ( | Event * | ev | ) |
Adds a new Event in the buffer.
There is no local copy made on this call. The Monitor stores just the event pointer. The user will have to handle properly the pointer when he/she retrieves it with get_event.
References MonitorDie, mxsize, and DAQpp::Condition::notify_all().
Referenced by DAQpp::RunManager::ModuleAcquire::operator()(), and stop_monitor().
Event * Monitor::get_event | ( | int | timeout = -1 |
) |
Retrieves the oldest Event from the queue.
This call will put the calling thread to sleep when there is no data available. As soon as a new Event is added to the buffer the calling thread will wake up and continue.
timeout | if >0, the routine does not block and will wake up after the given number of microseconds. |
References DAQpp::Mutex::acquire(), MonitorTimeOut, mtx, DAQpp::Mutex::release(), and DAQpp::Condition::wait().
Referenced by clean().
void Monitor::start_monitor | ( | ) |
Starts a new thread.
It is supposed that the thread will perform the required actions to retrieve the Event's in the buffer.
References clean(), DAQpp::Thread::is_running(), and DAQpp::Thread::start().
Event * Monitor::MonitorDie = (Event *)0xD1E00D1E [static] |
This is a magic number that get_event() may return.
If this is the case the Monitor should die.
Referenced by clean(), push_event(), stop_monitor(), and ~Monitor().
Event * Monitor::MonitorTimeOut = (Event *)0xD1E00AAA [static] |
This is a magic number that get_event() may return.
If this is the case the Monitor timed out waiting for new events in the queue
Referenced by get_event(), stop_monitor(), and ~Monitor().