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
38 /*! return true only if ob is a proxy and destroy flag set to true*/
39 static bool GetDestroyStatus( PyObject *ob );
40 static void DoNotTouchFileIfProxy( PyObject *ob );
41 static void UnlinkOnDestructorIfProxy( PyObject *ob );
45 virtual void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp) = 0;
46 //! returns (if any) an object, you have to deal with (UnRegister)
47 virtual Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const = 0;
48 //! returns an object, you have to deal with (UnRegister)
49 virtual void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer) = 0;
50 virtual Engines::PyNodeBase_var getRemoteInterpreterHandle() = 0;
51 virtual const char *getSerializationScript() const = 0;
53 void commonRemoteLoad(InlineNode *reqNode);
54 void loadRemoteContainer(InlineNode *reqNode);
55 Engines::Container_var loadPythonAdapter(InlineNode *reqNode, bool& isInitializeRequested);
56 void loadRemoteContext(InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested);
57 static std::string GetContainerLog(const std::string& mode, Container *container, const Task *askingTask);
58 virtual bool hasImposedResource()const;
59 static void IfProxyDoSomething( PyObject *ob, const char *meth );
63 PyObject *_pyfuncUnser;
64 PyObject *_pyfuncSimpleSer;
65 static PyObject *_pyClsBigObject;
66 std::string _imposedResource;
67 std::string _imposedContainer;
69 static const char SCRIPT_FOR_SIMPLE_SERIALIZATION[];
72 class YACSRUNTIMESALOME_EXPORT PythonNode : public InlineNode, public PythonEntry
75 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
76 // overload part of PythonEntry
77 void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer);
78 Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const;
79 void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
80 Engines::PyNodeBase_var getRemoteInterpreterHandle();
81 const char *getSerializationScript() const { return SCRIPT_FOR_SERIALIZATION; }
82 // A kernel container may manage several python contexts identified by
83 // their name (PyNode and PyScript node). This function returns the name
84 // of the context used by this object. See SALOME_Component.idl in KERNEL.
85 std::string pythonEntryName()const;
87 PythonNode(const PythonNode& other, ComposedNode *father);
88 PythonNode(const std::string& name);
89 virtual ~PythonNode();
90 virtual void checkBasicConsistency() const ;
91 virtual void execute();
93 virtual void loadRemote();
94 virtual void loadLocal();
95 virtual void executeRemote();
96 virtual void executeLocal();
97 virtual void shutdown(int level);
98 void imposeResource(const std::string& resource_name,
99 const std::string& container_name) override;
100 bool canAcceptImposedResource()override;
101 bool hasImposedResource()const override;
102 bool isUsingPythonCache()const;
103 std::string getContainerLog();
104 PythonNode* cloneNode(const std::string& name);
105 virtual std::string typeName() { return "YACS__ENGINE__PythonNode"; }
106 void applyDPLScope(ComposedNode *gfn);
107 void setSqueezeStatus(bool sqStatus) { _autoSqueeze=sqStatus; }
108 bool getSqueezeStatus() const { return _autoSqueeze; }
109 void squeezeMemorySafe();
111 void executeLocalInternal(const std::string& codeStr);
113 void squeezeMemory();
114 void squeezeMemoryRemote();
115 void freeKernelPynode();
117 static const char KIND[];
118 static const char IMPL_NAME[];
119 static const char SCRIPT_FOR_SERIALIZATION[];
120 static const char REMOTE_NAME[];
121 static const char DPL_INFO_NAME[];
123 bool _autoSqueeze = false;
124 Engines::PyScriptNode_var _pynode;
127 class YACSRUNTIMESALOME_EXPORT PyFuncNode : public InlineFuncNode, public PythonEntry
130 Node *simpleClone(ComposedNode *father, bool editionOnly) const;
131 // overload part of PythonEntry
132 void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer);Engines::
133 PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const;
134 void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
135 Engines::PyNodeBase_var getRemoteInterpreterHandle();
136 const char *getSerializationScript() const { return SCRIPT_FOR_SERIALIZATION; }
138 PyFuncNode(const PyFuncNode& other, ComposedNode *father);
139 PyFuncNode(const std::string& name);
140 virtual ~PyFuncNode();
141 virtual void init(bool start=true);
142 virtual void checkBasicConsistency() const ;
143 virtual void execute();
145 virtual void loadRemote();
146 virtual void loadLocal();
147 virtual void executeRemote();
148 virtual void executeLocal();
149 virtual void shutdown(int level);
150 void imposeResource(const std::string& resource_name,
151 const std::string& container_name) override;
152 bool canAcceptImposedResource()override;
153 bool hasImposedResource()const override;
154 std::string getContainerLog();
155 PyFuncNode* cloneNode(const std::string& name);
156 virtual std::string typeName() { return "YACS__ENGINE__PyFuncNode"; }
158 static const char SCRIPT_FOR_SERIALIZATION[];
161 Engines::PyNode_var _pynode;