1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : PyInterp_Dispatcher.h
24 // Author : Sergey Anikin, OCC
27 #ifndef PYINTERP_DISPATCHER_H
28 #define PYINTERP_DISPATCHER_H
30 #include "PyInterp.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
39 class PyInterp_Interp;
40 class PyInterp_Watcher;
41 class PyInterp_Dispatcher;
42 class PyInterp_ExecuteEvent;
44 class PYINTERP_EXPORT PyInterp_Request
46 friend class PyInterp_Dispatcher;
47 friend class PyInterp_ExecuteEvent;
50 PyInterp_Request( const PyInterp_Request& );
53 virtual ~PyInterp_Request() {};
54 // protected destructor - to control deletion of requests
57 PyInterp_Request( QObject* listener, bool sync = false )
58 : myIsSync( sync ), myListener( listener ) {};
60 static void Destroy( PyInterp_Request* );
63 bool IsSync() const { return myIsSync; }
64 // Returns true if this request should be processed synchronously,
65 // without putting it to a queue
68 virtual void safeExecute();
70 virtual void execute() = 0;
71 // Should be redefined in successors, contains actual request code
73 virtual QEvent* createEvent() const;
74 // This method can be overridden to customize notification event creation
76 virtual void processEvent( QObject* );
78 QObject* listener() const { return myListener; }
79 void setListener( QObject* );
90 class PYINTERP_EXPORT PyInterp_LockRequest : public PyInterp_Request
93 PyInterp_LockRequest( PyInterp_Interp* interp, QObject* listener = 0, bool sync = false )
94 : PyInterp_Request( listener, sync ), myInterp( interp ) {}
97 PyInterp_Interp* getInterp() const { return myInterp; }
99 virtual void safeExecute();
102 PyInterp_Interp* myInterp;
105 class PYINTERP_EXPORT PyInterp_Event : public QEvent
108 PyInterp_Event( const PyInterp_Event& );
112 enum { ES_NOTIFY = QEvent::User + 5000, ES_OK, ES_ERROR, ES_INCOMPLETE, ES_LAST };
114 PyInterp_Event( int type, PyInterp_Request* request )
115 : QEvent( (QEvent::Type)type ), myRequest( request ) {}
117 virtual ~PyInterp_Event();
119 PyInterp_Request* GetRequest() const { return myRequest; }
120 operator PyInterp_Request*() const { return myRequest; }
123 PyInterp_Request* myRequest;
126 class PYINTERP_EXPORT PyInterp_Dispatcher : protected QThread
128 PyInterp_Dispatcher(); // private constructor
131 static PyInterp_Dispatcher* Get();
133 virtual ~PyInterp_Dispatcher();
136 void Exec( PyInterp_Request* );
140 void processRequest( PyInterp_Request* );
141 void objectDestroyed( const QObject* );
144 typedef PyInterp_Request* RequestPtr;
146 QQueue<RequestPtr> myQueue;
148 PyInterp_Watcher* myWatcher;
150 static PyInterp_Dispatcher* myInstance;
152 friend class PyInterp_Watcher;
155 #endif // PYINTERP_DISPATCHER_H