Salome HOME
PR: embedded container C++ & Python, debug
[modules/kernel.git] / src / Container / Component_i.cxx
index 400072d0f32a15650fa51c36ca632881427d6104..fb2dc2b68b56aeb9ea35e099b83d196776bea664 100644 (file)
 //  Module : SALOME
 //  $Header$
 
-using namespace std;
+//#define private protected  // for pd_refCount trace
 #include "SALOME_Component_i.hxx"
+#include "SALOME_Container_i.hxx"
 #include "RegistryConnexion.hxx"
 #include "OpUtil.hxx"
 #include <stdio.h>
 #include <dlfcn.h>
+#include <cstdlib>
 #include "utilities.h"
 
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+
+using namespace std;
+
 extern bool _Sleeping ;
+static Engines_Component_i * theEngines_Component ;
+
+bool Engines_Component_i::_isMultiStudy = true;
+bool Engines_Component_i::_isMultiInstance = false;
+
+//=============================================================================
+/*! 
+ *  Default constructor, not for use
+ */
+//=============================================================================
 
 Engines_Component_i::Engines_Component_i()
 {
-//  MESSAGE("Component constructor");
+  ASSERT(0);
 }
 
+//=============================================================================
+/*! 
+ *  Standard Constructor for generic Component, used in derived class
+ *  Connection to Registry and Notification
+ *  \param orb Object Request broker given by Container
+ *  \parap poa Portable Object Adapter from Container (normally root_poa)
+ *  \param contId container CORBA id inside the server
+ *  \param instanceName unique instance name for this object (see Container_i)
+ *  \param interfaceName component class name
+ *  \param notif use of notification
+ */
+//=============================================================================
+
 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
                                         PortableServer::POA_ptr poa, 
                                         PortableServer::ObjectId * contId, 
                                         const char *instanceName,
                                         const char *interfaceName,
                                          bool notif) :
-  _instanceName(instanceName), _interfaceName(interfaceName),
-  _myConnexionToRegistry(0), _ThreadId(0) , _graphName("") , _nodeName("") {
+  _instanceName(instanceName),
+  _interfaceName(interfaceName),
+  _myConnexionToRegistry(0),
+  _ThreadId(0) ,
+  _ThreadCpuUsed(0) ,
+  _Executed(false) ,
+  _graphName("") ,
+  _nodeName(""),
+ _studyId(-1)
+{
   MESSAGE("Component constructor with instanceName "<< _instanceName);
+  //SCRUTE(pd_refCount);
   _orb = CORBA::ORB::_duplicate(orb);
   _poa = PortableServer::POA::_duplicate(poa);
   _contId = contId ;
   CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
   const CORBA::String_var ior = _orb->object_to_string(o);
-  _myConnexionToRegistry = new RegistryConnexion(0, 0, ior, "theSession", _instanceName.c_str());
+  _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
+                                                _instanceName.c_str());
 
   _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
+  //SCRUTE(pd_refCount);
 }
 
-// Constructeur pour composant parallele: ne pas faire appel au registry!!
+//=============================================================================
+/*! 
+ * Standard constructor for parallel component
+ *  Connection Notification (no connection to Registry !)
+ *  \param orb Object Request broker given by Container
+ *  \parap poa Portable Object Adapter from Container (normally root_poa)
+ *  \param contId container CORBA id inside the server
+ *  \param instanceName unique instance name for this object (see Container_i)
+ *  \param interfaceName component class name
+ *  \param flag not used...
+ *  \param notif use of notification
+ */
+//=============================================================================
+
 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
                                         PortableServer::POA_ptr poa, 
                                         PortableServer::ObjectId * contId, 
                                         const char *instanceName,
                                         const char *interfaceName,
                                         int flag,
-                                         bool notif )
-  : _instanceName(instanceName),
-    _interfaceName(interfaceName),
-    _myConnexionToRegistry(0),
-    _ThreadId(0)
+                                         bool notif ) :
+ _instanceName(instanceName),
+ _interfaceName(interfaceName),
+ _myConnexionToRegistry(0),
+ _ThreadId(0) ,
+ _ThreadCpuUsed(0) ,
+ _Executed(false) ,
+ _graphName("") ,
+ _nodeName(""),
+ _studyId(-1)
 {
-//  MESSAGE("Component constructor with instanceName "<< _instanceName);
   _orb = CORBA::ORB::_duplicate(orb);
   _poa = PortableServer::POA::_duplicate(poa);
   _contId = contId ;
-  //  CORBA::Object_var myself = this->_this(); //appel a _this = increment reference
 
   _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
 }
 
