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 class PYINTERP_EXPORT PyInterp_Request
30 friend class PyInterp_Dispatcher;
33 PyInterp_Request( const PyInterp_Request& );
36 virtual ~PyInterp_Request() {};
37 // protected destructor - to control deletion of requests
40 PyInterp_Request( QObject* listener, bool sync = false )
41 : myIsSync( sync ), myListener( listener ), myEvent( 0 ) {};
43 static void Destroy( PyInterp_Request* );
46 bool IsSync() const { return myIsSync; }
47 // Returns true if this request should be processed synchronously,
48 // without putting it to a queue
51 virtual void safeExecute();
53 virtual void execute() = 0;
54 // Should be redefined in successors, contains actual request code
56 virtual QEvent* createEvent() const;
57 // This method can be overridden to customize notification event creation
61 QObject* getListener() const { return myListener; }
62 void setListener( QObject* );
73 class PYINTERP_EXPORT PyInterp_LockRequest : public PyInterp_Request
76 PyInterp_LockRequest( PyInterp_base* interp, QObject* listener = 0, bool sync = false )
77 : PyInterp_Request( listener, sync ), myInterp( interp ) {}
80 PyInterp_base* getInterp() const { return myInterp; }
82 virtual void safeExecute();
85 PyInterp_base* myInterp;
88 class PYINTERP_EXPORT PyInterp_Event : public QCustomEvent
91 PyInterp_Event( const PyInterp_Event& );
94 enum { NOTIFY = QEvent::User + 5000, OK, ERROR, INCOMPLETE, LAST };
96 PyInterp_Event( int type, PyInterp_Request* request )
97 : QCustomEvent( (QEvent::Type)type ), myRequest( request ) {}
99 virtual ~PyInterp_Event();
101 PyInterp_Request* GetRequest() const { return myRequest; }
102 operator PyInterp_Request*() const { return myRequest; }
105 PyInterp_Request* myRequest;
108 class PYINTERP_EXPORT PyInterp_Dispatcher : protected QThread
110 PyInterp_Dispatcher(); // private constructor
113 static PyInterp_Dispatcher* Get();
115 virtual ~PyInterp_Dispatcher();
118 void Exec( PyInterp_Request* );
122 void processRequest( PyInterp_Request* );
123 void objectDestroyed( const QObject* );
126 typedef PyInterp_Request* RequestPtr;
128 std::list<RequestPtr> myQueue;
130 PyInterp_Watcher* myWatcher;
132 static PyInterp_Dispatcher* myInstance;
134 friend class PyInterp_Watcher;