Version: 9.16.0
SALOME_Event.h
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20// KERNEL SALOME_Event : Define event posting mechanism
21// File : SALOME_Event.h
22// Author : Sergey ANIKIN
23//
24#ifndef SALOME_EVENT_H
25#define SALOME_EVENT_H
26
27#include "Event.h"
28
29#include <QEvent>
30
32#define SALOME_EVENT QEvent::Type( QEvent::User + 10000 )
33
35{
36public:
37 SALOME_CustomEvent( int type );
38 SALOME_CustomEvent( QEvent::Type type, void* data );
39
40 void* data() const;
41 void setData( void* data );
42
43private:
44 void *d;
45};
46
47class QSemaphore;
48
50{
51public:
53 virtual ~SALOME_Event();
54
55 void ExecutePostedEvent();
56 virtual void Execute() = 0;
57
58 static bool IsSessionThread();
59 void process();
60
61protected:
62 void processed();
63 static void GetSessionThread();
64
65private:
66 QSemaphore* mySemaphore;
67};
68
69template<class TObject, typename TRes> class TMemFunEvent : public SALOME_Event
70{
71public:
72 typedef TRes TResult;
74 typedef TResult (TObject::* TAction)();
75 TMemFunEvent(TObject* theObject, TAction theAction,
76 TResult theResult = TResult()):
77 myObject(theObject),
78 myAction(theAction),
79 myResult(theResult)
80 {}
81 virtual void Execute()
82 {
84 }
85private:
86 TObject* myObject;
88};
89
90template<class TObject> class TVoidMemFunEvent : public SALOME_Event
91{
92public:
93 typedef void (TObject::* TAction)();
94 TVoidMemFunEvent(TObject* theObject, TAction theAction):
95 myObject(theObject),
96 myAction(theAction)
97 {}
98 virtual void Execute()
99 {
100 (myObject->*myAction)();
101 }
102private:
103 TObject* myObject;
105};
106
107template<class TObject, typename TRes, typename TArg, typename TStoreArg = TArg>
109{
110public:
111 typedef TRes TResult;
113 typedef TResult (TObject::* TAction)(TArg);
114 TMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg,
115 TResult theResult = TResult()):
116 myObject(theObject),
117 myAction(theAction),
118 myResult(theResult),
119 myArg(theArg)
120 {}
121 virtual void Execute()
122 {
124 }
125private:
126 TObject* myObject;
128 TStoreArg myArg;
129};
130
131template<class TObject, typename TArg, typename TStoreArg = TArg>
133{
134public:
135 typedef void (TObject::* TAction)(TArg);
136 TVoidMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg):
137 myObject(theObject),
138 myAction(theAction),
139 myArg(theArg)
140 {}
141 virtual void Execute()
142 {
144 }
145private:
146 TObject* myObject;
148 TStoreArg myArg;
149};
150
151template<class TObject, typename TRes, typename TArg, typename TArg1, typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
153{
154public:
155 typedef TRes TResult;
157 typedef TResult (TObject::* TAction)(TArg,TArg1);
158 TMemFun2ArgEvent(TObject* theObject, TAction theAction,
159 TArg theArg, TArg1 theArg1,
160 TResult theResult = TResult()):
161 myObject(theObject),
162 myAction(theAction),
163 myResult(theResult),
164 myArg(theArg),
165 myArg1(theArg1)
166 {}
167 virtual void Execute()
168 {
170 }
171private:
172 TObject* myObject;
174 TStoreArg myArg;
175 TStoreArg1 myArg1;
176};
177
178template<class TObject, typename TArg, typename TArg1, typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
180{
181public:
182 typedef void (TObject::* TAction)(TArg,TArg1);
183 TVoidMemFun2ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1):
184 myObject(theObject),
185 myAction(theAction),
186 myArg(theArg),
187 myArg1(theArg1)
188 {}
189 virtual void Execute()
190 {
192 }
193private:
194 TObject* myObject;
196 TStoreArg myArg;
197 TStoreArg1 myArg1;
198};
199
200template<class TEvent> inline typename TEvent::TResult ProcessEvent(TEvent* theEvent)
201{
202 typename TEvent::TResult aResult;
204 theEvent->Execute();
205 aResult = theEvent->myResult;
206 }
207 else {
208 theEvent->process();
209 aResult = theEvent->myResult;
210 }
211 delete theEvent;
212 return aResult;
213}
214
215inline void ProcessVoidEvent(SALOME_Event* theEvent)
216{
218 theEvent->Execute();
219 }
220 else {
221 theEvent->process();
222 }
223 delete theEvent;
224}
225
226#endif // SALOME_EVENT_H
#define EVENT_EXPORT
Definition: Event.h:33
TEvent::TResult ProcessEvent(TEvent *theEvent)
Definition: SALOME_Event.h:200
void ProcessVoidEvent(SALOME_Event *theEvent)
Definition: SALOME_Event.h:215
Generic event class for user-defined events.
Definition: SALOME_Event.h:35
void * d
internal data
Definition: SALOME_Event.h:44
The class which encapsulates data and functionality required for posting component-specific events to...
Definition: SALOME_Event.h:50
virtual void Execute()=0
This method should be redefined in the successor classes to do real work.
void process()
Post the event and wait for its completion. process() should be called from a secondary thread only.
Definition: SALOME_Event.cxx:243
QSemaphore * mySemaphore
internal semaphore
Definition: SALOME_Event.h:66
static bool IsSessionThread()
Check if the processing is in the main application thread.
Definition: SALOME_Event.cxx:192
Template class for event which calls the function with one argument and returning result.
Definition: SALOME_Event.h:109
TResult myResult
Definition: SALOME_Event.h:112
TResult(TObject::* TAction)(TArg)
Definition: SALOME_Event.h:113
TRes TResult
Definition: SALOME_Event.h:111
TStoreArg myArg
Definition: SALOME_Event.h:128
TAction myAction
Definition: SALOME_Event.h:127
TObject * myObject
Definition: SALOME_Event.h:126
TMemFun1ArgEvent(TObject *theObject, TAction theAction, TArg theArg, TResult theResult=TResult())
Definition: SALOME_Event.h:114
virtual void Execute()
This method should be redefined in the successor classes to do real work.
Definition: SALOME_Event.h:121
Template class for event which calls the function with two arguments and returning result.
Definition: SALOME_Event.h:153
TObject * myObject
Definition: SALOME_Event.h:172
virtual void Execute()
This method should be redefined in the successor classes to do real work.
Definition: SALOME_Event.h:167
TResult(TObject::* TAction)(TArg, TArg1)
Definition: SALOME_Event.h:157
TMemFun2ArgEvent(TObject *theObject, TAction theAction, TArg theArg, TArg1 theArg1, TResult theResult=TResult())
Definition: SALOME_Event.h:158
TStoreArg myArg
Definition: SALOME_Event.h:174
TRes TResult
Definition: SALOME_Event.h:155
TAction myAction
Definition: SALOME_Event.h:173
TResult myResult
Definition: SALOME_Event.h:156
TStoreArg1 myArg1
Definition: SALOME_Event.h:175
Template class for event which calls the function without arguments and returning result.
Definition: SALOME_Event.h:70
TAction myAction
Definition: SALOME_Event.h:87
TResult(TObject::* TAction)()
Definition: SALOME_Event.h:74
TResult myResult
Definition: SALOME_Event.h:73
TObject * myObject
Definition: SALOME_Event.h:86
TMemFunEvent(TObject *theObject, TAction theAction, TResult theResult=TResult())
Definition: SALOME_Event.h:75
virtual void Execute()
This method should be redefined in the successor classes to do real work.
Definition: SALOME_Event.h:81
TRes TResult
Definition: SALOME_Event.h:72
Template class for event which calls the function with one argument and without return value.
Definition: SALOME_Event.h:133
TObject * myObject
Definition: SALOME_Event.h:146
TStoreArg myArg
Definition: SALOME_Event.h:148
TVoidMemFun1ArgEvent(TObject *theObject, TAction theAction, TArg theArg)
Definition: SALOME_Event.h:136
TAction myAction
Definition: SALOME_Event.h:147
virtual void Execute()
This method should be redefined in the successor classes to do real work.
Definition: SALOME_Event.h:141
void(TObject::* TAction)(TArg)
Definition: SALOME_Event.h:135
Template class for event which calls the function with two arguments and without return value.
Definition: SALOME_Event.h:180
TVoidMemFun2ArgEvent(TObject *theObject, TAction theAction, TArg theArg, TArg1 theArg1)
Definition: SALOME_Event.h:183
void(TObject::* TAction)(TArg, TArg1)
Definition: SALOME_Event.h:182
TStoreArg myArg
Definition: SALOME_Event.h:196
TAction myAction
Definition: SALOME_Event.h:195
virtual void Execute()
This method should be redefined in the successor classes to do real work.
Definition: SALOME_Event.h:189
TStoreArg1 myArg1
Definition: SALOME_Event.h:197
TObject * myObject
Definition: SALOME_Event.h:194
Template class for event which calls the function without arguments and without return value.
Definition: SALOME_Event.h:91
TAction myAction
Definition: SALOME_Event.h:104
TObject * myObject
Definition: SALOME_Event.h:103
virtual void Execute()
This method should be redefined in the successor classes to do real work.
Definition: SALOME_Event.h:98
void(TObject::* TAction)()
Definition: SALOME_Event.h:93
TVoidMemFunEvent(TObject *theObject, TAction theAction)
Definition: SALOME_Event.h:94
int Type
Definition: VTKViewer_Actor.h:62