1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME Container : implementation of container and engine for Kernel
24 // File : SALOME_Container_i.hxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 #ifndef _SALOME_CONTAINER_I_HXX_
30 #define _SALOME_CONTAINER_I_HXX_
32 #include "SALOME_Container.hxx"
33 #include "Utils_Mutex.hxx"
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(SALOME_Component)
37 #include CORBA_SERVER_HEADER(SALOME_PyNode)
45 #include <sys/types.h>
46 #include <omnithread.h>
51 class SALOME_NamingService_Container_Abstract;
53 class CONTAINER_EXPORT Abstract_Engines_Container_i : public virtual POA_Engines::Container,
54 public virtual PortableServer::ServantBase
57 Abstract_Engines_Container_i();
58 Abstract_Engines_Container_i(CORBA::ORB_ptr orb,
59 PortableServer::POA_ptr poa,
61 int argc, char *argv[],
62 SALOME_NamingService_Container_Abstract *ns = nullptr,
63 bool isServantAloneInProcess = true);
64 virtual ~Abstract_Engines_Container_i();
66 virtual bool isSSLMode() const = 0;
70 virtual bool load_component_Library(const char *componentName, CORBA::String_out reason);
72 virtual Engines::EngineComponent_ptr
73 create_component_instance(const char *componentName);
75 void override_environment_python( const Engines::FieldsDict& env ) override;
77 void override_environment( const Engines::FieldsDict& env ) override;
79 Engines::FieldsDict *get_os_environment() override;
81 void execute_python_code(const char *code) override;
83 virtual Engines::EngineComponent_ptr
84 create_component_instance_env(const char *componentName,
85 const Engines::FieldsDict &env,
86 CORBA::String_out reason);
89 create_python_service_instance(const char *CompName,
90 CORBA::String_out reason);
92 Engines::EngineComponent_ptr
93 find_component_instance(const char *registeredName);
95 Engines::EngineComponent_ptr
96 load_impl(const char *nameToRegister,
97 const char *componentName);
99 bool is_SSL_mode() override { return this->isSSLMode(); }
101 Engines::EmbeddedNamingService_ptr get_embedded_NS_if_ssl() override;
103 SALOME_NamingService_Container_Abstract *getNS() const { return _NS; }
105 void remove_impl(Engines::EngineComponent_ptr component_i);
106 void finalize_removal();
109 CORBA::Long getNumberOfCPUCores();
110 Engines::vectorOfDouble* loadOfCPUCores();
111 void setPyScriptForCPULoad(const char *script);
112 void resetScriptForCPULoad();
113 CORBA::Long getTotalPhysicalMemory();
114 CORBA::Long getTotalPhysicalMemoryInUse();
115 CORBA::Long getTotalPhysicalMemoryInUseByMe();
118 char *logfilename() override;
119 void logfilename(const char *name) override;
120 char *locallogfilename() override;
121 void locallogfilename(const char *name) override;
122 CORBA::Long monitoringtimeresms() override;
123 void monitoringtimeresms(CORBA::Long intervalInMs) override;
124 void verbosity(bool& activated, CORBA::String_out level) override;
125 void setVerbosity(bool activated, const char *level) override;
127 void Shutdown() override;
128 void ShutdownNow() override;
130 CORBA::Long getPID();
131 //! Kill current container
134 Engines::fileRef_ptr createFileRef(const char *origFileName);
135 Engines::fileTransfer_ptr getFileTransfer();
137 virtual Engines::Salome_file_ptr createSalome_file(const char *origFileName);
138 void copyFile(Engines::Container_ptr container, const char *remoteFile, const char *localFile);
139 Engines::PyNode_ptr createPyNode(const char *nodeName, const char *code);
140 Engines::PyNode_ptr getDefaultPyNode(const char *nodeName);
141 Engines::PyScriptNode_ptr createPyScriptNode(const char *nodeName, const char *code);
142 void removePyScriptNode(const char *nodeName) override;
143 void cleanAllPyScripts() override;
144 Engines::PyScriptNode_ptr getDefaultPyScriptNode(const char *nodeName);
145 // --- local C++ methods
147 Engines::EngineComponent_ptr
148 find_or_create_instance(std::string genericRegisterName,
149 std::string componentLibraryName);
151 bool load_component_CppImplementation(const char *componentName, std::string &reason);
152 bool load_component_PythonImplementation(const char *componentName, std::string &reason);
153 bool load_component_ExecutableImplementation(const char *componentName, std::string &reason);
155 Engines::EngineComponent_ptr createPythonInstance(std::string CompName, std::string &error);
156 Engines::EngineComponent_ptr createExecutableInstance(std::string CompName, const Engines::FieldsDict &env, std::string &error);
157 Engines::EngineComponent_ptr createInstance(std::string genericRegisterName, void *handle, std::string &error);
159 static bool isPythonContainer(const char *ContainerName);
160 static void decInstanceCnt(std::string genericRegisterName);
161 //??? char* machineName();
163 // --- needed for parallel components, Numerical Platon
165 int getArgc() { return _argc; }
166 char **getArgv() { return _argv; }
168 void registerTemporaryFile(const std::string &fileName);
169 void unregisterTemporaryFile(const std::string &fileName);
170 void clearTemporaryFiles();
171 PortableServer::ObjectId *getCORBAId() const { return _id; }
173 static const int DFT_TIME_INTERVAL_BTW_MEASURE;
175 void ShutdownCommonPart();
177 static std::map<std::string, int> _cntInstances_map;
178 static std::map<std::string, void *> _library_map; // library names, loaded
179 static std::map<std::string, void *> _toRemove_map; // library names to remove
180 static omni_mutex _numInstanceMutex; // lib and instance protection
182 bool _isSupervContainer;
184 SALOME_NamingService_Container_Abstract *_NS;
185 std::string _library_path;
186 std::string _containerName;
187 std::string _logfilename;
188 std::string _localfilename;
189 std::string _load_script;
191 PortableServer::POA_var _poa;
192 PortableServer::ObjectId *_id;
194 std::map<std::string, Engines::EngineComponent_var> _listInstances_map;
195 std::map<std::string, Engines::fileRef_var> _fileRef_map;
196 std::map<std::string, Engines::Salome_file_var> _Salome_file_map;
197 std::map<std::string, Engines::PyScriptNode_var> _dftPyScriptNode;
198 std::map<std::string, Engines::PyNode_var> _dftPyNode;
199 Utils_Mutex _mutexForDftPy;
200 std::list<std::string> _tmp_files;
201 Engines::fileTransfer_var _fileTransfer;
206 bool _isServantAloneInProcess;
209 class CONTAINER_EXPORT Engines_Container_i : public Abstract_Engines_Container_i
212 Engines_Container_i() { }
213 Engines_Container_i(CORBA::ORB_ptr orb,
214 PortableServer::POA_ptr poa,
216 int argc, char *argv[],
217 SALOME_NamingService_Container_Abstract *ns = nullptr,
218 bool isServantAloneInProcess = true) :
219 Abstract_Engines_Container_i(orb, poa, containerName, argc, argv, ns, isServantAloneInProcess) {}
220 bool isSSLMode() const override { return false; }
223 class CONTAINER_EXPORT Engines_Container_SSL_i : public Abstract_Engines_Container_i
226 Engines_Container_SSL_i();
227 Engines_Container_SSL_i(CORBA::ORB_ptr orb,
228 PortableServer::POA_ptr poa,
230 int argc, char *argv[],
231 SALOME_NamingService_Container_Abstract *ns = nullptr,
232 bool isServantAloneInProcess = true) :
233 Abstract_Engines_Container_i(orb, poa, containerName, argc, argv, ns, isServantAloneInProcess) {}
234 bool isSSLMode() const override { return true; }
238 * Methods to be used in SSL mode to skip NS.
242 CONTAINER_EXPORT Engines_Container_SSL_i *getContainerSA();
243 CONTAINER_EXPORT Engines::Container_var getContainerRefSA();
244 } // namespace KERNEL