Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

CEvent Class Reference

#include <CEvent.h>

Inheritance diagram for CEvent:

CRegisteredObject CNamedObject CBufferEvent< T > CFileEvent CLocationEvent< T > CTimerEvent CServerConnectionEvent CServerInstance List of all members.

Public Member Functions

 CEvent (CEventMonitor &rMonitor, CReactor &rReactor, bool InformTimeouts=false, int nTimeoutMs=500)
 CEvent (const char *pName, CEventMonitor &rMonitor, CReactor &rReactor, bool InformTimeouts=false, int nTimeoutMs=500)
 CEvent (const STD(string)&rName, CEventMonitor &rMonitor, CReactor &rReactor, bool InformTimeouts=false, int nTimeoutMs=500)
virtual ~CEvent ()
bool isEnabled () const
 Return TRUE if the thread is enabled if not thread halt is pending.
bool isActive () const
 Return TRUE if the thread is running (active) (small timing hole).
bool getInformTimeout () const
 Return TRUE if Reactor also catches timeouts.
int getMsReactivity () const
 Return the reactivity of the event to programmatic stimulus.
CEventMonitorgetMonitor ()
 Allow manipulation of the event monitor:.
CReactorgetReactor ()
 Allow manipulation of the event reactor:.
DAQThreadId getThreadId () const
 Allow external manipulation of the thread:.
void Enable ()
void Disable ()
void setReactivity (int nMs)
void setEnable (bool fEnable)
void ReactToTimeouts (bool fReact=true)
virtual STD (string) DescribeSelf()

Protected Member Functions

void setActive (bool fActive)
 Set state of active flag.. implies thread is running.
void setTid (const DAQThreadId Tid)
 Set Thread ID: implies you know a lot about the system.
virtual void OnEvent (CEventMonitor::result why)
void Schedule ()
virtual int operator() (int nargs, char **ppArgs)
virtual void ProcessQueues ()
DAQStatus JoinThis ()

Private Member Functions

 CEvent (const CEvent &aCEvent)
 Copy Constructor - not allowed.
CEventoperator= (const CEvent &aCEvent)
 Operator= Assignment Operator - not allowed.
int operator== (const CEvent &aCEvent) const
 Operator== Equality Operator no point.

Private Attributes

bool m_fEnabled
 Event enabled flag.
bool m_fActive
 True if thread is active.
bool m_InformTimeouts
 Pass timeouts on to reactor.
int m_nMsReactivity
 Reactivity to external events.
CEventMonitorm_rMonitor
 Monitor which polls for event.
CReactorm_rReactor
 Reactor to the event when it fires.
DAQThreadId m_Tid
 spectrodaq thread identifier.

Constructor & Destructor Documentation

CEvent::CEvent CEventMonitor rMonitor,
CReactor rReactor,
bool  InformTimeouts = false,
int  nTimeoutMs = 500
 

Construct an "anonymous" event object. Anonymous event objects have names like EventThread(unique_index). All Event objects will be registered in the "Event" registry of the application's global object classified registry.

Parameters:
rMonitor - The monitor which notices events.
rReactor - The reactor which does stuff when an event fires.
InformTimeouts [false] - Optional parameter which, if true, allows the Reactor to be called when the monitor times out.
nTimeoutMs - The timeout in ms for the Event monitor. Timeouts are an essential part of the event thread. The thread can only react to externally generated attempts to Disable it after the Monitor returns. The timeout in ms therefore is a measure of the reactiveness of the event to programmatic stimulus from other threads. For 'permanent' events, use a timeout of -1 which will cause the monitor to be configured to run without a timeout. NOTE:
  • The Event runs as a separate thread in the process. Destruction implies an attempt to kill the thread and join with it and may therefore be a time consuming process if the thread is active with a long or nonexistent timeout.
  • All calls to the reactor are synchronized with the application global mutex.

Definition at line 363 of file CEvent.cpp.

References CNamedObject::AppendClassInfo(), and RegistryName.

CEvent::CEvent const char *  pName,
CEventMonitor rMonitor,
CReactor rReactor,
bool  InformTimeouts = false,
int  nTimeoutMs = 500
 

Construct a named event object. See the previous overload of CEvent::CEvent for most of the descriptive information. However:

Parameters:
pName - the name of the event object.
rMonitor - The event monitor that indicates the event condition has occured.
rReactor - The object that will react to the event.
InformTimeouts - True if the event should have a timeout on its wait, and if that timeout will be reported to the reactor.
nTimeoutMs - The number of milliseconds in the timeout.
Throws:

Definition at line 395 of file CEvent.cpp.

References CNamedObject::AppendClassInfo(), and RegistryName.

CEvent::CEvent const STD(string)&  rName,
CEventMonitor rMonitor,
CReactor rReactor,
bool  InformTimeouts = false,
int  nTimeoutMs = 500
 

CEvent::~CEvent  )  [virtual]
 

Destroys an instance of ourselves. This implies that our thread will exit. In general the destructor will not be called from this thread.

