28#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
29#define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
31#define DEBMSG ON_DEBUG debug()
32#define VERMSG ON_VERBOSE verbose()
40 std::vector<IService*> activeSvc(
const C& lst ) {
41 std::vector<IService*> v;
42 v.reserve( lst.size() );
43 for (
auto& i : lst ) {
44 if ( i.active ) v.push_back( i.service.get() );
59 for (
auto& svc :
m_listsvc ) svc.service->setServiceManager(
nullptr );
69 const std::string&
name = typeName.name();
70 std::string type = typeName.type();
71 if ( !typeName.haveType() ) {
73 auto it =
m_maptype.find( typeName.name() );
80 auto ip = type.find(
"__" );
81 if ( ip != std::string::npos ) type.erase( ip, type.length() );
85 fatal() <<
"No Service factory for " << type <<
" available." <<
endmsg;
90 fatal() <<
"Incompatible interface IService version for " << type <<
endmsg;
94 if (
name ==
"JobOptionsSvc" ) {
96 fatal() << typeName <<
" does not implement Gaudi::Interfaces::IOptionsSvc" <<
endmsg;
101 auto lck = std::scoped_lock{
m_gLock };
103 service->setServiceManager(
this );
109 auto it =
find( svc );
110 auto lck = std::scoped_lock{
m_gLock };
115 m_listsvc.emplace_back( svc, prio,
true );
121 auto it =
find( typeName.name() );
131 sc = svc->sysInitialize();
135 error() <<
"Unable to initialize service \"" << typeName.name() <<
"\"" <<
endmsg;
136 auto lck = std::scoped_lock{
m_gLock };
145 auto lck = std::scoped_lock{
m_gLock };
160 const std::string&
name = typeName.name();
168 auto lk = std::scoped_lock{ this->
m_gLock };
171 mit =
m_lockMap.emplace( std::piecewise_construct_t{}, std::forward_as_tuple(
name ), std::forward_as_tuple() )
179 auto lk2 = std::scoped_lock{ *imut };
185 error() <<
"Initialization loop detected when creating service \"" <<
name <<
"\"" <<
endmsg;
196 if ( createIf &&
addService( typeName ).isSuccess() ) {
return find(
name )->service; }
205 []( ListSvc::const_reference i ) {
return i.service.get(); } );
212 auto it =
find( svc );
226 m_maptype.insert_or_assign( std::move( svcname ), std::move( svctype ) );
238 for (
auto& it : activeSvc(
m_listsvc ) ) {
239 const std::string&
name = it->name();
240 switch ( it->FSMState() ) {
246 sc = it->sysInitialize();
253 error() <<
"Service " <<
name <<
" not in the correct state to be initialized (" << it->FSMState() <<
")"
269 for (
auto& it : activeSvc(
m_listsvc ) ) {
270 const std::string&
name = it->name();
271 switch ( it->FSMState() ) {
284 error() <<
"Service " <<
name <<
" not in the correct state to be started (" << it->FSMState() <<
")" <<
endmsg;
301 const std::string&
name = svc->name();
302 switch ( svc->FSMState() ) {
315 DEBMSG <<
"Service " <<
name <<
" not in the correct state to be stopped (" << svc->FSMState() <<
")" <<
endmsg;
330 for (
auto& svc : activeSvc(
m_listsvc ) ) {
331 sc = svc->sysReinitialize();
333 error() <<
"Unable to re-initialize Service: " << svc->name() <<
endmsg;
348 for (
auto& svc : activeSvc(
m_listsvc ) ) {
349 sc = svc->sysRestart();
351 error() <<
"Unable to re-start Service: " << svc->name() <<
endmsg;
362 if ( pri_tool != 0 ) {
375 std::vector<IIncidentListener*> postFinList;
378 p_inc->getListeners( postFinList, IncidentType::SvcPostFinalize );
393 const std::string&
name = svc->name();
397 if ( !svc->sysFinalize().isSuccess() ) {
405 if ( !postFinList.empty() ) {
406 DEBMSG <<
"Will call SvcPostFinalize for " << postFinList.size() <<
" clients" <<
endmsg;
407 Incident inc(
"ServiceManager", IncidentType::SvcPostFinalize );
408 for (
auto& itr : postFinList ) itr->handle( inc );
413 DEBMSG <<
"Looping over all active services..." <<
endmsg;
416 DEBMSG <<
"---- " << it->service->name() <<
" (refCount = " << it->service->refCount() <<
")" <<
endmsg;
417 if ( it->service->refCount() < 1 ) {
418 warning() <<
"Too low reference count for " << it->service->name() <<
" (should not go below 1 at this point)"
420 it->service->addRef();
433 return ( it !=
m_listsvc.end() ) ? it->priority : 0;
450 <<
"===================== listing all services ===================\n"
451 <<
" prior ref name active\n";
456 log.flags( std::ios_base::right );
457 log << svc.priority <<
" ";
459 log << svc.service->refCount() <<
" ";
461 log.flags( std::ios_base::left );
462 log << svc.service->name() <<
" ";
464 log << svc.active << std::endl;
467 log <<
"=================================================================\n";
474 const auto svc =
dynamic_cast<Service*
>( svcItem.service.get() );
bool isValidInterface(IFace *i)
Templated function that throws an exception if the version if the interface implemented by the object...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_OBJECT_FACTORY(x)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MSG::Level resetMessaging()
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Gaudi::StateMachine::State targetFSMState() const override
When we are in the middle of a transition, get the state where the transition is leading us.
Helper class to parse a string of format "type/name".
Definition of the basic interface.
General service interface definition.
Base class for all Incidents (computing events).
Base class for all services.
The ServiceManager class is in charge of the creation of concrete instances of Services.
StatusCode declareSvcType(std::string svcname, std::string svctype) override
implementation of ISvcManager::declareSvcType
const std::list< IService * > & getServices() const override
Return the list of Services.
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
bool loopCheckEnabled() const override
Get the value of the initialization loop check flag.
StatusCode start() override
Start (from INITIALIZED to RUNNING).
void outputLevelUpdate() override
Function to call to update the outputLevel of the components (after a change in MessageSvc).
StatusCode reinitialize() override
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
bool existsService(std::string_view name) const override
implementation of ISvcLocation::existsService
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
StatusCode removeService(IService *svc) override
implementation of ISvcManager::removeService
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).
StatusCode restart() override
Initialization (from RUNNING to RUNNING, via INITIALIZED).
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 > m_appSvc
Pointer to the application IService interface.
SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
Returns a smart pointer to a service.
~ServiceManager() override
virtual destructor
std::map< std::string, std::recursive_mutex > m_lockMap
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
ServiceManager(IInterface *application)
default creator
ListSvc::iterator find(std::string_view name)
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
bool m_loopCheck
Check for service initialization loops.
int getPriority(std::string_view name) const override
manage priorities of services
std::recursive_mutex m_gLock
Mutex to synchronize shared service initialization between threads.
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
StatusCode setPriority(std::string_view name, int pri) override
MapType m_maptype
Map of service name and service type.
Small smart pointer class with automatic reference counting for IInterface.
TYPE * get() const
Get interface pointer.
This class is used for returning status codes from appropriate routines.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
::details::reverse_wrapper< T > reverse(T &&iterable)
Interface for a component that manages application configuration options.
static const InterfaceID & interfaceID()