1 // Copyright (C) 2006-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef _PYTHONNODE_HXX_
21 #define _PYTHONNODE_HXX_
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)
35 class YACSRUNTIMESALOME_EXPORT 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;
48 void commonRemoteLoad(InlineNode *reqNode);
49 void loadRemoteContainer(InlineNode *reqNode);
50 Engines::Container_var loadPythonAdapter(InlineNode *reqNode, bool& isInitializeRequested);
51 void loadRemoteContext(InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested);
52 static std::string GetContainerLog(const std::string& mode, Container *container, const Task *askingTask);
53 bool hasImposedResource()const;
57 PyObject *_pyfuncUnser;
58 PyObject *_pyfuncSimpleSer;
59 std::string _imposedResource;
60 std::string _imposedContainer;
62 static const char SCRIPT_FOR_SIMPLE_SERIALIZATION[];
65 class YACSRUNTIMESALOME_EXPORT PythonNode : public InlineNode, public PythonEntry
68 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
69 // overload part of PythonEntry
70 void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer);
71 Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const;
72 void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
73 Engines::PyNodeBase_var getRemoteInterpreterHandle();
74 const char *getSerializationScript() const { return SCRIPT_FOR_SERIALIZATION; }
75 // A kernel container may manage several python contexts identified by
76 // their name (PyNode and PyScript node). This function returns the name
77 // of the context used by this object. See SALOME_Component.idl in KERNEL.
78 std::string pythonEntryName()const;
80 PythonNode(const PythonNode& other, ComposedNode *father);
81 PythonNode(const std::string& name);
82 virtual ~PythonNode();
83 virtual void checkBasicConsistency() const ;
84 virtual void execute();
86 virtual void loadRemote();
87 virtual void loadLocal();
88 virtual void executeRemote();
89 virtual void executeLocal();
90 virtual void shutdown(int level);
91 void imposeResource(const std::string& resource_name,
92 const std::string& container_name) override;
93 bool canAcceptImposedResource()override;
94 bool isUsingPythonCache()const;
95 std::string getContainerLog();
96 PythonNode* cloneNode(const std::string& name);
97 virtual std::string typeName() { return "YACS__ENGINE__PythonNode"; }
98 void applyDPLScope(ComposedNode *gfn);
99 void setSqueezeStatus(bool sqStatus) { _autoSqueeze=sqStatus; }
100 bool getSqueezeStatus() const { return _autoSqueeze; }
101 void squeezeMemorySafe();
103 void squeezeMemory();
104 void squeezeMemoryRemote();
106 static const char KIND[];
107 static const char IMPL_NAME[];
108 static const char SCRIPT_FOR_SERIALIZATION[];
109 static const char REMOTE_NAME[];
110 static const char DPL_INFO_NAME[];
112 bool _autoSqueeze = false;
113 Engines::PyScriptNode_var _pynode;
116 class YACSRUNTIMESALOME_EXPORT PyFuncNode : public InlineFuncNode, public PythonEntry
119 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
120 // overload part of PythonEntry
121 void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer);Engines::
122 PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const;
123 void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
124 Engines::PyNodeBase_var getRemoteInterpreterHandle();
125 const char *getSerializationScript() const { return SCRIPT_FOR_SERIALIZATION; }
127 PyFuncNode(const PyFuncNode& other, ComposedNode *father);
128 PyFuncNode(const std::string& name);
129 virtual ~PyFuncNode();
130 virtual void init(bool start=true);
131 virtual void checkBasicConsistency() const ;
132 virtual void execute();
134 virtual void loadRemote();
135 virtual void loadLocal();
136 virtual void executeRemote();
137 virtual void executeLocal();
138 virtual void shutdown(int level);
139 void imposeResource(const std::string& resource_name,
140 const std::string& container_name) override;
141 bool canAcceptImposedResource()override;
142 std::string getContainerLog();
143 PyFuncNode* cloneNode(const std::string& name);
144 virtual std::string typeName() { return "YACS__ENGINE__PyFuncNode"; }
146 static const char SCRIPT_FOR_SERIALIZATION[];
149 Engines::PyNode_var _pynode;