1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
21 // File : PyInterp_Dispatcher.h
22 // Author : Sergey Anikin, OCC
25 #ifndef _PYINTERP_DISPATCHER_H_
26 #define _PYINTERP_DISPATCHER_H_
38 class PyInterp_Watcher;
39 class PyInterp_Dispatcher;
41 class PYINTERP_EXPORT PyInterp_Request
43 friend class PyInterp_Dispatcher;
46 PyInterp_Request( const PyInterp_Request& );
49 virtual ~PyInterp_Request() {};
50 // protected destructor - to control deletion of requests
53 PyInterp_Request( QObject* listener, bool sync = false )
54 : myIsSync( sync ), myListener( listener ), myEvent( 0 ) {};
56 static void Destroy( PyInterp_Request* );
59 bool IsSync() const { return myIsSync; }
60 // Returns true if this request should be processed synchronously,
61 // without putting it to a queue
64 virtual void safeExecute();
66 virtual void execute() = 0;
67 // Should be redefined in successors, contains actual request code
69 virtual QEvent* createEvent() const;
70 // This method can be overridden to customize notification event creation
74 QObject* getListener() const { return myListener; }
75 void setListener( QObject* );
86 class PYINTERP_EXPORT PyInterp_LockRequest : public PyInterp_Request
89 PyInterp_LockRequest( PyInterp_base* interp, QObject* listener = 0, bool sync = false )
90 : PyInterp_Request( listener, sync ), myInterp( interp ) {}
93 PyInterp_base* getInterp() const { return myInterp; }
95 virtual void safeExecute();
98 PyInterp_base* myInterp;
101 class PYINTERP_EXPORT PyInterp_Event : public QCustomEvent
104 PyInterp_Event( const PyInterp_Event& );
107 enum { NOTIFY = QEvent::User + 5000, OK, ERROR, INCOMPLETE, LAST };
109 PyInterp_Event( int type, PyInterp_Request* request )
110 : QCustomEvent( (QEvent::Type)type ), myRequest( request ) {}
112 virtual ~PyInterp_Event();
114 PyInterp_Request* GetRequest() const { return myRequest; }
115 operator PyInterp_Request*() const { return myRequest; }
118 PyInterp_Request* myRequest;
121 class PYINTERP_EXPORT PyInterp_Dispatcher : protected QThread
123 PyInterp_Dispatcher(); // private constructor
126 static PyInterp_Dispatcher* Get();
128 virtual ~PyInterp_Dispatcher();
131 void Exec( PyInterp_Request* );
135 void processRequest( PyInterp_Request* );
136 void objectDestroyed( const QObject* );
139 typedef PyInterp_Request* RequestPtr;
141 std::list<RequestPtr> myQueue;
143 PyInterp_Watcher* myWatcher;
145 static PyInterp_Dispatcher* myInstance;
147 friend class PyInterp_Watcher;