Salome HOME
Merge from V6_main 11/02/2013
[modules/gui.git] / src / PyInterp / PyInterp_Dispatcher.h
index a7a4ae72f1d05ed65657f461a83cde6f4d391e3c..40b9f2fd3ff197e1dd9d29fb9f73fd68b3f2cf18 100755 (executable)
@@ -1,47 +1,61 @@
-//  SALOME SALOMEGUI : implementation of desktop and GUI kernel
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2005  CEA/DEN, EDF R&D
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 //  File   : PyInterp_Dispatcher.h
 //  Author : Sergey Anikin, OCC
 //  Module : SALOME
-//  $Header$
-
-#ifndef _PYINTERP_DISPATCHER_H_
-#define _PYINTERP_DISPATCHER_H_
-
-#include "PyInterp.h"
+//
+#ifndef PYINTERP_DISPATCHER_H
+#define PYINTERP_DISPATCHER_H
 
-#include <qthread.h>
-#include <qevent.h>
+#include "PyInterp.h"   // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
 
-#include <list>
+#include <QMutex>
+#include <QThread>
+#include <QEvent>
+#include <QQueue>
 
 class QObject;
 
-class PyInterp_base;
+class PyInterp_Interp;
 class PyInterp_Watcher;
 class PyInterp_Dispatcher;
+class PyInterp_ExecuteEvent;
 
-//////////////////////////////////////////////////////////
-// class : PyInterp_Request
-//////////////////////////////////////////////////////////
 class PYINTERP_EXPORT PyInterp_Request
 {
   friend class PyInterp_Dispatcher;
+  friend class PyInterp_ExecuteEvent;
 
   PyInterp_Request();
   PyInterp_Request( const PyInterp_Request& );
 
 protected:
-  virtual         ~PyInterp_Request() {}; 
+  virtual ~PyInterp_Request() {};
   // protected destructor - to control deletion of requests
 
 public:
   PyInterp_Request( QObject* listener, bool sync = false )
-    : myIsSync( sync ), myListener( listener ), myEvent( 0 ) {};
+    : myIsSync( sync ), myListener( listener ) {};
 
   static void     Destroy( PyInterp_Request* );
   // Deletes a request
@@ -59,48 +73,46 @@ protected:
   virtual QEvent* createEvent() const;
   // This method can be overridden to customize notification event creation
 
+  virtual void    processEvent( QObject* );
+
+  QObject*        listener() const { return myListener; }
+  void            setListener( QObject* );
+
 private:
   void            process();
-  QObject*        getListener() const { return myListener; }
-  void            setListener( QObject* );
-  QEvent*         getEvent();
-  void            postEvent();
 
 private:
+  QMutex          myMutex;
   bool            myIsSync;
   QObject*        myListener;
-  QEvent*         myEvent;
-  QMutex          myMutex;
 };
 
 class PYINTERP_EXPORT PyInterp_LockRequest : public PyInterp_Request
 {
 public:
-  PyInterp_LockRequest( PyInterp_base* interp, QObject* listener = 0, bool sync = false )
+  PyInterp_LockRequest( PyInterp_Interp* interp, QObject* listener = 0, bool sync = false )
     : PyInterp_Request( listener, sync ), myInterp( interp ) {}
 
 protected:
-  PyInterp_base*  getInterp() const { return myInterp; }
+  PyInterp_Interp*  getInterp() const { return myInterp; }
 
-  virtual void    safeExecute();
+  virtual void      safeExecute();
 
 private:
-  PyInterp_base*  myInterp;
+  PyInterp_Interp*  myInterp;
 };
 
-//////////////////////////////////////////////////////////
-// class : PyInterp_Event
-//////////////////////////////////////////////////////////
-class PYINTERP_EXPORT PyInterp_Event : public QCustomEvent
+class PYINTERP_EXPORT PyInterp_Event : public QEvent
 {
   PyInterp_Event();
   PyInterp_Event( const PyInterp_Event& );
 
 public:
-  enum { NOTIFY = QEvent::User + 5000, OK, ERROR, INCOMPLETE, LAST };
+  //Execution state
+  enum { ES_NOTIFY = QEvent::User + 5000, ES_OK, ES_ERROR, ES_INCOMPLETE, ES_LAST };
 
   PyInterp_Event( int type, PyInterp_Request* request )
-    : QCustomEvent( (QEvent::Type)type ), myRequest( request ) {}
+    : QEvent( (QEvent::Type)type ), myRequest( request ) {}
 
   virtual ~PyInterp_Event();
 
@@ -111,9 +123,6 @@ private:
   PyInterp_Request* myRequest;
 };
 
-//////////////////////////////////////////////////////////
-// class : PyInterp_Dispatcher
-//////////////////////////////////////////////////////////
 class PYINTERP_EXPORT PyInterp_Dispatcher : protected QThread
 {
   PyInterp_Dispatcher(); // private constructor
@@ -134,7 +143,7 @@ private:
 private:
   typedef PyInterp_Request*   RequestPtr;
 
-  std::list<RequestPtr>       myQueue;
+  QQueue<RequestPtr>          myQueue;
   QMutex                      myQueueMutex;
   PyInterp_Watcher*           myWatcher;
 
@@ -143,4 +152,4 @@ private:
   friend class PyInterp_Watcher;
 };
 
-#endif
+#endif // PYINTERP_DISPATCHER_H