Back to index

salome-kernel  6.5.0
SALOME_Container_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 
00023 //  SALOME Container : implementation of container and engine for Kernel
00024 //  File   : SALOME_Container_i.hxx
00025 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/Container/SALOME_Container_i.hxx,v 1.17.2.3.14.5.2.1 2012-04-12 14:05:03 vsr Exp $
00028 //
00029 #ifndef _SALOME_CONTAINER_I_HXX_
00030 #define _SALOME_CONTAINER_I_HXX_
00031 
00032 #include "SALOME_Container.hxx"
00033 
00034 #include <SALOMEconfig.h>
00035 #include CORBA_SERVER_HEADER(SALOME_Component)
00036 #include CORBA_SERVER_HEADER(SALOME_PyNode)
00037 
00038 #include <iostream>
00039 #include <signal.h>
00040 #include <stdlib.h>
00041 #ifndef WIN32
00042 #include <unistd.h>
00043 #endif
00044 #include <sys/types.h>
00045 #include <omnithread.h>
00046 #include <map>
00047 #include <list>
00048 #include <string>
00049 
00050 class SALOME_NamingService;
00051 
00052 class CONTAINER_EXPORT Engines_Container_i:
00053   public virtual POA_Engines::Container,
00054   public virtual PortableServer::ServantBase
00055 {
00056 public:
00057   Engines_Container_i();
00058   Engines_Container_i(CORBA::ORB_ptr orb, 
00059                       PortableServer::POA_ptr poa,
00060                       char * containerName ,
00061                       int argc, char* argv[],
00062                       bool activAndRegist = true,
00063                       bool isServantAloneInProcess = true);
00064   virtual ~Engines_Container_i();
00065 
00066   // --- CORBA methods
00067 
00068   virtual bool load_component_Library(const char* componentName, CORBA::String_out reason);
00069 
00070   virtual Engines::EngineComponent_ptr
00071   create_component_instance( const char* componentName,
00072                              CORBA::Long studyId); // 0 for multiStudy
00073 
00074   virtual Engines::EngineComponent_ptr
00075   create_component_instance_env( const char* componentName,
00076                                  CORBA::Long studyId,          // 0 for multiStudy
00077                                  const Engines::FieldsDict& env,
00078                                  CORBA::String_out reason); 
00079   Engines::EngineComponent_ptr
00080   find_component_instance( const char* registeredName,
00081                            CORBA::Long studyId); // 0 for multiStudy
00082 
00083   Engines::EngineComponent_ptr
00084   load_impl(const char* nameToRegister,
00085             const char* componentName);
00086 
00087 
00088   void remove_impl(Engines::EngineComponent_ptr component_i);
00089   void finalize_removal();
00090 
00091   virtual void ping();
00092   char* name();
00093   char* workingdir();
00094   char* logfilename();
00095   void logfilename(const char* name);
00096 
00097   virtual void Shutdown();
00098   char* getHostName();
00099   CORBA::Long getPID();
00101   bool Kill_impl();
00102 
00103   Engines::fileRef_ptr createFileRef(const char* origFileName);
00104   Engines::fileTransfer_ptr getFileTransfer();
00105 
00106   virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName);
00107   void copyFile(Engines::Container_ptr container, const char* remoteFile, const char* localFile);
00108   Engines::PyNode_ptr createPyNode(const char* nodeName, const char* code);
00109   Engines::PyScriptNode_ptr createPyScriptNode(const char* nodeName, const char* code);
00110   // --- local C++ methods
00111 
00112   Engines::EngineComponent_ptr
00113   find_or_create_instance( std::string genericRegisterName,
00114                            std::string componentLibraryName);
00115 
00116   bool load_component_CppImplementation(const char* componentName,std::string& reason);
00117   bool load_component_PythonImplementation(const char* componentName,std::string& reason);
00118   bool load_component_ExecutableImplementation(const char* componentName,std::string& reason);
00119 
00120   Engines::EngineComponent_ptr createPythonInstance(std::string CompName, int studyId, std::string& error);
00121   Engines::EngineComponent_ptr createExecutableInstance(std::string CompName, int studyId, const Engines::FieldsDict& env, std::string& error);
00122   Engines::EngineComponent_ptr createInstance(std::string genericRegisterName, void *handle, int studyId, std::string& error);
00123 
00124   static bool isPythonContainer(const char* ContainerName);
00125   static void decInstanceCnt(std::string genericRegisterName);
00126   //??? char* machineName();
00127 
00128   // --- needed for parallel components, Numerical Platon
00129 
00130   int getArgc() { return _argc; }
00131   char **getArgv() { return _argv; }
00132 
00133   void registerTemporaryFile( const std::string& fileName );
00134   void unregisterTemporaryFile( const std::string& fileName );
00135   void clearTemporaryFiles();
00136 
00137 protected:
00138 
00139   static std::map<std::string, int> _cntInstances_map;
00140   static std::map<std::string, void *> _library_map; // library names, loaded
00141   static std::map<std::string, void *> _toRemove_map;// library names to remove
00142   static omni_mutex _numInstanceMutex ; // lib and instance protection
00143 
00144   bool _isSupervContainer;
00145 
00146   SALOME_NamingService *_NS ;
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   std::map<std::string,Engines::EngineComponent_var> _listInstances_map;
00155   std::map<std::string,Engines::fileRef_var> _fileRef_map;
00156   std::map<std::string,Engines::Salome_file_var> _Salome_file_map;
00157   std::list<std::string> _tmp_files;
00158   Engines::fileTransfer_var _fileTransfer;
00159 
00160   int    _argc ;
00161   char** _argv ;
00162   long   _pid;
00163   bool   _isServantAloneInProcess;
00164 };
00165 
00166 #endif