FXEX::FXThreadEvent Class Reference

#include <FXThreadEvent.h>

Inheritance diagram for FXEX::FXThreadEvent:

FXEX::FXBaseObject FXObject

Detailed Description

:Description

Interthread communication object

------------------------------------------------------------------

Usage:

GUI_thread.h: ============

class MyGUI::FXWhatEver { // constructor MyGUI(...);

// message IDs enum { ID_THREAD_EVENT = FXWhatEver::ID_LAST, ID_LAST };

// message handler long onThreadEvent(FXObject*, FXSelector, void*);

// thread event object FXThreadEvent m_threadEvent; };

GUI_thread.cpp: ==============

// message map FXDEFMAP(MyGUI, FXWhatEver) = { FXMAPFUNC(SEL_THREAD_EVENT, MyGUI::ID_THREAD_EVENT, MyGUI::onThreadEvent) };

// constructor MyGUI::MyGUI(...) { m_threadEvent.setTarget(this), m_threadEvent.setSelector(ID_THREAD_EVENT); }

// message handler long onThreadEvent(FXObject*, FXSelector, void*) { do something with the GUI }

Worker_thread.cpp: =================

int threadFunction(...) { FXThreadEvent* pThreadEvent = (FXThreadEvent*)(ptr);

while (not_finished) { // work hard ...

// wake up GUI if (something_happened_and_the_GUI_needs_to_know_it) { pThreadEvent.signal(); } }

... }

Definition at line 110 of file FXThreadEvent.h.


Public Types

enum  {
  ID_NONE = 0, ID_DELETE = 6, ID_DISABLE, ID_ENABLE,
  ID_SETVALUE = 17, ID_SETINTVALUE, ID_SETREALVALUE, ID_SETSTRINGVALUE,
  ID_SETINTRANGE, ID_SETREALRANGE, ID_GETINTVALUE, ID_GETREALVALUE,
  ID_GETSTRINGVALUE, ID_XML, ID_META, ID_COMMENT,
  ID_DOCUMENT, ID_TAG, ID_CONTENT, ID_LAST
}
enum  { ID_THREAD_EVENT = FXBaseObject::ID_LAST, ID_LAST }

Public Member Functions

virtual void create ()
 create resource
virtual void destroy ()
 destroy resource
virtual void detach ()
 detach resource
virtual void disable ()
 disable us
virtual void enable ()
 enable us
 FXThreadEvent (FXObject *tgt=NULL, FXSelector sel=0)
 Construct an object capable of signaling the main FOX event loop.
FXApp * getApp ()
 application pointer
FXSelector getSelector ()
 get the message
FXObjectgetTarget ()
 get the target
void * getUserData ()
 get user data
FXuint getUserDataLen ()
 get user daat length
FXbool isEnabled ()
 are we enabled?
virtual FXbool isReadonly ()
 are we modifiable
virtual void load (FXStream &store)
 load object from stream
long onCmdDisable (FXObject *, FXSelector, void *)
long onCmdEnable (FXObject *, FXSelector, void *)
long onThreadEvent (FXObject *, FXSelector, void *)
long onThreadSignal (FXObject *, FXSelector, void *)
long onUpdate (FXObject *, FXSelector, void *)
virtual void save (FXStream &store) const
 save object to stream
virtual void setReadonly (FXbool mode=TRUE)
 set modifiable mode
void setSelector (FXSelector sel)
 set the selector
void setTarget (FXObject *tgt)
 set the target
void setUserData (void *d)
 set user data
void setUserDataLen (FXuint len)
 set the user data length
void signal (FXuint seltype)
void signal ()
virtual ~FXThreadEvent ()
 destructor

Protected Types

enum  {
  FLAG_ENABLED = 0x00000002, FLAG_UPDATE = 0x00000004, FLAG_FOCUSED = 0x00000010, FLAG_DIRTY = 0x00000020,
  FLAG_RECALC = 0x00000040, FLAG_DEFAULT = 0x00000200, FLAG_INITIAL = 0x00000400, FLAG_ACTIVE = 0x00001000,
  FLAG_CHANGED = 0x00010000, FLAG_READONLY = 0x10000000
}
 flags defined are the same as those defined in FXWindow, etc. More...

Protected Member Functions

 FXThreadEvent (const FXThreadEvent &)
FXThreadEventoperator= (const FXThreadEvent &)

Protected Attributes

void * data
FXuint datalen
FXuint flags
FXSelector message
FXuint options
FXObjecttarget

Private Attributes

FXThreadEventHandle event

Member Enumeration Documentation

anonymous enum [protected, inherited]

flags defined are the same as those defined in FXWindow, etc.

Enumerator:
FLAG_ENABLED 
FLAG_UPDATE 
FLAG_FOCUSED 
FLAG_DIRTY 
FLAG_RECALC 
FLAG_DEFAULT 
FLAG_INITIAL 
FLAG_ACTIVE 
FLAG_CHANGED 
FLAG_READONLY 

Definition at line 67 of file FXBaseObject.h.

00067          {
00068         FLAG_ENABLED  = 0x00000002,   // enabled
00069         FLAG_UPDATE   = 0x00000004,   // needs update
00070         FLAG_FOCUSED  = 0x00000010,   // has focus
00071         FLAG_DIRTY    = 0x00000020,   // dirty
00072         FLAG_RECALC   = 0x00000040,   // needs recalculation
00073         FLAG_DEFAULT  = 0x00000200,   // set to default
00074         FLAG_INITIAL  = 0x00000400,   // set to initial value
00075         FLAG_ACTIVE   = 0x00001000,   // active
00076         FLAG_CHANGED  = 0x00010000,   // changed
00077         FLAG_READONLY = 0x10000000    // read only
00078     };

anonymous enum [inherited]

Enumerator:
ID_NONE 
ID_DELETE 
ID_DISABLE 
ID_ENABLE 
ID_SETVALUE 
ID_SETINTVALUE 
ID_SETREALVALUE 
ID_SETSTRINGVALUE 
ID_SETINTRANGE 
ID_SETREALRANGE 
ID_GETINTVALUE 
ID_GETREALVALUE 
ID_GETSTRINGVALUE 
ID_XML 
ID_META 
ID_COMMENT 
ID_DOCUMENT 
ID_TAG 
ID_CONTENT 
ID_LAST 

Definition at line 92 of file FXBaseObject.h.

00092          {
00093         ID_NONE=0,
00094         ID_DELETE=6,
00095         ID_DISABLE,
00096         ID_ENABLE,
00097         ID_SETVALUE=17,
00098         ID_SETINTVALUE,
00099         ID_SETREALVALUE,
00100         ID_SETSTRINGVALUE,
00101         ID_SETINTRANGE,
00102         ID_SETREALRANGE,
00103         ID_GETINTVALUE,
00104         ID_GETREALVALUE,
00105         ID_GETSTRINGVALUE,
00106         ID_XML,
00107         ID_META,
00108         ID_COMMENT,
00109         ID_DOCUMENT,
00110         ID_TAG,
00111         ID_CONTENT,
00112         ID_LAST
00113     };

anonymous enum

Enumerator:
ID_THREAD_EVENT 
ID_LAST 

Definition at line 121 of file FXThreadEvent.h.

00121          {
00122         ID_THREAD_EVENT=FXBaseObject::ID_LAST,
00123         ID_LAST
00124     };


Constructor & Destructor Documentation

FXEX::FXThreadEvent::FXThreadEvent ( const FXThreadEvent  )  [protected]

FXEX::FXThreadEvent::FXThreadEvent ( FXObject tgt = NULL,
FXSelector  sel = 0 
)

Construct an object capable of signaling the main FOX event loop.

FXEX::FXThreadEvent::~FXThreadEvent (  )  [virtual]

destructor

Definition at line 89 of file FXThreadEvent.cpp.

References event, FXEX::FXBaseObject::getApp(), PIPE_READ, and PIPE_WRITE.

00089                               {
00090 #ifndef WIN32
00091     getApp()->removeInput(event[PIPE_READ],INPUT_READ);
00092     ::close(event[PIPE_READ]);
00093     ::close(event[PIPE_WRITE]);
00094     FXFREE(&event);
00095 #else
00096     getApp()->removeInput(event,INPUT_READ);
00097     ::CloseHandle(event);
00098 #endif
00099 }


Member Function Documentation

virtual void FXEX::FXBaseObject::create (  )  [inline, virtual, inherited]

create resource

Definition at line 194 of file FXBaseObject.h.

00194 {}

virtual void FXEX::FXBaseObject::destroy (  )  [inline, virtual, inherited]

destroy resource

Definition at line 200 of file FXBaseObject.h.

00200 {}

virtual void FXEX::FXBaseObject::detach (  )  [inline, virtual, inherited]

detach resource

Definition at line 197 of file FXBaseObject.h.

00197 {}

virtual void FXEX::FXBaseObject::disable (  )  [inline, virtual, inherited]

disable us

Definition at line 181 of file FXBaseObject.h.

References FXEX::FXBaseObject::FLAG_ENABLED, and FXEX::FXBaseObject::flags.

Referenced by FXEX::FXBaseObject::onCmdDisable().

00181                            {
00182         flags&=~FLAG_ENABLED;
00183     }

virtual void FXEX::FXBaseObject::enable (  )  [inline, virtual, inherited]

enable us

Definition at line 176 of file FXBaseObject.h.

References FXEX::FXBaseObject::FLAG_ENABLED, and FXEX::FXBaseObject::flags.

Referenced by FXEX::FXBaseObject::onCmdEnable().

00176                           {
00177         flags|=FLAG_ENABLED;
00178     }

FXApp * FXEX::FXBaseObject::getApp (  )  [inherited]

application pointer

Definition at line 123 of file FXBaseObject.cpp.

References FXEX::FXBaseObject::app.

Referenced by ~FXThreadEvent().

00123                             {
00124     if (app) return app;
00125     return FXApp::instance();
00126 }

FXSelector FXEX::FXBaseObject::getSelector (  )  [inline, inherited]

get the message

Definition at line 141 of file FXBaseObject.h.

References FXEX::FXBaseObject::message.

00141                              {
00142         return message;
00143     }

FXObject* FXEX::FXBaseObject::getTarget (  )  [inline, inherited]

get the target

Definition at line 131 of file FXBaseObject.h.

References FXEX::FXBaseObject::target.

00131                           {
00132         return target;
00133     }

void* FXEX::FXBaseObject::getUserData (  )  [inline, inherited]

get user data

Definition at line 151 of file FXBaseObject.h.

References FXEX::FXBaseObject::data.

00151                         {
00152         return data;
00153     }

FXuint FXEX::FXBaseObject::getUserDataLen (  )  [inline, inherited]

get user daat length

Definition at line 161 of file FXBaseObject.h.

References FXEX::FXBaseObject::datalen.

00161                             {
00162         return datalen;
00163     }

FXbool FXEX::FXBaseObject::isEnabled (  )  [inline, inherited]

are we enabled?

Definition at line 171 of file FXBaseObject.h.

References FXEX::FXBaseObject::FLAG_ENABLED, and FXEX::FXBaseObject::flags.

00171                        {
00172         return (flags&FLAG_ENABLED)!=0;
00173     }

virtual FXbool FXEX::FXBaseObject::isReadonly (  )  [inline, virtual, inherited]

are we modifiable

Definition at line 186 of file FXBaseObject.h.

References FXEX::FXBaseObject::FLAG_READONLY, and FXEX::FXBaseObject::flags.

00186                                 {
00187         return (flags&FLAG_READONLY)!=0;
00188     }

void FXEX::FXBaseObject::load ( FXStream &  store  )  [virtual, inherited]

load object from stream

Definition at line 111 of file FXBaseObject.cpp.

References FXEX::FXBaseObject::app, FXEX::FXBaseObject::data, FXEX::FXBaseObject::datalen, FXEX::FXBaseObject::flags, load(), FXEX::FXBaseObject::message, FXEX::FXBaseObject::options, and FXEX::FXBaseObject::target.

00111                                        {
00112     FXObject::load(store);
00113     store >> app;
00114     store >> target;
00115     store >> message;
00116     store >> flags;
00117     store >> options;
00118     store >> datalen;
00119     store.load((FXuchar*)data,(unsigned long)datalen);
00120 }

long FXEX::FXBaseObject::onCmdDisable ( FXObject ,
FXSelector  ,
void *   
) [inherited]

Definition at line 141 of file FXBaseObject.cpp.

References FXEX::FXBaseObject::disable().

00141                                                           {
00142     disable();
00143     return 1;
00144 }

long FXEX::FXBaseObject::onCmdEnable ( FXObject ,
FXSelector  ,
void *   
) [inherited]

Definition at line 135 of file FXBaseObject.cpp.

References FXEX::FXBaseObject::enable().

00135                                                          {
00136     enable();
00137     return 1;
00138 }

long FXEX::FXThreadEvent::onThreadEvent ( FXObject ,
FXSelector  sel,
void *   
)

Definition at line 138 of file FXThreadEvent.cpp.

References FXEX::FXBaseObject::message, and FXEX::FXBaseObject::target.

00138                                                                 {
00139     FXuint seltype = FXSELTYPE(sel);
00140     return target && target->handle(this,FXSEL(seltype,message),NULL);
00141 }

long FXEX::FXThreadEvent::onThreadSignal ( FXObject ,
FXSelector  ,
void *   
)

Definition at line 125 of file FXThreadEvent.cpp.

References PIPE_READ, and FXEX::SEL_THREAD.

00125                                                              {
00126     FXuint seltype=SEL_THREAD;
00127 #ifndef WIN32
00128     ::read(event[PIPE_READ],&seltype,sizeof(seltype));
00129 #else
00130     //FIXME need win32 support
00131 #endif
00132     handle(this,FXSEL(seltype,0),NULL);
00133     return 0;
00134 }

long FXEX::FXBaseObject::onUpdate ( FXObject sender,
FXSelector  ,
void *   
) [inherited]

Definition at line 147 of file FXBaseObject.cpp.

References FXEX::FXBaseObject::FLAG_ENABLED, and FXEX::FXBaseObject::flags.

00147                                                              {
00148     if (flags&FLAG_ENABLED)
00149         sender->handle(this,FXSEL(SEL_UPDATE,FXWindow::ID_ENABLE),NULL);
00150     else
00151         sender->handle(this,FXSEL(SEL_UPDATE,FXWindow::ID_DISABLE),NULL);
00152     return 1;
00153 }

FXThreadEvent& FXEX::FXThreadEvent::operator= ( const FXThreadEvent  )  [protected]

void FXEX::FXBaseObject::save ( FXStream &  store  )  const [virtual, inherited]

save object to stream

Definition at line 99 of file FXBaseObject.cpp.

References FXEX::FXBaseObject::app, FXEX::FXBaseObject::data, FXEX::FXBaseObject::datalen, FXEX::FXBaseObject::flags, FXEX::FXBaseObject::message, FXEX::FXBaseObject::options, and FXEX::FXBaseObject::target.

00099                                              {
00100     FXObject::save(store);
00101     store << app;
00102     store << target;
00103     store << message;
00104     store << flags;
00105     store << options;
00106     store << datalen;
00107     store.save((FXuchar*)data,(unsigned long)datalen);
00108 }

void FXEX::FXBaseObject::setReadonly ( FXbool  mode = TRUE  )  [virtual, inherited]

set modifiable mode

Definition at line 129 of file FXBaseObject.cpp.

References FXEX::FXBaseObject::FLAG_READONLY, and FXEX::FXBaseObject::flags.

00129                                           {
00130     if (mode) flags|=FLAG_READONLY;
00131     else flags&=~FLAG_READONLY;
00132 }

void FXEX::FXBaseObject::setSelector ( FXSelector  sel  )  [inline, inherited]

set the selector

Definition at line 146 of file FXBaseObject.h.

References FXEX::FXBaseObject::message.

Referenced by GUIApplicationWindow::dependentBuild().

00146                                      {
00147         message=sel;
00148     }

void FXEX::FXBaseObject::setTarget ( FXObject tgt  )  [inline, inherited]

set the target

Definition at line 136 of file FXBaseObject.h.

References FXEX::FXBaseObject::target.

Referenced by GUIApplicationWindow::dependentBuild().

00136                                   {
00137         target=tgt;
00138     }

void FXEX::FXBaseObject::setUserData ( void *  d  )  [inline, inherited]

set user data

Definition at line 156 of file FXBaseObject.h.

References FXEX::FXBaseObject::data.

00156                               {
00157         data=d;
00158     }

void FXEX::FXBaseObject::setUserDataLen ( FXuint  len  )  [inline, inherited]

set the user data length

Definition at line 166 of file FXBaseObject.h.

References FXEX::FXBaseObject::datalen.

00166                                     {
00167         datalen=len;
00168     }

void FXEX::FXThreadEvent::signal ( FXuint  seltype  ) 

Signal the event - using the specified FXSelector

This is meant to be called from the worker thread - it sends a mesage to the target, which is in another thread.

Definition at line 114 of file FXThreadEvent.cpp.

References event, and PIPE_WRITE.

00114                                          {
00115 #ifndef WIN32
00116     ::write(event[PIPE_WRITE],&seltype,sizeof(seltype));
00117 #else
00118     ::SetEvent(event);
00119 #endif
00120 }

void FXEX::FXThreadEvent::signal (  ) 

Signal the event - using the SEL_THREAD FXSelector type

This is meant to be called from the worker thread - it sends a mesage to the target, which is in another thread.

Definition at line 103 of file FXThreadEvent.cpp.

References event, PIPE_WRITE, and FXEX::SEL_THREAD.

Referenced by GUIRunThread::makeStep(), GUIRunThread::retrieveMessage(), GUILoadThread::retrieveMessage(), and GUILoadThread::submitEndAndCleanup().

00103                            {
00104     FXuint seltype=SEL_THREAD;
00105 #ifndef WIN32
00106     ::write(event[PIPE_WRITE],&seltype,sizeof(seltype));
00107 #else
00108     ::SetEvent(event);
00109 #endif
00110 }


Field Documentation

void* FXEX::FXBaseObject::data [protected, inherited]

FXuint FXEX::FXBaseObject::datalen [protected, inherited]

Definition at line 114 of file FXThreadEvent.h.

Referenced by signal(), and ~FXThreadEvent().

FXuint FXEX::FXBaseObject::flags [protected, inherited]

FXSelector FXEX::FXBaseObject::message [protected, inherited]

FXuint FXEX::FXBaseObject::options [protected, inherited]

Definition at line 89 of file FXBaseObject.h.

Referenced by FXEX::FXBaseObject::load(), and FXEX::FXBaseObject::save().

FXObject* FXEX::FXBaseObject::target [protected, inherited]


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

Generated on Wed May 5 00:07:02 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6