VRUT::Module Class Reference

General type module - abstract. More...

#include <module.h>

Inheritance diagram for VRUT::Module:

VRUT::_general VRUT::KernelModule VRUT::SceneModule VRUT::Tracking VRUT::Tracking VRUT::JSScriptingModule VRUT::_scene VRUT::Collision_detection VRUT::IOModule VRUT::ManipulatorModule VRUT::Optimize VRUT::RenderModule VRUT::TrackingManipulator

List of all members.

Public Member Functions

 Module (const MODULE_ID &_id, const wxString &_name, unsigned _type, EventHandler *msgSink)
 Class constructor.
virtual ~Module ()
 Class destructor.
MODULE_ID GetID () const
 Get module ID.
bool IsActive () const
 Is associated thread running this module?
void PostEvent (wxCommandEvent &evt, bool highPriority=false)
void PostToKernel (wxCommandEvent &evt, bool highPriority=false)
 Send message/event to kernel.
wxCommandEvent WaitForEvent (wxEventType evtType, long timeout, int evtID=-1, int evtInt=-1, const wxString evtStr=wxEmptyString)
bool TestExit () const
const wxString & GetName () const
 Get module name (name should be similar to library filename).
virtual wxString GetDesc () const =0
 Get module description.
bool IsOfType (MODULE_TYPE _type) const
 Get module type.

Protected Member Functions

virtual void processEvent (wxCommandEvent &evt)
virtual void processNextEvent ()
void releasePendingEvents ()
 Discard and release all pending events.
virtual void run ()
void * loop ()
 Main loop.

Protected Attributes

EventHandlerkernelMsgSink
 Kernel message handler for posting messages.
MessageQueue< wxCommandEvent > evtQueue
 Message queue for general events posted to module.
long eventTimeout
Parameter::ParameterIdentificator eventTimeoutParamID
 eventTimeout parameter identificator

Private Attributes

const MODULE_ID id
 Module ID.
const wxString name
 Module name.
const unsigned type
 Module type.
bool isLooping
 Should main loop keep on?
bool isDone
wxMutex mutexDone
 Mutex for isDone flag.
bool acceptEvents
 Accept events?
wxMutex mutexAcceptEvents
 Mutex for acceptEvents flag.
wxMutex evtArrivedMutex
 Mutex for conditionEvtArrived.
wxCondition conditionEvtArrived
 Condition to signal new event.

Friends

class ModuleThread


Detailed Description

General type module - abstract.

Definition at line 58 of file module.h.


Constructor & Destructor Documentation

VRUT::Module::Module ( const MODULE_ID _id,
const wxString &  _name,
unsigned  _type,
EventHandler msgSink 
) [inline]

Class constructor.

Don't use default log instance

Event driven by default so no run() method needed to be called often

Register listener

Definition at line 169 of file module.h.

00170                             : id(_id),
00171                             name(_name),
00172                             type(_type),
00173                             isLooping(false),
00174                             isDone(true),
00175                             acceptEvents(true),
00176                             kernelMsgSink(msgSink),
00177                             eventTimeoutParamID(_name, wxT("eventTimeout"), _id),
00178                             conditionEvtArrived(evtArrivedMutex)
00179               {
00181                      wxLog::DontCreateOnDemand();
00182                      wxASSERT_MSG(mutexDone.IsOk(), wxT("<Module>Failed to create mutex"));
00183                      wxASSERT_MSG(mutexAcceptEvents.IsOk(), wxT("<Module>Failed to create mutex"));
00184                      wxASSERT_MSG(conditionEvtArrived.IsOk(), wxT("<Module>Failed to create condition"));
00185                      wxASSERT_MSG(evtArrivedMutex.IsOk(), wxT("<Module>Failed to create mutex"));
00187                      eventTimeout = 1000;
00188                      REGISTER_PARAM(eventTimeoutParamID, wxT("1000"));
00190                      REGISTER_LISTENER(Event::EVT_EXIT);
00191                      REGISTER_LISTENER(Event::EVT_LOG_LEVEL_SET);
00192                      REGISTER_LISTENER(Event::EVT_LOG_SET);
00193                      REGISTER_LISTENER(Event::EVT_PARAM_SET);
00194               }

virtual VRUT::Module::~Module (  )  [inline, virtual]

Class destructor.

Definition at line 196 of file module.h.

00197               {
00198                      kernelMsgSink->UnregisterListener(id);
00199               }


Member Function Documentation

virtual void VRUT::Module::processEvent ( wxCommandEvent &  evt  )  [inline, protected, virtual]

Process general event Overload to process other events in derived module but do not forget to call this method

Reimplemented in VRUT::CameraManipulator, VRUT::IORdfModule, VRUT::IOStlModule, VRUT::Optimize, VRUT::RenderGl, VRUT::CameraModule, VRUT::IOModule, VRUT::ManipulatorModule, VRUT::RenderGlModule, VRUT::RenderModule, VRUT::SceneModule, VRUT::_general, VRUT::_io, VRUT::_manip, VRUT::_render, VRUT::_scene, VRUT::_render, VRUT::ChcRenderer, VRUT::Collision_detection, VRUT::IOVrmlModule, VRUT::Navigation, VRUT::_render, VRUT::RayTracer, VRUT::JSScriptingModule, VRUT::Tracking, VRUT::Tracking, and VRUT::TrackingManipulator.

