20 #define ON_DEBUG if (msgLevel(MSG::DEBUG)) 21 #define ON_VERBOSE if (msgLevel(MSG::VERBOSE)) 23 #define DEBMSG ON_DEBUG debug() 24 #define VERMSG ON_VERBOSE verbose() 35 if (i.active) v.
push_back(i.service.get());
54 for (
auto& svc :
m_listsvc) svc.service->setServiceManager(
nullptr);
79 auto ip = type.
find(
"__");
80 if ( ip != std::string::npos) type.
erase(ip,type.
length());
84 fatal() <<
"No Service factory for " << type <<
" available." <<
endmsg;
89 fatal() <<
"Incompatible interface IService version for " << type <<
endmsg;
103 ListSvc::iterator it =
find(svc);
134 error() <<
"Unable to initialize service \"" << typeName.
name() <<
"\"" 176 imut = mit->second.
get();
183 auto it =
find(name);
189 <<
"Initialization loop detected when creating service \"" << name
199 if( name ==
"ApplicationMgr" ||
206 if ( createIf &&
addService(typeName).isSuccess()){
207 return find(name)->service;
221 [](ListSvc::const_reference i) {
222 return const_cast<IService*
>(i.service.get());
248 auto it =
find(name);
261 if ( !p.second ) p.first->second = svctype;
278 switch (it->FSMState()) {
280 DEBMSG <<
"Service " << name <<
" already initialized" <<
endmsg;
284 sc = it->sysInitialize();
286 error() <<
"Unable to initialize Service: " << name <<
endmsg;
290 error() <<
"Service " << name
291 <<
" not in the correct state to be initialized (" 292 << it->FSMState() <<
")" <<
endmsg;
312 switch (it->FSMState()) {
314 DEBMSG <<
"Service " << name
315 <<
" already started" <<
endmsg;
321 error() <<
"Unable to start Service: " << name <<
endmsg;
325 error() <<
"Service " << name
326 <<
" not in the correct state to be started (" 327 << it->FSMState() <<
")" <<
endmsg;
349 switch (svc->FSMState()) {
351 DEBMSG <<
"Service " << name <<
" already stopped" <<
endmsg;
357 error() <<
"Unable to stop Service: " << name <<
endmsg;
361 DEBMSG <<
"Service " << name
362 <<
" not in the correct state to be stopped (" 363 << svc->FSMState() <<
")" <<
endmsg;
382 sc = svc->sysReinitialize();
384 error() <<
"Unable to re-initialize Service: " << svc->name() <<
endmsg;
403 sc = svc->sysRestart();
405 error() <<
"Unable to re-start Service: " << svc->name() <<
endmsg;
434 auto p_inc = service<IIncidentSvc>(
"IncidentSvc",
false);
436 p_inc->getListeners(postFinList,IncidentType::SvcPostFinalize);
458 if ( !svc->sysFinalize().isSuccess() ) {
459 warning() <<
"Finalization of service " << name <<
" failed" <<
endmsg;
466 if (!postFinList.
empty()) {
467 DEBMSG <<
"Will call SvcPostFinalize for " << postFinList.
size() <<
" clients" 469 Incident inc(
"ServiceManager", IncidentType::SvcPostFinalize);
470 for (
auto& itr : postFinList) itr->handle(inc);
475 DEBMSG <<
"Looping over all active services..." <<
endmsg;
478 DEBMSG <<
"---- " << it->service->name()
479 <<
" (refCount = " << it->service->refCount() <<
")" 481 if (it->service->refCount() < 1) {
482 warning() <<
"Too low reference count for " << it->service->name()
483 <<
" (should not go below 1 at this point)" <<
endmsg;
484 it->service->addRef();
500 auto it =
find(name);
508 auto it =
find(name);
536 <<
"===================== listing all services ===================\n" 537 <<
" prior ref name active\n";
542 log.flags(std::ios_base::right);
543 log << svc.priority <<
" ";
545 log << svc.service->refCount() <<
" ";
547 log.flags(std::ios_base::left);
548 log << svc.service->name() <<
" ";
554 log <<
"=================================================================\n";
The ServiceManager class is in charge of the creation of concrete instances of Services.
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
boost::lock_guard< Mutex_t > LockGuard_t
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
std::pair< iterator, bool > emplace(Args &&...args)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool isSuccess() const
Test for a status code of SUCCESS.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
bool m_loopCheck
Check for service initialization loops.
ServiceManager(IInterface *application)
default creator
Gaudi::StateMachine::State targetFSMState() const override
When we are in the middle of a transition, get the state where the transition is leading us...
#define DECLARE_OBJECT_FACTORY(x)
boost::recursive_mutex Mutex_t
Mutex to synchronize shared service initialization between threads.
StatusCode restart() override
Initialization (from RUNNING to RUNNING, via INITIALIZED).
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
bool isFailure() const
Test for a status code of FAILURE.
MapType m_maptype
Map of service name and service type.
TYPE * get() const
Get interface pointer.
virtual StatusCode sysInitialize()=0
Initialize Service.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
bool existsService(const std::string &name) const override
implementation of ISvcLocation::existsService
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
Helper class to parse a string of format "type/name".
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
bool loopCheckEnabled() const override
Get the value of the initialization loop check flag.
General service interface definition.
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
~ServiceManager() override
virtual destructor
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
iterator find(const key_type &key)
const std::list< IService * > & getServices() const override
Return the list of Services.
StatusCode start() override
Start (from INITIALIZED to RUNNING).
std::map< std::string, std::unique_ptr< Mutex_t > > m_lockMap
int getPriority(const std::string &name) const override
manage priorities of services
reverse_wrapper< T > reverse(T &&iterable)
virtual StatusCode sysStart()=0
Start Service.
T back_inserter(T...args)
const std::string & type() const
StatusCode reinitialize() override
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
Base class for all Incidents (computing events).
ListSvc::iterator find(const std::string &name)
StatusCode declareSvcType(const std::string &svcname, const std::string &svctype) override
implementation of ISvcManager::declareSvcType
const std::string & name() const
StatusCode setPriority(const std::string &name, int pri) override
StatusCode removeService(IService *svc) override
implementation of ISvcManager::removeService
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
Returns a smart pointer to a service.
std::string typeName(const std::type_info &typ)
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because...
virtual void setServiceManager(ISvcManager *)=0
SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype) override
implementation of ISvcManager::createService NOTE: as this returns a &, we must guarantee that once c...
SmartIF< IService > service
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).