1 // SALOME Container : implementation of container and engine for Kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : Container_i.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 //#define private public
38 #include "../../adm/win32/SALOME_WNT.hxx"
44 #include "utilities.h"
45 #include <SALOMEconfig.h>
47 #include CORBA_SERVER_HEADER(SALOME_Component)
49 #include <SALOME_Component.hh>
51 #include <pthread.h> // must be before Python.h !
52 #include "SALOME_Container_i.hxx"
53 #include "SALOME_Component_i.hxx"
54 #include "SALOME_FileRef_i.hxx"
55 #include "SALOME_FileTransfer_i.hxx"
56 #include "SALOME_NamingService.hxx"
60 #include "Container_init_python.hxx"
64 bool _Sleeping = false ;
66 // // Needed by multi-threaded Python --- Supervision
71 // Containers with name FactoryServer are started via rsh in LifeCycleCORBA
72 // Other Containers are started via start_impl of FactoryServer
74 extern "C" {void ActSigIntHandler() ; }
76 extern "C" {void SigIntHandler(int, siginfo_t *, void *) ; }
78 extern "C" {void SigIntHandler( int ) ; }
82 map<std::string, int> Engines_Container_i::_cntInstances_map;
83 map<std::string, void *> Engines_Container_i::_library_map;
84 map<std::string, void *> Engines_Container_i::_toRemove_map;
85 omni_mutex Engines_Container_i::_numInstanceMutex ;
87 //=============================================================================
89 * Default constructor, not for use
91 //=============================================================================
93 Engines_Container_i::Engines_Container_i () :
98 //=============================================================================
102 //=============================================================================
104 Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb,
105 PortableServer::POA_var poa,
106 char *containerName ,
107 int argc , char* argv[],
109 bool isServantAloneInProcess
111 _numInstance(0),_isServantAloneInProcess(isServantAloneInProcess)
113 _pid = (long)getpid();
121 string hostname = GetHostname();
122 MESSAGE(hostname << " " << getpid() << " Engines_Container_i starting argc "
123 << _argc << " Thread " << pthread_self() ) ;
128 MESSAGE(" argv" << i << " " << _argv[ i ]) ;
134 INFOS("SALOME_Container usage : SALOME_Container ServerName");
138 _isSupervContainer = false;
139 if (strcmp(argv[1],"SuperVisionContainer") == 0) _isSupervContainer = true;
141 if (_isSupervContainer)
147 _orb = CORBA::ORB::_duplicate(orb) ;
148 _poa = PortableServer::POA::_duplicate(poa) ;
150 // Pour les containers paralleles: il ne faut pas enregistrer et activer
151 // le container generique, mais le container specialise
155 _id = _poa->activate_object(this);
156 _NS = new SALOME_NamingService();
157 _NS->init_orb( CORBA::ORB::_duplicate(_orb) ) ;
158 CORBA::Object_var obj=_poa->id_to_reference(*_id);
159 Engines::Container_var pCont
160 = Engines::Container::_narrow(obj);
162 _containerName = _NS->BuildContainerNameForNS(containerName,
164 SCRUTE(_containerName);
165 _NS->Register(pCont, _containerName.c_str());
166 MESSAGE("Engines_Container_i::Engines_Container_i : Container name "
170 // import SALOME_Container
171 // pycont = SALOME_Container.SALOME_Container_i(containerIORStr)
173 CORBA::String_var sior = _orb->object_to_string(pCont);
174 string myCommand="pyCont = SALOME_Container.SALOME_Container_i('";
175 myCommand += _containerName + "','";
180 if (!_isSupervContainer)
182 Py_ACQUIRE_NEW_THREAD;
184 // mpv: this is temporary solution: there is a unregular crash if not
186 PyRun_SimpleString("import sys\n");
187 // first element is the path to Registry.dll, but it's wrong
188 PyRun_SimpleString("sys.path = sys.path[1:]\n");
190 PyRun_SimpleString("import SALOME_Container\n");
191 PyRun_SimpleString((char*)myCommand.c_str());
192 Py_RELEASE_NEW_THREAD;
195 fileTransfer_i* aFileTransfer = new fileTransfer_i();
196 _fileTransfer = Engines::fileTransfer::_narrow(aFileTransfer->_this());
200 //=============================================================================
204 //=============================================================================
206 Engines_Container_i::~Engines_Container_i()
208 MESSAGE("Container_i::~Container_i()");
212 //=============================================================================
214 * CORBA attribute: Container name (see constructor)
216 //=============================================================================
218 char* Engines_Container_i::name()
220 return CORBA::string_dup(_containerName.c_str()) ;
223 //=============================================================================
225 * CORBA method: Get the hostName of the Container (without domain extensions)
227 //=============================================================================
229 char* Engines_Container_i::getHostName()
231 string s = GetHostname();
232 // MESSAGE("Engines_Container_i::getHostName " << s);
233 return CORBA::string_dup(s.c_str()) ;
236 //=============================================================================
238 * CORBA method: Get the PID (process identification) of the Container
240 //=============================================================================
242 CORBA::Long Engines_Container_i::getPID()
244 return (CORBA::Long)getpid();
247 //=============================================================================
249 * CORBA method: check if servant is still alive
251 //=============================================================================
253 void Engines_Container_i::ping()
255 MESSAGE("Engines_Container_i::ping() pid "<< getpid());
258 //=============================================================================
260 * CORBA method, oneway: Server shutdown.
261 * - Container name removed from naming service,
262 * - servant deactivation,
263 * - orb shutdown if no other servants in the process
265 //=============================================================================
267 void Engines_Container_i::Shutdown()
269 MESSAGE("Engines_Container_i::Shutdown()");
270 _NS->Destroy_FullDirectory(_containerName.c_str());
272 //_poa->deactivate_object(*_id);
273 if(_isServantAloneInProcess)
275 MESSAGE("Effective Shutdown of container Begins...");
276 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
277 bp1->deleteInstance(bp1);
283 //=============================================================================
285 * CORBA method: load a new component class (Python or C++ implementation)
286 * \param componentName like COMPONENT
287 * try to make a Python import of COMPONENT,
288 * then a lib open of libCOMPONENTEngine.so
289 * \return true if dlopen successfull or already done, false otherwise
291 //=============================================================================
294 Engines_Container_i::load_component_Library(const char* componentName)
297 string aCompName = componentName;
299 // --- try dlopen C++ component
302 string impl_name = string ("lib") + aCompName + string("Engine.so");
304 string impl_name = aCompName + string("Engine.dll");
308 _numInstanceMutex.lock(); // lock to be alone
309 // (see decInstanceCnt, finalize_removal))
310 if (_toRemove_map[impl_name]) _toRemove_map.erase(impl_name);
311 if (_library_map[impl_name])
313 MESSAGE("Library " << impl_name << " already loaded");
314 _numInstanceMutex.unlock();
320 handle = dlopen( impl_name.c_str() , 0 ) ;
321 //#elif defined( __osf1__ )
322 // handle = dlopen( impl_name.c_str() , RTLD_NOW ) ;
324 handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ;
328 _library_map[impl_name] = handle;
329 _numInstanceMutex.unlock();
334 INFOS("Can't load shared library : " << impl_name);
335 INFOS("error dlopen: " << dlerror());
337 _numInstanceMutex.unlock();
339 // --- try import Python component
341 INFOS("try import Python component "<<componentName);
342 if (_isSupervContainer)
344 INFOS("Supervision Container does not support Python Component Engines");
347 if (_library_map[aCompName])
349 return true; // Python Component, already imported
353 Py_ACQUIRE_NEW_THREAD;
354 PyObject *mainmod = PyImport_AddModule("__main__");
355 PyObject *globals = PyModule_GetDict(mainmod);
356 PyObject *pyCont = PyDict_GetItemString(globals, "pyCont");
357 PyObject *result = PyObject_CallMethod(pyCont,
360 int ret= PyInt_AsLong(result);
362 Py_RELEASE_NEW_THREAD;
364 if (ret) // import possible: Python component
366 _numInstanceMutex.lock() ; // lock to be alone (stl container write)
367 _library_map[aCompName] = (void *)pyCont; // any non O value OK
368 _numInstanceMutex.unlock() ;
369 MESSAGE("import Python: "<<aCompName<<" OK");
376 //=============================================================================
378 * CORBA method: Creates a new servant instance of a component.
379 * The servant registers itself to naming service and Registry.
380 * \param genericRegisterName Name of the component instance to register
381 * in Registry & Name Service (without _inst_n suffix)
382 * \param studyId 0 for multiStudy instance,
383 * study Id (>0) otherwise
384 * \return a loaded component
386 //=============================================================================
388 Engines::Component_ptr
389 Engines_Container_i::create_component_instance(const char*genericRegisterName,
394 INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy");
395 return Engines::Component::_nil() ;
398 Engines::Component_var iobject = Engines::Component::_nil() ;
400 string aCompName = genericRegisterName;
401 if (_library_map[aCompName]) // Python component
403 if (_isSupervContainer)
405 INFOS("Supervision Container does not support Python Component Engines");
406 return Engines::Component::_nil();
408 _numInstanceMutex.lock() ; // lock on the instance number
410 int numInstance = _numInstance ;
411 _numInstanceMutex.unlock() ;
414 sprintf( aNumI , "%d" , numInstance ) ;
415 string instanceName = aCompName + "_inst_" + aNumI ;
416 string component_registerName =
417 _containerName + "/" + instanceName;
419 Py_ACQUIRE_NEW_THREAD;
420 PyObject *mainmod = PyImport_AddModule("__main__");
421 PyObject *globals = PyModule_GetDict(mainmod);
422 PyObject *pyCont = PyDict_GetItemString(globals, "pyCont");
423 PyObject *result = PyObject_CallMethod(pyCont,
424 "create_component_instance",
427 instanceName.c_str(),
429 string iors = PyString_AsString(result);
431 Py_RELEASE_NEW_THREAD;
435 CORBA::Object_var obj = _orb->string_to_object(iors.c_str());
436 iobject = Engines::Component::_narrow( obj ) ;
438 return iobject._retn();
444 string impl_name = string ("lib") + genericRegisterName +string("Engine.so");
446 string impl_name = genericRegisterName +string("Engine.dll");
448 void* handle = _library_map[impl_name];
451 INFOS("shared library " << impl_name <<"must be loaded before instance");
452 return Engines::Component::_nil() ;
456 iobject = createInstance(genericRegisterName,
459 return iobject._retn();
463 //=============================================================================
465 * CORBA method: Finds a servant instance of a component
466 * \param registeredName Name of the component in Registry or Name Service,
467 * without instance suffix number
468 * \param studyId 0 if instance is not associated to a study,
469 * >0 otherwise (== study id)
470 * \return the first instance found with same studyId
472 //=============================================================================
474 Engines::Component_ptr
475 Engines_Container_i::find_component_instance( const char* registeredName,
478 Engines::Component_var anEngine = Engines::Component::_nil();
479 map<string,Engines::Component_var>::iterator itm =_listInstances_map.begin();
480 while (itm != _listInstances_map.end())
482 string instance = (*itm).first;
484 if (instance.find(registeredName) == 0)
486 anEngine = (*itm).second;
487 if (studyId == anEngine->getStudyId())
489 return anEngine._retn();
494 return anEngine._retn();
497 //=============================================================================
499 * CORBA method: find or create an instance of the component (servant),
500 * load a new component class (dynamic library) if required,
501 * ---- FOR COMPATIBILITY WITH 2.2 ----
502 * ---- USE ONLY FOR MULTISTUDY INSTANCES ! --------
503 * The servant registers itself to naming service and Registry.
504 * \param genericRegisterName Name of the component to register
505 * in Registry & Name Service
506 * \param componentName Name of the constructed library of the component
507 * \return a loaded component
509 //=============================================================================
511 Engines::Component_ptr
512 Engines_Container_i::load_impl( const char* genericRegisterName,
513 const char* componentName )
515 string impl_name = string ("lib") + genericRegisterName +string("Engine.so");
516 Engines::Component_var iobject = Engines::Component::_nil() ;
517 if (load_component_Library(genericRegisterName))
518 iobject = find_or_create_instance(genericRegisterName, impl_name);
519 return iobject._retn();
523 //=============================================================================
525 * CORBA method: Stops the component servant, and deletes all related objects
526 * \param component_i Component to be removed
528 //=============================================================================
530 void Engines_Container_i::remove_impl(Engines::Component_ptr component_i)
532 ASSERT(! CORBA::is_nil(component_i));
533 string instanceName = component_i->instanceName() ;
534 MESSAGE("unload component " << instanceName);
535 _numInstanceMutex.lock() ; // lock to be alone (stl container write)
536 _listInstances_map.erase(instanceName);
537 _numInstanceMutex.unlock() ;
538 component_i->destroy() ;
539 _NS->Destroy_Name(instanceName.c_str());
542 //=============================================================================
544 * CORBA method: Discharges unused libraries from the container.
546 //=============================================================================
548 void Engines_Container_i::finalize_removal()
550 MESSAGE("finalize unload : dlclose");
551 _numInstanceMutex.lock(); // lock to be alone
552 // (see decInstanceCnt, load_component_Library)
553 map<string, void *>::iterator ith;
554 for (ith = _toRemove_map.begin(); ith != _toRemove_map.end(); ith++)
556 void *handle = (*ith).second;
557 string impl_name= (*ith).first;
562 // dlclose(handle); // SALOME unstable after ...
563 // _library_map.erase(impl_name);
566 _toRemove_map.clear();
567 _numInstanceMutex.unlock();
570 //=============================================================================
572 * CORBA method: Kill the container process with exit(0).
573 * To remove : never returns !
575 //=============================================================================
577 bool Engines_Container_i::Kill_impl()
579 MESSAGE("Engines_Container_i::Kill() pid "<< getpid() << " containerName "
580 << _containerName.c_str() << " machineName "
581 << GetHostname().c_str());
582 INFOS("===============================================================");
583 INFOS("= REMOVE calls to Kill_impl in C++ container =");
584 INFOS("===============================================================");
590 //=============================================================================
592 * CORBA method: get or create a fileRef object associated to a local file
593 * (a file on the computer on which runs the container server), which stores
594 * a list of (machine, localFileName) corresponding to copies already done.
596 * \param origFileName absolute path for a local file to copy on other
598 * \return a fileRef object associated to the file.
600 //=============================================================================
603 Engines_Container_i::createFileRef(const char* origFileName)
605 string origName(origFileName);
606 Engines::fileRef_var theFileRef = Engines::fileRef::_nil();
608 if (origName[0] != '/')
610 INFOS("path of file to copy must be an absolute path begining with '/'");
611 return Engines::fileRef::_nil();
614 if (CORBA::is_nil(_fileRef_map[origName]))
616 CORBA::Object_var obj=_poa->id_to_reference(*_id);
617 Engines::Container_var pCont = Engines::Container::_narrow(obj);
618 fileRef_i* aFileRef = new fileRef_i(pCont, origFileName);
619 theFileRef = Engines::fileRef::_narrow(aFileRef->_this());
620 _numInstanceMutex.lock() ; // lock to be alone (stl container write)
621 _fileRef_map[origName] = theFileRef;
622 _numInstanceMutex.unlock() ;
625 theFileRef = Engines::fileRef::_duplicate(_fileRef_map[origName]);
626 ASSERT(! CORBA::is_nil(theFileRef));
627 return theFileRef._retn();
630 //=============================================================================
633 * \return a reference to the fileTransfer object
635 //=============================================================================
637 Engines::fileTransfer_ptr
638 Engines_Container_i::getFileTransfer()
640 Engines::fileTransfer_var aFileTransfer
641 = Engines::fileTransfer::_duplicate(_fileTransfer);
642 return aFileTransfer._retn();
646 //=============================================================================
648 * C++ method: Finds an already existing servant instance of a component, or
649 * create an instance.
650 * ---- USE ONLY FOR MULTISTUDY INSTANCES ! --------
651 * \param genericRegisterName Name of the component instance to register
652 * in Registry & Name Service,
653 * (without _inst_n suffix, like "COMPONENT")
654 * \param componentLibraryName like "libCOMPONENTEngine.so"
655 * \return a loaded component
657 * example with names:
658 * aGenRegisterName = COMPONENT (= first argument)
659 * impl_name = libCOMPONENTEngine.so (= second argument)
660 * _containerName = /Containers/cli76ce/FactoryServer
661 * factoryName = COMPONENTEngine_factory
662 * component_registerBase = /Containers/cli76ce/FactoryServer/COMPONENT
664 * instanceName = COMPONENT_inst_1
665 * component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1
667 //=============================================================================
669 Engines::Component_ptr
670 Engines_Container_i::find_or_create_instance(string genericRegisterName,
671 string componentLibraryName)
673 string aGenRegisterName = genericRegisterName;
674 string impl_name = componentLibraryName;
675 void* handle = _library_map[impl_name];
678 INFOS("shared library " << impl_name <<"must be loaded before instance");
679 return Engines::Component::_nil() ;
683 // --- find a registered instance in naming service, or create
685 string component_registerBase =
686 _containerName + "/" + aGenRegisterName;
687 Engines::Component_var iobject = Engines::Component::_nil() ;
690 CORBA::Object_var obj =
691 _NS->ResolveFirst( component_registerBase.c_str());
692 if ( CORBA::is_nil( obj ) )
694 iobject = createInstance(genericRegisterName,
696 0); // force multiStudy instance here !
700 iobject = Engines::Component::_narrow( obj ) ;
701 Engines_Component_i *servant =
702 dynamic_cast<Engines_Component_i*>
703 (_poa->reference_to_servant(iobject));
705 int studyId = servant->getStudyId();
706 ASSERT (studyId >= 0);
707 if (studyId == 0) // multiStudy instance, OK
710 MESSAGE(component_registerBase.c_str()<<" already bound");
712 else // monoStudy instance: NOK
714 iobject = Engines::Component::_nil();
715 INFOS("load_impl & find_component_instance methods "
716 << "NOT SUITABLE for mono study components");
722 INFOS( "Container_i::load_impl catched" ) ;
724 return iobject._retn();
728 //=============================================================================
730 * C++ method: create a servant instance of a component.
731 * \param genericRegisterName Name of the component instance to register
732 * in Registry & Name Service,
733 * (without _inst_n suffix, like "COMPONENT")
734 * \param handle loaded library handle
735 * \param studyId 0 for multiStudy instance,
736 * study Id (>0) otherwise
737 * \return a loaded component
739 * example with names:
740 * aGenRegisterName = COMPONENT (= first argument)
741 * _containerName = /Containers/cli76ce/FactoryServer
742 * factoryName = COMPONENTEngine_factory
743 * component_registerBase = /Containers/cli76ce/FactoryServer/COMPONENT
744 * instanceName = COMPONENT_inst_1
745 * component_registerName = /Containers/cli76ce/FactoryServer/COMPONENT_inst_1
747 //=============================================================================
749 Engines::Component_ptr
750 Engines_Container_i::createInstance(string genericRegisterName,
754 // --- find the factory
756 string aGenRegisterName = genericRegisterName;
757 string factory_name = aGenRegisterName + string("Engine_factory");
758 SCRUTE(factory_name) ;
760 typedef PortableServer::ObjectId * (*FACTORY_FUNCTION)
762 PortableServer::POA_ptr,
763 PortableServer::ObjectId *,
767 FACTORY_FUNCTION Component_factory
768 = (FACTORY_FUNCTION) dlsym(handle, factory_name.c_str());
771 if ( (error = dlerror() ) != NULL)
773 INFOS("Can't resolve symbol: " + factory_name);
775 return Engines::Component::_nil() ;
778 // --- create instance
780 Engines::Component_var iobject = Engines::Component::_nil() ;
784 _numInstanceMutex.lock() ; // lock on the instance number
786 int numInstance = _numInstance ;
787 _numInstanceMutex.unlock() ;
790 sprintf( aNumI , "%d" , numInstance ) ;
791 string instanceName = aGenRegisterName + "_inst_" + aNumI ;
792 string component_registerName =
793 _containerName + "/" + instanceName;
795 // --- Instanciate required CORBA object
797 PortableServer::ObjectId *id ; //not owner, do not delete (nore use var)
798 id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str(),
799 aGenRegisterName.c_str() ) ;
801 // --- get reference & servant from id
803 CORBA::Object_var obj = _poa->id_to_reference(*id);
804 iobject = Engines::Component::_narrow( obj ) ;
806 Engines_Component_i *servant =
807 dynamic_cast<Engines_Component_i*>(_poa->reference_to_servant(iobject));
809 //SCRUTE(servant->pd_refCount);
810 servant->_remove_ref(); // compensate previous id_to_reference
811 //SCRUTE(servant->pd_refCount);
812 _numInstanceMutex.lock() ; // lock to be alone (stl container write)
813 _listInstances_map[instanceName] = iobject;
814 _cntInstances_map[aGenRegisterName] += 1;
815 _numInstanceMutex.unlock() ;
816 SCRUTE(aGenRegisterName);
817 SCRUTE(_cntInstances_map[aGenRegisterName]);
818 //SCRUTE(servant->pd_refCount);
819 bool ret_studyId = servant->setStudyId(studyId);
822 // --- register the engine under the name
823 // containerName(.dir)/instanceName(.object)
825 _NS->Register( iobject , component_registerName.c_str() ) ;
826 MESSAGE( component_registerName.c_str() << " bound" ) ;
830 INFOS( "Container_i::createInstance exception catched" ) ;
832 return iobject._retn();
835 //=============================================================================
839 //=============================================================================
841 void Engines_Container_i::decInstanceCnt(string genericRegisterName)
843 string aGenRegisterName =genericRegisterName;
844 MESSAGE("Engines_Container_i::decInstanceCnt " << aGenRegisterName);
845 ASSERT(_cntInstances_map[aGenRegisterName] > 0);
846 _numInstanceMutex.lock(); // lock to be alone
847 // (see finalize_removal, load_component_Library)
848 _cntInstances_map[aGenRegisterName] -= 1;
849 SCRUTE(_cntInstances_map[aGenRegisterName]);
850 if (_cntInstances_map[aGenRegisterName] == 0)
853 Engines_Component_i::GetDynLibraryName(aGenRegisterName.c_str());
855 void* handle = _library_map[impl_name];
857 _toRemove_map[impl_name] = handle;
859 _numInstanceMutex.unlock();
862 //=============================================================================
864 * Retrieves only with container naming convention if it is a python container
866 //=============================================================================
868 bool Engines_Container_i::isPythonContainer(const char* ContainerName)
871 int len=strlen(ContainerName);
873 if(strcmp(ContainerName+len-2,"Py")==0)
878 //=============================================================================
882 //=============================================================================
884 void ActSigIntHandler()
887 struct sigaction SigIntAct ;
888 SigIntAct.sa_sigaction = &SigIntHandler ;
889 SigIntAct.sa_flags = SA_SIGINFO ;
892 // DEBUG 03.02.2005 : the first parameter of sigaction is not a mask of signals
893 // (SIGINT | SIGUSR1) :
894 // it must be only one signal ===> one call for SIGINT
895 // and an other one for SIGUSR1
898 if ( sigaction( SIGINT , &SigIntAct, NULL ) )
900 perror("SALOME_Container main ") ;
903 if ( sigaction( SIGUSR1 , &SigIntAct, NULL ) )
905 perror("SALOME_Container main ") ;
908 if ( sigaction( SIGUSR2 , &SigIntAct, NULL ) )
910 perror("SALOME_Container main ") ;
914 //PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers)
915 // use of streams (and so on) should never be used because :
916 // streams of C++ are naturally thread-safe and use pthread_mutex_lock ===>
917 // A stream operation may be interrupted by a signal and if the Handler use stream we
918 // may have a "Dead-Lock" ===HangUp
919 //==INFOS is commented
920 // INFOS(pthread_self() << "SigIntHandler activated") ;
923 signal( SIGINT, SigIntHandler );
924 signal( SIGUSR1, SigIntHandler );
930 void CallCancelThread() ;
933 void SigIntHandler(int what ,
934 siginfo_t * siginfo ,
937 //PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers)
938 // use of streams (and so on) should never be used because :
939 // streams of C++ are naturally thread-safe and use pthread_mutex_lock ===>
940 // A stream operation may be interrupted by a signal and if the Handler use stream we
941 // may have a "Dead-Lock" ===HangUp
942 //==MESSAGE is commented
943 // MESSAGE(pthread_self() << "SigIntHandler what " << what << endl
944 // << " si_signo " << siginfo->si_signo << endl
945 // << " si_code " << siginfo->si_code << endl
946 // << " si_pid " << siginfo->si_pid) ;
951 // MESSAGE("SigIntHandler END sleeping.") ;
957 if ( siginfo->si_signo == SIGUSR1 )
961 else if ( siginfo->si_signo == SIGUSR2 )
968 // MESSAGE("SigIntHandler BEGIN sleeping.") ;
975 // MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ;
981 void SigIntHandler( int what )
983 MESSAGE( pthread_self() << "SigIntHandler what " << what << endl );
987 MESSAGE("SigIntHandler END sleeping.") ;
993 if ( what == SIGUSR1 )
1000 MESSAGE("SigIntHandler BEGIN sleeping.") ;
1007 MESSAGE("SigIntHandler LEAVE sleeping after " << count << " s.") ;