]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/PythonNode.hxx
Salome HOME
The final tuning for remote python nodes.
[modules/yacs.git] / src / runtime / PythonNode.hxx
1 // Copyright (C) 2006-2014  CEA/DEN, EDF R&D
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 _PYTHONNODE_HXX_
21 #define _PYTHONNODE_HXX_
22
23 #include "YACSRuntimeSALOMEExport.hxx"
24 #include "InlineNode.hxx"
25 #include <SALOMEconfig.h>
26 #include CORBA_CLIENT_HEADER(SALOME_PyNode)
27 #include CORBA_CLIENT_HEADER(SALOME_Component)
28
29 #include <Python.h>
30
31 namespace YACS
32 {
33   namespace ENGINE
34   {
35     class YACSRUNTIMESALOME_EXPORT PythonEntry
36     {
37     protected:
38       PythonEntry();
39       ~PythonEntry();
40       virtual void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp) = 0;
41       //! returns (if any) an object, you have to deal with (UnRegister)
42       virtual Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const = 0;
43       //! returns an object, you have to deal with (UnRegister)
44       virtual void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer) = 0;
45       virtual Engines::PyNodeBase_var getRemoteInterpreterHandle() = 0;
46       virtual const char *getSerializationScript() const = 0;
47       //
48       void commonRemoteLoad(InlineNode *reqNode);
49     protected:
50       PyObject *_context;
51       PyObject *_pyfuncSer;
52       PyObject *_pyfuncUnser;
53     };
54
55     class YACSRUNTIMESALOME_EXPORT PythonNode : public InlineNode, public PythonEntry
56     {
57     protected:
58       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
59       // overload part of PythonEntry
60       void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer);
61       Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const;
62       void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
63       Engines::PyNodeBase_var getRemoteInterpreterHandle();
64       const char *getSerializationScript() const  { return SCRIPT_FOR_SERIALIZATION; }
65     public:
66       PythonNode(const PythonNode& other, ComposedNode *father);
67       PythonNode(const std::string& name);
68       virtual ~PythonNode();
69       virtual void checkBasicConsistency() const throw(Exception);
70       virtual void execute();
71       virtual void load();
72       virtual void loadRemote();
73       virtual void loadLocal();
74       virtual void executeRemote();
75       virtual void executeLocal();
76       virtual void shutdown(int level);
77       std::string getContainerLog();
78       PythonNode* cloneNode(const std::string& name);
79       virtual std::string typeName() { return "YACS__ENGINE__PythonNode"; }
80     public:
81       static const char KIND[];
82       static const char IMPL_NAME[];
83       static const char SCRIPT_FOR_SERIALIZATION[];
84     protected:
85       Engines::PyScriptNode_var _pynode;
86     };
87
88     class PyFuncNode : public InlineFuncNode, public PythonEntry
89     {
90     protected:
91       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
92       // overload part of PythonEntry
93       void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer);Engines::
94       PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const;
95       void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
96       Engines::PyNodeBase_var getRemoteInterpreterHandle();
97       const char *getSerializationScript() const { return SCRIPT_FOR_SERIALIZATION; }
98     public:
99       PyFuncNode(const PyFuncNode& other, ComposedNode *father);
100       PyFuncNode(const std::string& name);
101       virtual ~PyFuncNode();
102       virtual void checkBasicConsistency() const throw(Exception);
103       virtual void execute();
104       virtual void load();
105       virtual void loadRemote();
106       virtual void loadLocal();
107       virtual void executeRemote();
108       virtual void executeLocal();
109       virtual void shutdown(int level);
110       std::string getContainerLog();
111       PyFuncNode* cloneNode(const std::string& name);
112       virtual std::string typeName() { return "YACS__ENGINE__PyFuncNode"; }
113     public:
114       static const char SCRIPT_FOR_SERIALIZATION[];
115     protected:
116       PyObject* _pyfunc;
117       Engines::PyNode_var _pynode;
118     };
119   }
120 }
121
122 #endif