+
+//=============================================================================
+/*!
+ * C++ method: return CORBA instance id, the id is set in derived class
+ * constructor, when instance is activated.
+ */
+//=============================================================================
+
+PortableServer::ObjectId * Engines_Component_i::getId()
+{
+// MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
+ return _id ;
+}
+
+//=============================================================================
+/*!
+ * C++ method: used by derived classes for supervision
+ */
+//=============================================================================
+
+void Engines_Component_i::beginService(const char *serviceName)
+{
+ std::cerr << "beginService for " << serviceName << " Component instance : " << _instanceName << std::endl;
+
+#ifndef WIN32
+ _ThreadId = pthread_self() ;
+#else
+ _ThreadId = new pthread_t;
+ _ThreadId->p = pthread_self().p ;
+ _ThreadId->x = pthread_self().x ;
+#endif
+ _StartUsed = 0 ;
+ _StartUsed = CpuUsed_impl() ;
+ _ThreadCpuUsed = 0 ;
+ _Executed = true ;
+ _serviceName = serviceName ;
+ theEngines_Component = this ;
+ if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
+ {
+ perror("pthread_setcanceltype ") ;
+ exit(0) ;
+ }
+ if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
+ {
+ perror("pthread_setcancelstate ") ;
+ exit(0) ;
+ }
+
+ // --- all strings given with setProperties are set in environment
+ std::map<std::string,CORBA::Any>::iterator it;
+ for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
+ {
+ std::string cle((*it).first);
+ if ((*it).second.type()->kind() == CORBA::tk_string)
+ {
+ const char* value;
+ (*it).second >>= value;
+ std::string s(cle);
+ s+='=';
+ s+=value;
+ putenv((char *)s.c_str());
+ MESSAGE("--- setenv: "<<cle<<" = "<< value);
+ }
+ }
+}
+
+//=============================================================================
+/*!
+ * C++ method: used by derived classes for supervision
+ */
+//=============================================================================
+
+void Engines_Component_i::endService(const char *serviceName)
+{
+ if ( !_CanceledThread )
+ _ThreadCpuUsed = CpuUsed_impl() ;
+
+ float cpus=_ThreadCpuUsed/1000.;
+ std::cerr << "endService for " << serviceName << " Component instance : " << _instanceName ;
+ std::cerr << " Cpu Used: " << cpus << " (s) " << std::endl;
+ MESSAGE("Send EndService notification for " << serviceName
+ << std::endl << " Component instance : " << _instanceName << " StartUsed "
+ << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << std::endl <<std::endl);
+ _ThreadId = 0 ;
+}
+
+//=============================================================================
+/*!
+ * C++ method: -- CHECK IF USED --
+ */
+//=============================================================================
+
+char* Engines_Component_i::graphName()
+{
+ return CORBA::string_dup( _graphName.c_str() ) ;
+}
+
+//=============================================================================
+/*!
+ * C++ method: -- CHECK IF USED --
+ */
+//=============================================================================
+
+char* Engines_Component_i::nodeName()
+{
+ return CORBA::string_dup( _nodeName.c_str() ) ;
+}
+
+//=============================================================================
+/*!
+ * C++ method: used in Supervision (see kill_impl)
+ */
+//=============================================================================
+
+bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
+{
+#ifndef WIN32
+ if ( ThreadId )
+#else
+ if ( ThreadId.p )
+#endif
+ {
+ if ( signum == 0 )
+ {
+ if ( pthread_cancel( ThreadId ) )
+ {
+ perror("Killer pthread_cancel error") ;
+ return false ;
+ }
+ else
+ {
+#ifdef WIN32
+ MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_canceled") ;
+#else
+ MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
+#endif
+ }
+ }
+ else
+ {
+ if ( pthread_kill( ThreadId , signum ) == -1 )
+ {
+ perror("Killer pthread_kill error") ;
+ return false ;
+ }
+ else
+ {
+#ifdef WIN32
+ MESSAGE("Killer : ThreadId " << ThreadId.p << " pthread_killed(" << signum << ")") ;
+#else
+ MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed(" << signum << ")") ;
+#endif
+ }
+ }
+ }
+ return true ;
+}
+
+void SetCpuUsed();
+void CallCancelThread();
+
+//=============================================================================
+/*!
+ * C++ method:
+ */
+//=============================================================================
+
+void SetCpuUsed()
+{
+ if ( theEngines_Component )
+ theEngines_Component->SetCurCpu() ;
+}
+
+//=============================================================================
+/*!
+ * C++ method:
+ */
+//=============================================================================
+
+void Engines_Component_i::SetCurCpu()
+{