1 // Copyright (C) 2007-2015 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"
34 #include <SALOMEconfig.h>
35 #include CORBA_SERVER_HEADER(SALOME_Component)
36 #include CORBA_SERVER_HEADER(SALOME_PyNode)
44 #include <sys/types.h>
45 #include <omnithread.h>
50 class SALOME_NamingService;
52 class CONTAINER_EXPORT Engines_Container_i:
53 public virtual POA_Engines::Container,
54 public virtual PortableServer::ServantBase
57 Engines_Container_i();
58 Engines_Container_i(CORBA::ORB_ptr orb,
59 PortableServer::POA_ptr poa,
60 char * containerName ,
61 int argc, char* argv[],
62 bool activAndRegist = true,
63 bool isServantAloneInProcess = true);
64 virtual ~Engines_Container_i();
68 virtual bool load_component_Library(const char* componentName, CORBA::String_out reason);
70 virtual Engines::EngineComponent_ptr
71 create_component_instance( const char* componentName,
72 CORBA::Long studyId); // 0 for multiStudy
74 virtual Engines::EngineComponent_ptr
75 create_component_instance_env( const char* componentName,
76 CORBA::Long studyId, // 0 for multiStudy
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,
86 CORBA::Long studyId); // 0 for multiStudy
88 Engines::EngineComponent_ptr
89 load_impl(const char* nameToRegister,
90 const char* componentName);
93 void remove_impl(Engines::EngineComponent_ptr component_i);
94 void finalize_removal();
100 void logfilename(const char* name);
102 virtual void Shutdown();
104 CORBA::Long getPID();
105 //! Kill current container
108 Engines::fileRef_ptr createFileRef(const char* origFileName);
109 Engines::fileTransfer_ptr getFileTransfer();
111 virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName);
112 void copyFile(Engines::Container_ptr container, const char* remoteFile, const char* localFile);
113 Engines::PyNode_ptr createPyNode(const char* nodeName, const char* code);
114 Engines::PyNode_ptr getDefaultPyNode(const char *nodeName);
115 Engines::PyScriptNode_ptr createPyScriptNode(const char* nodeName, const char* code);
116 Engines::PyScriptNode_ptr getDefaultPyScriptNode(const char *nodeName);
117 // --- local C++ methods
119 Engines::EngineComponent_ptr
120 find_or_create_instance( std::string genericRegisterName,
121 std::string componentLibraryName);
123 bool load_component_CppImplementation(const char* componentName,std::string& reason);
124 bool load_component_PythonImplementation(const char* componentName,std::string& reason);
125 bool load_component_ExecutableImplementation(const char* componentName,std::string& reason);
127 Engines::EngineComponent_ptr createPythonInstance(std::string CompName, int studyId, std::string& error);
128 Engines::EngineComponent_ptr createExecutableInstance(std::string CompName, int studyId, const Engines::FieldsDict& env, std::string& error);
129 Engines::EngineComponent_ptr createInstance(std::string genericRegisterName, void *handle, int studyId, std::string& error);
131 static bool isPythonContainer(const char* ContainerName);
132 static void decInstanceCnt(std::string genericRegisterName);
133 //??? char* machineName();
135 // --- needed for parallel components, Numerical Platon
137 int getArgc() { return _argc; }
138 char **getArgv() { return _argv; }
140 void registerTemporaryFile( const std::string& fileName );
141 void unregisterTemporaryFile( const std::string& fileName );
142 void clearTemporaryFiles();
146 static std::map<std::string, int> _cntInstances_map;
147 static std::map<std::string, void *> _library_map; // library names, loaded
148 static std::map<std::string, void *> _toRemove_map;// library names to remove
149 static omni_mutex _numInstanceMutex ; // lib and instance protection
151 bool _isSupervContainer;
153 SALOME_NamingService *_NS ;
154 std::string _library_path;
155 std::string _containerName;
156 std::string _logfilename;
158 PortableServer::POA_var _poa;
159 PortableServer::ObjectId * _id ;
161 std::map<std::string,Engines::EngineComponent_var> _listInstances_map;
162 std::map<std::string,Engines::fileRef_var> _fileRef_map;
163 std::map<std::string,Engines::Salome_file_var> _Salome_file_map;
164 Engines::PyScriptNode_var _dftPyScriptNode;
165 Engines::PyNode_var _dftPyNode;
166 std::list<std::string> _tmp_files;
167 Engines::fileTransfer_var _fileTransfer;
172 bool _isServantAloneInProcess;