Back to index

salome-kernel  6.5.0
SALOME_ParallelComponent_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_ParallelComponent : implementation of container and engine for Parallel Kernel
00024 //  File   : SALOME_ParallelComponent_i.hxx
00025 //  Author : André RIBES, EDF
00026 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
00027 //
00028 #ifndef _SALOME_PARALLEL_COMPONENT_I_HXX_
00029 #define _SALOME_PARALLEL_COMPONENT_I_HXX_
00030 
00031 #include <iostream>
00032 #include <signal.h>
00033 #include <stdlib.h>
00034 #ifndef WIN32
00035 #include <unistd.h>
00036 #endif
00037 #include <sys/types.h>
00038 #include <string>
00039 #include <map>
00040 #include <SALOMEconfig.h>
00041 
00042 #include "SALOME_PACOExtensionPaCO_Engines_Parallel_Component_server.hxx"
00043 
00044 #include "NOTIFICATION.hxx"
00045 #include "RegistryConnexion.hxx"
00046 #include "Parallel_Salome_file_i.hxx"
00047 
00048 class Engines_Parallel_Container_i;
00049 
00050 #ifdef WIN32
00051 # if defined CONTAINER_EXPORTS || defined SalomeParallelContainer_EXPORTS
00052 #  define CONTAINER_EXPORT __declspec( dllexport )
00053 # else
00054 #  define CONTAINER_EXPORT __declspec( dllimport )
00055 # endif
00056 #else
00057 # define CONTAINER_EXPORT
00058 #endif
00059 
00060 class CONTAINER_EXPORT Engines_Parallel_Component_i: 
00061   public virtual Engines::Parallel_Component_serv,
00062   public virtual PortableServer::RefCountServantBase
00063 {
00064 public:
00065   Engines_Parallel_Component_i(CORBA::ORB_ptr orb, char * ior, int rank,
00066                                PortableServer::POA_ptr poa,
00067                                PortableServer::ObjectId * contId, 
00068                                const char *instanceName, 
00069                                const char *interfaceName,
00070                                bool notif = false,
00071                                bool regist = true);
00072 
00073   virtual ~Engines_Parallel_Component_i();
00074 
00075   // --- CORBA methods
00076 
00077   char* instanceName();
00078   char* interfaceName();
00079 
00080   void ping();
00081   void destroy();
00082 
00083   CORBA::Long getStudyId();
00084   Engines::Container_ptr GetContainerRef();
00085 
00086   void setProperties(const Engines::FieldsDict& dico);
00087   Engines::FieldsDict* getProperties();
00088 
00089   void Names( const char * graphName , const char * nodeName ) ;
00090   bool Kill_impl();
00091   bool Stop_impl();
00092   bool Suspend_impl();
00093   bool Resume_impl();
00094   CORBA::Long CpuUsed_impl() ;
00095 
00096  virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
00097                                       CORBA::Boolean isPublished,
00098                                       CORBA::Boolean isMultiFile,
00099                                       CORBA::Boolean& isValidScript);
00100 
00101  // CORBA operations for Salome_file
00102  virtual Engines::Salome_file_ptr getInputFileToService(const char* service_name, 
00103                                                         const char* Salome_file_name);
00104  virtual Engines::Salome_file_ptr getOutputFileToService(const char* service_name, 
00105                                                          const char* Salome_file_name);
00106 
00107  virtual void checkInputFilesToService(const char* service_name);
00108  virtual Engines::Salome_file_ptr setInputFileToService(const char* service_name, 
00109                                                         const char* Salome_file_name);
00110 
00111  virtual void checkOutputFilesToService(const char* service_name);
00112  virtual Engines::Salome_file_ptr setOutputFileToService(const char* service_name, 
00113                                                          const char* Salome_file_name);
00114 
00115  void send_parallel_proxy_object(CORBA::Object_ptr proxy_ref);
00116 
00117   // Object information
00118   virtual bool hasObjectInfo() { return false; }
00119   virtual char* getObjectInfo(CORBA::Long studyId, const char* entry) { return ""; }
00120 
00121   // --- local C++ methods
00122 
00123   PortableServer::ObjectId * getId(); 
00124   Engines_Parallel_Container_i *GetContainerPtr();
00125 
00126   bool setStudyId(CORBA::Long studyId);
00127   static bool isMultiStudy();
00128   static bool isMultiInstance();
00129   static std::string GetDynLibraryName(const char *componentName);
00130 
00131   void beginService(const char *serviceName);
00132   void endService(const char *serviceName);
00133   void sendMessage(const char *event_type, const char *message);
00134   char * graphName() ;
00135   char * nodeName() ;
00136   bool Killer( pthread_t ThreadId , int signum );
00137   void SetCurCpu() ;
00138   long CpuUsed() ;
00139   void CancelThread();
00140 
00141   void wait_parallel_object_proxy();
00142   char * get_parallel_proxy_object();
00143 
00144   virtual void configureSalome_file(std::string service_name,
00145                                     std::string file_port_name,
00146                                     Engines::Parallel_Salome_file_proxy_impl * file);
00147 
00148 protected:
00149   int _studyId; // -1: not initialised; 0: multiStudy; >0: study
00150   static bool _isMultiStudy;
00151   static bool _isMultiInstance;
00152 
00153   std::string _instanceName ;
00154   std::string _interfaceName ;
00155 
00156   CORBA::ORB_var _orb;
00157   PortableServer::POA_var _poa;
00158   PortableServer::ObjectId * _id;
00159   PortableServer::ObjectId * _contId;
00160   Engines_Parallel_Component_i * _thisObj ;
00161   RegistryConnexion *_myConnexionToRegistry;
00162   NOTIFICATION_Supplier* _notifSupplier;
00163   std::map<std::string,CORBA::Any>_fieldsDict;
00164 
00165   // Map Salome_file_name to Parallel_Salome_file*
00166   typedef std::map<std::string, Parallel_Salome_file_i*> _t_Salome_file_map;
00167   typedef std::map<std::string, Engines::Parallel_Salome_file_proxy_impl*> _t_Proxy_Salome_file_map;
00168   typedef std::map<std::string, std::string> _t_IOR_Proxy_Salome_file_map;
00169 
00170   // Map Service_name to  _Salome_file_map
00171   typedef std::map<std::string, Engines_Parallel_Component_i::_t_Salome_file_map*> _t_Service_file_map;
00172   typedef std::map<std::string, Engines_Parallel_Component_i::_t_Proxy_Salome_file_map*> _t_Proxy_Service_file_map;
00173   typedef std::map<std::string, Engines_Parallel_Component_i::_t_IOR_Proxy_Salome_file_map*> _t_IOR_Proxy_Service_file_map;
00174   
00175   _t_Service_file_map _Input_Service_file_map;
00176   _t_Service_file_map _Output_Service_file_map;
00177   _t_Service_file_map::iterator _Service_file_map_it;
00178   _t_Salome_file_map::iterator _Salome_file_map_it;
00179 
00180   _t_Proxy_Service_file_map _Proxy_Input_Service_file_map;
00181   _t_Proxy_Service_file_map _Proxy_Output_Service_file_map;
00182   _t_Proxy_Service_file_map::iterator _Proxy_Service_file_map_it;
00183   _t_Proxy_Salome_file_map::iterator _Proxy_Salome_file_map_it;
00184 
00185   _t_IOR_Proxy_Service_file_map _IOR_Proxy_Input_Service_file_map;
00186   _t_IOR_Proxy_Service_file_map _IOR_Proxy_Output_Service_file_map;
00187   _t_IOR_Proxy_Service_file_map::iterator _IOR_Proxy_Service_file_map_it;
00188   _t_IOR_Proxy_Salome_file_map::iterator _IOR_Proxy_Salome_file_map_it;
00189 
00190   std::string _serviceName ;
00191   std::string _graphName ;
00192   std::string _nodeName ;
00193 
00194   pthread_mutex_t * deploy_mutex;
00195   char * _proxy;
00196 
00197 private:
00198 #ifndef WIN32
00199   pthread_t _ThreadId ;
00200 #else
00201   pthread_t* _ThreadId ;
00202 #endif
00203   long      _StartUsed ;
00204   long      _ThreadCpuUsed ;
00205   bool      _Executed ;
00206   bool      _CanceledThread ;
00207   bool      _destroyed;
00208 };
00209 
00210 #endif