|
Gaudi Framework, version v21r10p1 |
| Home | Generated: 29 Jul 2010 |


Public Member Functions | |
| StopSignalHandler (const std::string &name, ISvcLocator *svcLoc) | |
| StatusCode | initialize () |
| StatusCode | finalize () |
| virtual void | handle (const Incident &) |
| Inform that a new incident has occurred. | |
Private Member Functions | |
| std::pair< int, bool > | i_decodeSignal (const std::string &sig) |
| Function to translate the signal name to the signal number. | |
Private Attributes | |
| std::vector< std::string > | m_usedSignals |
| List of signal names or numbers (encoded as strings) to use to schedule a stop. | |
| std::map< int, bool > | m_signals |
| Map of monitored signal numbers to the flag telling if they have to be propagated or not. | |
| bool | m_stopRequested |
| Flag to remember if the stop has been requested because of a signal. | |
| SmartIF< Gaudi::ISignalMonitor > | m_signalMonitor |
| Pointer to the signal monitor service. | |
| SmartIF< IIncidentSvc > | m_incidentSvc |
| Pointer to the incident service. | |
| SmartIF< IProperty > | m_appProperty |
| Pointer to the interface to set the return code of the application. | |
The signals to be intercepted have to be declared in the property Signals as a list of strings (signal names or numbers). If '+' is appended to the signal name, then the signal is propagated to the signal handlers already registered when this service is initialized.
Definition at line 345 of file SignalMonitorSvc.cpp.
| Gaudi::Utils::StopSignalHandler::StopSignalHandler | ( | const std::string & | name, | |
| ISvcLocator * | svcLoc | |||
| ) | [inline] |
Definition at line 347 of file SignalMonitorSvc.cpp.
00347 : base_class(name, svcLoc) { 00348 m_usedSignals.reserve(2); 00349 m_usedSignals.push_back("SIGINT"); 00350 m_usedSignals.push_back("SIGXCPU"); 00351 declareProperty("Signals", m_usedSignals, 00352 "List of signal names or numbers to use to schedule a stop. " 00353 "If the signal is followed by a '+' the signal is propagated the previously " 00354 "registered handler (if any)."); 00355 }
| StatusCode Gaudi::Utils::StopSignalHandler::initialize | ( | ) | [inline, virtual] |
Reimplemented from Service.
Definition at line 356 of file SignalMonitorSvc.cpp.
00356 { 00357 StatusCode sc = Service::initialize(); 00358 if (sc.isFailure()) { 00359 return sc; 00360 } 00361 std::string serviceName("Gaudi::Utils::SignalMonitorSvc"); 00362 m_signalMonitor = serviceLocator()->service(serviceName); 00363 if ( ! m_signalMonitor ) { 00364 error() << "Cannot retrieve " << serviceName << endmsg; 00365 return StatusCode::FAILURE; 00366 } 00367 serviceName = "IncidentSvc"; 00368 m_incidentSvc = serviceLocator()->service(serviceName); 00369 if ( ! m_incidentSvc ) { 00370 error() << "Cannot retrieve " << serviceName << endmsg; 00371 return StatusCode::FAILURE; 00372 } 00373 // Get the IMainAppStatus interface of the ApplicationMgr 00374 m_appProperty = serviceLocator(); 00375 if ( ! m_appProperty ) { 00376 warning() << "Cannot retrieve IProperty interface of ApplicationMgr, " 00377 "the return code will not be changed" << endmsg; 00378 } 00379 // Decode the signal names 00380 std::pair<int, bool> sigid; 00381 for (std::vector<std::string>::const_iterator signame = m_usedSignals.begin(); 00382 signame != m_usedSignals.end(); ++signame) { 00383 sigid = i_decodeSignal(*signame); 00384 if (sigid.first >= 0) { 00385 m_signals[sigid.first] = sigid.second; 00386 } 00387 } 00388 debug() << "Stopping on the signals:" << endmsg; 00389 const SigMap& sigmap(SigMap::instance()); 00390 for (std::map<int, bool>::const_iterator s = m_signals.begin(); 00391 s != m_signals.end(); ++s) { 00392 debug() << "\t" << sigmap.name(s->first) << ": " 00393 << sigmap.desc(s->first) << " (" << s->first << ")"; 00394 if (s->second) debug() << " propagated"; 00395 debug() << endmsg; 00396 // tell the signal monitor that we are interested in these signals 00397 m_signalMonitor->monitorSignal(s->first, s->second); 00398 } 00399 m_stopRequested = false; 00400 debug() << "Register to the IncidentSvc" << endmsg; 00401 m_incidentSvc->addListener(this, IncidentType::BeginEvent); 00402 return StatusCode::SUCCESS; 00403 }
| StatusCode Gaudi::Utils::StopSignalHandler::finalize | ( | ) | [inline, virtual] |
Reimplemented from Service.
Definition at line 404 of file SignalMonitorSvc.cpp.
00404 { 00405 m_incidentSvc->removeListener(this, IncidentType::BeginEvent); 00406 m_incidentSvc.reset(); 00407 // disable the monitoring of the signals 00408 for (std::map<int, bool>::const_iterator s = m_signals.begin(); 00409 s != m_signals.end(); ++s) { 00410 // tell the signal monitor that we are interested in these signals 00411 m_signalMonitor->ignoreSignal(s->first); 00412 } 00413 m_signalMonitor.reset(); 00414 return Service::finalize(); 00415 }
| virtual void Gaudi::Utils::StopSignalHandler::handle | ( | const Incident & | ) | [inline, virtual] |
Inform that a new incident has occurred.
Implements IIncidentListener.
Definition at line 417 of file SignalMonitorSvc.cpp.
00417 { 00418 if (!m_stopRequested) { 00419 const SigMap& sigmap(SigMap::instance()); 00420 for (std::map<int, bool>::const_iterator s = m_signals.begin(); 00421 s != m_signals.end(); ++s) { 00422 if (m_signalMonitor->gotSignal(s->first)) { 00423 warning() << "Received signal '" << sigmap.name(s->first) 00424 << "' (" << s->first; 00425 const std::string &desc = sigmap.desc(s->first); 00426 if ( ! desc.empty() ) { 00427 warning() << ", " << desc; 00428 } 00429 warning() << ")" << endmsg; 00430 m_stopRequested = true; 00431 // Report the termination by signal at the end of the application 00432 if (Gaudi::setAppReturnCode(m_appProperty, 128 + s->first).isFailure()) { 00433 error() << "Could not set return code of the application (" 00434 << 128 + s->first << ")" 00435 << endmsg; 00436 } 00437 if (m_appProperty) { 00438 // Check the current return code (we want to keep the first error) 00439 IntegerProperty returnCode("ReturnCode", 0); 00440 StatusCode sc = m_appProperty->getProperty(&returnCode); 00441 if (sc.isSuccess()) { 00442 if (returnCode.value() == 0) { 00443 returnCode.setValue(128 + s->first); 00444 sc = m_appProperty->setProperty(returnCode); 00445 } 00446 } 00447 if (sc.isFailure()) { 00448 error() << "Could not set return code of the application (" 00449 << 128 + s->first << ")" 00450 << endmsg; 00451 } 00452 } 00453 } 00454 } 00455 if (m_stopRequested) { 00456 SmartIF<IEventProcessor> ep(serviceLocator()); 00457 if (ep) { 00458 warning() << "Scheduling a stop" << endmsg; 00459 ep->stopRun().ignore(); 00460 } 00461 else { 00462 warning() << "Cannot stop the processing because the IEventProcessor interface cannot be retrieved." << endmsg; 00463 } 00464 } 00465 } 00466 }
| std::pair<int, bool> Gaudi::Utils::StopSignalHandler::i_decodeSignal | ( | const std::string & | sig | ) | [inline, private] |
Function to translate the signal name to the signal number.
Definition at line 481 of file SignalMonitorSvc.cpp.
00481 { 00482 debug() << "Decoding signal declaration '" << sig << "'" << endmsg; 00483 if ( sig.empty() || sig == "+" ) { 00484 debug() << "Empty signal, ignored" << endmsg; 00485 return std::make_pair<int, bool>(-1, false); // silently ignore empty strings 00486 } 00487 const SigMap& sigmap(SigMap::instance()); 00488 std::string signal = sig; 00489 bool propagate = false; 00490 // Check if the signal must be propagated 00491 if (signal[signal.size() - 1] == '+') { 00492 debug() << "Must be propagated to previously registered signal handlers" << endmsg; 00493 propagate = true; 00494 signal.erase(signal.size() - 1, 1); // remove the '+' at the end of the string 00495 } 00496 int signum = -1; 00497 // check if the signal is a number 00498 if (std::isdigit(signal[0])){ 00499 std::istringstream ss(signal); 00500 ss >> signum; 00501 } else { 00502 // try to find the signal name in the list of known signals 00503 signum = sigmap.signum(signal); 00504 } 00505 if (signum < 0) { 00506 warning() << "Cannot understand signal identifier '" << sig << "', ignored" << endmsg; 00507 } else { 00508 verbose() << "Matched signal '" << sigmap.name(signum) 00509 << "' (" << signum; 00510 const std::string &desc = sigmap.desc(signum); 00511 if ( ! desc.empty() ) { 00512 verbose() << ", " << desc; 00513 } 00514 verbose() << ")" << endmsg; 00515 } 00516 return std::make_pair<int, bool>(signum, propagate); 00517 }
std::vector<std::string> Gaudi::Utils::StopSignalHandler::m_usedSignals [private] |
List of signal names or numbers (encoded as strings) to use to schedule a stop.
Definition at line 469 of file SignalMonitorSvc.cpp.
std::map<int, bool> Gaudi::Utils::StopSignalHandler::m_signals [private] |
Map of monitored signal numbers to the flag telling if they have to be propagated or not.
Definition at line 471 of file SignalMonitorSvc.cpp.
bool Gaudi::Utils::StopSignalHandler::m_stopRequested [private] |
Flag to remember if the stop has been requested because of a signal.
Definition at line 473 of file SignalMonitorSvc.cpp.
SmartIF<Gaudi::ISignalMonitor> Gaudi::Utils::StopSignalHandler::m_signalMonitor [private] |
SmartIF<IIncidentSvc> Gaudi::Utils::StopSignalHandler::m_incidentSvc [private] |
Pointer to the interface to set the return code of the application.
Definition at line 479 of file SignalMonitorSvc.cpp.