|
Gaudi Framework, version v21r11 |
| Home | Generated: 30 Sep 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 using Gaudi::ReturnCode::SignalOffset; 00433 if (Gaudi::setAppReturnCode(m_appProperty, SignalOffset + s->first).isFailure()) { 00434 error() << "Could not set return code of the application (" 00435 << SignalOffset + s->first << ")" 00436 << endmsg; 00437 } 00438 } 00439 } 00440 if (m_stopRequested) { 00441 SmartIF<IEventProcessor> ep(serviceLocator()); 00442 if (ep) { 00443 warning() << "Scheduling a stop" << endmsg; 00444 ep->stopRun().ignore(); 00445 } 00446 else { 00447 warning() << "Cannot stop the processing because the IEventProcessor interface cannot be retrieved." << endmsg; 00448 } 00449 } 00450 } 00451 }
| 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 466 of file SignalMonitorSvc.cpp.
00466 { 00467 debug() << "Decoding signal declaration '" << sig << "'" << endmsg; 00468 if ( sig.empty() || sig == "+" ) { 00469 debug() << "Empty signal, ignored" << endmsg; 00470 return std::make_pair<int, bool>(-1, false); // silently ignore empty strings 00471 } 00472 const SigMap& sigmap(SigMap::instance()); 00473 std::string signal = sig; 00474 bool propagate = false; 00475 // Check if the signal must be propagated 00476 if (signal[signal.size() - 1] == '+') { 00477 debug() << "Must be propagated to previously registered signal handlers" << endmsg; 00478 propagate = true; 00479 signal.erase(signal.size() - 1, 1); // remove the '+' at the end of the string 00480 } 00481 int signum = -1; 00482 // check if the signal is a number 00483 if (std::isdigit(signal[0])){ 00484 std::istringstream ss(signal); 00485 ss >> signum; 00486 } else { 00487 // try to find the signal name in the list of known signals 00488 signum = sigmap.signum(signal); 00489 } 00490 if (signum < 0) { 00491 warning() << "Cannot understand signal identifier '" << sig << "', ignored" << endmsg; 00492 } else { 00493 verbose() << "Matched signal '" << sigmap.name(signum) 00494 << "' (" << signum; 00495 const std::string &desc = sigmap.desc(signum); 00496 if ( ! desc.empty() ) { 00497 verbose() << ", " << desc; 00498 } 00499 verbose() << ")" << endmsg; 00500 } 00501 return std::make_pair<int, bool>(signum, propagate); 00502 }
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 454 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 456 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 458 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 464 of file SignalMonitorSvc.cpp.