![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * I n t e r - T h r e a d M e s s a g i n g C h a n n e l * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2006,2010 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************/ 00021 #ifndef FXMESSAGECHANNEL_H 00022 #define FXMESSAGECHANNEL_H 00023 00024 #ifndef FXOBJECT_H 00025 #include "FXObject.h" 00026 #endif 00027 00028 00029 namespace FX { 00030 00031 class FXApp; 00032 00033 00034 /** 00035 * FXMessageChannel manages a messaging channel between a worker thread and the main 00036 * user-interface thread. 00037 * When an FXMessageChannel is constructed, it automatically calls addInput() function to 00038 * register itself as the message handler for the SEL_IO_READ message from FXApp. 00039 * Likewise, when FXMessageChannel is destroyed, it calls removeInput() to remove itself 00040 * as the message handler for the SEL_IO_READ message from FXApp. 00041 * When a worker thread calls the message() API, the target and message, as well 00042 * as optional message data, are written into the message channel. 00043 * The main user-interface thread is awakened and subsequently dispatches to the 00044 * onMessage handler of FXMessageChannel, which reads the target, selector, and optional 00045 * message data from the channel and then dispatches to this target using the given 00046 * selector. 00047 * Thus, FXMessageChannel provides a worker thread with a way to asynchronously invoke 00048 * any message handler in the context of the main user-interface thread. 00049 * If the size of the optional data is zero, the message handler will be passed a 00050 * NULL pointer. 00051 */ 00052 class FXAPI FXMessageChannel : public FXObject { 00053 FXDECLARE(FXMessageChannel) 00054 private: 00055 FXApp *app; 00056 protected: 00057 FXInputHandle h[3]; 00058 FXMutex m; 00059 protected: 00060 FXMessageChannel(); 00061 private: 00062 FXMessageChannel(const FXMessageChannel&); 00063 FXMessageChannel& operator=(const FXMessageChannel&); 00064 public: 00065 enum{ 00066 ID_IO_READ=1, 00067 ID_LAST 00068 }; 00069 public: 00070 long onMessage(FXObject*,FXSelector,void*); 00071 public: 00072 00073 /// Initialize message channel 00074 FXMessageChannel(FXApp* a); 00075 00076 /// Get application pointer 00077 FXApp* getApp() const { return app; } 00078 00079 /// Send a message msg comprising of FXSEL(type,id) to a target tgt, and pass optional data of size bytes 00080 FXbool message(FXObject* tgt,FXSelector msg,const void* data=NULL,FXint size=0); 00081 00082 /// Clean up message channel 00083 virtual ~FXMessageChannel(); 00084 }; 00085 00086 } 00087 00088 #endif 00089 00090
|
|