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