Salome HOME
Models for object browser created
[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 // PYINTERP_EXPORT
19 class PyInterp_Request
20 {
21   friend class PyInterp_Dispatcher;
22   friend class PyInterp_ExecuteEvent;
23
24   PyInterp_Request();
25   PyInterp_Request( const PyInterp_Request& );
26
27 protected:
28   virtual ~PyInterp_Request() {};
29   // protected destructor - to control deletion of requests
30
31 public:
32   PyInterp_Request( QObject* listener, bool sync = false )
33     : myIsSync( sync ), myListener( listener ) {};
34
35   static void     Destroy( PyInterp_Request* );
36   // Deletes a request
37
38   bool            IsSync() const { return myIsSync; }
39   // Returns true if this request should be processed synchronously,
40   // without putting it to a queue
41
42 protected:
43   virtual void    safeExecute();
44
45   virtual void    execute() = 0;
46   // Should be redefined in successors, contains actual request code
47
48   virtual QEvent* createEvent();
49   // This method can be overridden to customize notification event creation
50
51   virtual void    processEvent( QObject* );
52
53   QObject*        listener() const { return myListener; }
54   void            setListener( QObject* );
55
56 private:
57   void            process();
58
59 private:
60   QMutex          myMutex;
61   bool            myIsSync;
62   QObject*        myListener;
63 };
64
65 //PYINTERP_EXPORT
66 class PyInterp_LockRequest : public PyInterp_Request
67 {
68 public:
69
70   PyInterp_LockRequest( PyInterp_Interp* interp, QObject* listener = 0, bool sync = false )
71     : PyInterp_Request( listener, sync ), myInterp( interp )
72   {}
73
74 protected:
75   PyInterp_Interp*  getInterp() const { return myInterp; }
76
77   virtual void      safeExecute();
78
79 private:
80   PyInterp_Interp*  myInterp;
81 };
82
83 #endif // PYINTERP_REQUEST_H