1 // Copyright (C) 2006-2022 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 virtual bool hasImposedResource()const;
57 PyObject *_pyfuncUnser;
58 PyObject *_pyfuncSimpleSer;
59 PyObject *_pyClsBigObject;
60 std::string _imposedResource;
61 std::string _imposedContainer;
63 static const char SCRIPT_FOR_SIMPLE_SERIALIZATION[];
66 class YACSRUNTIMESALOME_EXPORT PythonNode : public InlineNode, public PythonEntry
69 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
70 // overload part of PythonEntry
71 void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer);
72 Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const;
73 void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
74 Engines::PyNodeBase_var getRemoteInterpreterHandle();
75 const char *getSerializationScript() const { return SCRIPT_FOR_SERIALIZATION; }
76 // A kernel container may manage several python contexts identified by
77 // their name (PyNode and PyScript node). This function returns the name
78 // of the context used by this object. See SALOME_Component.idl in KERNEL.
79 std::string pythonEntryName()const;
81 PythonNode(const PythonNode& other, ComposedNode *father);
82 PythonNode(const std::string& name);
83 virtual ~PythonNode();
84 virtual void checkBasicConsistency() const ;
85 virtual void execute();
87 virtual void loadRemote();
88 virtual void loadLocal();
89 virtual void executeRemote();
90 virtual void executeLocal();
91 virtual void shutdown(int level);
92 void imposeResource(const std::string& resource_name,
93 const std::string& container_name) override;
94 bool canAcceptImposedResource()override;
95 bool hasImposedResource()const override;
96 bool isUsingPythonCache()const;
97 std::string getContainerLog();
98 PythonNode* cloneNode(const std::string& name);
99 virtual std::string typeName() { return "YACS__ENGINE__PythonNode"; }
100 void applyDPLScope(ComposedNode *gfn);
101 void setSqueezeStatus(bool sqStatus) { _autoSqueeze=sqStatus; }
102 bool getSqueezeStatus() const { return _autoSqueeze; }
103 void squeezeMemorySafe();
105 void squeezeMemory();
106 void squeezeMemoryRemote();
107 void freeKernelPynode();
109 static const char KIND[];
110 static const char IMPL_NAME[];
111 static const char SCRIPT_FOR_SERIALIZATION[];
112 static const char REMOTE_NAME[];
113 static const char DPL_INFO_NAME[];
115 bool _autoSqueeze = false;
116 Engines::PyScriptNode_var _pynode;
119 class YACSRUNTIMESALOME_EXPORT PyFuncNode : public InlineFuncNode, public PythonEntry
122 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
123 // overload part of PythonEntry
124 void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer);Engines::
125 PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const;
126 void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
127 Engines::PyNodeBase_var getRemoteInterpreterHandle();
128 const char *getSerializationScript() const { return SCRIPT_FOR_SERIALIZATION; }
130 PyFuncNode(const PyFuncNode& other, ComposedNode *father);
131 PyFuncNode(const std::string& name);
132 virtual ~PyFuncNode();
133 virtual void init(bool start=true);
134 virtual void checkBasicConsistency() const ;
135 virtual void execute();
137 virtual void loadRemote();
138 virtual void loadLocal();
139 virtual void executeRemote();
140 virtual void executeLocal();
141 virtual void shutdown(int level);
142 void imposeResource(const std::string& resource_name,
143 const std::string& container_name) override;
144 bool canAcceptImposedResource()override;
145 bool hasImposedResource()const override;
146 std::string getContainerLog();
147 PyFuncNode* cloneNode(const std::string& name);
148 virtual std::string typeName() { return "YACS__ENGINE__PyFuncNode"; }
150 static const char SCRIPT_FOR_SERIALIZATION[];
153 Engines::PyNode_var _pynode;