#include <module.h>

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 | |
| EventHandler * | kernelMsgSink |
| 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 |
Definition at line 58 of file module.h.
| 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 }
| 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.
| 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] |
| bool VRUT::Module::IsActive | ( | ) | const [inline] |
| void VRUT::Module::PostEvent | ( | wxCommandEvent & | evt, | |
| bool | highPriority = false | |||
| ) | [inline] |
Post general event
| [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
| [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 |
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
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] |
| virtual wxString VRUT::Module::GetDesc | ( | ) | const [pure virtual] |
Get module description.
Implemented in VRUT::CameraManipulator, VRUT::IOFhsModule, VRUT::IOImageModule, VRUT::IOObjModule, VRUT::IORdfModule, VRUT::IOStlModule, VRUT::Optimize, VRUT::RenderGl, VRUT::RenderGlModule, 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::IOScriptingModule, VRUT::JSScriptingModule, VRUT::Tracking, VRUT::Tracking, and VRUT::TrackingManipulator.
| bool VRUT::Module::IsOfType | ( | MODULE_TYPE | _type | ) | const [inline] |
friend class ModuleThread [friend] |
const MODULE_ID VRUT::Module::id [private] |
const wxString VRUT::Module::name [private] |
const unsigned VRUT::Module::type [private] |
bool VRUT::Module::isLooping [private] |
bool VRUT::Module::isDone [private] |
wxMutex VRUT::Module::mutexDone [mutable, private] |
bool VRUT::Module::acceptEvents [private] |
wxMutex VRUT::Module::mutexAcceptEvents [mutable, private] |
wxMutex VRUT::Module::evtArrivedMutex [mutable, private] |
wxCondition VRUT::Module::conditionEvtArrived [mutable, private] |
EventHandler* VRUT::Module::kernelMsgSink [protected] |
MessageQueue<wxCommandEvent> VRUT::Module::evtQueue [protected] |
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
1.5.5