VRUT::JSHandler Class Reference

#include <jshandler.h>

List of all members.

Public Member Functions

 JSHandler (JSScriptingModule *_module)
 Constructor.
 ~JSHandler ()
 Destructor.
bool Sleep (unsigned long milis)
 The method for script sleeping.
wxCommandEvent * WaitForEvent (Event::EVENT_TYPE type, unsigned long milis, bool waitFromNow)
 The method for waiting for event.
void PostEvent (wxCommandEvent &evt)
 Posts event to modules.
void PostToKernel (wxCommandEvent &evt)
 Posts event to kernel.
void ProcessEvent (wxCommandEvent &evt)
 Event's processing.
bool RunScript ()
 Executing the script.
bool IsEnd ()
 Test the script demand for exiting.

Private Attributes

std::queue< RunDataexecutions
 The queue with all executions.
JSScriptingModulemodule
 The pointer to class JSScriptingModule.
JSEnvironmentjsEnv
 The pointer to class JSEnvironment.

Static Private Attributes

static const unsigned long TIMEOUT_WAITING = 50
 Number of miliseconds for sleeping in the method WaitingForEvent.
static const unsigned long TIMEOUT_SLEEP = 50
 Number of miliseconds for sleeping in the method Sleep.

Friends

class JSEnvironment

Classes

struct  RunData
 The structure with saved data for starting script. More...


Detailed Description

Definition at line 25 of file jshandler.h.


Constructor & Destructor Documentation

JSHandler::JSHandler ( JSScriptingModule _module  ) 

Constructor.

Definition at line 20 of file jshandler.cpp.

00021 {
00022        module = _module;
00023        jsEnv = new JSEnvironment(this);
00024 }

JSHandler::~JSHandler (  ) 

Destructor.

Definition at line 26 of file jshandler.cpp.

00027 {
00028        delete jsEnv;
00029 }


Member Function Documentation

bool JSHandler::Sleep ( unsigned long  milis  ) 

The method for script sleeping.

Definition at line 31 of file jshandler.cpp.

00032 {
00033        unsigned long t;
00034        if (milis > TIMEOUT_SLEEP)
00035        {
00036               t = milis % TIMEOUT_SLEEP;
00037               int steps = milis / TIMEOUT_SLEEP;
00038               for (int i = 0; i < steps; i++)
00039               {
00040                      wxThread::Sleep(TIMEOUT_SLEEP);
00041                      if (IsEnd())
00042                             return false;
00043               }
00044        }
00045        else
00046               t = milis;
00047 
00048        if (t)
00049               wxThread::Sleep(t);
00050 
00051        return true;
00052 }

wxCommandEvent * JSHandler::WaitForEvent ( Event::EVENT_TYPE  type,
unsigned long  milis,
bool  waitFromNow 
)

The method for waiting for event.

events before calling method for waiting

Definition at line 54 of file jshandler.cpp.

00055 {
00056        wxCommandEvent *pevt = NULL;
00057        MessageQueueError err;
00058        size_t size;
00059 
00060        if (waitFromNow)
00061        {
00063               size = module->evtQueue.GetSize();
00064               for (unsigned i = 0; i < size; i++)
00065               {
00066                      wxCommandEvent evt1 = module->evtQueue.ReceiveTimeout(0, err);
00067                      if (err)
00068                             return NULL;
00069                      ProcessEvent(evt1);
00070               }
00071        }
00072 
00073        bool unlimited = (milis == 0);
00074        while (unlimited || milis > 0)
00075        {
00076               size = module->evtQueue.GetSize();
00077               for (unsigned i = 0; i < size; i++)
00078               {
00079                      wxCommandEvent evt2 = module->evtQueue.ReceiveTimeout(0, err);
00080                      //cout << "event: " << int(evt2.GetEventType()) << endl;
00081                      if (err)
00082                             return NULL;
00083                      if (evt2.GetEventType() == type)
00084                             return new wxCommandEvent(evt2);
00085                      ProcessEvent(evt2);
00086               }
00087 
00088               wxThread::Sleep(TIMEOUT_WAITING);
00089               if (IsEnd())
00090                      return NULL;
00091 
00092               if (!unlimited)
00093                      milis -= TIMEOUT_WAITING;
00094        }
00095 
00096        return NULL;
00097 }

void JSHandler::PostEvent ( wxCommandEvent &  evt  ) 

Posts event to modules.

Definition at line 99 of file jshandler.cpp.

00100 {
00101        module->PostEvent(evt);
00102 }

void JSHandler::PostToKernel ( wxCommandEvent &  evt  ) 

Posts event to kernel.

Definition at line 104 of file jshandler.cpp.

00105 {
00106        module->PostToKernel(evt);
00107 }

void JSHandler::ProcessEvent ( wxCommandEvent &  evt  ) 

Event's processing.

Definition at line 109 of file jshandler.cpp.

00110 {
00111        if (evt.GetEventType() == Event::EVT_PARAM_SET)
00112        {
00113               if (IS_PARAM(evt, module->sceneParamID))
00114               {
00115                      long val;
00116                      if (((wxString *) evt.GetClientData())->AfterFirst('=').ToLong(&val) && val >= 0)
00117                             module->sceneID = (SCENE_ID) val;
00118                      else
00119                             module->sceneID = SCENE_ID_NONE;
00120               }
00121               else if (IS_PARAM(evt, module->runParamID))
00122                      executions.push(RunData(module->scriptPath, module->sceneID));
00123               else
00124                      UPDATE_PARAM_FROM_EVENT_STRING(module->pathParamID, module->scriptPath, evt);
00125        }
00126 }

bool JSHandler::RunScript (  ) 

Executing the script.

Definition at line 128 of file jshandler.cpp.

00129 {
00130        if (executions.empty())
00131               return false;
00132        RunData data = executions.front();
00133        executions.pop();
00134        jsEnv->RunScript(module->kernel, data.scriptPath.ToAscii(), data.sceneID);
00135        return true;
00136 }

bool JSHandler::IsEnd (  ) 

Test the script demand for exiting.

Definition at line 139 of file jshandler.cpp.

00140 {
00141        return module->TestExit();
00142 }


Friends And Related Function Documentation

friend class JSEnvironment [friend]

Definition at line 73 of file jshandler.h.


Member Data Documentation

const unsigned long VRUT::JSHandler::TIMEOUT_WAITING = 50 [static, private]

Number of miliseconds for sleeping in the method WaitingForEvent.

Definition at line 29 of file jshandler.h.

const unsigned long VRUT::JSHandler::TIMEOUT_SLEEP = 50 [static, private]

Number of miliseconds for sleeping in the method Sleep.

Definition at line 31 of file jshandler.h.

std::queue<RunData> VRUT::JSHandler::executions [private]

The queue with all executions.

Definition at line 44 of file jshandler.h.

The pointer to class JSScriptingModule.

Definition at line 47 of file jshandler.h.

The pointer to class JSEnvironment.

Definition at line 49 of file jshandler.h.


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

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