+//=============================================================================
+/*! 
+ *  Destructor: call Container for decrement of instances count.
+ *  When instances count falls to 0, the container tries to remove the
+ *  component library (dlclose)
+ */
+//=============================================================================
+
 Engines_Component_i::~Engines_Component_i()
 {
   MESSAGE("Component destructor");
-//   delete _myConnexionToRegistry;
-//   _myConnexionToRegistry = 0 ;
+  Engines_Container_i::decInstanceCnt(_interfaceName);
 }
 
-char* Engines_Component_i::instanceName() {
+//=============================================================================
+/*! 
+ *  CORBA method: return name of the instance, unique in this Container
+ */
+//=============================================================================
+
+char* Engines_Component_i::instanceName()
+{
    return CORBA::string_dup(_instanceName.c_str()) ;
 }
 
-char* Engines_Component_i::interfaceName() {
-   return CORBA::string_dup(_interfaceName.c_str()) ;
+//=============================================================================
+/*! 
+ *  CORBA method: return name of the component class
+ */
+//=============================================================================
+
+char* Engines_Component_i::interfaceName()
+{
+  return CORBA::string_dup(_interfaceName.c_str()) ;
 }
 
+//=============================================================================
+/*! 
+ *  CORBA method: Get study Id
+ *  \return -1: not initialised (Internal Error)
+ *           0: multistudy component instance
+ *          >0: study id associated to this instance
+ */
+//=============================================================================
+
+CORBA::Long Engines_Component_i::getStudyId()
+{
+  return _studyId;
+}
+
+//=============================================================================
+/*! 
+ *  CORBA method: Test if instance is alive and responds
+ */
+//=============================================================================
+
 void Engines_Component_i::ping()
 {
   MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
           << pthread_self());
 }
 
+//=============================================================================
+/*! 
+ *  CORBA method: Deactivate this instance. CORBA object is deactivated (do not
+ *  respond any more to CORBA calls), the connection to Regsitry is removed
+ *  (Registry informed of deactivation), internal server reference counter on
+ *  the derived servant class is decremented, to allow destruction of the class
+ *  (delete) by POA, when there are no more references.
+ *  -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
+ */
+//=============================================================================
+
 void Engines_Component_i::destroy()
 {
   MESSAGE("Engines_Component_i::destroy()");
+  //SCRUTE(pd_refCount);
 
   delete _notifSupplier;
   _notifSupplier = 0;
@@ -115,10 +226,19 @@ void Engines_Component_i::destroy()
   _poa->deactivate_object(*_id) ;
   CORBA::release(_poa) ;
   delete(_id) ;
+  //SCRUTE(pd_refCount);
   _thisObj->_remove_ref();
+  //SCRUTE(pd_refCount);
   MESSAGE("Engines_Component_i::destroyed") ;
 }
 
+//=============================================================================
+/*! 
+ *  CORBA method: return CORBA reference of the Container
+ *
+ */
+//=============================================================================
+
 Engines::Container_ptr Engines_Component_i::GetContainerRef()
 {
   MESSAGE("Engines_Component_i::GetContainerRef");
@@ -126,168 +246,488 @@ Engines::Container_ptr Engines_Component_i::GetContainerRef()
   return Engines::Container::_narrow(o);
 }
 
-PortableServer::ObjectId * Engines_Component_i::getId()
-{
-//  MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
-  return _id ;
-}
+//=============================================================================
+/*! 
+ *  CORBA method: 
+ *  Gives a sequence of (key=string,value=any) to the component. 
+ *  Base class component stores the sequence in a map.
+ *  The map is cleared before.
+ *  This map is for use by derived classes. 
+ *  \param dico sequence of (key=string,value=any)
+ */
+//=============================================================================
 
-void Engines_Component_i::beginService(const char *serviceName)
+void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
 {
-  MESSAGE("Send BeginService notification for " << serviceName << endl
-         << "Component instance : " << _instanceName << endl << endl);
-  _ThreadId = pthread_self() ;
-  _StartUsed = 0 ;
-  _StartUsed = CpuUsed_impl() ;
-  _serviceName = serviceName ;
-  if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) {
-    perror("pthread_setcanceltype ") ;
-    exit(0) ;
-  }
-  if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) ) {
-    perror("pthread_setcancelstate ") ;
-    exit(0) ;
-  }
-  MESSAGE("Return from BeginService for " << serviceName
-          << " ThreadId " << _ThreadId
-          << " _graphName " << _graphName << " _nodeName " << _nodeName );
+  _fieldsDict.clear();
+  for (CORBA::ULong i=0; i<dico.length(); i++)
+    {
+      std::string cle(dico[i].key);
+      _fieldsDict[cle] = dico[i].value;
+    }
 }
 
