|
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
|
00001 /********************************************************************************
00002 * *
00003 * Base type for threadable objects *
00004 * *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or *
00009 * modify it under the terms of the GNU Lesser General Public *
00010 * License as published by the Free Software Foundation; either *
00011 * version 2.1 of the License, or (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 GNU *
00016 * Lesser General Public License for more details. *
00017 * *
00018 * You should have received a copy of the GNU Lesser General Public *
00019 * License along with this library; if not, write to the Free Software *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
00021 *********************************************************************************/
00022 #ifndef FXTHREADEDOBJECT_H
00023 #define FXTHREADEDOBJECT_H
00024
00025 #ifndef FXOBJECT_H
00026 #include <fox/FXObject.h>
00027 using namespace FX;
00028 #endif
00029 namespace FXEX {
00030 class FXSynchronise;
00031 class FXThreadEvent;
00032 class FXMutex;
00033
00034 /**
00035 * FXThreadedObject is the base class for synchronisation object, for thread-aware classes
00036 */
00037 class FXAPI FXThreadedObject : public FXObject {
00038 FXDECLARE_ABSTRACT(FXThreadedObject)
00039 friend class FXSynchronise;
00040
00041 private:
00042 FXObject *target; // target object
00043 FXSelector message; // message ID
00044 FXThreadEvent *event; // resource for signaling main/GUI thread from this thread
00045
00046 protected:
00047 FXMutex *mutex; // used to control access to some public methods
00048
00049 public:
00050 enum {
00051 ID_THREADED_OBJECT,
00052 ID_LAST
00053 };
00054
00055 public:
00056 long onThreadSignal(FXObject*,FXSelector,void*);
00057 long onThreadEvent(FXObject*,FXSelector,void*);
00058
00059 protected:
00060 /// A runnable just implements the basic stuff for threads
00061 FXThreadedObject(FXObject *tgt=NULL,FXSelector sel=0);
00062
00063 public:
00064 /// application object
00065 FXApp* getApp();
00066
00067 /// set to new target object - thread safe
00068 void setTarget(FXObject *tgt);
00069
00070 /// get the target - thread safe
00071 FXObject* getTarget();
00072
00073 /// set the selector - thread safe
00074 void setSelector(FXSelector sel);
00075
00076 /// get the selector - thread safe
00077 FXSelector getSelector();
00078
00079 /**
00080 * Signal the main thread
00081 * This is meant to be called from the worker thread
00082 */
00083 void signal();
00084
00085 /**
00086 * Signal the main thread using a specific FXSelector
00087 * This is meant to be called from the worker thread
00088 */
00089 void signal(FXuint seltype);
00090
00091 /// dtor
00092 virtual ~FXThreadedObject();
00093 };
00094
00095 } // namespace FXEX
00096 #endif // FXTHREADEDOBJECT_H