Version: 9.16.0
PythonPorts.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef _PYTHONPORTS_HXX_
21#define _PYTHONPORTS_HXX_
22
23#include <Python.h>
24
26#include "InputPort.hxx"
27#include "OutputPort.hxx"
28
29namespace YACS
30{
31 namespace ENGINE
32 {
34 {
35 public:
37 gstate_ = PyGILState_Ensure();
38 }
40 PyGILState_Release(gstate_);
41 }
42 private:
43 PyGILState_STATE gstate_;
44 };
45
47 public:
49 tstate_ = PyEval_SaveThread();
50 }
52 PyEval_RestoreThread(tstate_);
53 }
54 inline void lock() {
55 PyEval_RestoreThread(tstate_);
56 }
57 inline void unlock() {
58 tstate_ = PyEval_SaveThread();
59 }
60 private:
61 PyThreadState* tstate_;
62 };
63
64
65 typedef PyObject PyObj;
66
74 {
75 public:
76 InputPyPort(const std::string& name, Node * node, TypeCode * type);
77 InputPyPort(const InputPyPort& other, Node *newHelder);
79 bool edIsManuallyInitialized() const;
80 void edRemoveManInit();
81 virtual void put(const void *data);
82 void releaseData() override;
83 void put(PyObject *data);
84 InputPort *clone(Node *newHelder) const;
85 //special typedef PyObj used in SWIG to increment ref count on output
86 virtual PyObj * getPyObj() const;
87 virtual std::string getAsString();
88 void *get() const ;
89 virtual std::string getHumanRepr();
90 virtual bool isEmpty();
91 virtual void exSaveInit();
92 virtual void exRestoreInit();
93 virtual std::string dump();
94 virtual std::string typeName() {return "YACS__ENGINE__InputPyPort";}
95 virtual std::string valToStr();
96 virtual void valFromStr(std::string valstr);
97 protected:
98 void releaseDataUnsafe();
99 protected:
100 PyObject* _data;
101 PyObject* _initData;
103 };
104
106 {
107 public:
108 OutputPyPort(const std::string& name, Node * node, TypeCode * type);
109 OutputPyPort(const OutputPyPort& other, Node *newHelder);
111 virtual void put(const void *data);
112 void putWithoutForward(PyObject *data);
113 void put(PyObject *data);
114 OutputPort *clone(Node *newHelder) const;
115 virtual PyObject * get() const;
116 //special typedef PyObj used in SWIG to increment ref count on output
117 virtual PyObj * getPyObj() const;
118 virtual std::string getAsString();
119 virtual std::string dump();
120 virtual std::string typeName() {return "YACS__ENGINE__OutputPyPort";}
121 virtual std::string valToStr();
122 virtual void valFromStr(std::string valstr);
123 protected:
124 PyObject* _data;
125 };
126
127
128
129 }
130}
131
132#endif
#define YACSRUNTIMESALOME_EXPORT
Base class for Input Ports.
Definition: InputPort.hxx:44
Class for Python Ports.
Definition: PythonPorts.hxx:74
virtual std::string typeName()
Definition: PythonPorts.hxx:94
Base class for all nodes.
Definition: Node.hxx:70
virtual std::string typeName()
Base class for all type objects.
Definition: TypeCode.hxx:68
PyObject PyObj
Definition: PythonPorts.hxx:65