![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 //:Header-----------------------------*- mode: c++; tab-width: 2 -*- 00002 // 00003 // $Id: FXThreadEvent.h,v 1.5 2001/03/02 11:41:11 dgehrige Exp $ 00004 // 00005 // Copyright (C) 2000 by Daniel Gehriger. All Rights Reserved 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Library General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 2 of the License, or (at your option) any later version. 00011 // 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 // Library General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Library General Public 00018 // License along with this library; if not, write to the Free 00019 // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 // 00021 // $Id: FXThreadEvent.h,v 1.5 2001/03/02 11:41:11 dgehrige Exp $ 00022 // 00023 //------------------------------------------------------------------ 00024 #ifndef FXTHREADEVENT_H 00025 #define FXTHREADEVENT_H 00026 00027 #ifndef FXBASEOBJECT_H 00028 #include "FXBaseObject.h" 00029 #endif 00030 namespace FXEX { 00031 00032 /** 00033 * :Description 00034 * 00035 * Interthread communication object 00036 * 00037 *------------------------------------------------------------------ 00038 * 00039 * Usage: 00040 * 00041 * GUI_thread.h: 00042 * ============ 00043 * 00044 * class MyGUI::FXWhatEver 00045 * { 00046 * // constructor 00047 * MyGUI(...); 00048 * 00049 * // message IDs 00050 * enum { 00051 * ID_THREAD_EVENT = FXWhatEver::ID_LAST, 00052 * ID_LAST }; 00053 * 00054 * // message handler 00055 * long onThreadEvent(FXObject*, FXSelector, void*); 00056 * 00057 * // thread event object 00058 * FXThreadEvent m_threadEvent; 00059 * }; 00060 * 00061 * GUI_thread.cpp: 00062 * ============== 00063 * 00064 * // message map 00065 * FXDEFMAP(MyGUI, FXWhatEver) = { 00066 * FXMAPFUNC(SEL_THREAD_EVENT, MyGUI::ID_THREAD_EVENT, MyGUI::onThreadEvent) 00067 * }; 00068 * 00069 * // constructor 00070 * MyGUI::MyGUI(...) 00071 * { 00072 * m_threadEvent.setTarget(this), 00073 * m_threadEvent.setSelector(ID_THREAD_EVENT); 00074 * } 00075 * 00076 * // message handler 00077 * long onThreadEvent(FXObject*, FXSelector, void*) 00078 * { 00079 * do something with the GUI 00080 * } 00081 * 00082 * Worker_thread.cpp: 00083 * ================= 00084 * 00085 * int threadFunction(...) 00086 * { 00087 * FXThreadEvent* pThreadEvent = (FXThreadEvent*)(ptr); 00088 * 00089 * while (not_finished) { 00090 * // work hard 00091 * ... 00092 * 00093 * // wake up GUI 00094 * if (something_happened_and_the_GUI_needs_to_know_it) { 00095 * pThreadEvent.signal(); 00096 * } 00097 * } 00098 * 00099 * ... 00100 * } 00101 * 00102 */ 00103 class FXAPI FXThreadEvent : public FXBaseObject { 00104 FXDECLARE(FXThreadEvent); 00105 00106 private: 00107 FXThreadEventHandle event; 00108 00109 protected: 00110 FXThreadEvent(const FXThreadEvent&); 00111 FXThreadEvent& operator=(const FXThreadEvent&); 00112 00113 public: 00114 enum { 00115 ID_THREAD_EVENT=FXBaseObject::ID_LAST, 00116 ID_LAST 00117 }; 00118 00119 public: 00120 long onThreadSignal(FXObject*,FXSelector,void*); 00121 long onThreadEvent(FXObject*,FXSelector,void*); 00122 00123 public: 00124 /// Construct an object capable of signaling the main FOX event loop 00125 FXThreadEvent(FXObject* tgt=NULL,FXSelector sel=0); 00126 00127 /** 00128 * Signal the event - using the SEL_THREAD FXSelector type 00129 * 00130 * This is meant to be called from the worker thread - it sends a mesage to 00131 * the target, which is in another thread. 00132 */ 00133 void signal(); 00134 00135 /** 00136 * Signal the event - using the specified FXSelector 00137 * 00138 * This is meant to be called from the worker thread - it sends a mesage to 00139 * the target, which is in another thread. 00140 */ 00141 void signal(FXuint seltype); 00142 00143 /// destructor 00144 virtual ~FXThreadEvent(); 00145 }; 00146 00147 } // namespace FXEX 00148 #endif // FXTHREADEVENT_H