1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // KERNEL SALOME_Event : Define event posting mechanism
21 // File : SALOME_Event.h
22 // Author : Sergey ANIKIN
24 #ifndef SALOME_EVENT_H
25 #define SALOME_EVENT_H
31 //! SALOME custom event type
32 #define SALOME_EVENT QEvent::Type( QEvent::User + 10000 )
34 class EVENT_EXPORT SALOME_CustomEvent : public QEvent
37 SALOME_CustomEvent( int type );
38 SALOME_CustomEvent( QEvent::Type type, void* data );
41 void setData( void* data );
44 void *d; //!< internal data
49 class EVENT_EXPORT SALOME_Event
53 virtual ~SALOME_Event();
55 void ExecutePostedEvent();
56 virtual void Execute() = 0;
58 static bool IsSessionThread();
63 static void GetSessionThread();
66 QSemaphore* mySemaphore; //!< internal semaphore
69 template<class TObject, typename TRes> class TMemFunEvent : public SALOME_Event
74 typedef TResult (TObject::* TAction)();
75 TMemFunEvent(TObject* theObject, TAction theAction,
76 TResult theResult = TResult()):
81 virtual void Execute()
83 myResult = (myObject->*myAction)();
90 template<class TObject> class TVoidMemFunEvent : public SALOME_Event
93 typedef void (TObject::* TAction)();
94 TVoidMemFunEvent(TObject* theObject, TAction theAction):
98 virtual void Execute()
100 (myObject->*myAction)();
107 template<class TObject, typename TRes, typename TArg, typename TStoreArg = TArg>
108 class TMemFun1ArgEvent : public SALOME_Event
111 typedef TRes TResult;
113 typedef TResult (TObject::* TAction)(TArg);
114 TMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg,
115 TResult theResult = TResult()):
121 virtual void Execute()
123 myResult = (myObject->*myAction)(myArg);
131 template<class TObject, typename TArg, typename TStoreArg = TArg>
132 class TVoidMemFun1ArgEvent : public SALOME_Event
135 typedef void (TObject::* TAction)(TArg);
136 TVoidMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg):
141 virtual void Execute()
143 (myObject->*myAction)(myArg);
151 template<class TObject, typename TRes, typename TArg, typename TArg1, typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
152 class TMemFun2ArgEvent: public SALOME_Event
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()):
167 virtual void Execute()
169 myResult = (myObject->*myAction)(myArg,myArg1);
178 template<class TObject, typename TArg, typename TArg1, typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
179 class TVoidMemFun2ArgEvent : public SALOME_Event
182 typedef void (TObject::* TAction)(TArg,TArg1);
183 TVoidMemFun2ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1):
189 virtual void Execute()
191 (myObject->*myAction)(myArg,myArg1);
200 template<class TEvent> inline typename TEvent::TResult ProcessEvent(TEvent* theEvent)
202 typename TEvent::TResult aResult;
203 if(SALOME_Event::IsSessionThread()) {
205 aResult = theEvent->myResult;
209 aResult = theEvent->myResult;
215 inline void ProcessVoidEvent(SALOME_Event* theEvent)
217 if(SALOME_Event::IsSessionThread()) {
226 #endif // SALOME_EVENT_H