Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / runtime / PythonPorts.hxx
1
2 #ifndef _PYTHONPORTS_HXX_
3 #define _PYTHONPORTS_HXX_
4
5 #include <Python.h>
6
7 #include "InputPort.hxx"
8 #include "OutputPort.hxx"
9
10 namespace YACS
11 {
12   namespace ENGINE
13   {
14     class InterpreterUnlocker 
15     {
16     public:
17       InterpreterUnlocker() {
18           gstate_ = PyGILState_Ensure();
19       }
20       ~InterpreterUnlocker() {
21           PyGILState_Release(gstate_);
22       }
23     private:
24       PyGILState_STATE gstate_;
25     };
26
27 /*! \brief Class for Python Ports
28  *
29  * \ingroup Ports
30  *
31  * \see PythonNode
32  */
33     class InputPyPort : public InputPort
34     {
35     public:
36       InputPyPort(const std::string& name, Node * node, TypeCode * type);
37       InputPyPort(const InputPyPort& other, Node *newHelder);
38       ~InputPyPort();
39       bool edIsManuallyInitialized() const;
40       void edRemoveManInit();
41       virtual void put(const void *data) throw(ConversionException);
42       void put(PyObject *data) throw(ConversionException);
43       InputPort *clone(Node *newHelder) const;
44       virtual PyObject * getPyObj() const;
45       void *get() const throw(Exception);
46       virtual bool isEmpty();
47       virtual void exSaveInit();
48       virtual void exRestoreInit();
49       virtual std::string dump();
50     protected:
51       PyObject* _data;
52       PyObject* _initData;
53     };
54
55     class OutputPyPort : public OutputPort
56     {
57     public:
58       OutputPyPort(const std::string& name, Node * node, TypeCode * type);
59       OutputPyPort(const OutputPyPort& other, Node *newHelder);
60       ~OutputPyPort();
61       virtual void put(const void *data) throw(ConversionException);
62       void put(PyObject *data) throw(ConversionException);
63       OutputPort *clone(Node *newHelder) const;
64       virtual PyObject * get() const;
65       virtual std::string dump();
66     protected:
67       PyObject* _data;
68     };
69
70
71
72   }
73 }
74
75 #endif