Salome HOME
Make result part as a container of the document
[modules/shaper.git] / src / PyInterp / PyInterp_Request.h
1
2
3 #ifndef PYINTERP_REQUEST_H
4 #define PYINTERP_REQUEST_H
5
6 #include "PyInterp.h"
7 #include "PyInterp_Event.h"
8
9 #include <QMutex>
10 #include <QObject>
11
12 class PyInterp_Interp;
13 class PyInterp_Watcher;
14 class PyInterp_Dispatcher;
15 class PyInterp_ExecuteEvent;
16 class PyConsole_Editor;
17
18 class PYINTERP_EXPORT PyInterp_Request
19 {
20   friend class PyInterp_Dispatcher;
21   friend class PyInterp_ExecuteEvent;
22
23   PyInterp_Request();
24   PyInterp_Request( const PyInterp_Request& );
25
26 protected:
27   virtual ~PyInterp_Request() {};
28   // protected destructor - to control deletion of requests
29
30 public:
31   PyInterp_Request( QObject* listener, bool sync = false )
32     : myIsSync( sync ), myListener( listener ) {};
33
34   static void     Destroy( PyInterp_Request* );
35   // Deletes a request
36
37   bool            IsSync() const { return myIsSync; }
38   // Returns true if this request should be processed synchronously,
39   // without putting it to a queue
40
41 protected:
42   virtual void    safeExecute();
43
44   virtual void    execute() = 0;
45   // Should be redefined in successors, contains actual request code
46
47   virtual QEvent* createEvent();
48   // This method can be overridden to customize notification event creation
49
50   virtual void    processEvent( QObject* );
51
52   QObject*        listener() const { return myListener; }
53   void            setListener( QObject* );
54
55 private:
56   void            process();
57
58 private:
59   QMutex          myMutex;
60   bool            myIsSync;
61   QObject*        myListener;
62 };
63
64 class PYINTERP_EXPORT PyInterp_LockRequest : public PyInterp_Request
65 {
66 public:
67
68   PyInterp_LockRequest( PyInterp_Interp* interp, QObject* listener = 0, bool sync = false )
69     : PyInterp_Request( listener, sync ), myInterp( interp )
70   {}
71
72 protected:
73   PyInterp_Interp*  getInterp() const { return myInterp; }
74
75   virtual void      safeExecute();
76
77 private:
78   PyInterp_Interp*  myInterp;
79 };
80
81 #endif // PYINTERP_REQUEST_H