Definition at line 447 of file CEvent.cpp.

References Disable().

CEvent::CEvent const CEvent aCEvent  )  [private]
 

Copy Constructor - not allowed.


Member Function Documentation

void CEvent::Disable  ) 
 

Disable execution of the event. A join is done with the event to ensure that it actually exits. There are two cases:

  • m_fActive == true - The thread is active m_fEnabled is set false, after some time, the thread will actually exit. We join with it to ensure that by the time Disable is exited, the thread has exited too.
  • m_fActive == false - The thread is not active, we can just return.

Note:
If the calling thread owns the global serialization mutex, it will be temporarily released. If this were not done, the Join could deadlock the initiating thread and the thread being killed:
  • The initiating thread will wait on the event thread to die, while holding the serialization mutex.
  • The Event thread will wait on the serialization mutex before it can notice that it has been asked to exit.

Definition at line 495 of file CEvent.cpp.

References CThreadRecursiveMutex::getLockLevel(), CThreadRecursiveMutex::getOwningThread(), CThreadRecursiveMutex::Lock(), m_fEnabled, and CThreadRecursiveMutex::UnLockCompletely().

Referenced by ~CEvent().

void CEvent::Enable  ) 
 

Enable execution of the event. This is intended to be called from outside the Event thread. This allows us to directly schedule the object as a thread, rather than going through the rigmarole required by CEvent::Schedule

  • Enabling an active thread is a no-op.
  • The enable state is a flag, not a counter, so only a single disable is required to kill the thread regardless of the number of Enable calls.

Reimplemented in CTimerEvent.

Definition at line 465 of file CEvent.cpp.

References CApplicationSerializer::getInstance(), CThreadRecursiveMutex::Lock(), m_fEnabled, m_Tid, and CThreadRecursiveMutex::UnLock().

Referenced by CTimerEvent::Enable().

bool CEvent::getInformTimeout  )  const [inline]
 

Return TRUE if Reactor also catches timeouts.

Definition at line 396 of file CEvent.h.

CEventMonitor& CEvent::getMonitor  )  [inline]
 

Allow manipulation of the event monitor:.

Reimplemented in CBufferEvent< T >, CLocationEvent< T >, CTimerEvent, and CBufferEvent< U >.

Definition at line 404 of file CEvent.h.

Referenced by CFileEvent::MonitorExceptions(), CFileEvent::MonitorReadable(), CFileEvent::MonitorWritable(), and CFileEvent::~CFileEvent().

int CEvent::getMsReactivity  )  const [inline]
 

Return the reactivity of the event to programmatic stimulus.

Definition at line 400 of file CEvent.h.

CReactor& CEvent::getReactor  )  [inline]
 

Allow manipulation of the event reactor:.

Reimplemented in CBufferEvent< T >, CLocationEvent< T >, CTimerEvent, and CBufferEvent< U >.

Definition at line 408 of file CEvent.h.

Referenced by CFileEvent::~CFileEvent().

DAQThreadId CEvent::getThreadId  )  const [inline]
 

Allow external manipulation of the thread:.

Definition at line 412 of file CEvent.h.

bool CEvent::isActive  )  const [inline]
 

Return TRUE if the thread is running (active) (small timing hole).

Definition at line 392 of file CEvent.h.

bool CEvent::isEnabled  )  const [inline]
 

Return TRUE if the thread is enabled if not thread halt is pending.

Definition at line 388 of file CEvent.h.

DAQStatus CEvent::JoinThis  )  [protected]
 

Does a join on the current object. The assumption is that at some time this object exists as a thread and will exit to be joined before restarting.

Definition at line 654 of file CEvent.cpp.

References m_Tid.

void CEvent::OnEvent CEventMonitor::result  why  )  [protected, virtual]
 

Called when the event monitor indicates that an event has occured. The default action (overridable) is to: 1. Lock the global serialization mutex. 2. Call the Event reactor's operator() member function. 3. Unlock the global serialization mutex.

Parameters:
why - Indicates what condition the monitor signalled.

Definition at line 581 of file CEvent.cpp.

References CApplicationSerializer::getInstance(), CThreadRecursiveMutex::Lock(), m_rMonitor, m_rReactor, ProcessQueues(), and CThreadRecursiveMutex::UnLock().

Referenced by operator()().

int CEvent::operator() int  nargs,
char **  ppArgs
[protected, virtual]
 

This is the Event thread's entry point when scheduled.

  • Reap the scheduler thread.
  • Delete the scheduler object which started us.
  • Enter the main event loop of polling the monitor and dipatching to the reactor.

Parameters:
nargs - Number of parameters.
ppArgs - Pointer to the arguments. In this case it's just a pointer to the dispatching thread's object.

Reimplemented in CLocationEvent< T >.

Definition at line 632 of file CEvent.cpp.

References m_fActive, m_nMsReactivity, m_rMonitor, m_Tid, OnEvent(), and CEventMonitor::setTimeout().

