3 #include "GaudiKernel/IService.h"
4 #include "GaudiKernel/MsgStream.h"
5 #include "GaudiKernel/TypeNameString.h"
6 #include "GaudiKernel/System.h"
7 #include "GaudiKernel/Service.h"
8 #include "GaudiKernel/ObjectFactory.h"
9 #include "GaudiKernel/SmartIF.h"
10 #include "GaudiKernel/IIncidentSvc.h"
11 #include "GaudiKernel/IIncidentListener.h"
12 #include "GaudiKernel/Incident.h"
13 #include "GaudiKernel/reverse.h"
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()
32 std::vector<IService*> activeSvc(
const C& lst) {
33 std::vector<IService*> v; v.reserve(lst.size());
35 if (
i.active) v.push_back(
i.service.get());
55 for (
auto& svc :
m_listsvc) svc.service->setServiceManager(
nullptr);
69 const std::string &
name = typeName.
name();
80 auto ip = type.find(
"__");
81 if ( ip != std::string::npos) type.erase(ip,type.length());
89 fatal() <<
"Incompatible interface IService version for " << type <<
endmsg;
95 fatal() <<
"No Service factory for " << type <<
" available." <<
endmsg;
134 error() <<
"Unable to initialize service \"" << typeName.
name() <<
"\""
163 const std::string &
name = typeName.
name();
168 auto it =
find(name);
174 <<
"Initialization loop detected when creating service \"" << name
183 if( name ==
"ApplicationMgr" ||
187 }
else if ( createIf ){
190 return find(name)->service;
204 [](ListSvc::const_reference
i) {
205 return const_cast<IService*
>(i.service.get());
214 return find(
name) != m_listsvc.end();
233 auto it =
find(name);
243 const std::string& svctype )
248 if ( !p.second ) p.first->second = svctype;
264 const std::string&
name = it->name();
265 switch (it->FSMState()) {
267 DEBMSG <<
"Service " << name <<
" already initialized" <<
endmsg;
271 sc = it->sysInitialize();
273 error() <<
"Unable to initialize Service: " << name <<
endmsg;
277 error() <<
"Service " << name
278 <<
" not in the correct state to be initialized ("
279 << it->FSMState() <<
")" <<
endmsg;
298 const std::string&
name = it->name();
299 switch (it->FSMState()) {
301 DEBMSG <<
"Service " << name
302 <<
" already started" <<
endmsg;
308 error() <<
"Unable to start Service: " << name <<
endmsg;
312 error() <<
"Service " << name
313 <<
" not in the correct state to be started ("
314 << it->FSMState() <<
")" <<
endmsg;
335 const std::string&
name = svc->name();
336 switch (svc->FSMState()) {
338 DEBMSG <<
"Service " << name <<
" already stopped" <<
endmsg;
344 error() <<
"Unable to stop Service: " << name <<
endmsg;
348 DEBMSG <<
"Service " << name
349 <<
" not in the correct state to be stopped ("
350 << svc->FSMState() <<
")" <<
endmsg;
369 sc = svc->sysReinitialize();
371 error() <<
"Unable to re-initialize Service: " << svc->name() <<
endmsg;
390 sc = svc->sysRestart();
392 error() <<
"Unable to re-start Service: " << svc->name() <<
endmsg;
420 std::vector<IIncidentListener*> postFinList;
422 auto p_inc = service<IIncidentSvc>(
"IncidentSvc",
false);
442 const std::string&
name = svc->name();
446 if ( !svc->sysFinalize().isSuccess() ) {
447 warning() <<
"Finalization of service " << name <<
" failed" <<
endmsg;
454 if (!postFinList.empty()) {
455 DEBMSG <<
"Will call SvcPostFinalize for " << postFinList.size() <<
" clients"
458 for (
auto& itr : postFinList) itr->handle(inc);
463 DEBMSG <<
"Looping over all active services..." <<
endmsg;
466 DEBMSG <<
"---- " << it->service->name()
467 <<
" (refCount = " << it->service->refCount() <<
")"
469 if (it->service->refCount() < 1) {
470 warning() <<
"Too low reference count for " << it->service->name()
471 <<
" (should not go below 1 at this point)" <<
endmsg;
472 it->service->addRef();
488 auto it =
find(name);
489 return (it !=
m_listsvc.end()) ? it->priority: 0;
496 auto it =
find(name);
524 <<
"===================== listing all services ===================\n"
525 <<
" prior ref name active\n";
530 log.
flags(std::ios_base::right);
531 log << svc.priority <<
" ";
533 log << svc.service->refCount() <<
" ";
535 log.
flags(std::ios_base::left);
536 log << svc.service->name() <<
" ";
538 log << svc.active << std::endl;
542 log <<
"=================================================================\n";
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
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()
Definition of the MsgStream class used to transmit messages.
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
reverse_wrapper< T > reverse(T &&iterable)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
std::pair< iterator, bool > emplace(Args &&...args)
int getPriority(const std::string &name) const override
manage priorities of services
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
auto begin(reverse_wrapper< T > &w)
bool isSuccess() const
Test for a status code of SUCCESS.
bool m_loopCheck
Check for service initialization loops.
ServiceManager(IInterface *application)
default creator
virtual const std::list< IService * > & getServices() const
Return the list of Services.
StatusCode restart() override
Initialization (from RUNNING to RUNNING, via INITIALIZED).
#define DECLARE_OBJECT_FACTORY(x)
const std::string SvcPostFinalize
ONLY For Services that need something after they've been finalized.
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.
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
Helper class to parse a string of format "type/name".
std::recursive_mutex m_svcinitmutex
Mutex to synchronize shared service initialization between threads.
auto end(reverse_wrapper< T > &w)
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
iterator find(const key_type &key)
StatusCode start() override
Start (from INITIALIZED to RUNNING).
virtual bool existsService(const std::string &name) const
implementation of ISvcLocation::existsService
virtual StatusCode sysStart()=0
Start Service.
Base class used to extend a class implementing other interfaces.
long flags() const
IOS emulation.
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
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 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...
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).