Definition at line 99 of file module.h.

00100               {
00101                      switch (evt.GetEventType())
00102                      {
00103                      case Event::EVT_LOG_SET:
00104                             wxLog::SetActiveTarget((wxLog *)evt.GetClientData());
00105                             break;
00106                      case Event::EVT_LOG_LEVEL_SET:
00107                             wxLog::SetLogLevel(evt.GetInt());
00108                             break;
00109                      case Event::EVT_EXIT:
00110                             isLooping = false;
00111                             break;
00112                      case Event::EVT_PARAM_SET:
00113                             UPDATE_PARAM_FROM_EVENT_LONG(eventTimeoutParamID, eventTimeout, evt);
00114                             break;
00115                      default:
00116                             break;
00117                      }
00118               }

virtual void VRUT::Module::processNextEvent (  )  [inline, protected, virtual]

Process next event Overload only if you have more message queues to process

Reimplemented in VRUT::ManipulatorModule.

Definition at line 121 of file module.h.

00122               {
00123                      MessageQueueError err;
00124                      wxCommandEvent evt = evtQueue.ReceiveTimeout(eventTimeout, err);
00125                      if (err == wxMSGQUEUE_NO_ERROR)
00126                      {
00127                             processEvent(evt);
00128                             kernelMsgSink->ReleaseEvent(evt, true);
00129                      }
00130               }

void VRUT::Module::releasePendingEvents (  )  [inline, protected]

Discard and release all pending events.

Definition at line 132 of file module.h.

00133               {
00134                      wxMutexLocker accEvtLocker(mutexAcceptEvents);
00135                      acceptEvents = false;
00136                      while (evtQueue.GetSize())
00137                      {
00138                             MessageQueueError err;
00139                             wxCommandEvent evt = evtQueue.ReceiveTimeout(0, err);
00140                             if (err == wxMSGQUEUE_NO_ERROR)
00141                                    kernelMsgSink->ReleaseEvent(evt, true);
00142                      }
00143               }

virtual void VRUT::Module::run (  )  [inline, protected, virtual]

Run method - is called every iteration of loop Overload if you need something to be done every iteration

Reimplemented in VRUT::_general, VRUT::_io, VRUT::_scene, VRUT::Collision_detection, VRUT::Navigation, VRUT::Tracking, and VRUT::Tracking.

Definition at line 146 of file module.h.

00147               {
00148               }

void* VRUT::Module::loop (  )  [inline, protected]

Main loop.

Definition at line 150 of file module.h.

00151               {
00152                      mutexDone.Lock();
00153                      isDone = false;
00154                      mutexDone.Unlock();
00155                      isLooping = true;
00156                      while (isLooping)
00157                      {
00158                             processNextEvent();
00159                             run();
00160                      }
00161                      wxMutexLocker doneLock(mutexDone);
00162                      releasePendingEvents();
00163                      isDone = true;
00164                      return 0;
00165               }

MODULE_ID VRUT::Module::GetID (  )  const [inline]

Get module ID.

Definition at line 202 of file module.h.

00203               {
00204                      return id;
00205               }

bool VRUT::Module::IsActive (  )  const [inline]

Is associated thread running this module?

Definition at line 207 of file module.h.

00208               {
00209                      wxMutexLocker doneLock(mutexDone);
00210                      return !isDone;
00211               }

void VRUT::Module::PostEvent ( wxCommandEvent &  evt,
bool  highPriority = false 
) [inline]

Post general event

Parameters:
[in] evt Event to post
[in] highPriority Event will be processed before any others in queue if true

Definition at line 215 of file module.h.

00216               {
00217                      wxMutexLocker accEvtLocker(mutexAcceptEvents);
00218                      if (!acceptEvents)
00219                             return;
00220                      if (evt.GetEventType() == Event::EVT_EXIT)
00221                      {
00222                             wxMutexLocker doneLock(mutexDone);
00223                             if (isDone)
00224                                    return;
00225                      }
00226                      wxMutexLocker evtLocker(evtArrivedMutex);
00227                      MessageQueueError err = evtQueue.Post(evt, highPriority);
00228                      wxASSERT_MSG(err == wxMSGQUEUE_NO_ERROR, wxT("<Module>Error posting event - exceeded message queue limit"));
00229                      conditionEvtArrived.Signal();
00230               }

void VRUT::Module::PostToKernel ( wxCommandEvent &  evt,
bool  highPriority = false 
) [inline]

Send message/event to kernel.

Definition at line 232 of file module.h.

00233               {
00234                      evt.SetExtraLong(id.GetID());
00235                      kernelMsgSink->PostEvent(evt, highPriority);
00236               }

