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