1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // KERNEL SALOME_Event : Define event posting mechanism
23 // File : SALOME_Event.h
24 // Author : Sergey ANIKIN
26 #ifndef SALOME_EVENT_H
27 #define SALOME_EVENT_H
33 //! SALOME custom event type
34 #define SALOME_EVENT QEvent::Type( QEvent::User + 10000 )
36 class EVENT_EXPORT SALOME_CustomEvent : public QEvent
39 SALOME_CustomEvent( int type );
40 SALOME_CustomEvent( QEvent::Type type, void* data );
43 void setData( void* data );
46 void *d; //!< internal data
51 class EVENT_EXPORT SALOME_Event
55 virtual ~SALOME_Event();
57 void ExecutePostedEvent();
58 virtual void Execute() = 0;
60 static bool IsSessionThread();
65 static void GetSessionThread();
68 QSemaphore* mySemaphore; //!< internal semaphore
71 template<class TObject, typename TRes> class TMemFunEvent : public SALOME_Event
76 typedef TResult (TObject::* TAction)();
77 TMemFunEvent(TObject* theObject, TAction theAction,
78 TResult theResult = TResult()):
83 virtual void Execute()
85 myResult = (myObject->*myAction)();
92 template<class TObject> class TVoidMemFunEvent : public SALOME_Event
95 typedef void (TObject::* TAction)();
96 TVoidMemFunEvent(TObject* theObject, TAction theAction):
100 virtual void Execute()
102 (myObject->*myAction)();
109 template<class TObject, typename TRes, typename TArg, typename TStoreArg = TArg>
110 class TMemFun1ArgEvent : public SALOME_Event
113 typedef TRes TResult;
115 typedef TResult (TObject::* TAction)(TArg);
116 TMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg,
117 TResult theResult = TResult()):
123 virtual void Execute()
125 myResult = (myObject->*myAction)(myArg);
133 template<class TObject, typename TArg, typename TStoreArg = TArg>
134 class TVoidMemFun1ArgEvent : public SALOME_Event
137 typedef void (TObject::* TAction)(TArg);
138 TVoidMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg):
143 virtual void Execute()
145 (myObject->*myAction)(myArg);
153 template<class TObject, typename TRes, typename TArg, typename TArg1, typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
154 class TMemFun2ArgEvent: public SALOME_Event
157 typedef TRes TResult;
159 typedef TResult (TObject::* TAction)(TArg,TArg1);
160 TMemFun2ArgEvent(TObject* theObject, TAction theAction,
161 TArg theArg, TArg1 theArg1,
162 TResult theResult = TResult()):
169 virtual void Execute()
171 myResult = (myObject->*myAction)(myArg,myArg1);
180 template<class TObject, typename TArg, typename TArg1, typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
181 class TVoidMemFun2ArgEvent : public SALOME_Event
184 typedef void (TObject::* TAction)(TArg,TArg1);
185 TVoidMemFun2ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1):
191 virtual void Execute()
193 (myObject->*myAction)(myArg,myArg1);
202 template<class TEvent> inline typename TEvent::TResult ProcessEvent(TEvent* theEvent)
204 typename TEvent::TResult aResult;
205 if(SALOME_Event::IsSessionThread()) {
207 aResult = theEvent->myResult;
211 aResult = theEvent->myResult;
217 inline void ProcessVoidEvent(SALOME_Event* theEvent)
219 if(SALOME_Event::IsSessionThread()) {
228 #endif // SALOME_EVENT_H