1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2004-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file FXThreadEvent.h 11 /// @author Mathew Robertson 12 /// @author Daniel Krajzewicz 13 /// @author Michael Behrisch 14 /// @date 2004-03-19 15 /// @version $Id$ 16 /// 17 // 18 /****************************************************************************/ 19 #ifndef FXThreadEvent_h 20 #define FXThreadEvent_h 21 22 23 // =========================================================================== 24 // included modules 25 // =========================================================================== 26 #include <config.h> 27 28 #include "fxexdefs.h" 29 30 #ifndef FXBASEOBJECT_H 31 #include "FXBaseObject.h" 32 #endif 33 namespace FXEX { 34 35 /** 36 * :Description 37 * 38 * Interthread communication object 39 * 40 *------------------------------------------------------------------ 41 * 42 * Usage: 43 * 44 * GUI_thread.h: 45 * ============ 46 * 47 * class MyGUI::FXWhatEver 48 * { 49 * // constructor 50 * MyGUI(...); 51 * 52 * // message IDs 53 * enum { 54 * ID_THREAD_EVENT = FXWhatEver::ID_LAST, 55 * ID_LAST }; 56 * 57 * // message handler 58 * long onThreadEvent(FXObject*, FXSelector, void*); 59 * 60 * // thread event object 61 * FXThreadEvent m_threadEvent; 62 * }; 63 * 64 * GUI_thread.cpp: 65 * ============== 66 * 67 * // message map 68 * FXDEFMAP(MyGUI, FXWhatEver) = { 69 * FXMAPFUNC(SEL_THREAD_EVENT, MyGUI::ID_THREAD_EVENT, MyGUI::onThreadEvent) 70 * }; 71 * 72 * // constructor 73 * MyGUI::MyGUI(...) 74 * { 75 * m_threadEvent.setTarget(this), 76 * m_threadEvent.setSelector(ID_THREAD_EVENT); 77 * } 78 * 79 * // message handler 80 * long onThreadEvent(FXObject*, FXSelector, void*) 81 * { 82 * do something with the GUI 83 * } 84 * 85 * Worker_thread.cpp: 86 * ================= 87 * 88 * int threadFunction(...) 89 * { 90 * FXThreadEvent* pThreadEvent = (FXThreadEvent*)(ptr); 91 * 92 * while (not_finished) { 93 * // work hard 94 * ... 95 * 96 * // wake up GUI 97 * if (something_happened_and_the_GUI_needs_to_know_it) { 98 * pThreadEvent.signal(); 99 * } 100 * } 101 * 102 * ... 103 * } 104 * 105 */ 106 class /*FXAPI */FXThreadEvent : public FXBaseObject { 107 FXDECLARE(FXThreadEvent) 108 109 private: 110 FXThreadEventHandle event; 111 112 protected: 113 FXThreadEvent(const FXThreadEvent&); 114 FXThreadEvent& operator=(const FXThreadEvent&); 115 116 public: 117 enum { 118 ID_THREAD_EVENT = FXBaseObject::ID_LAST, 119 ID_LAST 120 }; 121 122 public: 123 long onThreadSignal(FXObject*, FXSelector, void*); 124 long onThreadEvent(FXObject*, FXSelector, void*); 125 126 public: 127 /// Construct an object capable of signaling the main FOX event loop 128 FXThreadEvent(FXObject* tgt = NULL, FXSelector sel = 0); 129 130 /** 131 * Signal the event - using the SEL_THREAD FXSelector type 132 * 133 * This is meant to be called from the worker thread - it sends a mesage to 134 * the target, which is in another thread. 135 */ 136 void signal(); 137 138 /** 139 * Signal the event - using the specified FXSelector 140 * 141 * This is meant to be called from the worker thread - it sends a mesage to 142 * the target, which is in another thread. 143 */ 144 void signal(FXuint seltype); 145 146 /// destructor 147 virtual ~FXThreadEvent(); 148 }; 149 150 } // namespace FXEX 151 152 153 #endif 154 155 /****************************************************************************/ 156 157