Referenced by CLocationEvent< T >::operator()().

CEvent& CEvent::operator= const CEvent aCEvent  )  [private]
 

Operator= Assignment Operator - not allowed.

int CEvent::operator== const CEvent aCEvent  )  const [private]
 

Operator== Equality Operator no point.

void CEvent::ProcessQueues  )  [protected, virtual]
 

Called periodically in event thread context to process any inter thread communication primitives which may require action at event context.

Reimplemented in CBufferEvent< T >, and CBufferEvent< U >.

Definition at line 666 of file CEvent.cpp.

Referenced by OnEvent().

void CEvent::ReactToTimeouts bool  fReact = true  ) 
 

Determines whether or not Monitor timeouts will cause a reactor to be fired. Timeouts are used regardless in order to sense the dropping of the m_fEnabled flag. However if a timeout occurs and m_fInformTimeouts is false, the Reactor will not be called.

Parameters:
fReact [true] - true if reactivity is desired...

Definition at line 542 of file CEvent.cpp.

References m_InformTimeouts.

void CEvent::Schedule  )  [protected]
 

Called to schedule this process. Eric feels that it is not safe to just start this process off directly, e.g. from the constructor, because execution may start while the constructor is still executing either at this or a lower level of the class hierarchy if this is a class derived from CEvent. Therefore we do the following tricky startup:

  • Create a new thread (EventStartupThread).
  • Schedule that thread this is a parameter.
  • The thread will wait for some period of ms. which hopefully will ensure that the constructors have all exited.
  • The thread will start this object as a thread, passing itself to our operator()
  • Our operator() will do a Join on the thread which started us up to reap it.
  • Our operator() will enter the main event loop.

Definition at line 611 of file CEvent.cpp.

References m_fEnabled.

void CEvent::setActive bool  fActive  )  [inline, protected]
 

Set state of active flag.. implies thread is running.

Definition at line 420 of file CEvent.h.

References m_fActive.

void CEvent::setEnable bool  fEnable  )  [inline]
 

< Allows thread resident code to end event.

Definition at line 433 of file CEvent.h.

References m_fEnabled.

Referenced by CTimerEvent::InternalOnTimer(), and CServerInstance::Shutdown().

void CEvent::setReactivity int  nMs  ) 
 

Changes the Monitor timeout. This will take effect after the next exit from the monitor.. which may require as much as the current value of timeout.

Parameters:
nMs - Number of milliseconds in the new timeout. -1 disables timeouts which in turn makes the time required to kill the thread unbounded.

Definition at line 528 of file CEvent.cpp.

References m_nMsReactivity.

Referenced by CTimerEvent::CTimerEvent(), CTimerEvent::Enable(), and CTimerEvent::SetTimeout().

void CEvent::setTid const DAQThreadId  Tid  )  [inline, protected]
 

Set Thread ID: implies you know a lot about the system.

Definition at line 424 of file CEvent.h.

References m_Tid.

virtual CEvent::STD string   )  [virtual]
 

The name of the object

Reimplemented from CNamedObject.

Reimplemented in CBufferEvent< T >, CBufferEvent< T >, CFileEvent, CLocationEvent< T >, CServerConnectionEvent, CServerInstance, CTimerEvent, CBufferEvent< U >, and CBufferEvent< U >.


Member Data Documentation

bool CEvent::m_fActive [private]
 

True if thread is active.

Definition at line 344 of file CEvent.h.

Referenced by operator()(), and setActive().

bool CEvent::m_fEnabled [private]
 

Event enabled flag.

Definition at line 343 of file CEvent.h.

Referenced by Disable(), Enable(), Schedule(), and setEnable().

bool CEvent::m_InformTimeouts [private]
 

Pass timeouts on to reactor.

Definition at line 345 of file CEvent.h.

Referenced by ReactToTimeouts().

int CEvent::m_nMsReactivity [private]
 

Reactivity to external events.

Definition at line 346 of file CEvent.h.

Referenced by operator()(), and setReactivity().

CEventMonitor& CEvent::m_rMonitor [private]
 

Monitor which polls for event.

Reimplemented in CBufferEvent< T >, CLocationEvent< T >, CTimerEvent, and CBufferEvent< U >.

Definition at line 347 of file CEvent.h.

Referenced by OnEvent(), and operator()().

CReactor& CEvent::m_rReactor [private]
 

Reactor to the event when it fires.

Reimplemented in CBufferEvent< T >, CLocationEvent< T >, CTimerEvent, and CBufferEvent< U >.

Definition at line 348 of file CEvent.h.

Referenced by OnEvent().

DAQThreadId CEvent::m_Tid [private]
 

spectrodaq thread identifier.

Definition at line 349 of file CEvent.h.

Referenced by Enable(), JoinThis(), operator()(), and setTid().


The documentation for this class was generated from the following files:
Generated on Thu Jan 6 16:58:44 2005 for Spectrodaq External Event Framework by  doxygen 1.3.9.1