-void Engines_Component_i::endService(const char *serviceName)
+//=============================================================================
+/*! 
+ *  CORBA method: 
+ *  returns a previously stored map (key=string,value=any) as a sequence.
+ *  (see setProperties)
+ */
+//=============================================================================
+
+Engines::FieldsDict* Engines_Component_i::getProperties()
 {
-  MESSAGE("Send EndService notification for " << serviceName << endl
-         << "Component instance : " << _instanceName << endl << endl);
-  _ThreadId = 0 ;
+  Engines::FieldsDict_var copie = new Engines::FieldsDict;
+  copie->length(_fieldsDict.size());
+  map<std::string,CORBA::Any>::iterator it;
+  CORBA::ULong i = 0;
+  for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
+    {
+      std::string cle((*it).first);
+      copie[i].key = CORBA::string_dup(cle.c_str());
+      copie[i].value = _fieldsDict[cle];
+    }
+  return copie._retn();
 }
 
+//=============================================================================
+/*! 
+ *  CORBA method: used by Supervision to give names to this instance
+ */
+//=============================================================================
+
 void Engines_Component_i::Names( const char * graphName ,
-                                 const char * nodeName ) {
+                                 const char * nodeName )
+{
   _graphName = graphName ;
   _nodeName = nodeName ;
-//  MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
-//          << _nodeName << "' )");
-}
-
-char* Engines_Component_i::graphName() {
-  return CORBA::string_dup( _graphName.c_str() ) ;
+  //  MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
+  //          << _nodeName << "' )");
 }
 
-char* Engines_Component_i::nodeName() {
-  return CORBA::string_dup( _nodeName.c_str() ) ;
-}
+//=============================================================================
+/*! 
+ *  CORBA method: used in Supervision
+ */
+//=============================================================================
 
-bool Killer( int ThreadId , int signum ) {
-  if ( ThreadId ) {
-    if ( signum == 0 ) {
-      if ( pthread_cancel( ThreadId ) ) {
-        perror("Killer pthread_cancel error") ;
-        return false ;
-      }
-      else {
-        MESSAGE("Killer : ThreadId " << ThreadId << " pthread_canceled") ;
-      }
-    }
-    else {
-      if ( pthread_kill( ThreadId , signum ) == -1 ) {
-        perror("Killer pthread_kill error") ;
-        return false ;
-      }
-      else {
-        MESSAGE("Killer : ThreadId " << ThreadId << " pthread_killed("
-                << signum << ")") ;
-      }
-    }
-  }
-  return true ;
-}
+bool Engines_Component_i::Kill_impl() 
+{
+//  MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
+//          << " pid " << getpid() << " instanceName "
+//          << _instanceName.c_str() << " interface " << _interfaceName.c_str()
+//          << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
+//          << dec << " _ThreadId " << _ThreadId << " this " << hex << this
+//          << dec ) ;
 
-bool Engines_Component_i::Kill_impl() {
-  MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
-          << " pid " << getpid() << " instanceName "
-          << _instanceName.c_str() << " interface " << _interfaceName.c_str()
-          << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
-          << dec << " _ThreadId " << _ThreadId << " this " << hex << this
-          << dec ) ;
   bool RetVal = false ;
-  if ( _ThreadId > 0 && pthread_self() != _ThreadId ) {
-    RetVal = Killer( _ThreadId , 0 ) ;
-    _ThreadId = (pthread_t ) -1 ;
-  }
+  if ( _ThreadId > 0 && pthread_self() != _ThreadId )
+    {
+      RetVal = Killer( _ThreadId , 0 ) ;
+      _ThreadId = (pthread_t ) -1 ;
+    }
   return RetVal ;
 }
 
-bool Engines_Component_i::Stop_impl() {
+//=============================================================================
+/*! 
+ *  CORBA method: used in Supervision
+ */
+//=============================================================================
+
+bool Engines_Component_i::Stop_impl()
+{
   MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
           << " pid " << getpid() << " instanceName "
           << _instanceName.c_str() << " interface " << _interfaceName.c_str()
           << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
           << dec << " _ThreadId " << _ThreadId );
+  
+
   bool RetVal = false ;
-  if ( _ThreadId > 0 && pthread_self() != _ThreadId ) {
-    RetVal = Killer( _ThreadId , 0 ) ;
-    _ThreadId = (pthread_t ) -1 ;
-  }
+  if ( _ThreadId > 0 && pthread_self() != _ThreadId )
+    {
+      RetVal = Killer( _ThreadId , 0 ) ;
+      _ThreadId = (pthread_t ) -1 ;
+    }
   return RetVal ;
 }
 