wxCommandEvent VRUT::Module::WaitForEvent ( wxEventType  evtType,
long  timeout,
int  evtID = -1,
int  evtInt = -1,
const wxString  evtStr = wxEmptyString 
) [inline]

Synchronize with kernel - wait for specific event arrival

Parameters:
[in] evtType Wait for arrival of event with this type
[in] timeout Timeout limit to wait in milliseconds
[in] evtID Only event with this ID is accepted, -1 if don't care
[in] evtInt Only event with this integer member is accepted, -1 if don't care
[in] evtStr Only event with this string member is accepted, empty if don't care
Returns:
wxEVT_NULL type event if timeout or exit event arrived (always check TestExit), awaited event otherwise (event is removed from queue)

Our event -> remove it from queue

Definition at line 244 of file module.h.

00245               {
00246                      wxMutexLocker evtLocker(evtArrivedMutex);
00247                      const wxMilliClock_t waitUntil = wxGetLocalTimeMillis() + timeout;
00248                      wxMilliClock_t now;
00249                      do
00250                      {
00251                             wxCondError result = conditionEvtArrived.WaitTimeout(timeout);
00252                             if (result == wxCOND_NO_ERROR)
00253                             {
00254                                    wxCommandEvent newEvt = evtQueue.GetLast();
00255                                    if (newEvt.GetEventType() == Event::EVT_EXIT)
00256                                           return wxCommandEvent();
00257                                    if ((newEvt.GetEventType() == evtType)
00258                                           && ( (evtID == -1) || (evtID == newEvt.GetId()) )
00259                                           && ( (evtInt == -1) || (evtInt == newEvt.GetInt()) )
00260                                           && ( evtStr.IsEmpty() || evtStr.IsSameAs(newEvt.GetString()) ))
00261                                    {
00263                                           return evtQueue.GetLast(true);
00264                                    }
00265                             }
00266                             else
00267                                    return wxCommandEvent();
00268 
00269                             now = wxGetLocalTimeMillis();
00270                             timeout = (waitUntil - now).ToLong();
00271                      } while (now < waitUntil);
00272                      return wxCommandEvent();
00273               }

bool VRUT::Module::TestExit (  )  const [inline]

Check if module thread is to be stopped and exited Helper method for very long operations inside module where this method should be checked periodically

Returns:
true if module is to be stopped

Definition at line 277 of file module.h.

00278               {
00279                      return evtQueue.CheckFirst().GetEventType() == Event::EVT_EXIT;
00280               }

const wxString& VRUT::Module::GetName (  )  const [inline]

Get module name (name should be similar to library filename).

Definition at line 282 of file module.h.

00283               {
00284                      return name;
00285               }

virtual wxString VRUT::Module::GetDesc (  )  const [pure virtual]

bool VRUT::Module::IsOfType ( MODULE_TYPE  _type  )  const [inline]

Get module type.

Definition at line 289 of file module.h.

00290               {
00291                      return ( type & _type ) != 0;
00292               }


Friends And Related Function Documentation

friend class ModuleThread [friend]

Definition at line 294 of file module.h.


Member Data Documentation

const MODULE_ID VRUT::Module::id [private]

Module ID.

Definition at line 62 of file module.h.

const wxString VRUT::Module::name [private]

Module name.

Definition at line 64 of file module.h.

const unsigned VRUT::Module::type [private]

Module type.

Definition at line 66 of file module.h.

bool VRUT::Module::isLooping [private]

Should main loop keep on?

Definition at line 68 of file module.h.

bool VRUT::Module::isDone [private]

Has loop finished (or never started)? NOTE: Associated thread is inactive if true

Definition at line 71 of file module.h.

wxMutex VRUT::Module::mutexDone [mutable, private]

Mutex for isDone flag.

Definition at line 73 of file module.h.

Accept events?

Definition at line 75 of file module.h.

wxMutex VRUT::Module::mutexAcceptEvents [mutable, private]

Mutex for acceptEvents flag.

Definition at line 77 of file module.h.

wxMutex VRUT::Module::evtArrivedMutex [mutable, private]

Mutex for conditionEvtArrived.

Definition at line 79 of file module.h.

wxCondition VRUT::Module::conditionEvtArrived [mutable, private]

Condition to signal new event.

Definition at line 81 of file module.h.

Kernel message handler for posting messages.

Definition at line 85 of file module.h.

MessageQueue<wxCommandEvent> VRUT::Module::evtQueue [protected]

Message queue for general events posted to module.

Definition at line 87 of file module.h.

long VRUT::Module::eventTimeout [protected]

Amount of time in milliseconds to wait for incoming event every loop 0 .. no waiting, module is looping until event arrives, continues after event is processed (eg. manipulator) T .. waits at least T ms, if no event arrives run method is called (or other queue processing) (eg. import/export or other 'one-time purpose' modules should have T high

Definition at line 93 of file module.h.

eventTimeout parameter identificator

Definition at line 95 of file module.h.


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

Generated on Tue Mar 10 14:41:44 2009 for VRUT by  doxygen 1.5.5