1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : PyInterp_base.h
8 // Author : Christian CAREMOLI, Paul RASCLE, EDF
12 #ifndef _PYINTERP_BASE_H_
13 #define _PYINTERP_BASE_H_
21 // include order important!
22 // pthread then python then qt
23 //#include <pthread.h> // must be before Python.h !
25 #include <Python.h> // must be before qt includes ...
30 extern "C" PyObject * PyEval_EvalCode(PyObject *co, PyObject *g, PyObject *l);
32 #define TOP_HISTORY_PY "--- top of history ---"
33 #define BEGIN_HISTORY_PY "--- begin of history ---"
37 QSemaphore* mySemaphore;
38 std::string myComment;
40 SemaphoreLock(QSemaphore* theSemaphore, const char* theComment = "");
45 class PYINTERP_EXPORT PyLockWrapper
47 PyThreadState* myThreadState;
48 PyThreadState* mySaveThreadState;
50 PyLockWrapper(PyThreadState* theThreadState);
58 std::string myComment;
60 ThreadLock(QMutex* theMutex, const char* theComment = "");
67 ThreadLock GetPyThreadLock(const char* theComment = "");
69 class PYINTERP_EXPORT PyInterp_base{
71 // static PyThreadState *_gtstate;
74 static PyObject *builtinmodule;
79 virtual void initialize();
80 static void init_python();
82 virtual int run(const char *command);
84 PyLockWrapper GetLockWrapper();
86 std::string getbanner();
87 std::string getverr();
88 std::string getvout();
90 const char * getPrevious();
91 const char * getNext();
94 PyThreadState * _tstate;
99 std::list<std::string> _history;
100 std::list<std::string>::iterator _ith;
103 int simpleRun(const char* command);
106 virtual bool initState() = 0;
107 virtual bool initContext() = 0;
111 class PYINTERP_EXPORT PyObjWrapper{
114 PyObjWrapper(PyObject* theObject): myObject(theObject) {}
115 PyObjWrapper(): myObject(0) {}
116 operator PyObject*(){
119 PyObject* operator->(){
128 bool operator==(PyObject* theObject){
129 return myObject == theObject;
131 PyObject** operator&(){
134 PyObjWrapper& operator=(PyObjWrapper* theObjWrapper){
135 Py_XDECREF(myObject);
136 myObject = theObjWrapper->myObject;
139 virtual ~PyObjWrapper(){
140 Py_XDECREF(myObject);