| The Gaudi Framework v29r1 (5cd95fa2)

- 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
133 void outputLevelUpdate() override;
134
135 private:
136 inline ListSvc::iterator find( const std::string& name )
137 {
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::const_iterator find( const std::string& name ) const
142 {
143 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
144 return std::find( m_listsvc.begin(), m_listsvc.end(), name );
145 }
146 inline ListSvc::iterator find( const IService* ptr )
147 {
148 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
149 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
150 }
151 inline ListSvc::const_iterator find( const IService* ptr ) const
152 {
153 boost::lock_guard<boost::recursive_mutex> lck( m_gLock );
154 return std::find( m_listsvc.begin(), m_listsvc.end(), ptr );
155 }
156
157 private:
158 ListSvc m_listsvc;
159 MapType m_maptype;
173 bool m_loopCheck = true;
174
176 SmartIF<IService> m_appSvc;
177
179 mutable std::list<IService*> m_listOfPtrs;
180
181 GaudiUtils::Map<InterfaceID, SmartIF<IInterface>> m_defaultImplementations;
182
184 typedef boost::recursive_mutex Mutex_t;
185 typedef boost::lock_guard<Mutex_t> LockGuard_t;
186
187 mutable Mutex_t m_gLock;
188 mutable std::map<std::string, std::unique_ptr<Mutex_t>> m_lockMap;
189
190 private:
191 void dump() const;
192 };
193 #endif // GAUDISVC_ServiceManager_H
ServiceManager::find
ListSvc::const_iterator find(const IService *ptr) const
Definition: ServiceManager.h:151
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:179
ServiceManager::setLoopCheckEnabled
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
Definition: ServiceManager.cpp:507
ServiceManager::m_appSvc
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
Definition: ServiceManager.h:176
SmartIF< IService >
Kernel.h
GaudiUtils::Map< std::string, std::string >
ServiceManager::LockGuard_t
boost::lock_guard< Mutex_t > LockGuard_t
Definition: ServiceManager.h:185
ServiceManager::m_gLock
Mutex_t m_gLock
Definition: ServiceManager.h:187
ServiceManager::find
ListSvc::iterator find(const IService *ptr)
Definition: ServiceManager.h:146
ServiceManager::m_defaultImplementations
GaudiUtils::Map< InterfaceID, SmartIF< IInterface > > m_defaultImplementations
Definition: ServiceManager.h:181
ServiceManager::finalize
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
Definition: ServiceManager.cpp:404
ComponentManager::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Definition: ComponentManager.h:78
ServiceManager::m_loopCheck
bool m_loopCheck
Check for service initialization loops.
Definition: ServiceManager.h:173
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:45
ServiceManager::Mutex_t
boost::recursive_mutex Mutex_t
Mutex to synchronize shared service initialization between threads.
Definition: ServiceManager.h:184
ServiceManager::ServiceItem
Definition: ServiceManager.h:39
ServiceManager::restart
StatusCode restart() override
Initialization (from RUNNING to RUNNING, via INITIALIZED).
Definition: ServiceManager.cpp:383
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:172
std::string
STL class.
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
ServiceManager::existsService
bool existsService(const std::string &name) const override
implementation of ISvcLocation::existsService
Definition: ServiceManager.cpp:224
ServiceManager::stop
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
Definition: ServiceManager.cpp:328
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:503
ServiceManager::dump
void dump() const
Definition: ServiceManager.cpp:512
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:28
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:277
ServiceManager::~ServiceManager
~ServiceManager() override
virtual destructor
Definition: ServiceManager.cpp:54
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:38
ServiceManager::getServices
const std::list< IService * > & getServices() const override
Return the list of Services.
Definition: ServiceManager.cpp:214
ServiceManager::start
StatusCode start() override
Start (from INITIALIZED to RUNNING).
Definition: ServiceManager.cpp:295
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:188
ServiceManager::getPriority
int getPriority(const std::string &name) const override
manage priorities of services
Definition: ServiceManager.cpp:483
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:538
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:362
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:141
gaudirun.s
string s
Definition: gaudirun.py:253
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:136
ServiceManager::declareSvcType
StatusCode declareSvcType(const std::string &svcname, const std::string &svctype) override
implementation of ISvcManager::declareSvcType
Definition: ServiceManager.cpp:251
ComponentManager.h
ServiceManager::setPriority
StatusCode setPriority(const std::string &name, int pri) override
Definition: ServiceManager.cpp:491
ServiceManager::removeService
StatusCode removeService(IService *svc) override
implementation of ISvcManager::removeService
Definition: ServiceManager.cpp:231
GaudiDict::typeName
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:23
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:158
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:62
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:104
ServiceManager::initialize
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).
Definition: ServiceManager.cpp:261