1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2005 CEA/DEN, EDF R&D
7 // File : PyInterp_Dispatcher.h
8 // Author : Sergey Anikin, OCC
12 #ifndef _PYINTERP_DISPATCHER_H_
13 #define _PYINTERP_DISPATCHER_H_
25 class PyInterp_Watcher;
26 class PyInterp_Dispatcher;
28 //////////////////////////////////////////////////////////
29 // class : PyInterp_Request
30 //////////////////////////////////////////////////////////
31 class PYINTERP_EXPORT PyInterp_Request
33 friend class PyInterp_Dispatcher;
36 PyInterp_Request( const PyInterp_Request& );
39 virtual ~PyInterp_Request() {};
40 // protected destructor - to control deletion of requests
43 PyInterp_Request( QObject* listener, bool sync = false )
44 : myIsSync( sync ), myListener( listener ), myEvent( 0 ) {};
46 static void Destroy( PyInterp_Request* );
49 bool IsSync() const { return myIsSync; }
50 // Returns true if this request should be processed synchronously,
51 // without putting it to a queue
54 virtual void safeExecute();
56 virtual void execute() = 0;
57 // Should be redefined in successors, contains actual request code
59 virtual QEvent* createEvent() const;
60 // This method can be overridden to customize notification event creation
64 QObject* getListener() const { return myListener; }
65 void setListener( QObject* );
76 class PYINTERP_EXPORT PyInterp_LockRequest : public PyInterp_Request
79 PyInterp_LockRequest( PyInterp_base* interp, QObject* listener = 0, bool sync = false )
80 : PyInterp_Request( listener, sync ), myInterp( interp ) {}
83 PyInterp_base* getInterp() const { return myInterp; }
85 virtual void safeExecute();
88 PyInterp_base* myInterp;
91 //////////////////////////////////////////////////////////
92 // class : PyInterp_Event
93 //////////////////////////////////////////////////////////
94 class PYINTERP_EXPORT PyInterp_Event : public QCustomEvent
97 PyInterp_Event( const PyInterp_Event& );
100 enum { NOTIFY = QEvent::User + 5000, OK, ERROR, INCOMPLETE, LAST };
102 PyInterp_Event( int type, PyInterp_Request* request )
103 : QCustomEvent( (QEvent::Type)type ), myRequest( request ) {}
105 virtual ~PyInterp_Event();
107 PyInterp_Request* GetRequest() const { return myRequest; }
108 operator PyInterp_Request*() const { return myRequest; }
111 PyInterp_Request* myRequest;
114 //////////////////////////////////////////////////////////
115 // class : PyInterp_Dispatcher
116 //////////////////////////////////////////////////////////
117 class PYINTERP_EXPORT PyInterp_Dispatcher : protected QThread
119 PyInterp_Dispatcher(); // private constructor
122 static PyInterp_Dispatcher* Get();
124 virtual ~PyInterp_Dispatcher();
127 void Exec( PyInterp_Request* );
131 void processRequest( PyInterp_Request* );
132 void objectDestroyed( const QObject* );
135 typedef PyInterp_Request* RequestPtr;
137 std::list<RequestPtr> myQueue;
139 PyInterp_Watcher* myWatcher;
141 static PyInterp_Dispatcher* myInstance;
143 friend class PyInterp_Watcher;