30 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 31 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 33 #define DEBMSG ON_DEBUG debug() 34 #define VERMSG ON_VERBOSE verbose() 45 for (
auto& i : lst ) {
46 if ( i.active ) v.
push_back( i.service.get() );
63 for (
auto& svc :
m_listsvc ) svc.service->setServiceManager(
nullptr );
88 auto ip =
type.find(
"__" );
89 if ( ip != std::string::npos )
type.erase( ip,
type.length() );
93 fatal() <<
"No Service factory for " <<
type <<
" available." <<
endmsg;
98 fatal() <<
"Incompatible interface IService version for " <<
type <<
endmsg;
113 auto it =
find( svc );
114 auto lck = std::scoped_lock{
m_gLock};
144 auto lck = std::scoped_lock{
m_gLock};
153 auto lck = std::scoped_lock{
m_gLock};
178 auto lk = std::scoped_lock{this->
m_gLock};
189 auto lk2 = std::scoped_lock{*imut};
195 error() <<
"Initialization loop detected when creating service \"" <<
name <<
"\"" <<
endmsg;
218 []( ListSvc::const_reference i ) {
return i.service.get(); } );
226 return find(
name ) != m_listsvc.end();
233 auto it =
find( svc );
268 for (
auto& it : activeSvc(
m_listsvc ) ) {
270 switch ( it->FSMState() ) {
276 sc = it->sysInitialize();
283 error() <<
"Service " <<
name <<
" not in the correct state to be initialized (" << it->FSMState() <<
")" 302 for (
auto& it : activeSvc(
m_listsvc ) ) {
304 switch ( it->FSMState() ) {
317 error() <<
"Service " <<
name <<
" not in the correct state to be started (" << it->FSMState() <<
")" <<
endmsg;
338 switch ( svc->FSMState() ) {
351 DEBMSG <<
"Service " <<
name <<
" not in the correct state to be stopped (" << svc->FSMState() <<
")" <<
endmsg;
369 for (
auto& svc : activeSvc(
m_listsvc ) ) {
370 sc = svc->sysReinitialize();
372 error() <<
"Unable to re-initialize Service: " << svc->name() <<
endmsg;
390 for (
auto& svc : activeSvc(
m_listsvc ) ) {
391 sc = svc->sysRestart();
393 error() <<
"Unable to re-start Service: " << svc->name() <<
endmsg;
407 if ( pri_tool != 0 ) {
421 auto p_inc = service<IIncidentSvc>(
"IncidentSvc",
false );
423 p_inc->getListeners( postFinList, IncidentType::SvcPostFinalize );
445 if ( !svc->sysFinalize().isSuccess() ) {
453 if ( !postFinList.
empty() ) {
454 DEBMSG <<
"Will call SvcPostFinalize for " << postFinList.
size() <<
" clients" <<
endmsg;
455 Incident inc(
"ServiceManager", IncidentType::SvcPostFinalize );
456 for (
auto& itr : postFinList ) itr->handle( inc );
461 DEBMSG <<
"Looping over all active services..." <<
endmsg;
464 DEBMSG <<
"---- " << it->service->name() <<
" (refCount = " << it->service->refCount() <<
")" <<
endmsg;
465 if ( it->service->refCount() < 1 ) {
466 warning() <<
"Too low reference count for " << it->service->name() <<
" (should not go below 1 at this point)" 468 it->service->addRef();
511 <<
"===================== listing all services ===================\n" 512 <<
" prior ref name active\n";
517 log.flags( std::ios_base::right );
518 log << svc.priority <<
" ";
520 log << svc.service->refCount() <<
" ";
522 log.flags( std::ios_base::left );
523 log << svc.service->name() <<
" ";
528 log <<
"=================================================================\n";
535 const auto svc = dynamic_cast<Service*>( svcItem.service.get() );
536 if ( svc ) svc->resetMessaging();
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()
Gaudi::StateMachine::State targetFSMState() const override
When we are in the middle of a transition, get the state where the transition is leading us.
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
int getPriority(std::string_view name) const override
manage priorities of services
ListSvc::iterator find(std::string_view name)
T forward_as_tuple(T... args)
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
std::recursive_mutex m_gLock
Mutex to synchronize shared service initialization between threads.
MSG::Level resetMessaging()
Reinitialize internal states.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
bool m_loopCheck
Check for service initialization loops.
::details::reverse_wrapper< T > reverse(T &&iterable)
ServiceManager(IInterface *application)
default creator
constexpr static const auto SUCCESS
std::map< std::string, std::recursive_mutex > m_lockMap
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...
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool existsService(std::string_view name) const override
implementation of ISvcLocation::existsService
TYPE * get() const
Get interface pointer.
MapType m_maptype
Map of service name and service type.
virtual StatusCode sysInitialize()=0
Initialize Service.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
Helper class to parse a string of format "type/name".
StatusCode setPriority(std::string_view name, int pri) override
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.
const std::list< IService * > & getServices() const override
Return the list of Services.
~ServiceManager() override
virtual destructor
#define DECLARE_OBJECT_FACTORY(x)
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
StatusCode start() override
Start (from INITIALIZED to RUNNING).
const StatusCode & ignore() const
Ignore/check StatusCode.
void outputLevelUpdate() override
Function to call to update the outputLevel of the components (after a change in MessageSvc).
virtual StatusCode sysStart()=0
Start Service.
T back_inserter(T... args)
StatusCode reinitialize() override
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
Base class for all Incidents (computing events).
constexpr static const auto FAILURE
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<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...
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
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 declareSvcType(std::string svcname, std::string svctype) override
implementation of ISvcManager::declareSvcType
T emplace_back(T... args)
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).