2 //=============================================================================
3 // File : Component_i.cxx
4 // Created : jeu jui 12 08:04:40 CEST 2001
5 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
7 // Copyright : EDF 2001 - CEA 2001
9 //=============================================================================
11 #include "SALOME_Component_i.hxx"
12 #include "RegistryConnexion.hxx"
16 #include "utilities.h"
18 extern bool _Sleeping ;
20 Engines_Component_i::Engines_Component_i()
22 // MESSAGE("Component constructor");
25 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
26 PortableServer::POA_ptr poa,
27 PortableServer::ObjectId * contId,
28 const char *instanceName,
29 const char *interfaceName,
31 _instanceName(instanceName), _interfaceName(interfaceName),
32 _myConnexionToRegistry(0), _ThreadId(0) , _graphName("") , _nodeName("") {
33 MESSAGE("Component constructor with instanceName "<< _instanceName);
34 _orb = CORBA::ORB::_duplicate(orb);
35 _poa = PortableServer::POA::_duplicate(poa);
37 CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
38 const CORBA::String_var ior = _orb->object_to_string(o);
39 _myConnexionToRegistry = new RegistryConnexion(0, 0, ior, "theSession", _instanceName.c_str());
41 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
44 // Constructeur pour composant parallele: ne pas faire appel au registry!!
45 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
46 PortableServer::POA_ptr poa,
47 PortableServer::ObjectId * contId,
48 const char *instanceName,
49 const char *interfaceName,
52 : _instanceName(instanceName),
53 _interfaceName(interfaceName),
54 _myConnexionToRegistry(0),
57 // MESSAGE("Component constructor with instanceName "<< _instanceName);
58 _orb = CORBA::ORB::_duplicate(orb);
59 _poa = PortableServer::POA::_duplicate(poa);
61 // CORBA::Object_var myself = this->_this(); //appel a _this = increment reference
63 _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
66 Engines_Component_i::~Engines_Component_i()
68 MESSAGE("Component destructor");
69 // delete _myConnexionToRegistry;
70 // _myConnexionToRegistry = 0 ;
73 char* Engines_Component_i::instanceName() {
74 return CORBA::string_dup(_instanceName.c_str()) ;
77 char* Engines_Component_i::interfaceName() {
78 return CORBA::string_dup(_interfaceName.c_str()) ;
81 void Engines_Component_i::ping()
83 MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
87 void Engines_Component_i::destroy()
89 MESSAGE("Engines_Component_i::destroy()");
91 delete _notifSupplier;
94 delete _myConnexionToRegistry;
95 _myConnexionToRegistry = 0 ;
96 _poa->deactivate_object(*_id) ;
97 CORBA::release(_poa) ;
99 _thisObj->_remove_ref();
100 MESSAGE("Engines_Component_i::destroyed") ;
103 Engines::Container_ptr Engines_Component_i::GetContainerRef()
105 MESSAGE("Engines_Component_i::GetContainerRef");
106 CORBA::Object_ptr o = _poa->id_to_reference(*_contId) ;
107 return Engines::Container::_narrow(o);
110 PortableServer::ObjectId * Engines_Component_i::getId()
112 // MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
116 void Engines_Component_i::beginService(const char *serviceName)
118 MESSAGE("Send BeginService notification for " << serviceName << endl
119 << "Component instance : " << _instanceName << endl << endl);
120 _ThreadId = pthread_self() ;
121 _serviceName = serviceName ;
122 if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
123 perror("pthread_setcanceltype ") ;
126 if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
127 perror("pthread_setcancelstate ") ;
130 MESSAGE("Return from BeginService for " << serviceName
131 << " ThreadId " << _ThreadId
132 << " _graphName " << _graphName << " _nodeName " << _nodeName );
135 void Engines_Component_i::endService(const char *serviceName)
137 MESSAGE("Send EndService notification for " << serviceName << endl
138 << "Component instance : " << _instanceName << endl << endl);
142 void Engines_Component_i::Names( const char * graphName ,
143 const char * nodeName ) {
144 _graphName = graphName ;
145 _nodeName = nodeName ;
146 // MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
147 // << _nodeName << "' )");
150 char* Engines_Component_i::graphName() {
151 return CORBA::string_dup( _graphName.c_str() ) ;
154 char* Engines_Component_i::nodeName() {
155 return CORBA::string_dup( _nodeName.c_str() ) ;
158 bool Killer( int ThreadId , int signum ) {
161 if ( pthread_cancel( ThreadId ) ) {
162 perror("Killer pthread_cancel error") ;
166 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_cancel") ;
170 if ( pthread_kill( ThreadId , signum ) == -1 ) {
171 perror("Killer pthread_kill error") ;
175 MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed("
183 bool Engines_Component_i::Kill_impl() {
184 MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
185 << " pid " << getpid() << " instanceName "
186 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
187 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
188 << dec << " _ThreadId " << _ThreadId << " this " << hex << this
190 bool RetVal = false ;
191 if ( _ThreadId > 0 && pthread_self() != _ThreadId ) {
192 RetVal = Killer( _ThreadId , 0 ) ;
193 _ThreadId = (pthread_t ) -1 ;
198 bool Engines_Component_i::Stop_impl() {
199 MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
200 << " pid " << getpid() << " instanceName "
201 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
202 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
203 << dec << " _ThreadId " << _ThreadId );
204 bool RetVal = false ;
205 if ( _ThreadId > 0 && pthread_self() != _ThreadId ) {
206 RetVal = Killer( _ThreadId , 0 ) ;
207 _ThreadId = (pthread_t ) -1 ;
212 bool Engines_Component_i::Suspend_impl() {
213 MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
214 << " pid " << getpid() << " instanceName "
215 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
216 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
217 << dec << " _ThreadId " << _ThreadId );
218 bool RetVal = false ;
219 if ( _ThreadId > 0 && pthread_self() != _ThreadId ) {
224 RetVal = Killer( _ThreadId ,SIGINT ) ;
230 bool Engines_Component_i::Resume_impl() {
231 MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
232 << " pid " << getpid() << " instanceName "
233 << _instanceName.c_str() << " interface " << _interfaceName.c_str()
234 << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
235 << dec << " _ThreadId " << _ThreadId );
236 bool RetVal = false ;
237 if ( _ThreadId > 0 && pthread_self() != _ThreadId ) {
250 // Send message to event channel
252 void Engines_Component_i::sendMessage(const char *event_type, const char *message) {
253 _notifSupplier->Send(graphName(), nodeName(), event_type, message);