+}
+
+//=============================================================================
+/*!
+ * 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.f;
+ 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()
+{
+ _ThreadCpuUsed = CpuUsed() ;
+ // MESSAGE(pthread_self() <<
+ // " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
+}
+
+//=============================================================================
+/*!
+ * C++ method:
+ */
+//=============================================================================
+
+long Engines_Component_i::CpuUsed()
+{
+ long cpu = 0 ;
+#ifndef WIN32
+ struct rusage usage ;
+ if ( _ThreadId || _Executed )
+ {
+ if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
+ {
+ perror("Engines_Component_i::CpuUsed") ;
+ return 0 ;
+ }
+ //cpu time is calculated in millisecond (user+system times)
+ cpu = usage.ru_utime.tv_sec*1000 +usage.ru_utime.tv_usec/1000;
+ cpu = cpu+ usage.ru_stime.tv_sec*1000 +usage.ru_stime.tv_usec/1000;
+ cpu=cpu-_StartUsed ;
+ // std::cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
+ // << _serviceName << usage.ru_utime.tv_sec << " - " << _StartUsed
+ // << " = " << cpu << std::endl ;
+ }
+ else
+ {
+ // std::cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
+ // << _ThreadId << " " << _serviceName<< " _StartUsed "
+ // << _StartUsed << std::endl ;
+ }
+#else
+ // NOT implemented yet
+#endif
+
+
+ return cpu ;
+}
+
+void CallCancelThread()
+{
+ if ( theEngines_Component )
+ theEngines_Component->CancelThread() ;
+}
+
+//=============================================================================
+/*!
+ * C++ method:
+ */
+//=============================================================================
+
+void Engines_Component_i::CancelThread()
+{
+ _CanceledThread = true;
+}
+
+//=============================================================================
+/*!
+ * C++ method: Send message to event channel
+ */
+//=============================================================================
+
+void Engines_Component_i::sendMessage(const char *event_type,
+ const char *message)
+{
+ _notifSupplier->Send(_graphName.c_str(), _nodeName.c_str(), event_type, message);
+}
+
+//=============================================================================
+/*!
+ * C++ method: return standard library name built on component name
+ */
+//=============================================================================
+
+std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
+{
+ std::string prefix, suffix;
+ std::string cname = componentName;
+#if !defined(WIN32)
+ prefix = "lib";
+#endif
+#if defined(WIN32)
+ suffix = "dll";
+#elif defined(__APPLE__)
+ suffix = "dylib";
+#else
+ suffix = "so";
+#endif
+ std::string ret = prefix + cname + std::string("Engine.") + suffix;
+ return ret;
+}
+
+//=============================================================================
+/*!
+ * C++ method: DumpPython default implementation
+ */
+//=============================================================================
+
+Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Boolean /*isPublished*/,
+ CORBA::Boolean isMultiFile,
+ CORBA::Boolean& isValidScript)
+{
+ const char* aScript = isMultiFile ? "def RebuildData(): pass" : "";
+ char* aBuffer = new char[strlen(aScript)+1];
+ strcpy(aBuffer, aScript);
+ size_t aBufferSize = strlen(aBuffer)+1;
+ Engines::TMPFile_var aStreamFile = new Engines::TMPFile((CORBA::ULong)aBufferSize, (CORBA::ULong)aBufferSize, (CORBA::Octet*)aBuffer, 1);
+ isValidScript = true;
+ return aStreamFile._retn();
+}
+
+Engines::Salome_file_ptr
+Engines_Component_i::getInputFileToService(const char* service_name,
+ const char* Salome_file_name)
+{
+ // Try to find the service, if it doesn't exist, we throw an exception.
+ _Service_file_map_it = _Input_Service_file_map.find(service_name);
+ if (_Service_file_map_it == _Input_Service_file_map.end()) {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::INTERNAL_ERROR;
+ es.text = "service doesn't have salome files";
+ throw SALOME::SALOME_Exception(es);