Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXGUISignal.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * S i g n a l G U I T h r e a d *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2005,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXGUISignal.h,v 1.6.2.1 2006/05/24 12:08:45 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXGUISIGNAL_H
25 #define FXGUISIGNAL_H
26 
27 #ifndef FXOBJECT_H
28 #include "FXObject.h"
29 #endif
30 
31 namespace FX {
32 
33 class FXApp;
34 
35 
36 /**
37 * An FXGUISignal manages a waitable object which is used to awaken the
38 * main user-interface thread from a worker thread. When a FXGUISignal is
39 * constructed, it automatically calls addInput() function to register itself
40 * as the message handler for the SEL_IO_READ message from FXApp. Likewise,
41 * when FXGUISignal is destroyed, it calls removeInput() to remove itself as
42 * the message handler for the SEL_IO_READ message from FXApp.
43 * When a worker thread calls the signal() API, the waitable object managed by
44 * FXGUISignal is set to the signaled state, after which the worker thread
45 * continues execution immediately.
46 * Meanwhile, the main user-interface thread is awakened because one of its
47 * inputs has become signaled. It invokes the onSignal handler of FXGUISignal,
48 * which clears the waitable object's state and subsequently dispatches to the
49 * target of FXGUISignal through the SEL_IO_READ message.
50 * Thus, the SEL_IO_READ handler in FXGUISignal is executed in the context of
51 * the user-interface thread, allowing any user-interaction without blocking
52 * a worker thread.
53 * In a typical scenario, a worker thread updates some common data structure,
54 * then notifies the main user-interface thread (via the FXGUISignal) to update
55 * the user interface and perform some appropriate action.
56 */
57 class FXAPI FXGUISignal : public FXObject {
59 private:
60  FXApp *app; // Application
61 protected:
62  FXObject *target; // Target object
63  void *data; // User data
64  FXSelector message; // Message id
65 private:
66 #ifndef WIN32
67  FXInputHandle fd[2];
68 #else
69  FXInputHandle event;
70 #endif
71 protected:
73 private:
74  FXGUISignal(const FXGUISignal&);
75  FXGUISignal& operator=(const FXGUISignal&);
76 public:
77  enum{
78  ID_IO_READ=0,
79  ID_LAST
80  };
81 public:
82  long onSignal(FXObject*,FXSelector,void*);
83 public:
84 
85  /// Constructor
86  FXGUISignal(FXApp* a,FXObject* tgt=NULL,FXSelector sel=0,void* ptr=NULL);
87 
88  /// Get application
89  FXApp* getApp() const { return app; }
90 
91  /// Set the message target object
92  void setTarget(FXObject *t){ target=t; }
93 
94  /// Get the message target object, if any
95  FXObject* getTarget() const { return target; }
96 
97  /// Set the message identifier
98  void setSelector(FXSelector sel){ message=sel; }
99 
100  /// Get the message identifier
101  FXSelector getSelector() const { return message; }
102 
103  /// Set user data pointer
104  void setData(void *ptr){ data=ptr; }
105 
106  /// Get user data pointer
107  void* getData() const { return data; }
108 
109  /**
110  * Signal the event; this API may be called by the worker thread
111  * to send a message to the user-interface thread.
112  */
113  void signal();
114 
115  /// Destructor
116  virtual ~FXGUISignal();
117  };
118 
119 }
120 
121 #endif
122 
123 
FXuint FXSelector
Association key.
Definition: FXObject.h:53
#define FXAPI
Definition: fxdefs.h:122
Application Object.
Definition: FXApp.h:158
#define NULL
Definition: fxdefs.h:41
Definition: FX4Splitter.h:31
An FXGUISignal manages a waitable object which is used to awaken the main user-interface thread from ...
Definition: FXGUISignal.h:57
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
FXint FXInputHandle
Definition: fxdefs.h:468
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92

Copyright © 1997-2005 Jeroen van der Zijp