| The Gaudi Framework v32r1 (f65d50dc)

ServiceManager.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_ServiceManager_H
2 #define GAUDISVC_ServiceManager_H
3
4 // Include files
5 #include "GaudiKernel/ComponentManager.h"
6 #include "GaudiKernel/IStateful.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/ISvcManager.h"
9 #include "GaudiKernel/Kernel.h"
10 #include "GaudiKernel/Map.h"
11 #include "GaudiKernel/SmartIF.h"
12
13 #include "boost/thread.hpp"
14 #include <algorithm>
15 #include <list>
16 #include <memory>
17 #include <string>
18 #include <vector>
19
20 // Forward declarations
21 class IService;
22 class IMessageSvc;
23
36 class ServiceManager : public extends<ComponentManager, ISvcManager, ISvcLocator> {
37 public:
38 struct ServiceItem final {
39 ServiceItem( IService* s, long p = 0, bool act = false ) : service( s ), priority( p ), active( act ) {}
40 SmartIF<IService> service;
41 long priority;
42 bool active;
43 inline bool operator==( const std::string& name ) const { return service->name() == name; }
44 inline bool operator==( const IService* ptr ) const { return service.get() == ptr; }
45 inline bool operator<( const ServiceItem& rhs ) const { return priority < rhs.priority; }
46 };
47
48 // typedefs and classes
49 typedef std::list<ServiceItem> ListSvc;
50 typedef GaudiUtils::Map<std::string, std::string> MapType;
51
53 ServiceManager( IInterface* application );
54
56 inline SmartIF<ISvcLocator>& serviceLocator() const override { return m_svcLocator; }
57
59 ~ServiceManager() override;
60
62 const std::list<IService*>& getServices() const override;
63
65 bool existsService( const std::string& name ) const override;
66
68 StatusCode addService( IService* svc, int prio = DEFAULT_SVC_PRIORITY ) override;
70 StatusCode addService( const Gaudi::Utils::TypeNameString& typeName, int prio = DEFAULT_SVC_PRIORITY ) override;
72 StatusCode removeService( IService* svc ) override;
74 StatusCode removeService( const std::string& name ) override;
75
77 StatusCode declareSvcType( const std::string& svcname, const std::string& svctype ) override;
78
84 SmartIF<IService>& createService( const Gaudi::Utils::TypeNameString& nametype ) override;
85
87 StatusCode initialize() override;
89 StatusCode start() override;
91 StatusCode stop() override;
93 StatusCode finalize() override;
94
96 StatusCode reinitialize() override;
98 StatusCode restart() override;
99
101 int getPriority( const std::string& name ) const override;
102 StatusCode setPriority( const std::string& name, int pri ) override;
103
105 bool loopCheckEnabled() const override;
107 void setLoopCheckEnabled( bool en ) override;
108
110 const std::string& name() const override {
111 static std::string _name = "ServiceManager";
112 return _name;
113 }
114
116 SmartIF<IService>& service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) override;
117
119 template <typename T>
120 inline SmartIF<T> service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) {
121 return SmartIF<T>{service( typeName, createIf )};
122 }
123
124 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
125 using ISvcManager::addService;
126 using ISvcManager::createService;
127 #endif
128
130 void outputLevelUpdate() override;
131
132 private:
133 inline ListSvc::iterator find( const std::string& name ) {
134 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
135 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
136 }
137 inline ListSvc::const_iterator find( const std::string& name ) const {
138 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
139 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
140 }
141 inline ListSvc::iterator find( const IService* ptr ) {
142 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
143 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
144 }
145 inline ListSvc::const_iterator find( const IService* ptr ) const {
146 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
147 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
148 }
149
150 private:
151 ListSvc m_listsvc;
152 MapType m_maptype;
166 bool m_loopCheck = true;
167
169 SmartIF<IService> m_appSvc;
170
172 mutable std::list<IService*> m_listOfPtrs;
173
174 GaudiUtils::Map<InterfaceID, SmartIF<IInterface>> m_defaultImplementations;
175
177 typedef boost::recursive_mutex Mutex_t;
178 typedef boost::lock_guard<Mutex_t> LockGuard_t;
179
180 mutable Mutex_t m_gLock;
181 mutable std::map<std::string, Mutex_t> m_lockMap;
182
183 private:
184 void dump() const;
185 };
186 #endif // GAUDISVC_ServiceManager_H
ServiceManager
The ServiceManager class is in charge of the creation of concrete instances of Services.
Definition: ServiceManager.h:36
ISvcManager::addService
virtual StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY)=0
Add a service to the "active" list of services of the factory.
ServiceManager::m_listOfPtrs
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
Definition: ServiceManager.h:172
ServiceManager::setLoopCheckEnabled
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
Definition: ServiceManager.cpp:495
ServiceManager::m_appSvc
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
Definition: ServiceManager.h:169
SmartIF< IService >
Kernel.h
GaudiUtils::Map< std::string, std::string >
ServiceManager::ServiceItem::operator==
bool operator==(const std::string &name) const
Definition: ServiceManager.h:43
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:178
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:180
ServiceManager::find
ListSvc::iterator find(const IService *ptr)
Definition: ServiceManager.h:141
ServiceManager::m_defaultImplementations
GaudiUtils::Map< InterfaceID, SmartIF< IInterface > > m_defaultImplementations
Definition: ServiceManager.h:174
ServiceManager::finalize
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
Definition: ServiceManager.cpp:394
ServiceManager::getPriority
int getPriority(const std::string &name) const override
manage priorities of services
Definition: ServiceManager.cpp:473
ServiceManager::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Function needed by CommonMessaging.
Definition: ServiceManager.h:56
ComponentManager::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Definition: ComponentManager.h:76
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:166
ServiceManager::existsService
bool existsService(const std::string &name) const override
implementation of ISvcLocation::existsService
Definition: ServiceManager.cpp:214
ServiceManager::ServiceManager
ServiceManager(IInterface *application)
default creator
Definition: ServiceManager.cpp:43
ServiceManager::Mutex_t
boost::recursive_mutex Mutex_t
Mutex to synchronize shared service initialization between threads.
Definition: ServiceManager.h:177
ServiceManager::ServiceItem
Definition: ServiceManager.h:38
ServiceManager::restart
StatusCode restart() override
Initialization (from RUNNING to RUNNING, via INITIALIZED).
Definition: ServiceManager.cpp:373
std::list::end
T end(T... args)
Map.h
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
std::map< std::string, Mutex_t >
ISvcManager.h
ServiceManager::m_maptype
MapType m_maptype
Map of service name and service type.
Definition: ServiceManager.h:165
std::string
STL class.
ServiceManager::stop
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
Definition: ServiceManager.cpp:318
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:10
ServiceManager::ServiceItem::operator==
bool operator==(const IService *ptr) const
Definition: ServiceManager.h:44
ServiceManager::loopCheckEnabled
bool loopCheckEnabled() const override
Get the value of the initialization loop check flag.
Definition: ServiceManager.cpp:491
IService
General service interface definition.
Definition: IService.h:18
ServiceManager::service
SmartIF< T > service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
Returns a smart pointer to the requested interface of a service.
Definition: ServiceManager.h:120
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
ISvcManager::createService
virtual SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype)=0
Creates and instance of a service type that has been declared beforehand and assigns it a name.
IInterface
Definition of the basic interface.
Definition: IInterface.h:244
ServiceManager::getServices
const std::list< IService * > & getServices() const override
Return the list of Services.
Definition: ServiceManager.cpp:204
ServiceManager::~ServiceManager
~ServiceManager() override
virtual destructor
Definition: ServiceManager.cpp:51
SmartIF.h
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:37
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:110
ServiceManager::dump
void dump() const
Definition: ServiceManager.cpp:500
ServiceManager::start
StatusCode start() override
Start (from INITIALIZED to RUNNING).
Definition: ServiceManager.cpp:285
ServiceManager::ServiceItem::priority
long priority
Definition: ServiceManager.h:41
IStateful.h
std::list< ServiceItem >
ServiceManager::ServiceItem::operator<
bool operator<(const ServiceItem &rhs) const
Definition: ServiceManager.h:45
std::find
T find(T... args)
ServiceManager::outputLevelUpdate
void outputLevelUpdate() override
Function to call to update the outputLevel of the components (after a change in MessageSvc).
Definition: ServiceManager.cpp:525
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
std::list::begin
T begin(T... args)
ServiceManager::ServiceItem::active
bool active
Definition: ServiceManager.h:42
ServiceManager::reinitialize
StatusCode reinitialize() override
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
Definition: ServiceManager.cpp:352
ServiceManager::find
ListSvc::const_iterator find(const std::string &name) const
Definition: ServiceManager.h:137
ServiceManager::MapType
GaudiUtils::Map< std::string, std::string > MapType
Definition: ServiceManager.h:50
gaudirun.s
string s
Definition: gaudirun.py:316
gaudirun.application
application
Definition: gaudirun.py:295
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:133
ServiceManager::declareSvcType
StatusCode declareSvcType(const std::string &svcname, const std::string &svctype) override
implementation of ISvcManager::declareSvcType
Definition: ServiceManager.cpp:241
ComponentManager.h
ServiceManager::setPriority
StatusCode setPriority(const std::string &name, int pri) override
Definition: ServiceManager.cpp:480
ServiceManager::removeService
StatusCode removeService(IService *svc) override
implementation of ISvcManager::removeService
Definition: ServiceManager.cpp:221
ServiceManager::service
SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
Returns a smart pointer to a service.
Definition: ServiceManager.cpp:159
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:21
ServiceManager::ListSvc
std::list< ServiceItem > ListSvc
Definition: ServiceManager.h:49
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
Definition: ServiceManager.h:151
ServiceManager::createService
SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype) override
implementation of ISvcManager::createService NOTE: as this returns a &, we must guarantee that once c...
Definition: ServiceManager.cpp:58
ServiceManager::ServiceItem::ServiceItem
ServiceItem(IService *s, long p=0, bool act=false)
Definition: ServiceManager.h:39
ISvcLocator.h
ServiceManager::ServiceItem::service
SmartIF< IService > service
Definition: ServiceManager.h:40
ServiceManager::m_lockMap
std::map< std::string, Mutex_t > m_lockMap
Definition: ServiceManager.h:181
ServiceManager::addService
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
Definition: ServiceManager.cpp:100
ServiceManager::find
ListSvc::const_iterator find(const IService *ptr) const
Definition: ServiceManager.h:145
ServiceManager::initialize
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).
Definition: ServiceManager.cpp:251