| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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/Kernel.h"
6 #include "GaudiKernel/ISvcManager.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/IStateful.h"
9 #include "GaudiKernel/SmartIF.h"
10 #include "GaudiKernel/ComponentManager.h"
11 #include "GaudiKernel/Map.h"
12 #include <string>
13 #include <list>
14 #include <vector>
15 #include <algorithm>
16 #include <memory>
17 #include "boost/thread.hpp"
18
19 // Forward declarations
20 class IService;
21 class IMessageSvc;
22 class Property;
23
36 class ServiceManager : public extends<ComponentManager,
37 ISvcManager,
38 ISvcLocator> {
39 public:
40
41 struct ServiceItem final {
42 ServiceItem(IService *s, long p = 0, bool act = false):
43 service(s), priority(p), active(act) {}
44 SmartIF<IService> service;
45 long priority;
46 bool active;
47 inline bool operator==(const std::string &name) const {
48 return service->name() == name;
49 }
50 inline bool operator==(const IService *ptr) const {
51 return service.get() == ptr;
52 }
53 inline bool operator<(const ServiceItem& rhs) const {
54 return priority < rhs.priority;
55 }
56 };
57
58 // typedefs and classes
59 typedef std::list<ServiceItem> ListSvc;
60 typedef GaudiUtils::Map<std::string, std::string> MapType;
61
63 ServiceManager(IInterface* application);
64
66 inline SmartIF<ISvcLocator>& serviceLocator() const override {
67 return m_svcLocator;
68 }
69
71 ~ServiceManager() override;
72
74 const std::list<IService*>& getServices() const override;
75
77 bool existsService(const std::string& name) const override;
78
80 StatusCode addService(IService* svc, int prio = DEFAULT_SVC_PRIORITY) override;
82 StatusCode addService(const Gaudi::Utils::TypeNameString& typeName, int prio = DEFAULT_SVC_PRIORITY) override;
84 StatusCode removeService(IService* svc) override;
86 StatusCode removeService(const std::string& name) override;
87
89 StatusCode declareSvcType(const std::string& svcname, const std::string& svctype) override;
90
96 SmartIF<IService>& createService(const Gaudi::Utils::TypeNameString& nametype) override;
97
99 StatusCode initialize() override;
101 StatusCode start() override;
103 StatusCode stop() override;
105 StatusCode finalize() override;
106
108 StatusCode reinitialize() override;
110 StatusCode restart() override;
111
113 int getPriority(const std::string& name) const override;
114 StatusCode setPriority(const std::string& name, int pri) override;
115
117 bool loopCheckEnabled() const override;
119 void setLoopCheckEnabled(bool en) override;
120
122 const std::string &name() const override {
123 static std::string _name = "ServiceManager";
124 return _name;
125 }
126
128 SmartIF<IService> &service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true) override;
129
131 template <typename T>
132 inline SmartIF<T> service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true) {
133 return SmartIF<T>{service(typeName, createIf)};
134 }
135
136 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
137 using ISvcManager::createService;
138 using ISvcManager::addService;
139 #endif
140
141 private:
142
143 inline ListSvc::iterator find(const std::string &name) {
144 boost::lock_guard<boost::recursive_mutex> lck(m_gLock);
145 return std::find(m_listsvc.begin(), m_listsvc.end(), name);
146 }
147 inline ListSvc::const_iterator find(const std::string &name) const {
148 boost::lock_guard<boost::recursive_mutex> lck(m_gLock);
149 return std::find(m_listsvc.begin(), m_listsvc.end(), name);
150 }
151 inline ListSvc::iterator find(const IService *ptr) {
152 boost::lock_guard<boost::recursive_mutex> lck(m_gLock);
153 return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
154 }
155 inline ListSvc::const_iterator find(const IService *ptr) const {
156 boost::lock_guard<boost::recursive_mutex> lck(m_gLock);
157 return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
158 }
159
160 private:
161 ListSvc m_listsvc;
162 MapType m_maptype;
176 bool m_loopCheck = true;
177
179 SmartIF<IService> m_appSvc;
180
182 mutable std::list<IService*> m_listOfPtrs;
183
184 GaudiUtils::Map<InterfaceID, SmartIF<IInterface> > m_defaultImplementations;
185
187 typedef boost::recursive_mutex Mutex_t;
188 typedef boost::lock_guard<Mutex_t> LockGuard_t;
189
190 mutable Mutex_t m_gLock;
191 mutable std::map<std::string, std::unique_ptr<Mutex_t> > m_lockMap;
192
193
194 private:
195 void dump() const;
196
197 };
198 #endif // GAUDISVC_ServiceManager_H
ServiceManager::find
ListSvc::const_iterator find(const IService *ptr) const
Definition: ServiceManager.h:155
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:182
ServiceManager::setLoopCheckEnabled
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
Definition: ServiceManager.cpp:523
ServiceManager::m_appSvc
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
Definition: ServiceManager.h:179
SmartIF< IService >
Kernel.h
GaudiUtils::Map< std::string, std::string >
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:188
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:190
ServiceManager::find
ListSvc::iterator find(const IService *ptr)
Definition: ServiceManager.h:151
ServiceManager::m_defaultImplementations
GaudiUtils::Map< InterfaceID, SmartIF< IInterface > > m_defaultImplementations
Definition: ServiceManager.h:184
ServiceManager::finalize
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
Definition: ServiceManager.cpp:413
ServiceManager::getPriority
int getPriority(const std::string &name) const override
manage priorities of services
Definition: ServiceManager.cpp:498
ServiceManager::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Function needed by CommonMessaging.
Definition: ServiceManager.h:66
ComponentManager::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Definition: ComponentManager.h:80
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:176
ServiceManager::existsService
bool existsService(const std::string &name) const override
implementation of ISvcLocation::existsService
Definition: ServiceManager.cpp:228
ServiceManager::ServiceManager
ServiceManager(IInterface *application)
default creator
Definition: ServiceManager.cpp:42
ServiceManager::Mutex_t
boost::recursive_mutex Mutex_t
Mutex to synchronize shared service initialization between threads.
Definition: ServiceManager.h:187
ServiceManager::ServiceItem
Definition: ServiceManager.h:41
ServiceManager::restart
StatusCode restart() override
Initialization (from RUNNING to RUNNING, via INITIALIZED).
Definition: ServiceManager.cpp:392
std::list::end
T end(T...args)
Map.h
std::map
STL class.
ISvcManager.h
ServiceManager::m_maptype
MapType m_maptype
Map of service name and service type.
Definition: ServiceManager.h:175
std::string
STL class.
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
ServiceManager::stop
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
Definition: ServiceManager.cpp:336
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
ServiceManager::dump
void dump() const
Definition: ServiceManager.cpp:531
ServiceManager::loopCheckEnabled
bool loopCheckEnabled() const override
Get the value of the initialization loop check flag.
Definition: ServiceManager.cpp:517
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:132
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
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:234
ServiceManager::getServices
const std::list< IService * > & getServices() const override
Return the list of Services.
Definition: ServiceManager.cpp:215
ServiceManager::~ServiceManager
~ServiceManager() override
virtual destructor
Definition: ServiceManager.cpp:52
SmartIF.h
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:122
ServiceManager::start
StatusCode start() override
Start (from INITIALIZED to RUNNING).
Definition: ServiceManager.cpp:300
ServiceManager::ServiceItem::priority
long priority
Definition: ServiceManager.h:45
ServiceManager::ServiceItem::operator==
bool operator==(const std::string &name) const
Definition: ServiceManager.h:47
IStateful.h
std::list< ServiceItem >
ServiceManager::m_lockMap
std::map< std::string, std::unique_ptr< Mutex_t > > m_lockMap
Definition: ServiceManager.h:191
std::find
T find(T...args)
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
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:46
ServiceManager::reinitialize
StatusCode reinitialize() override
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
Definition: ServiceManager.cpp:371
ServiceManager::MapType
GaudiUtils::Map< std::string, std::string > MapType
Definition: ServiceManager.h:60
ServiceManager::find
ListSvc::const_iterator find(const std::string &name) const
Definition: ServiceManager.h:147
gaudirun.s
string s
Definition: gaudirun.py:245
ServiceManager::ServiceItem::operator<
bool operator<(const ServiceItem &rhs) const
Definition: ServiceManager.h:53
ServiceManager::find
ListSvc::iterator find(const std::string &name)
Definition: ServiceManager.h:143
ServiceManager::declareSvcType
StatusCode declareSvcType(const std::string &svcname, const std::string &svctype) override
implementation of ISvcManager::declareSvcType
Definition: ServiceManager.cpp:255
ComponentManager.h
ServiceManager::setPriority
StatusCode setPriority(const std::string &name, int pri) override
Definition: ServiceManager.cpp:506
ServiceManager::removeService
StatusCode removeService(IService *svc) override
implementation of ISvcManager::removeService
Definition: ServiceManager.cpp:235
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:161
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:21
ServiceManager::ListSvc
std::list< ServiceItem > ListSvc
Definition: ServiceManager.h:59
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF for all services – and because...
Definition: ServiceManager.h:161
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:59
ServiceManager::ServiceItem::ServiceItem
ServiceItem(IService *s, long p=0, bool act=false)
Definition: ServiceManager.h:42
ISvcLocator.h
ServiceManager::ServiceItem::operator==
bool operator==(const IService *ptr) const
Definition: ServiceManager.h:50
ServiceManager::ServiceItem::service
SmartIF< IService > service
Definition: ServiceManager.h:44
ServiceManager::addService
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
Definition: ServiceManager.cpp:100
ServiceManager::initialize
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).
Definition: ServiceManager.cpp:266