Salome HOME
PR: from Sergey Mozokhin, Supervisor problem, crash after killing a dataflow execution.
[modules/kernel.git] / src / Container / SALOME_Component_i.hxx
1 //  SALOME Container : implementation of container and engine for Kernel
2 //
3 //  Copyright (C) 2003  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 //
23 //
24 //  File   : SALOME_Component_i.hxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef _SALOME_COMPONENT_I_HXX_
30 #define _SALOME_COMPONENT_I_HXX_
31
32 #include <iostream>
33 #include <signal.h>
34 #include <stdlib.h>
35 #ifndef WNT
36 #include <unistd.h>
37 #endif
38 #include <sys/types.h>
39 #include <string>
40 #include <map>
41 #include <SALOMEconfig.h>
42 #include CORBA_SERVER_HEADER(SALOME_Component)
43 #include "NOTIFICATION.hxx"
44
45 class RegistryConnexion;
46 class Engines_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_Component_i: 
63   public virtual POA_Engines::Component,
64   public virtual PortableServer::RefCountServantBase
65 {
66 public:
67   Engines_Component_i();
68   Engines_Component_i(CORBA::ORB_ptr orb,
69                       PortableServer::POA_ptr poa,
70                       PortableServer::ObjectId * contId, 
71                       const char *instanceName, 
72                       const char *interfaceName,
73                       bool notif = false);
74   // Consructeur pour composant parallele: ne pas faire appel au registry
75   Engines_Component_i(CORBA::ORB_ptr orb,
76                       PortableServer::POA_ptr poa,
77                       PortableServer::ObjectId * contId, 
78                       const char *instanceName, 
79                       const char *interfaceName,
80                       int flag,
81                       bool notif = false);
82
83   virtual ~Engines_Component_i();
84
85   // --- CORBA methods
86
87   char* instanceName();
88   char* interfaceName();
89
90   void ping();
91   void destroy();
92
93   CORBA::Long getStudyId();
94   Engines::Container_ptr GetContainerRef();
95
96   void setProperties(const Engines::FieldsDict& dico);
97   Engines::FieldsDict* getProperties();
98
99   void Names( const char * graphName , const char * nodeName ) ;
100   bool Kill_impl();
101   bool Stop_impl();
102   bool Suspend_impl();
103   bool Resume_impl();
104   CORBA::Long CpuUsed_impl() ;
105
106  virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
107                                       CORBA::Boolean isPublished,
108                                       CORBA::Boolean& isValidScript);
109
110
111   // --- local C++ methods
112
113   PortableServer::ObjectId * getId(); 
114   Engines_Container_i *GetContainerPtr();
115
116   bool setStudyId(CORBA::Long studyId);
117   static bool isMultiStudy();
118   static bool isMultiInstance();
119   static std::string GetDynLibraryName(const char *componentName);
120
121   void beginService(const char *serviceName);
122   void endService(const char *serviceName);
123   void sendMessage(const char *event_type, const char *message);
124   char * graphName() ;
125   char * nodeName() ;
126   bool Killer( pthread_t ThreadId , int signum );
127   void SetCurCpu() ;
128   long CpuUsed() ;
129   void CancelThread() ;
130
131 protected:
132   int _studyId; // -1: not initialised; 0: multiStudy; >0: study
133   static bool _isMultiStudy;
134   static bool _isMultiInstance;
135
136   std::string _instanceName ;
137   std::string _interfaceName ;
138
139   CORBA::ORB_ptr _orb;
140   PortableServer::POA_ptr _poa;
141   PortableServer::ObjectId * _id;
142   PortableServer::ObjectId * _contId;
143   Engines_Component_i * _thisObj ;
144   RegistryConnexion *_myConnexionToRegistry;
145   NOTIFICATION_Supplier* _notifSupplier;
146   std::map<std::string,CORBA::Any>_fieldsDict;
147
148   std::string _serviceName ;
149   std::string _graphName ;
150   std::string _nodeName ;
151
152 private:
153 #ifndef WNT
154   pthread_t _ThreadId ;
155 #else
156   pthread_t* _ThreadId ;
157 #endif
158   long      _StartUsed ;
159   long      _ThreadCpuUsed ;
160   bool      _Executed ;
161   bool      _CanceledThread ;
162 };
163
164 #endif