Salome HOME
- New Version with PaCO++
[modules/kernel.git] / src / ParallelContainer / SALOME_ParallelComponent_i.hxx
1 //  Copyright (C) 2007-2008  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_ParallelComponent : implementation of container and engine for Parallel Kernel
23 //  File   : SALOME_ParallelComponent_i.hxx
24 //  Author : AndrĂ© RIBES, EDF
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //
27 #ifndef _SALOME_PARALLEL_COMPONENT_I_HXX_
28 #define _SALOME_PARALLEL_COMPONENT_I_HXX_
29
30 #include <iostream>
31 #include <signal.h>
32 #include <stdlib.h>
33 #ifndef WIN32
34 #include <unistd.h>
35 #endif
36 #include <sys/types.h>
37 #include <string>
38 #include <map>
39 #include <SALOMEconfig.h>
40
41 #include "SALOME_PACOExtensionPaCO_Engines_Parallel_Component_server.hxx"
42
43 #include "NOTIFICATION.hxx"
44 #include "RegistryConnexion.hxx"
45 #include "Parallel_Salome_file_i.hxx"
46
47 class Engines_Parallel_Container_i;
48
49 #ifdef WIN32
50 # if defined CONTAINER_EXPORTS || defined SalomeParallelContainer_EXPORTS
51 #  define CONTAINER_EXPORT __declspec( dllexport )
52 # else
53 #  define CONTAINER_EXPORT __declspec( dllimport )
54 # endif
55 #else
56 # define CONTAINER_EXPORT
57 #endif
58
59 class CONTAINER_EXPORT Engines_Parallel_Component_i: 
60   public virtual Engines::Parallel_Component_serv,
61   public virtual PortableServer::RefCountServantBase
62 {
63 public:
64   Engines_Parallel_Component_i(CORBA::ORB_ptr orb, char * ior, int rank,
65                                PortableServer::POA_ptr poa,
66                                PortableServer::ObjectId * contId, 
67                                const char *instanceName, 
68                                const char *interfaceName,
69                                bool notif = false,
70                                bool regist = true);
71
72   virtual ~Engines_Parallel_Component_i();
73
74   // --- CORBA methods
75
76   char* instanceName();
77   char* interfaceName();
78
79   void ping();
80   void destroy();
81
82   CORBA::Long getStudyId();
83   Engines::Container_ptr GetContainerRef();
84
85   void setProperties(const Engines::FieldsDict& dico);
86   Engines::FieldsDict* getProperties();
87
88   void Names( const char * graphName , const char * nodeName ) ;
89   bool Kill_impl();
90   bool Stop_impl();
91   bool Suspend_impl();
92   bool Resume_impl();
93   CORBA::Long CpuUsed_impl() ;
94
95  virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
96                                       CORBA::Boolean isPublished,
97                                       CORBA::Boolean& isValidScript);
98
99  // CORBA operations for Salome_file
100  virtual Engines::Salome_file_ptr getInputFileToService(const char* service_name, 
101                                                         const char* Salome_file_name);
102  virtual Engines::Salome_file_ptr getOutputFileToService(const char* service_name, 
103                                                          const char* Salome_file_name);
104
105  virtual void checkInputFilesToService(const char* service_name);
106  virtual Engines::Salome_file_ptr setInputFileToService(const char* service_name, 
107                                                         const char* Salome_file_name);
108
109  virtual void checkOutputFilesToService(const char* service_name);
110  virtual Engines::Salome_file_ptr setOutputFileToService(const char* service_name, 
111                                                          const char* Salome_file_name);
112
113  void send_parallel_proxy_object(CORBA::Object_ptr proxy_ref);
114
115   // Object information
116   virtual bool hasObjectInfo() { return false; }
117   virtual char* getObjectInfo(CORBA::Long studyId, const char* entry) { return ""; }
118
119   // --- local C++ methods
120
121   PortableServer::ObjectId * getId(); 
122   Engines_Parallel_Container_i *GetContainerPtr();
123
124   bool setStudyId(CORBA::Long studyId);
125   static bool isMultiStudy();
126   static bool isMultiInstance();
127   static std::string GetDynLibraryName(const char *componentName);
128
129   void beginService(const char *serviceName);
130   void endService(const char *serviceName);
131   void sendMessage(const char *event_type, const char *message);
132   char * graphName() ;
133   char * nodeName() ;
134   bool Killer( pthread_t ThreadId , int signum );
135   void SetCurCpu() ;
136   long CpuUsed() ;
137   void CancelThread();
138
139   void wait_parallel_object_proxy();
140   char * get_parallel_proxy_object();
141
142   virtual void configureSalome_file(std::string service_name,
143                                     std::string file_port_name,
144                                     Engines::Parallel_Salome_file_proxy_impl * file);
145
146 protected:
147   int _studyId; // -1: not initialised; 0: multiStudy; >0: study
148   static bool _isMultiStudy;
149   static bool _isMultiInstance;
150
151   std::string _instanceName ;
152   std::string _interfaceName ;
153
154   CORBA::ORB_var _orb;
155   PortableServer::POA_var _poa;
156   PortableServer::ObjectId * _id;
157   PortableServer::ObjectId * _contId;
158   Engines_Parallel_Component_i * _thisObj ;
159   RegistryConnexion *_myConnexionToRegistry;
160   NOTIFICATION_Supplier* _notifSupplier;
161   std::map<std::string,CORBA::Any>_fieldsDict;
162
163   // Map Salome_file_name to Parallel_Salome_file*
164   typedef std::map<std::string, Parallel_Salome_file_i*> _t_Salome_file_map;
165   typedef std::map<std::string, Engines::Parallel_Salome_file_proxy_impl*> _t_Proxy_Salome_file_map;
166   typedef std::map<std::string, std::string> _t_IOR_Proxy_Salome_file_map;
167
168   // Map Service_name to  _Salome_file_map
169   typedef std::map<std::string, Engines_Parallel_Component_i::_t_Salome_file_map*> _t_Service_file_map;
170   typedef std::map<std::string, Engines_Parallel_Component_i::_t_Proxy_Salome_file_map*> _t_Proxy_Service_file_map;
171   typedef std::map<std::string, Engines_Parallel_Component_i::_t_IOR_Proxy_Salome_file_map*> _t_IOR_Proxy_Service_file_map;
172   
173   _t_Service_file_map _Input_Service_file_map;
174   _t_Service_file_map _Output_Service_file_map;
175   _t_Service_file_map::iterator _Service_file_map_it;
176   _t_Salome_file_map::iterator _Salome_file_map_it;
177
178   _t_Proxy_Service_file_map _Proxy_Input_Service_file_map;
179   _t_Proxy_Service_file_map _Proxy_Output_Service_file_map;
180   _t_Proxy_Service_file_map::iterator _Proxy_Service_file_map_it;
181   _t_Proxy_Salome_file_map::iterator _Proxy_Salome_file_map_it;
182
183   _t_IOR_Proxy_Service_file_map _IOR_Proxy_Input_Service_file_map;
184   _t_IOR_Proxy_Service_file_map _IOR_Proxy_Output_Service_file_map;
185   _t_IOR_Proxy_Service_file_map::iterator _IOR_Proxy_Service_file_map_it;
186   _t_IOR_Proxy_Salome_file_map::iterator _IOR_Proxy_Salome_file_map_it;
187
188   std::string _serviceName ;
189   std::string _graphName ;
190   std::string _nodeName ;
191
192   pthread_mutex_t * deploy_mutex;
193   char * _proxy;
194
195 private:
196 #ifndef WIN32
197   pthread_t _ThreadId ;
198 #else
199   pthread_t* _ThreadId ;
200 #endif
201   long      _StartUsed ;
202   long      _ThreadCpuUsed ;
203   bool      _Executed ;
204   bool      _CanceledThread ;
205   bool      _destroyed;
206 };
207
208 #endif