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