All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ServiceManager.h
Go to the documentation of this file.
1 // $Id: ServiceManager.h,v 1.9 2008/11/10 15:29:09 marcocle Exp $
2 #ifndef GAUDISVC_ServiceManager_H
3 #define GAUDISVC_ServiceManager_H
4 
5 // Include files
6 #include "GaudiKernel/Kernel.h"
10 #include "GaudiKernel/SmartIF.h"
12 #include "GaudiKernel/Map.h"
13 #include <string>
14 #include <list>
15 #include <map>
16 #include <algorithm>
17 #include "boost/thread.hpp"
18 
19 // Forward declarations
20 class IService;
21 class IMessageSvc;
22 class Property;
23 
36 class ServiceManager : public extends2<ComponentManager, ISvcManager, ISvcLocator>{
37 public:
38 
39  struct ServiceItem {
40  ServiceItem(IService *s, long p = 0, bool act = false):
41  service(s), priority(p), active(act) {}
43  long priority;
44  bool active;
45  inline bool operator==(const std::string &name) const {
46  return service->name() == name;
47  }
48  inline bool operator==(const IService *ptr) const {
49  return service.get() == ptr;
50  }
51  inline bool operator<(const ServiceItem& rhs) const {
52  return priority < rhs.priority;
53  }
54  };
55 
56  // typedefs and classes
57  typedef std::list<ServiceItem> ListSvc;
59 
61  ServiceManager(IInterface* application);
62 
65  return m_svcLocator;
66  }
67 
69  virtual ~ServiceManager();
70 
72  virtual const std::list<IService*>& getServices() const;
73 
75  virtual bool existsService(const std::string& name) const;
76 
78  virtual StatusCode addService(IService* svc, int prio = DEFAULT_SVC_PRIORITY);
82  virtual StatusCode removeService(IService* svc);
84  virtual StatusCode removeService(const std::string& name);
85 
87  virtual StatusCode declareSvcType(const std::string& svcname, const std::string& svctype);
88 
91 
93  virtual StatusCode initialize();
95  virtual StatusCode start();
97  virtual StatusCode stop();
99  virtual StatusCode finalize();
100 
102  virtual StatusCode reinitialize();
104  virtual StatusCode restart();
105 
107  virtual int getPriority(const std::string& name) const;
108  virtual StatusCode setPriority(const std::string& name, int pri);
109 
111  virtual bool loopCheckEnabled() const;
113  virtual void setLoopCheckEnabled(bool en);
114 
116  const std::string &name() const {
117  static std::string _name = "ServiceManager";
118  return _name;
119  }
120 
122  virtual SmartIF<IService> &service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true);
123 
124 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
127 #endif
128 
129 private:
130 
131  inline ListSvc::iterator find(const std::string &name) {
132  return std::find(m_listsvc.begin(), m_listsvc.end(), name);
133  }
134  inline ListSvc::const_iterator find(const std::string &name) const {
135  return std::find(m_listsvc.begin(), m_listsvc.end(), name);
136  }
137  inline ListSvc::iterator find(const IService *ptr) {
138  return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
139  }
140  inline ListSvc::const_iterator find(const IService *ptr) const {
141  return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
142  }
143 
144 private:
147  bool m_loopCheck;
148 
151 
153  mutable std::list<IService*> m_listOfPtrs;
154 
156 
158  boost::recursive_mutex m_svcinitmutex;
159 
160 private:
161  void dump() const;
162 
163 };
164 #endif // GAUDISVC_ServiceManager_H
165 
ListSvc::const_iterator find(const IService *ptr) const
The ServiceManager class is in charge of the creation of concrete instances of Services.
virtual StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY)=0
Add a service to the "active" list of services of the factory.
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
ListSvc::iterator find(const IService *ptr)
GaudiUtils::Map< InterfaceID, SmartIF< IInterface > > m_defaultImplementations
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
bool m_loopCheck
Check for service initialization loops.
virtual int getPriority(const std::string &name) const
manage priorities of services
ServiceManager(IInterface *application)
default creator
virtual const std::list< IService * > & getServices() const
Return the list of Services.
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
Base class used to extend a class implementing other interfaces.
Definition: extends.h:75
SmartIF< ISvcLocator > & serviceLocator() const
Function needed by CommonMessaging.
MapType m_maptype
Map of service name and service type.
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
void dump() const
virtual SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype)
implementation of ISvcManager::createService
General service interface definition.
Definition: IService.h:19
virtual StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY)
implementation of ISvcManager::addService
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
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...
Definition of the basic interface.
Definition: IInterface.h:160
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
virtual StatusCode setPriority(const std::string &name, int pri)
virtual void setLoopCheckEnabled(bool en)
Set the value of the initialization loop check flag.
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
bool operator==(const std::string &name) const
static const int DEFAULT_SVC_PRIORITY
Definition: ISvcManager.h:34
virtual bool existsService(const std::string &name) const
implementation of ISvcLocation::existsService
virtual StatusCode declareSvcType(const std::string &svcname, const std::string &svctype)
implementation of ISvcManager::declareSvcType
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
virtual StatusCode removeService(IService *svc)
implementation of ISvcManager::removeService
virtual ~ServiceManager()
virtual destructor
GaudiUtils::Map< std::string, std::string > MapType
ListSvc::const_iterator find(const std::string &name) const
string s
Definition: gaudirun.py:210
bool operator<(const ServiceItem &rhs) const
ListSvc::iterator find(const std::string &name)
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
Returns a smart pointer to a service.
virtual bool loopCheckEnabled() const
Get the value of the initialization loop check flag.
boost::recursive_mutex m_svcinitmutex
Mutex to synchronize shared service initialization between threads.
virtual StatusCode restart()
Initialization (from RUNNING to RUNNING, via INITIALIZED).
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:22
std::list< ServiceItem > ListSvc
ListSvc m_listsvc
List of service maintained by ServiceManager.
ServiceItem(IService *s, long p=0, bool act=false)
bool operator==(const IService *ptr) const
SmartIF< IService > service
virtual StatusCode start()
Start (from INITIALIZED to RUNNING).