Salome HOME
0023299: [CEA] Finalize multi-study removal
[modules/kernel.git] / src / Container / SALOME_Container_i.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME Container : implementation of container and engine for Kernel
24 //  File   : SALOME_Container_i.hxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28 //
29 #ifndef _SALOME_CONTAINER_I_HXX_
30 #define _SALOME_CONTAINER_I_HXX_
31
32 #include "SALOME_Container.hxx"
33 #include "Utils_Mutex.hxx"
34
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(SALOME_Component)
37 #include CORBA_SERVER_HEADER(SALOME_PyNode)
38
39 #include <iostream>
40 #include <signal.h>
41 #include <stdlib.h>
42 #ifndef WIN32
43 #include <unistd.h>
44 #endif
45 #include <sys/types.h>
46 #include <omnithread.h>
47 #include <map>
48 #include <list>
49 #include <string>
50
51 class SALOME_NamingService;
52
53 class CONTAINER_EXPORT Engines_Container_i:
54   public virtual POA_Engines::Container,
55   public virtual PortableServer::ServantBase
56 {
57 public:
58   Engines_Container_i();
59   Engines_Container_i(CORBA::ORB_ptr orb, 
60                       PortableServer::POA_ptr poa,
61                       char * containerName ,
62                       int argc, char* argv[],
63                       bool activAndRegist = true,
64                       bool isServantAloneInProcess = true);
65   virtual ~Engines_Container_i();
66
67   // --- CORBA methods
68
69   virtual bool load_component_Library(const char* componentName, CORBA::String_out reason);
70
71   virtual Engines::EngineComponent_ptr
72   create_component_instance( const char* componentName);
73
74   virtual Engines::EngineComponent_ptr
75   create_component_instance_env( const char* componentName,
76                                  const Engines::FieldsDict& env,
77                                  CORBA::String_out reason);
78
79   virtual char *
80   create_python_service_instance(const char* CompName,
81                                  CORBA::String_out reason);
82
83   Engines::EngineComponent_ptr
84   find_component_instance( const char* registeredName);
85
86   Engines::EngineComponent_ptr
87   load_impl(const char* nameToRegister,
88             const char* componentName);
89
90
91   void remove_impl(Engines::EngineComponent_ptr component_i);
92   void finalize_removal();
93
94   virtual void ping();
95   char* name();
96   char* workingdir();
97   char* logfilename();
98   void logfilename(const char* name);
99
100   virtual void Shutdown();
101   char* getHostName();
102   CORBA::Long getPID();
103   //! Kill current container
104   bool Kill_impl();
105
106   Engines::fileRef_ptr createFileRef(const char* origFileName);
107   Engines::fileTransfer_ptr getFileTransfer();
108
109   virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName);
110   void copyFile(Engines::Container_ptr container, const char* remoteFile, const char* localFile);
111   Engines::PyNode_ptr createPyNode(const char* nodeName, const char* code);
112   Engines::PyNode_ptr getDefaultPyNode(const char *nodeName);
113   Engines::PyScriptNode_ptr createPyScriptNode(const char* nodeName, const char* code);
114   Engines::PyScriptNode_ptr getDefaultPyScriptNode(const char *nodeName);
115   // --- local C++ methods
116
117   Engines::EngineComponent_ptr
118   find_or_create_instance( std::string genericRegisterName,
119                            std::string componentLibraryName);
120
121   bool load_component_CppImplementation(const char* componentName,std::string& reason);
122   bool load_component_PythonImplementation(const char* componentName,std::string& reason);
123   bool load_component_ExecutableImplementation(const char* componentName,std::string& reason);
124
125   Engines::EngineComponent_ptr createPythonInstance(std::string CompName, std::string& error);
126   Engines::EngineComponent_ptr createExecutableInstance(std::string CompName, const Engines::FieldsDict& env, std::string& error);
127   Engines::EngineComponent_ptr createInstance(std::string genericRegisterName, void *handle, std::string& error);
128
129   static bool isPythonContainer(const char* ContainerName);
130   static void decInstanceCnt(std::string genericRegisterName);
131   //??? char* machineName();
132
133   // --- needed for parallel components, Numerical Platon
134
135   int getArgc() { return _argc; }
136   char **getArgv() { return _argv; }
137
138   void registerTemporaryFile( const std::string& fileName );
139   void unregisterTemporaryFile( const std::string& fileName );
140   void clearTemporaryFiles();
141
142 protected:
143
144   static std::map<std::string, int> _cntInstances_map;
145   static std::map<std::string, void *> _library_map; // library names, loaded
146   static std::map<std::string, void *> _toRemove_map;// library names to remove
147   static omni_mutex _numInstanceMutex ; // lib and instance protection
148
149   bool _isSupervContainer;
150
151   SALOME_NamingService *_NS ;
152   std::string _library_path;
153   std::string _containerName;
154   std::string _logfilename;
155   CORBA::ORB_var _orb;
156   PortableServer::POA_var _poa;
157   PortableServer::ObjectId * _id ;
158   int _numInstance ;
159   std::map<std::string,Engines::EngineComponent_var> _listInstances_map;
160   std::map<std::string,Engines::fileRef_var> _fileRef_map;
161   std::map<std::string,Engines::Salome_file_var> _Salome_file_map;
162   std::map<std::string,Engines::PyScriptNode_var> _dftPyScriptNode;
163   std::map<std::string,Engines::PyNode_var> _dftPyNode;
164   Utils_Mutex _mutexForDftPy;
165   std::list<std::string> _tmp_files;
166   Engines::fileTransfer_var _fileTransfer;
167
168   int    _argc ;
169   char** _argv ;
170   long   _pid;
171   bool   _isServantAloneInProcess;
172 };
173
174 #endif