Back to index

salome-kernel  6.5.0
SALOME_ParallelContainer_i.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : SALOME_ParallelContainer_i.hxx
00023 //  Author : André RIBES, EDF
00024 
00025 #ifndef _SALOME_PARALLEL_CONTAINER_I_HXX_
00026 #define _SALOME_PARALLEL_CONTAINER_I_HXX_
00027 
00028 #include <SALOMEconfig.h>
00029 
00030 #include "SALOME_PACOExtensionPaCO_Engines_PACO_Container_server.hxx"
00031 #include "SALOME_ParallelGlobalProcessVar_i.hxx"
00032 
00033 #include <iostream>
00034 #include <signal.h>
00035 #include <stdlib.h>
00036 #ifndef WIN32
00037 #include <unistd.h>
00038 #endif
00039 #include <sys/types.h>
00040 #include <omnithread.h>
00041 #include <map>
00042 #include <string>
00043 
00044 class SALOME_NamingService;
00045 
00046 #ifdef WIN32
00047 # if defined CONTAINER_EXPORTS || defined SalomeParallelContainer_EXPORTS
00048 #  define CONTAINER_EXPORT __declspec( dllexport )
00049 # else
00050 #  define CONTAINER_EXPORT __declspec( dllimport )
00051 # endif
00052 #else
00053 # define CONTAINER_EXPORT
00054 #endif
00055 
00056 class CONTAINER_EXPORT Engines_Parallel_Container_i:
00057   virtual public Engines::PACO_Container_serv,
00058   virtual public ParallelGlobalProcessVar_i,
00059   virtual public PortableServer::RefCountServantBase
00060 {
00061 public:
00062   Engines_Parallel_Container_i(CORBA::ORB_ptr orb, 
00063                                char * ior, 
00064                                int rank,
00065                                PortableServer::POA_ptr poa,
00066                                std::string containerName ,
00067                                bool isServantAloneInProcess = true);
00068 
00069   virtual ~Engines_Parallel_Container_i();
00070 
00071   // --- CORBA methods
00072 
00073   virtual bool load_component_Library(const char* componentName, CORBA::String_out reason);
00074 
00075   virtual Engines::EngineComponent_ptr
00076   create_component_instance( const char* componentName,
00077                              CORBA::Long studyId); // 0 for multiStudy
00078 
00079   virtual Engines::EngineComponent_ptr
00080   create_component_instance_env( const char* componentName,
00081                                  CORBA::Long studyId,          // 0 for multiStudy
00082                                  const Engines::FieldsDict& env,
00083                                  CORBA::String_out reason);
00084 
00085   Engines::EngineComponent_ptr
00086   find_component_instance( const char* registeredName,
00087                            CORBA::Long studyId); // 0 for multiStudy
00088 
00089   Engines::EngineComponent_ptr
00090   load_impl(const char* nameToRegister,
00091             const char* componentName);
00092 
00093   void
00094   create_paco_component_node_instance(const char* componentName,
00095                                       const char* proxy_containerName,
00096                                       CORBA::Long studyId); // 0 for multiStudy
00097 
00098   void updateInstanceNumber();
00099 
00100   void remove_impl(Engines::EngineComponent_ptr component_i);
00101   void finalize_removal();
00102 
00103   virtual void ping();
00104   char* name();
00105   char* workingdir();
00106   char* logfilename();
00107   void logfilename(const char* name);
00108 
00109   virtual void Shutdown();
00110   char* getHostName();
00111   CORBA::Long getPID();
00112 
00114   bool Kill_impl() ;
00115 
00116   // --- local C++ methods
00117   Engines::EngineComponent_ptr
00118   find_or_create_instance(std::string genericRegisterName);
00119 
00120   Engines::EngineComponent_ptr
00121   createCPPInstance(std::string genericRegisterName,
00122                     void *handle,
00123                     int studyId);
00124 
00125   Engines::EngineComponent_ptr
00126   createPythonInstance(std::string genericRegisterName,
00127                        int studyId);
00128 
00129   static bool isPythonContainer(const char* ContainerName);
00130   static void decInstanceCnt(std::string genericRegisterName);
00131 
00132   // --- needed for parallel components, Numerical Platon
00133   void set_id(PortableServer::ObjectId * id) { _id = id;}
00134 
00135   Engines::fileRef_ptr createFileRef(const char* origFileName);
00136   Engines::fileTransfer_ptr getFileTransfer();
00137 
00138   virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName);
00139   void copyFile(Engines::Container_ptr container, const char* remoteFile, const char* localFile);
00140   Engines::PyNode_ptr createPyNode(const char* nodeName, const char* code);
00141   Engines::PyScriptNode_ptr createPyScriptNode(const char* nodeName, const char* code);
00142 
00143 protected:
00144 
00145   SALOME_NamingService *_NS;
00146   std::string _hostname;
00147   std::string _library_path;
00148   std::string _containerName;
00149   std::string _logfilename;
00150   CORBA::ORB_var _orb;
00151   PortableServer::POA_var _poa;
00152   PortableServer::ObjectId * _id;
00153   int _numInstance;
00154   CORBA::Long   _pid;
00155   bool   _isServantAloneInProcess;
00156   Engines::fileTransfer_var _fileTransfer;
00157 
00158   typedef std::map<std::string,Engines::EngineComponent_var> _listInstances_map_t;
00159   typedef std::map<std::string,Engines::fileRef_var> _fileRef_map_t;
00160   typedef std::map<std::string,Engines::Salome_file_var> _Salome_file_map_t;
00161   _listInstances_map_t _listInstances_map;
00162   _fileRef_map_t _fileRef_map;
00163   _Salome_file_map_t _Salome_file_map;
00164 
00165   // Cette map contient les references vers les différentes
00166   // instances d'objets parallèles.
00167   std::map<std::string, PortableServer::ObjectId *> _par_obj_inst_map;
00168 
00169   typedef  PortableServer::ObjectId * (*FACTORY_FUNCTION) (CORBA::ORB_ptr, char *, int,
00170                                                            PortableServer::POA_ptr, 
00171                                                            PortableServer::ObjectId *, 
00172                                                            const char *, 
00173                                                            const char *);
00174 };
00175 
00176 #endif