Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[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     typedef PyObject PyObj;
28
29 /*! \brief Class for Python Ports
30  *
31  * \ingroup Ports
32  *
33  * \see PythonNode
34  */
35     class InputPyPort : public InputPort
36     {
37     public:
38       InputPyPort(const std::string& name, Node * node, TypeCode * type);
39       InputPyPort(const InputPyPort& other, Node *newHelder);
40       ~InputPyPort();
41       bool edIsManuallyInitialized() const;
42       void edRemoveManInit();
43       virtual void put(const void *data) throw(ConversionException);
44       void put(PyObject *data) throw(ConversionException);
45       InputPort *clone(Node *newHelder) const;
46       virtual PyObj * getPyObj() const;
47       void *get() const throw(Exception);
48       virtual bool isEmpty();
49       virtual void exSaveInit();
50       virtual void exRestoreInit();
51       virtual std::string dump();
52       virtual std::string typeName() {return "YACS__ENGINE__InputPyPort";}
53     protected:
54       PyObject* _data;
55       PyObject* _initData;
56     };
57
58     class OutputPyPort : public OutputPort
59     {
60     public:
61       OutputPyPort(const std::string& name, Node * node, TypeCode * type);
62       OutputPyPort(const OutputPyPort& other, Node *newHelder);
63       ~OutputPyPort();
64       virtual void put(const void *data) throw(ConversionException);
65       void put(PyObject *data) throw(ConversionException);
66       OutputPort *clone(Node *newHelder) const;
67       virtual PyObject * get() const;
68       virtual PyObj * getPyObj() const;
69       virtual std::string dump();
70       virtual std::string typeName() {return "YACS__ENGINE__OutputPyPort";}
71     protected:
72       PyObject* _data;
73     };
74
75
76
77   }
78 }
79
80 #endif