Salome HOME
81a76c5e68c8eeb8b21e83cc0cfbf3f97747cb57
[modules/yacs.git] / src / SALOMEGUI / PyInterp_base.h
1 //=============================================================================
2 // File      : PyInterp_base.h
3 // Created   : ven fév  7 10:01:36 CET 2003
4 // Author    : Christian CAREMOLI, Paul RASCLE, EDF
5 // Project   : SALOME
6 // Copyright : EDF 2003
7 // $Header$
8 //=============================================================================
9
10 #ifndef _PYINTERP_BASE_H_
11 #define _PYINTERP_BASE_H_
12
13 using namespace std;
14 #include <iostream>
15 #include <Python.h>
16 #include <list>
17 #include <string>
18
19 #define TOP_HISTORY_PY "--- top of history ---"
20 #define BEGIN_HISTORY_PY "--- begin of history ---"
21
22 /*!
23  * We have our own routines which are identical to the SIP routines
24  * to not depend from SIP software evolutions
25  */
26
27 extern "C" void salomeAcquireLock();
28 extern "C" void salomeReleaseLock();
29 extern "C" int salomeCondAcquireLock();
30 extern "C" void salomeCondReleaseLock(int rellock);
31
32 /*! this class can only be used with derivation : 
33  *  2 pure virtual methods, initstate() & initcontext()
34  */
35
36 class PyInterp_base
37 {
38  public:
39   static PyThreadState *_gtstate;
40   static int _argc;
41   static char* _argv[];
42   static PyObject *builtinmodule;
43   static PyObject *salome_shared_modules_module;
44
45   PyInterp_base();
46   ~PyInterp_base();
47   void initialize();
48   int run(const char *command); 
49   char * getverr();
50   char * getvout();  
51   string getbanner(); 
52   const char * getPrevious();
53   const char * getNext();    
54   void enter();
55   void quit();
56   void basicRun(const char *command);
57
58  protected:
59   PyThreadState * _tstate;
60   PyObject      * _vout;
61   PyObject      * _verr;
62   PyObject      * _g;
63   list <string> _history;
64   list <string>::iterator _ith;
65   bool _atFirst;
66
67   int simpleRun(const char* command);
68   int initRun();
69
70   virtual void initState() = 0;
71   virtual void initContext() =0;  
72 };
73
74 #endif