Salome HOME
Merge branch 'master' of ssh://git.salome-platform.org/modules/gui
[modules/gui.git] / src / PyInterp / PyInterp_Request.h
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : PyInterp_Request.h
23 //  Author : Sergey Anikin (OCC), Adrien Bruneton (CEA/DEN)
24 //  Module : GUI
25
26 #ifndef PYINTERP_REQUEST_H
27 #define PYINTERP_REQUEST_H
28
29 #include "PyInterp.h"
30 #include "PyInterp_Event.h"
31
32 #include <QMutex>
33 #include <QObject>
34
35 class PyInterp_Interp;
36 class PyInterp_Watcher;
37 class PyInterp_Dispatcher;
38 class PyInterp_ExecuteEvent;
39 class PyConsole_Editor;
40
41 class PYINTERP_EXPORT PyInterp_Request
42 {
43   friend class PyInterp_Dispatcher;
44   friend class PyInterp_ExecuteEvent;
45
46 private:
47   PyInterp_Request();
48   PyInterp_Request( const PyInterp_Request& );
49
50 protected:
51   virtual ~PyInterp_Request() {};
52   // protected destructor - to control deletion of requests
53
54 public:
55   PyInterp_Request( QObject* listener, bool sync = true )
56     : myIsSync( sync ), myListener( listener ) {};
57
58   static void     Destroy( PyInterp_Request* );
59   // Deletes a request
60
61   bool            IsSync() const { return myIsSync; }
62   // Returns true if this request should be processed synchronously,
63   // without putting it to a queue
64
65 protected:
66   virtual void    safeExecute();
67
68   virtual void    execute() = 0;
69   // Should be redefined in successors, contains actual request code
70
71   virtual QEvent* createEvent();
72   // This method can be overridden to customize notification event creation
73
74   virtual void    processEvent( QObject* );
75
76   QObject*        listener() const { return myListener; }
77   void            setListener( QObject* );
78
79 private:
80   void            process();
81
82 private:
83   QMutex          myMutex;
84   bool            myIsSync;
85   QObject*        myListener;
86 };
87
88 class PYINTERP_EXPORT PyInterp_LockRequest : public PyInterp_Request
89 {
90 public:
91
92   PyInterp_LockRequest( PyInterp_Interp* interp, QObject* listener=0, bool sync=true )
93     : PyInterp_Request( listener, sync ), myInterp( interp )
94   {}
95
96 protected:
97   PyInterp_Interp*  getInterp() const { return myInterp; }
98
99   virtual void      safeExecute();
100
101 private:
102   PyInterp_Interp*  myInterp;
103 };
104
105 #endif // PYINTERP_REQUEST_H