Salome HOME
merge from branch BR_For40_DSC tag mergeto_BR_Dev_For_4_0_16apr07
[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_Component_server.h"
41
42 #include "NOTIFICATION.hxx"
43 #include "RegistryConnexion.hxx"
44
45 class Engines_Parallel_Container_i;
46
47 #if defined CONTAINER_EXPORTS
48 #if defined WIN32
49 #define CONTAINER_EXPORT __declspec( dllexport )
50 #else
51 #define CONTAINER_EXPORT
52 #endif
53 #else
54 #if defined WNT
55 #define CONTAINER_EXPORT __declspec( dllimport )
56 #else
57 #define CONTAINER_EXPORT
58 #endif
59 #endif
60
61 class CONTAINER_EXPORT Engines_Parallel_Component_i: 
62   public virtual Engines::Component_serv,
63   public virtual PortableServer::RefCountServantBase
64 {
65 public:
66   Engines_Parallel_Component_i(CORBA::ORB_ptr orb, char * ior);
67   Engines_Parallel_Component_i(CORBA::ORB_ptr orb, char * ior,
68                                PortableServer::POA_ptr poa,
69                                PortableServer::ObjectId * contId, 
70                                const char *instanceName, 
71                                const char *interfaceName,
72                                bool notif = false);
73
74   virtual ~Engines_Parallel_Component_i();
75
76   // --- CORBA methods
77
78   char* instanceName();
79   char* interfaceName();
80
81   void ping();
82   void destroy();
83
84   CORBA::Long getStudyId();
85   Engines::Container_ptr GetContainerRef();
86
87   void setProperties(const Engines::FieldsDict& dico);
88   Engines::FieldsDict* getProperties();
89
90   void Names( const char * graphName , const char * nodeName ) ;
91   bool Kill_impl();
92   bool Stop_impl();
93   bool Suspend_impl();
94   bool Resume_impl();
95   CORBA::Long CpuUsed_impl() ;
96
97  virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
98                                       CORBA::Boolean isPublished,
99                                       CORBA::Boolean& isValidScript);
100
101
102   // --- local C++ methods
103
104   PortableServer::ObjectId * getId(); 
105   Engines_Parallel_Container_i *GetContainerPtr();
106
107   bool setStudyId(CORBA::Long studyId);
108   static bool isMultiStudy();
109   static bool isMultiInstance();
110   static std::string GetDynLibraryName(const char *componentName);
111
112   void beginService(const char *serviceName);
113   void endService(const char *serviceName);
114   void sendMessage(const char *event_type, const char *message);
115   char * graphName() ;
116   char * nodeName() ;
117   bool Killer( pthread_t ThreadId , int signum );
118   void SetCurCpu() ;
119   long CpuUsed() ;
120
121 protected:
122   int _studyId; // -1: not initialised; 0: multiStudy; >0: study
123   static bool _isMultiStudy;
124   static bool _isMultiInstance;
125
126   std::string _instanceName ;
127   std::string _interfaceName ;
128
129   CORBA::ORB_ptr _orb;
130   PortableServer::POA_ptr _poa;
131   PortableServer::ObjectId * _id;
132   PortableServer::ObjectId * _contId;
133   Engines_Parallel_Component_i * _thisObj ;
134   RegistryConnexion *_myConnexionToRegistry;
135   NOTIFICATION_Supplier* _notifSupplier;
136   std::map<std::string,CORBA::Any>_fieldsDict;
137
138   std::string _serviceName ;
139   std::string _graphName ;
140   std::string _nodeName ;
141
142 private:
143 #ifndef WNT
144   pthread_t _ThreadId ;
145 #else
146   pthread_t* _ThreadId ;
147 #endif
148   long      _StartUsed ;
149   long      _ThreadCpuUsed ;
150   bool      _Executed ;
151 };
152
153 #endif