Salome HOME
Issue 0013373: EDF PAL 273 : Option Single/Multi file dump
[modules/kernel.git] / src / ParallelContainer / SALOME_ParallelContainer_i.hxx
1 //  Copyright (C) 2007-2010  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.
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 //  SALOME_ParallelContainer : implementation of container and engine for Parallel Kernel
23 //  File   : SALOME_ParallelContainer_i.hxx
24 //  Author : André RIBES, EDF
25
26 #ifndef _SALOME_PARALLEL_CONTAINER_I_HXX_
27 #define _SALOME_PARALLEL_CONTAINER_I_HXX_
28
29 #include <SALOMEconfig.h>
30
31 #include "SALOME_PACOExtensionPaCO_Engines_PACO_Container_server.hxx"
32 #include "SALOME_ParallelGlobalProcessVar_i.hxx"
33
34 #include <iostream>
35 #include <signal.h>
36 #include <stdlib.h>
37 #ifndef WIN32
38 #include <unistd.h>
39 #endif
40 #include <sys/types.h>
41 #include <omnithread.h>
42 #include <map>
43 #include <string>
44
45 class SALOME_NamingService;
46
47 #ifdef WIN32
48 # if defined CONTAINER_EXPORTS || defined SalomeParallelContainer_EXPORTS
49 #  define CONTAINER_EXPORT __declspec( dllexport )
50 # else
51 #  define CONTAINER_EXPORT __declspec( dllimport )
52 # endif
53 #else
54 # define CONTAINER_EXPORT
55 #endif
56
57 class CONTAINER_EXPORT Engines_Parallel_Container_i:
58   virtual public Engines::PACO_Container_serv,
59   virtual public ParallelGlobalProcessVar_i,
60   virtual public PortableServer::RefCountServantBase
61 {
62 public:
63   Engines_Parallel_Container_i(CORBA::ORB_ptr orb, 
64                                char * ior, 
65                                int rank,
66                                PortableServer::POA_ptr poa,
67                                std::string containerName ,
68                                bool isServantAloneInProcess = true);
69
70   virtual ~Engines_Parallel_Container_i();
71
72   // --- CORBA methods
73
74   virtual bool load_component_Library(const char* componentName, CORBA::String_out reason);
75
76   virtual Engines::EngineComponent_ptr
77   create_component_instance( const char* componentName,
78                              CORBA::Long studyId); // 0 for multiStudy
79
80   virtual Engines::EngineComponent_ptr
81   create_component_instance_env( const char* componentName,
82                                  CORBA::Long studyId,          // 0 for multiStudy
83                                  const Engines::FieldsDict& env,
84                                  CORBA::String_out reason);
85
86   Engines::EngineComponent_ptr
87   find_component_instance( const char* registeredName,
88                            CORBA::Long studyId); // 0 for multiStudy
89
90   Engines::EngineComponent_ptr
91   load_impl(const char* nameToRegister,
92             const char* componentName);
93
94   void
95   create_paco_component_node_instance(const char* componentName,
96                                       const char* proxy_containerName,
97                                       CORBA::Long studyId); // 0 for multiStudy
98
99   void updateInstanceNumber();
100
101   void remove_impl(Engines::EngineComponent_ptr component_i);
102   void finalize_removal();
103
104   virtual void ping();
105   char* name();
106   char* workingdir();
107   char* logfilename();
108   void logfilename(const char* name);
109
110   virtual void Shutdown();
111   char* getHostName();
112   CORBA::Long getPID();
113
114   //! Kill current container
115   bool Kill_impl() ;
116
117   // --- local C++ methods
118   Engines::EngineComponent_ptr
119   find_or_create_instance(std::string genericRegisterName);
120
121   Engines::EngineComponent_ptr
122   createCPPInstance(std::string genericRegisterName,
123                     void *handle,
124                     int studyId);
125
126   Engines::EngineComponent_ptr
127   createPythonInstance(std::string genericRegisterName,
128                        int studyId);
129
130   static bool isPythonContainer(const char* ContainerName);
131   static void decInstanceCnt(std::string genericRegisterName);
132
133   // --- needed for parallel components, Numerical Platon
134   void set_id(PortableServer::ObjectId * id) { _id = id;}
135
136   Engines::fileRef_ptr createFileRef(const char* origFileName);
137   Engines::fileTransfer_ptr getFileTransfer();
138
139   virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName);
140   void copyFile(Engines::Container_ptr container, const char* remoteFile, const char* localFile);
141   Engines::PyNode_ptr createPyNode(const char* nodeName, const char* code);
142
143 protected:
144
145   SALOME_NamingService *_NS;
146   std::string _hostname;
147   std::string _library_path;
148   std::string _containerName;
149   std::string _logfilename;
150   CORBA::ORB_var _orb;
151   PortableServer::POA_var _poa;
152   PortableServer::ObjectId * _id;
153   int _numInstance;
154   CORBA::Long   _pid;
155   bool   _isServantAloneInProcess;
156   Engines::fileTransfer_var _fileTransfer;
157
158   typedef std::map<std::string,Engines::EngineComponent_var> _listInstances_map_t;
159   typedef std::map<std::string,Engines::fileRef_var> _fileRef_map_t;
160   typedef std::map<std::string,Engines::Salome_file_var> _Salome_file_map_t;
161   _listInstances_map_t _listInstances_map;
162   _fileRef_map_t _fileRef_map;
163   _Salome_file_map_t _Salome_file_map;
164
165   // Cette map contient les references vers les différentes
166   // instances d'objets parallèles.
167   std::map<std::string, PortableServer::ObjectId *> _par_obj_inst_map;
168
169   typedef  PortableServer::ObjectId * (*FACTORY_FUNCTION) (CORBA::ORB_ptr, char *, int,
170                                                            PortableServer::POA_ptr, 
171                                                            PortableServer::ObjectId *, 
172                                                            const char *, 
173                                                            const char *);
174 };
175
176 #endif