| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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/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 {
38 public:
39 struct ServiceItem final {
40 ServiceItem( IService* s, long p = 0, bool act = false ) : service( s ), priority( p ), active( act ) {}
41 SmartIF<IService> service;
42 long priority;
43 bool active;
44 inline bool operator==( const std::string& name ) const { return service->name() == name; }
45 inline bool operator==( const IService* ptr ) const { return service.get() == ptr; }
46 inline bool operator<( const ServiceItem& rhs ) const { return priority < rhs.priority; }
47 };
48
49 // typedefs and classes
50 typedef std::list<ServiceItem> ListSvc;
51 typedef GaudiUtils::Map<std::string, std::string> MapType;
52
54 ServiceManager( IInterface* application );
55
57 inline SmartIF<ISvcLocator>& serviceLocator() const override { return m_svcLocator; }
58
60 ~ServiceManager() override;
61
63 const std::list<IService*>& getServices() const override;
64
66 bool existsService( const std::string& name ) const override;
67
69 StatusCode addService( IService* svc, int prio = DEFAULT_SVC_PRIORITY ) override;
71 StatusCode addService( const Gaudi::Utils::TypeNameString& typeName, int prio = DEFAULT_SVC_PRIORITY ) override;
73 StatusCode removeService( IService* svc ) override;
75 StatusCode removeService( const std::string& name ) override;
76
78 StatusCode declareSvcType( const std::string& svcname, const std::string& svctype ) override;
79
85 SmartIF<IService>& createService( const Gaudi::Utils::TypeNameString& nametype ) override;
86
88 StatusCode initialize() override;
90 StatusCode start() override;
92 StatusCode stop() override;
94 StatusCode finalize() override;
95
97 StatusCode reinitialize() override;
99 StatusCode restart() override;
100
102 int getPriority( const std::string& name ) const override;
103 StatusCode setPriority( const std::string& name, int pri ) override;
104
106 bool loopCheckEnabled() const override;
108 void setLoopCheckEnabled( bool en ) override;
109
111 const std::string& name() const override
112 {
113 static std::string _name = "ServiceManager";
114 return _name;
115 }
116
118 SmartIF<IService>& service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) override;
119
121 template <typename T>
122 inline SmartIF<T> service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true )
123 {
124 return SmartIF<T>{service( typeName, createIf )};
125 }
126
127 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
128 using ISvcManager::createService;
129 using ISvcManager::addService;
130 #endif
131
132 private:
133 inline ListSvc::iterator find( const std::string& name )
134 {
135 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
136 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
137 }
138 inline ListSvc::const_iterator find( const std::string& name ) const
139 {
140 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
141 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
142 }
143 inline ListSvc::iterator find( const IService* ptr )
144 {
145 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
146 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
147 }
148 inline ListSvc::const_iterator find( const IService* ptr ) const
149 {
150 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
151 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
152 }
153
154 private:
155 ListSvc m_listsvc;
156 MapType m_maptype;
170 bool m_loopCheck = true;
171
173 SmartIF<IService> m_appSvc;
174
176 mutable std::list<IService*> m_listOfPtrs;
177
178 GaudiUtils::Map<InterfaceID, SmartIF<IInterface>> m_defaultImplementations;
179
181 typedef boost::recursive_mutex Mutex_t;
182 typedef boost::lock_guard<Mutex_t> LockGuard_t;
183
184 mutable Mutex_t m_gLock;
185 mutable std::map<std::string, std::unique_ptr<Mutex_t>> m_lockMap;
186
187 private:
188 void dump() const;
189 };
190 #endif // GAUDISVC_ServiceManager_H
ServiceManager::find
ListSvc::const_iterator find(const IService *ptr) const
Definition: ServiceManager.h:148
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:176
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:173
SmartIF< IService >
Kernel.h
GaudiUtils::Map< std::string, std::string >
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:182
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:184
ServiceManager::find
ListSvc::iterator find(const IService *ptr)
Definition: ServiceManager.h:143
ServiceManager::m_defaultImplementations
GaudiUtils::Map< InterfaceID, SmartIF< IInterface > > m_defaultImplementations
Definition: ServiceManager.h:178
ServiceManager::finalize
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
Definition: ServiceManager.cpp:413
ComponentManager::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Definition: ComponentManager.h:77
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:170
ServiceManager::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Function needed by CommonMessaging.
Definition: ServiceManager.h:57
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:181
ServiceManager::ServiceItem
Definition: ServiceManager.h:39
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:169
std::string
STL class.
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
ServiceManager::existsService
bool existsService(const std::string &name) const override
implementation of ISvcLocation::existsService
Definition: ServiceManager.cpp:228
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:12
ServiceManager::loopCheckEnabled
bool loopCheckEnabled() const override
Get the value of the initialization loop check flag.
Definition: ServiceManager.cpp:517
ServiceManager::dump
void dump() const
Definition: ServiceManager.cpp:531
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:122
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::~ServiceManager
~ServiceManager() override
virtual destructor
Definition: ServiceManager.cpp:52
SmartIF.h
ServiceManager::name
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
Definition: ServiceManager.h:111
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
ServiceManager::getServices
const std::list< IService * > & getServices() const override
Return the list of Services.
Definition: ServiceManager.cpp:215
ServiceManager::start
StatusCode start() override
Start (from INITIALIZED to RUNNING).
Definition: ServiceManager.cpp:300
ServiceManager::ServiceItem::priority
long priority
Definition: ServiceManager.h:42
ServiceManager::ServiceItem::operator==
bool operator==(const std::string &name) const
Definition: ServiceManager.h:44
IStateful.h
std::list< ServiceItem >
ServiceManager::m_lockMap
std::map< std::string, std::unique_ptr< Mutex_t > > m_lockMap
Definition: ServiceManager.h:185
ServiceManager::getPriority
int getPriority(const std::string &name) const override
manage priorities of services
Definition: ServiceManager.cpp:498
std::find
T find(T...args)
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:43
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:51
ServiceManager::find
ListSvc::const_iterator find(const std::string &name) const
Definition: ServiceManager.h:138
gaudirun.s
string s
Definition: gaudirun.py:245
ServiceManager::ServiceItem::operator<
bool operator<(const ServiceItem &rhs) const
Definition: ServiceManager.h:46
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: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
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:21
ServiceManager::ListSvc
std::list< ServiceItem > ListSvc
Definition: ServiceManager.h:50
ServiceManager::m_listsvc
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because...
Definition: ServiceManager.h:155
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:40
ISvcLocator.h
ServiceManager::ServiceItem::operator==
bool operator==(const IService *ptr) const
Definition: ServiceManager.h:45
ServiceManager::ServiceItem::service
SmartIF< IService > service
Definition: ServiceManager.h:41
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