DAQpp::Monitor Class Reference
[Monitoring tools]

class Monitor. More...

#include <Monitor.h>

Inheritance diagram for DAQpp::Monitor:

Inheritance graph
Collaboration diagram for DAQpp::Monitor:

Collaboration graph

List of all members.

Public Member Functions

 Monitor (int sz=50)
 ~Monitor ()
void push_event (Event *ev)
 Adds a new Event in the buffer.
Eventget_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 EventMonitorDie = (Event *)0xD1E00D1E
 This is a magic number that get_event() may return.
static EventMonitorTimeOut = (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.

Detailed Description

class Monitor.

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.

Carlos Lacasta

Constructor & Destructor Documentation

Monitor::Monitor ( int  sz = 50  ) 


sz maximum size of the buffer

Member Function Documentation

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.
A pointer to an event. There are two exceptions to that. 1) MonitorDie: the monitor thread should quit. 2) MonitorTimeOut: we gave a time out parameter and that time elapsed without receiveing any Event.
The event pointer returned should be deleted by the calling thread.

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

Member Data Documentation

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

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

Generated on Mon Apr 21 10:00:04 2008 for DAQ++ by  doxygen 1.5.5