1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, 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 virtual Engines::EngineComponent_ptr
76 create_component_instance_env(const char *componentName,
77 const Engines::FieldsDict &env,
78 CORBA::String_out reason);
81 create_python_service_instance(const char *CompName,
82 CORBA::String_out reason);
84 Engines::EngineComponent_ptr
85 find_component_instance(const char *registeredName);
87 Engines::EngineComponent_ptr
88 load_impl(const char *nameToRegister,
89 const char *componentName);
91 Engines::EmbeddedNamingService_ptr get_embedded_NS_if_ssl() override;
93 SALOME_NamingService_Container_Abstract *getNS() const { return _NS; }
95 void remove_impl(Engines::EngineComponent_ptr component_i);
96 void finalize_removal();
99 CORBA::Long getNumberOfCPUCores();
100 Engines::vectorOfDouble* loadOfCPUCores();
101 void setPyScriptForCPULoad(const char *script);
102 void resetScriptForCPULoad();
103 CORBA::Long getTotalPhysicalMemory();
104 CORBA::Long getTotalPhysicalMemoryInUse();
105 CORBA::Long getTotalPhysicalMemoryInUseByMe();
109 void logfilename(const char *name);
111 virtual void Shutdown();
113 CORBA::Long getPID();
114 //! Kill current container
117 Engines::fileRef_ptr createFileRef(const char *origFileName);
118 Engines::fileTransfer_ptr getFileTransfer();
120 virtual Engines::Salome_file_ptr createSalome_file(const char *origFileName);
121 void copyFile(Engines::Container_ptr container, const char *remoteFile, const char *localFile);
122 Engines::PyNode_ptr createPyNode(const char *nodeName, const char *code);
123 Engines::PyNode_ptr getDefaultPyNode(const char *nodeName);
124 Engines::PyScriptNode_ptr createPyScriptNode(const char *nodeName, const char *code);
125 void removePyScriptNode(const char *nodeName) override;
126 void cleanAllPyScripts() override;
127 Engines::PyScriptNode_ptr getDefaultPyScriptNode(const char *nodeName);
128 // --- local C++ methods
130 Engines::EngineComponent_ptr
131 find_or_create_instance(std::string genericRegisterName,
132 std::string componentLibraryName);
134 bool load_component_CppImplementation(const char *componentName, std::string &reason);
135 bool load_component_PythonImplementation(const char *componentName, std::string &reason);
136 bool load_component_ExecutableImplementation(const char *componentName, std::string &reason);
138 Engines::EngineComponent_ptr createPythonInstance(std::string CompName, std::string &error);
139 Engines::EngineComponent_ptr createExecutableInstance(std::string CompName, const Engines::FieldsDict &env, std::string &error);
140 Engines::EngineComponent_ptr createInstance(std::string genericRegisterName, void *handle, std::string &error);
142 static bool isPythonContainer(const char *ContainerName);
143 static void decInstanceCnt(std::string genericRegisterName);
144 //??? char* machineName();
146 // --- needed for parallel components, Numerical Platon
148 int getArgc() { return _argc; }
149 char **getArgv() { return _argv; }
151 void registerTemporaryFile(const std::string &fileName);
152 void unregisterTemporaryFile(const std::string &fileName);
153 void clearTemporaryFiles();
154 PortableServer::ObjectId *getCORBAId() const { return _id; }
157 static std::map<std::string, int> _cntInstances_map;
158 static std::map<std::string, void *> _library_map; // library names, loaded
159 static std::map<std::string, void *> _toRemove_map; // library names to remove
160 static omni_mutex _numInstanceMutex; // lib and instance protection
162 bool _isSupervContainer;
164 SALOME_NamingService_Container_Abstract *_NS;
165 std::string _library_path;
166 std::string _containerName;
167 std::string _logfilename;
168 std::string _load_script;
170 PortableServer::POA_var _poa;
171 PortableServer::ObjectId *_id;
173 std::map<std::string, Engines::EngineComponent_var> _listInstances_map;
174 std::map<std::string, Engines::fileRef_var> _fileRef_map;
175 std::map<std::string, Engines::Salome_file_var> _Salome_file_map;
176 std::map<std::string, Engines::PyScriptNode_var> _dftPyScriptNode;
177 std::map<std::string, Engines::PyNode_var> _dftPyNode;
178 Utils_Mutex _mutexForDftPy;
179 std::list<std::string> _tmp_files;
180 Engines::fileTransfer_var _fileTransfer;
185 bool _isServantAloneInProcess;
188 class CONTAINER_EXPORT Engines_Container_i : public Abstract_Engines_Container_i
191 Engines_Container_i() { }
192 Engines_Container_i(CORBA::ORB_ptr orb,
193 PortableServer::POA_ptr poa,
195 int argc, char *argv[],
196 SALOME_NamingService_Container_Abstract *ns = nullptr,
197 bool isServantAloneInProcess = true) :
198 Abstract_Engines_Container_i(orb, poa, containerName, argc, argv, ns, isServantAloneInProcess) {}
199 bool isSSLMode() const override { return false; }
202 class CONTAINER_EXPORT Engines_Container_SSL_i : public Abstract_Engines_Container_i
205 Engines_Container_SSL_i();
206 Engines_Container_SSL_i(CORBA::ORB_ptr orb,
207 PortableServer::POA_ptr poa,
209 int argc, char *argv[],
210 SALOME_NamingService_Container_Abstract *ns = nullptr,
211 bool isServantAloneInProcess = true) :
212 Abstract_Engines_Container_i(orb, poa, containerName, argc, argv, ns, isServantAloneInProcess) {}
213 bool isSSLMode() const override { return true; }
217 * Methods to be used in SSL mode to skip NS.
221 CONTAINER_EXPORT Engines_Container_SSL_i *getContainerSA();
222 CONTAINER_EXPORT Engines::Container_var getContainerRefSA();
223 } // namespace KERNEL