2 #ifndef PyEvent_PYEVENT_H
3 #define PyEvent_PYEVENT_H
9 //! SALOME custom event type
10 #define PyEvent_EVENT QEvent::Type( QEvent::User + 10000 )
12 class PYEVENT_EXPORT PyEvent_CustomEvent : public QEvent
15 PyEvent_CustomEvent( int type );
16 PyEvent_CustomEvent( QEvent::Type type, void* data );
19 void setData( void* data );
22 void *d; //!< internal data
27 class PYEVENT_EXPORT PyEvent_Event
31 virtual ~PyEvent_Event();
33 void ExecutePostedEvent();
34 virtual void Execute() = 0;
36 static bool IsSessionThread();
41 static void GetSessionThread();
44 QSemaphore* mySemaphore; //!< internal semaphore
47 template<class TObject, typename TRes> class TMemFunEvent : public PyEvent_Event
52 typedef TResult (TObject::* TAction)();
53 TMemFunEvent(TObject* theObject, TAction theAction,
54 TResult theResult = TResult()):
59 virtual void Execute()
61 myResult = (myObject->*myAction)();
68 template<class TObject> class TVoidMemFunEvent : public PyEvent_Event
71 typedef void (TObject::* TAction)();
72 TVoidMemFunEvent(TObject* theObject, TAction theAction):
76 virtual void Execute()
78 (myObject->*myAction)();
85 template<class TObject, typename TRes, typename TArg, typename TStoreArg = TArg>
86 class TMemFun1ArgEvent : public PyEvent_Event
91 typedef TResult (TObject::* TAction)(TArg);
92 TMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg,
93 TResult theResult = TResult()):
99 virtual void Execute()
101 myResult = (myObject->*myAction)(myArg);
109 template<class TObject, typename TArg, typename TStoreArg = TArg>
110 class TVoidMemFun1ArgEvent : public PyEvent_Event
113 typedef void (TObject::* TAction)(TArg);
114 TVoidMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg):
119 virtual void Execute()
121 (myObject->*myAction)(myArg);
129 template<class TObject, typename TRes, typename TArg, typename TArg1, typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
130 class TMemFun2ArgEvent: public PyEvent_Event
133 typedef TRes TResult;
135 typedef TResult (TObject::* TAction)(TArg,TArg1);
136 TMemFun2ArgEvent(TObject* theObject, TAction theAction,
137 TArg theArg, TArg1 theArg1,
138 TResult theResult = TResult()):
145 virtual void Execute()
147 myResult = (myObject->*myAction)(myArg,myArg1);
156 template<class TObject, typename TArg, typename TArg1, typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
157 class TVoidMemFun2ArgEvent : public PyEvent_Event
160 typedef void (TObject::* TAction)(TArg,TArg1);
161 TVoidMemFun2ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1):
167 virtual void Execute()
169 (myObject->*myAction)(myArg,myArg1);
178 template<class TEvent> inline typename TEvent::TResult ProcessEvent(TEvent* theEvent)
180 typename TEvent::TResult aResult;
181 if(PyEvent_Event::IsSessionThread()) {
183 aResult = theEvent->myResult;
187 aResult = theEvent->myResult;
193 inline void ProcessVoidEvent(PyEvent_Event* theEvent)
195 if(PyEvent_Event::IsSessionThread()) {
204 #endif // PyEvent_PYEVENT_H