Salome HOME
Merging from V3_2_6pre4
[modules/kernel.git] / src / Container / Component_i.cxx
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   : Component_i.cxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 //#define private protected  // for pd_refCount trace
30 #include "SALOME_Component_i.hxx"
31 #include "SALOME_Container_i.hxx"
32 #include "RegistryConnexion.hxx"
33 #include "OpUtil.hxx"
34 #include <stdio.h>
35 #ifndef WNT
36 #include <dlfcn.h>
37 #endif
38 #include <cstdlib>
39 #include "utilities.h"
40
41 #ifndef WNT
42 #include <sys/time.h>
43 #include <sys/resource.h>
44 #include <unistd.h>
45 #else
46 #include <sys/timeb.h>
47 int SIGUSR11 = 1000;
48 #endif
49
50
51 using namespace std;
52
53 extern bool _Sleeping ;
54 static Engines_Component_i * theEngines_Component ;
55
56 bool Engines_Component_i::_isMultiStudy = true;
57 bool Engines_Component_i::_isMultiInstance = false;
58
59 //=============================================================================
60 /*! 
61  *  Default constructor, not for use
62  */
63 //=============================================================================
64
65 Engines_Component_i::Engines_Component_i()
66 {
67   //ASSERT(0);
68   MESSAGE("Default Constructor, not for normal use...");
69 }
70
71 //=============================================================================
72 /*! 
73  *  Standard Constructor for generic Component, used in derived class
74  *  Connection to Registry and Notification
75  *  \param orb Object Request broker given by Container
76  *  \param poa Portable Object Adapter from Container (normally root_poa)
77  *  \param contId container CORBA id inside the server
78  *  \param instanceName unique instance name for this object (see Container_i)
79  *  \param interfaceName component class name
80  *  \param notif use of notification
81  */
82 //=============================================================================
83
84 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
85                                          PortableServer::POA_ptr poa, 
86                                          PortableServer::ObjectId * contId, 
87                                          const char *instanceName,
88                                          const char *interfaceName,
89                                          bool notif) :
90   _instanceName(instanceName),
91   _interfaceName(interfaceName),
92   _myConnexionToRegistry(0),
93   _ThreadId(0) ,
94   _ThreadCpuUsed(0) ,
95   _Executed(false) ,
96   _graphName("") ,
97   _nodeName(""),
98   _studyId(-1),
99   _CanceledThread(false)
100 {
101   MESSAGE("Component constructor with instanceName "<< _instanceName);
102   //SCRUTE(pd_refCount);
103   _orb = CORBA::ORB::_duplicate(orb);
104   _poa = PortableServer::POA::_duplicate(poa);
105   _contId = contId ;
106   CORBA::Object_var o = _poa->id_to_reference(*contId); // container ior...
107   const CORBA::String_var ior = _orb->object_to_string(o);
108   _myConnexionToRegistry = new RegistryConnexion(0, 0, ior,"theSession",
109                                                  _instanceName.c_str());
110
111   _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
112   //SCRUTE(pd_refCount);
113 }
114
115 //=============================================================================
116 /*! 
117  * Standard constructor for parallel component
118  *  Connection Notification (no connection to Registry !)
119  *  \param orb Object Request broker given by Container
120  *  \param poa Portable Object Adapter from Container (normally root_poa)
121  *  \param contId container CORBA id inside the server
122  *  \param instanceName unique instance name for this object (see Container_i)
123  *  \param interfaceName component class name
124  *  \param flag not used...
125  *  \param notif use of notification
126  */
127 //=============================================================================
128
129 Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb,
130                                          PortableServer::POA_ptr poa, 
131                                          PortableServer::ObjectId * contId, 
132                                          const char *instanceName,
133                                          const char *interfaceName,
134                                          int flag,
135                                          bool notif ) :
136  _instanceName(instanceName),
137  _interfaceName(interfaceName),
138  _myConnexionToRegistry(0),
139  _ThreadId(0) ,
140  _ThreadCpuUsed(0) ,
141  _Executed(false) ,
142  _graphName("") ,
143  _nodeName(""),
144  _studyId(-1),
145  _CanceledThread(false)
146 {
147   _orb = CORBA::ORB::_duplicate(orb);
148   _poa = PortableServer::POA::_duplicate(poa);
149   _contId = contId ;
150
151   _notifSupplier = new NOTIFICATION_Supplier(instanceName, notif);
152 }
153
154 //=============================================================================
155 /*! 
156  *  Destructor: call Container for decrement of instances count.
157  *  When instances count falls to 0, the container tries to remove the
158  *  component library (dlclose)
159  */
160 //=============================================================================
161
162 Engines_Component_i::~Engines_Component_i()
163 {
164   MESSAGE("Component destructor");
165   Engines_Container_i::decInstanceCnt(_interfaceName);
166 }
167
168 //=============================================================================
169 /*! 
170  *  CORBA method: return name of the instance, unique in this Container
171  */
172 //=============================================================================
173
174 char* Engines_Component_i::instanceName()
175 {
176    return CORBA::string_dup(_instanceName.c_str()) ;
177 }
178
179 //=============================================================================
180 /*! 
181  *  CORBA method: return name of the component class
182  */
183 //=============================================================================
184
185 char* Engines_Component_i::interfaceName()
186 {
187   return CORBA::string_dup(_interfaceName.c_str()) ;
188 }
189
190 //=============================================================================
191 /*! 
192  *  CORBA method: Get study Id
193  *  \return -1: not initialised (Internal Error)
194  *           0: multistudy component instance
195  *          >0: study id associated to this instance
196  */
197 //=============================================================================
198
199 CORBA::Long Engines_Component_i::getStudyId()
200 {
201   return _studyId;
202 }
203
204 //=============================================================================
205 /*! 
206  *  CORBA method: Test if instance is alive and responds
207  */
208 //=============================================================================
209
210 void Engines_Component_i::ping()
211 {
212   MESSAGE("Engines_Component_i::ping() pid "<< getpid() << " threadid "
213           << pthread_self());
214 }
215
216 //=============================================================================
217 /*! 
218  *  CORBA method: Deactivate this instance. CORBA object is deactivated (do not
219  *  respond any more to CORBA calls), the connection to Regsitry is removed
220  *  (Registry informed of deactivation), internal server reference counter on
221  *  the derived servant class is decremented, to allow destruction of the class
222  *  (delete) by POA, when there are no more references.
223  *  -- TO BE USED BY CONTAINER ONLY (Container housekeeping) --
224  */
225 //=============================================================================
226
227 void Engines_Component_i::destroy()
228 {
229   MESSAGE("Engines_Component_i::destroy()");
230   //SCRUTE(pd_refCount);
231
232   delete _notifSupplier;
233   _notifSupplier = 0;
234
235   delete _myConnexionToRegistry;
236   _myConnexionToRegistry = 0 ;
237   _poa->deactivate_object(*_id) ;
238   CORBA::release(_poa) ;
239   delete(_id) ;
240   //SCRUTE(pd_refCount);
241   _thisObj->_remove_ref();
242   //SCRUTE(pd_refCount);
243   MESSAGE("Engines_Component_i::destroyed") ;
244 }
245
246 //=============================================================================
247 /*! 
248  *  CORBA method: return CORBA reference of the Container
249  *
250  */
251 //=============================================================================
252
253 Engines::Container_ptr Engines_Component_i::GetContainerRef()
254 {
255   //  MESSAGE("Engines_Component_i::GetContainerRef");
256   CORBA::Object_ptr o = _poa->id_to_reference(*_contId) ;
257   return Engines::Container::_narrow(o);
258 }
259
260 //=============================================================================
261 /*! 
262  *  CORBA method: 
263  *  Gives a sequence of (key=string,value=any) to the component. 
264  *  Base class component stores the sequence in a map.
265  *  The map is cleared before.
266  *  This map is for use by derived classes. 
267  *  \param dico sequence of (key=string,value=any)
268  */
269 //=============================================================================
270
271 void Engines_Component_i::setProperties(const Engines::FieldsDict& dico)
272 {
273   _fieldsDict.clear();
274   for (CORBA::ULong i=0; i<dico.length(); i++)
275     {
276       std::string cle(dico[i].key);
277       _fieldsDict[cle] = dico[i].value;
278     }
279 }
280
281 //=============================================================================
282 /*! 
283  *  CORBA method: 
284  *  returns a previously stored map (key=string,value=any) as a sequence.
285  *  (see setProperties)
286  */
287 //=============================================================================
288
289 Engines::FieldsDict* Engines_Component_i::getProperties()
290 {
291   Engines::FieldsDict_var copie = new Engines::FieldsDict;
292   copie->length(_fieldsDict.size());
293   map<std::string,CORBA::Any>::iterator it;
294   CORBA::ULong i = 0;
295   for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++)
296     {
297       std::string cle((*it).first);
298       copie[i].key = CORBA::string_dup(cle.c_str());
299       copie[i].value = _fieldsDict[cle];
300     }
301   return copie._retn();
302 }
303
304 //=============================================================================
305 /*! 
306  *  CORBA method: used by Supervision to give names to this instance
307  */
308 //=============================================================================
309
310 void Engines_Component_i::Names( const char * graphName ,
311                                  const char * nodeName )
312 {
313   _graphName = graphName ;
314   _nodeName = nodeName ;
315   //  MESSAGE("Engines_Component_i::Names( '" << _graphName << "' , '"
316   //          << _nodeName << "' )");
317 }
318
319 //=============================================================================
320 /*! 
321  *  CORBA method: used in Supervision
322  */
323 //=============================================================================
324
325 bool Engines_Component_i::Kill_impl() 
326 {
327 //  MESSAGE("Engines_Component_i::Kill_i() pthread_t "<< pthread_self()
328 //          << " pid " << getpid() << " instanceName "
329 //          << _instanceName.c_str() << " interface " << _interfaceName.c_str()
330 //          << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
331 //          << dec << " _ThreadId " << _ThreadId << " this " << hex << this
332 //          << dec ) ;
333
334   bool RetVal = false ;
335 #ifndef WNT
336   if ( _ThreadId > 0 && pthread_self() != _ThreadId )
337     {
338       RetVal = Killer( _ThreadId , SIGUSR2 ) ;
339       _ThreadId = (pthread_t ) -1 ;
340     }
341
342 #else
343   if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
344     {
345       RetVal = Killer( *_ThreadId , 0 ) ;
346       _ThreadId = (pthread_t* ) 0 ;
347     }
348
349 #endif
350   return RetVal ;
351 }
352
353 //=============================================================================
354 /*! 
355  *  CORBA method: used in Supervision
356  */
357 //=============================================================================
358
359 bool Engines_Component_i::Stop_impl()
360 {
361   MESSAGE("Engines_Component_i::Stop_i() pthread_t "<< pthread_self()
362           << " pid " << getpid() << " instanceName "
363           << _instanceName.c_str() << " interface " << _interfaceName.c_str()
364           << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
365           << dec << " _ThreadId " << _ThreadId );
366   
367
368   bool RetVal = false ;
369 #ifndef WNT
370   if ( _ThreadId > 0 && pthread_self() != _ThreadId )
371     {
372       RetVal = Killer( _ThreadId , 0 ) ;
373       _ThreadId = (pthread_t ) -1 ;
374     }
375 #else
376   if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
377     {
378       RetVal = Killer( *_ThreadId , 0 ) ;
379       _ThreadId = (pthread_t* ) 0 ;
380     }
381 #endif
382   return RetVal ;
383 }
384
385 //=============================================================================
386 /*! 
387  *  CORBA method: used in Supervision
388  */
389 //=============================================================================
390
391 bool Engines_Component_i::Suspend_impl()
392 {
393   MESSAGE("Engines_Component_i::Suspend_i() pthread_t "<< pthread_self()
394           << " pid " << getpid() << " instanceName "
395           << _instanceName.c_str() << " interface " << _interfaceName.c_str()
396           << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
397           << dec << " _ThreadId " << _ThreadId );
398
399   bool RetVal = false ;
400 #ifndef WNT
401   if ( _ThreadId > 0 && pthread_self() != _ThreadId )
402 #else
403   if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
404 #endif
405     {
406       if ( _Sleeping )
407         {
408           return false ;
409         }
410     else 
411       {
412 #ifndef WNT
413         RetVal = Killer( _ThreadId ,SIGINT ) ;
414 #else
415         RetVal = Killer( *_ThreadId ,SIGINT ) ;
416 #endif
417         //if ( RetVal ) _Sleeping = true;
418
419       }
420     }
421   return RetVal ;
422 }
423
424 //=============================================================================
425 /*! 
426  *  CORBA method: used in Supervision
427  */
428 //=============================================================================
429
430 bool Engines_Component_i::Resume_impl()
431 {
432   MESSAGE("Engines_Component_i::Resume_i() pthread_t "<< pthread_self()
433           << " pid " << getpid() << " instanceName "
434           << _instanceName.c_str() << " interface " << _interfaceName.c_str()
435           << " machineName " << GetHostname().c_str()<< " _id " << hex << _id
436           << dec << " _ThreadId " << _ThreadId );
437   bool RetVal = false ;
438 #ifndef WNT
439   if ( _ThreadId > 0 && pthread_self() != _ThreadId )
440 #else
441   if ( _ThreadId > 0 && pthread_self().p != _ThreadId->p )
442 #endif
443     {
444     if ( _Sleeping ) 
445       {
446         _Sleeping = false ;
447         RetVal = true ;
448       }
449     else
450       {
451         RetVal = false ;
452       }
453     }
454   return RetVal ;
455 }
456
457 //=============================================================================
458 /*! 
459  *  CORBA method: 
460  */
461 //=============================================================================
462
463 CORBA::Long Engines_Component_i::CpuUsed_impl()
464 {
465   long cpu = 0 ;
466   if ( _ThreadId || _Executed )
467     {
468     if ( _ThreadId > 0 )
469       {
470 #ifndef WNT
471       if ( pthread_self() != _ThreadId )
472 #else
473       if ( pthread_self().p != _ThreadId->p )
474 #endif
475         {
476         if ( _Sleeping )
477           {
478           }
479         else
480           {
481             // Get Cpu in the appropriate thread with that object !...
482             theEngines_Component = this ;
483 #ifndef WNT
484             Killer( _ThreadId ,SIGUSR1 ) ;
485 #else
486             Killer( *_ThreadId ,SIGUSR11 ) ;
487 #endif
488           }
489         cpu = _ThreadCpuUsed ;
490         }
491       else
492         {
493           _ThreadCpuUsed = CpuUsed() ;
494           cpu = _ThreadCpuUsed ;
495           // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
496           //      << _serviceName << " " << cpu << endl ;
497       }
498     }
499     else 
500       {
501         cpu = _ThreadCpuUsed ;
502         // cout << pthread_self() << " Engines_Component_i::CpuUsed_impl "
503         //      << _serviceName << " " << cpu<< endl ;
504       }
505     }
506   else
507     {
508       // cout<< pthread_self()<<"Engines_Component_i::CpuUsed_impl _ThreadId "
509       //     <<_ThreadId <<" "<<_serviceName<<" _StartUsed "<<_StartUsed<<endl;
510     }
511   return cpu ;
512 }
513
514
515 //=============================================================================
516 /*! 
517  *  C++ method: return Container Servant
518  */
519 //=============================================================================
520
521 Engines_Container_i *Engines_Component_i::GetContainerPtr()
522 {
523   return dynamic_cast<Engines_Container_i*>(_poa->id_to_servant(*_contId)) ;
524 }
525
526 //=============================================================================
527 /*! 
528  *  C++ method: set study Id
529  *  \param studyId         0 if instance is not associated to a study, 
530  *                         >0 otherwise (== study id)
531  *  \return true if the set of study Id is OK
532  *  must be set once by Container, at instance creation,
533  *  and cannot be changed after.
534  */
535 //=============================================================================
536
537 CORBA::Boolean Engines_Component_i::setStudyId(CORBA::Long studyId)
538 {
539   ASSERT( studyId >= 0);
540   CORBA::Boolean ret = false;
541   if (_studyId < 0) // --- not yet initialized 
542     {
543       _studyId = studyId;
544       ret = true;
545     }
546   else
547     if ( _studyId == studyId) ret = true;
548   return ret;
549 }
550
551 //=============================================================================
552 /*! 
553  *  C++ method: return CORBA instance id, the id is set in derived class
554  *  constructor, when instance is activated.
555  */
556 //=============================================================================
557
558 PortableServer::ObjectId * Engines_Component_i::getId()
559 {
560 //  MESSAGE("PortableServer::ObjectId * Engines_Component_i::getId()");
561   return _id ;
562 }
563
564 //=============================================================================
565 /*! 
566  *  C++ method: used by derived classes for supervision
567  */
568 //=============================================================================
569
570 void Engines_Component_i::beginService(const char *serviceName)
571 {
572   MESSAGE(pthread_self() << "Send BeginService notification for " <<serviceName
573           << endl << "Component instance : " << _instanceName << endl << endl);
574 #ifndef WNT
575   _ThreadId = pthread_self() ;
576 #else
577   _ThreadId = new pthread_t;
578   _ThreadId->p = pthread_self().p ;
579   _ThreadId->x = pthread_self().x ;
580 #endif
581   _StartUsed = 0 ;
582   _StartUsed = CpuUsed_impl() ;
583   _ThreadCpuUsed = 0 ;
584   _Executed = true ;
585   _serviceName = serviceName ;
586   theEngines_Component = this ;
587   if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) )
588     {
589       perror("pthread_setcanceltype ") ;
590       exit(0) ;
591     }
592   if ( pthread_setcancelstate( PTHREAD_CANCEL_ENABLE , NULL ) )
593     {
594       perror("pthread_setcancelstate ") ;
595       exit(0) ;
596     }
597 //  MESSAGE(pthread_self() << " Return from BeginService for " << serviceName
598 //          << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed
599 //          << " _graphName " << _graphName << " _nodeName " << _nodeName );
600
601   // --- for supervisor : all strings given with setProperties
602   //     are set in environment
603   bool overwrite = true;
604   map<std::string,CORBA::Any>::iterator it;
605   for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
606     {
607       std::string cle((*it).first);
608       if ((*it).second.type()->kind() == CORBA::tk_string)
609         {
610           const char* value;
611           (*it).second >>= value;
612           // ---todo: replace __GNUC__ test by an autoconf macro AC_CHECK_FUNC.
613 #if defined __GNUC__
614           int ret = setenv(cle.c_str(), value, overwrite);
615 #else
616           //CCRT porting : setenv not defined in stdlib.h
617           std::string s(cle);
618           s+='=';
619           s+=value;
620           // char* cast because 1st arg of linux putenv function
621           // is not a const char* !
622           int ret=putenv((char *)s.c_str());
623           //End of CCRT porting
624 #endif
625           MESSAGE("--- setenv: "<<cle<<" = "<< value);
626         }
627     }
628 }
629
630 //=============================================================================
631 /*! 
632  *  C++ method: used by derived classes for supervision
633  */
634 //=============================================================================
635
636 void Engines_Component_i::endService(const char *serviceName)
637 {
638   if ( !_CanceledThread )
639     _ThreadCpuUsed = CpuUsed_impl() ;
640   MESSAGE(pthread_self() << " Send EndService notification for " << serviceName
641           << endl << " Component instance : " << _instanceName << " StartUsed "
642           << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <<endl);
643   _ThreadId = 0 ;
644 }
645
646 //=============================================================================
647 /*! 
648  *  C++ method: -- CHECK IF USED --
649  */
650 //=============================================================================
651
652 char* Engines_Component_i::graphName()
653 {
654   return CORBA::string_dup( _graphName.c_str() ) ;
655 }
656
657 //=============================================================================
658 /*! 
659  *  C++ method: -- CHECK IF USED --
660  */
661 //=============================================================================
662
663 char* Engines_Component_i::nodeName()
664 {
665   return CORBA::string_dup( _nodeName.c_str() ) ;
666 }
667
668 //=============================================================================
669 /*! 
670  *  C++ method: used in Supervision (see kill_impl)
671  */
672 //=============================================================================
673
674 bool Engines_Component_i::Killer( pthread_t ThreadId , int signum )
675 {
676 #ifndef WNT
677   if ( ThreadId )
678 #else
679   if ( ThreadId.p )
680 #endif
681     {
682       if ( signum == 0 )
683         {
684           if ( pthread_cancel( ThreadId ) )
685             {
686               perror("Killer pthread_cancel error") ;
687               return false ;
688             }
689           else
690             {
691               MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
692                       << " pthread_canceled") ;
693             }
694         }
695       else
696         {
697           if ( pthread_kill( ThreadId , signum ) == -1 )
698             {
699               perror("Killer pthread_kill error") ;
700               return false ;
701             }
702           else 
703             {
704               MESSAGE(pthread_self() << "Killer : ThreadId " << ThreadId
705                       << " pthread_killed(" << signum << ")") ;
706             }
707         }
708     }
709   return true ;
710 }
711
712 //=============================================================================
713 /*! 
714  *  C++ method:
715  */ 
716 //=============================================================================
717
718 void SetCpuUsed()
719 {
720   if ( theEngines_Component )
721     theEngines_Component->SetCurCpu() ;
722 }
723
724 //=============================================================================
725 /*! 
726  *  C++ method:
727  */
728 //=============================================================================
729
730 void Engines_Component_i::SetCurCpu()
731 {
732   _ThreadCpuUsed =  CpuUsed() ;
733   //  MESSAGE(pthread_self() << 
734   //  " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ;
735 }
736
737 //=============================================================================
738 /*! 
739  *  C++ method:
740  */
741 //=============================================================================
742
743 long Engines_Component_i::CpuUsed()
744 {
745   long cpu = 0 ;
746 #ifndef WNT
747   struct rusage usage ;
748   if ( _ThreadId || _Executed )
749     {
750       if ( getrusage( RUSAGE_SELF , &usage ) == -1 )
751         {
752           perror("Engines_Component_i::CpuUsed") ;
753           return 0 ;
754         }
755       cpu = usage.ru_utime.tv_sec - _StartUsed ;
756       // cout << pthread_self() << " Engines_Component_i::CpuUsed " << " "
757       //      << _serviceName   << usage.ru_utime.tv_sec << " - " << _StartUsed
758       //      << " = " << cpu << endl ;
759     }
760   else
761     {
762       // cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId "
763       //      << _ThreadId << " " << _serviceName<< " _StartUsed " 
764       //      << _StartUsed << endl ;
765     }
766 #else
767         // NOT implementet yet
768 #endif
769
770
771   return cpu ;
772 }
773
774 void CallCancelThread()
775 {
776   if ( theEngines_Component )
777     theEngines_Component->CancelThread() ;
778 }
779
780 //=============================================================================
781 /*!
782  *  C++ method:
783  */
784 //=============================================================================
785
786 void Engines_Component_i::CancelThread()
787 {
788   _CanceledThread = true;
789 }
790
791 //=============================================================================
792 /*! 
793  *  C++ method: Send message to event channel
794  */
795 //=============================================================================
796
797 void Engines_Component_i::sendMessage(const char *event_type,
798                                       const char *message)
799 {
800     _notifSupplier->Send(graphName(), nodeName(), event_type, message);
801 }
802
803 //=============================================================================
804 /*! 
805  *  C++ method: return standard library name built on component name
806  */
807 //=============================================================================
808
809 string Engines_Component_i::GetDynLibraryName(const char *componentName)
810 {
811   string ret="lib";
812   ret+=componentName;
813   ret+="Engine.so";
814   return ret;
815 }
816
817 //=============================================================================
818 /*! 
819  *  C++ method: DumpPython default implementation
820  */
821 //=============================================================================
822
823 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy, 
824                                                   CORBA::Boolean isPublished, 
825                                                   CORBA::Boolean& isValidScript)
826 {
827   char* aScript = "def RebuildData(theStudy): pass";
828   char* aBuffer = new char[strlen(aScript)+1];
829   strcpy(aBuffer, aScript);
830   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
831   int aBufferSize = strlen(aBuffer)+1;
832   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1); 
833   isValidScript = true;
834   return aStreamFile._retn(); 
835 }