-bool Engines_Component_i::Suspend_impl() {
+//=============================================================================
+/*! 
+ *  CORBA method: used in Supervision
+ */
+//=============================================================================
+
+bool Engines_Component_i::Suspend_impl()
+{
   MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
           << " pid " << getpid() << " instanceName "
           << _instanceName.c_str() << " interface " << _interfaceName.c_str()
           << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
           << dec << " _ThreadId " << _ThreadId );
+
   bool RetVal = false ;
-  if ( _ThreadId > 0 && pthread_self() != _ThreadId ) {
-    if ( _Sleeping ) {
-      return false ;
-    }
-    else {
-      RetVal = Killer( _ThreadId ,SIGINT ) ;
+  if ( _ThreadId > 0 && pthread_self() != _ThreadId )
+    {
+      if ( _Sleeping )
+       {
+         return false ;
+       }
+    else 
+      {
+       RetVal = Killer( _ThreadId ,SIGINT ) ;
+      }
     }
-  }
   return RetVal ;
 }
 
-bool Engines_Component_i::Resume_impl() {
+//=============================================================================
+/*! 
+ *  CORBA method: used in Supervision
+ */
+//=============================================================================
+
+bool Engines_Component_i::Resume_impl()
+{
   MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
           << " pid " << getpid() << " instanceName "
           << _instanceName.c_str() << " interface " << _interfaceName.c_str()
           << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
           << dec << " _ThreadId " << _ThreadId );
   bool RetVal = false ;
-  if ( _ThreadId > 0 && pthread_self() != _ThreadId ) {
-    if ( _Sleeping ) {
-      _Sleeping = false ;
-      RetVal = true ;
-    }
-    else {
-      RetVal = false ;
+  if ( _ThreadId > 0 && pthread_self() != _ThreadId )
+    {
+    if ( _Sleeping ) 
+      {
+       _Sleeping = false ;
+       RetVal = true ;
+      }
+    else
+      {
+       RetVal = false ;
+      }
     }
-  }
   return RetVal ;
+}
+
+//=============================================================================
+/*! 
+ *  CORBA method: 
+ */
+//=============================================================================
 
+CORBA::Long Engines_Component_i::CpuUsed_impl()
+{
+  long cpu = 0 ;
+  if ( _ThreadId || _Executed )
+    {
+    if ( _ThreadId > 0 )
+      {
+      if ( pthread_self() != _ThreadId )
+       {
+        if ( _Sleeping )
+         {
+         }
+        else
+         {
+           // Get Cpu in the appropriate thread with that object !...
+           theEngines_Component = this ;
+           Killer( _ThreadId ,SIGUSR1 ) ;
+         }
+        cpu = _ThreadCpuUsed ;
+       }
+      else
+       {
+         _ThreadCpuUsed = CpuUsed() ;
+         cpu = _ThreadCpuUsed ;
+         // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
+         //      << _serviceName << " " << cpu << endl ;
+      }
+    }
+    else 
+      {
+       cpu = _ThreadCpuUsed ;
+       // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
+       //      << _serviceName << " " << cpu<< endl ;
+      }
+    }
+  else
+    {
+      // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
+      //     <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
+    }
+  return cpu ;
 }
 
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <unistd.h>
+//=============================================================================
+/*! 
+ *  C++ method: set study Id
+ *  \param studyId         0 if instance is not associated to a study, 
+ *                         >0 otherwise (== study id)
+ *  \return true if the set of study Id is OK
+ *  must be set once by Container, and cannot be changed after.
+ */
+//=============================================================================
+
+CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
+{
+  ASSERT( studyId >= 0);
+  CORBA::Boolean ret = false;
+  if (_studyId < 0)
+    {
+      _studyId = studyId;
+      ret = true;
+    }
+  else
+    if ( _studyId == studyId) ret = true;
+  return ret;
+}
+
+//=============================================================================
+/*! 
+ *  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)
+{
+  MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
+         << endl << "Component instance : " << _instanceName << endl << endl);
+  _ThreadId = pthread_self() ;
+  _StartUsed = 0 ;
+  _StartUsed = CpuUsed_impl() ;
+  _ThreadCpuUsed = 0 ;
+  _Executed = true ;
+  _serviceName = serviceName ;
+  if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
+    {
+      perror("pthread_setcanceltype ") ;
+      exit(0) ;
+    }
+  if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
+    {
+      perror("pthread_setcancelstate ") ;
+      exit(0) ;
+    }
+//  MESSAGE(pthread_self() << " Return from BeginService for " << serviceName
+//          << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed
+//          << " _graphName " << _graphName << " _nodeName " << _nodeName );
+
+  // --- for supervisor : all strings given with setProperties
+  //     are set in environment
+  bool overwrite = true;
+  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;
+         // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC.
+#if defined __GNUC__
+         int ret = setenv(cle.c_str(), value, overwrite);
+#else
+         //CCRT porting : setenv not defined in stdlib.h
+         std::string s(cle);
+         s+='=';
+         s+=value;
+         // char* cast because 1st arg of linux putenv function
+         // is not a const char* !
+         int ret=putenv((char *)s.c_str());
+         //End of CCRT porting
+#endif
+         MESSAGE("--- setenv: "<<cle<<" = "<< value);
+       }
+    }
+}
+
+//=============================================================================
+/*! 
+ *  C++ method: used by derived classes for supervision
+ */
+//=============================================================================
+
+void Engines_Component_i::endService(const char *serviceName)
+{
+  _ThreadCpuUsed = CpuUsed_impl() ;
+  MESSAGE(pthread_self() << " Send EndService notification for " << serviceName
+         << endl << " Component instance : " << _instanceName << " StartUsed "
+          << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
+  _ThreadId = 0 ;
+}
 
-long Engines_Component_i::CpuUsed_impl() {
+//=============================================================================
+/*! 
+ *  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 )
+{
+  if ( ThreadId )
+    {
+      if ( signum == 0 )
+       {
+         if ( pthread_cancel( ThreadId ) )
+           {
+             perror("Killer pthread_cancel error") ;
+             return false ;
+           }
+         else
+           {
+             MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
+                     << " pthread_canceled") ;
+           }
+       }
+      else
+       {
+         if ( pthread_kill( ThreadId , signum ) == -1 )
+           {
+             perror("Killer pthread_kill error") ;
+             return false ;
+           }
+         else 
+           {
+             MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
+                     << " pthread_killed(" << signum << ")") ;
+           }
+       }
+    }
+  return true ;
+}
+
+//=============================================================================
+/*! 
+ *  C++ method:
+ */ 
+//=============================================================================
+
+void SetCpuUsed()
+{
+  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 ;
   struct rusage usage ;
-  long cpu ;
-  if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
-    perror("GraphBase::CpuUsed") ;
-    return 0 ;
-  }
-//  return usage.ru_utime.__time_t tv_sec ;
-  cout << "CpuUsed " << usage.ru_utime.tv_sec << " " << usage.ru_utime.tv_usec << " "
-       << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec << endl ;
-  cpu = usage.ru_utime.tv_sec - _StartUsed ;
+  if ( _ThreadId || _Executed )
+    {
+      if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
+       {
+         perror("Engines_Component_i::CpuUsed") ;
+         return 0 ;
+       }
+      cpu = usage.ru_utime.tv_sec - _StartUsed ;
+      // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
+      //      << _serviceName   << usage.ru_utime.tv_sec << " - " << _StartUsed
+      //      << " = " << cpu << endl ;
+    }
+  else
+    {
+      // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
+      //      << _ThreadId << " " << _serviceName<< " _StartUsed " 
+      //      << _StartUsed << endl ;
+    }
   return cpu ;
 }
 
-// Send message to event channel
+//=============================================================================
+/*! 
+ *  C++ method: Send message to event channel
+ */
+//=============================================================================
 
-void Engines_Component_i::sendMessage(const char *event_type, const char *message) {
+void Engines_Component_i::sendMessage(const char *event_type,
+                                     const char *message)
+{
     _notifSupplier->Send(graphName(), nodeName(), event_type, message);
 }
+
+//=============================================================================
+/*! 
+ *  C++ method:
+ */
+//=============================================================================
+
+string Engines_Component_i::GetDynLibraryName(const char *componentName)
+{
+  string ret="lib";
+  ret+=componentName;
+  ret+="Engine.so";
+  return ret;
+}
+
+//=============================================================================
+/*! 
+ *  C++ method:
+ */
+//=============================================================================
+
+string Engines_Component_i::BuildComponentNameForNS(const char *ComponentName,
+                                                   const char *ContainerName,
+                                                   const char *hostname)
+{
+  string ret =
+    Engines_Container_i::BuildContainerNameForNS(ContainerName,hostname);
+  ret+="/";
+  ret+=ComponentName;
+  return ret;
+}
+