ServiceLocatorHelper.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_SERVICELOCATORHELPER_H
2 #define GAUDIKERNEL_SERVICELOCATORHELPER_H
3 
4 #include <string>
6 #include <GaudiKernel/SmartIF.h>
7 #include <GaudiKernel/IService.h>
8 
9 class ISvcLocator;
10 class InterfaceID;
11 class MsgStream;
12 
18 public:
19  ServiceLocatorHelper(ISvcLocator& svcLoc, const INamedInterface& requester):
20  m_svcLoc(svcLoc),
21  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requester.name()), //use requester msg level
22  m_requesterName(requester.name()) {
23  }
25  const std::string& loggedName,
26  const std::string& requesterName):
27  m_svcLoc(svcLoc),
28  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), loggedName), //use requester msg level
29  m_requesterName(requesterName) {
30  }
31  ServiceLocatorHelper(ISvcLocator& svcLoc, const std::string& requesterName):
32  m_svcLoc(svcLoc),
33  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requesterName), //use requester msg level
34  m_requesterName(requesterName) {
35  }
36 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
38  const MsgStream& log, //use requester msg level
39  const std::string& requesterName):
40  m_svcLoc(svcLoc), m_msgLog(log), m_requesterName(requesterName) {}
41 #endif
42 
44  bool createIf,
45  const InterfaceID& iid,
46  void** ppSvc) const {
47  return createIf ? createService(name, iid, ppSvc)
48  : locateService(name, iid, ppSvc, true);
49  }
50 
51  StatusCode locateService(const std::string& name,
52  const InterfaceID& iid,
53  void** ppSvc,
54  bool quiet=false) const;
55 
56  StatusCode createService(const std::string& name,
57  const InterfaceID& iid,
58  void** ppSvc) const;
59 
60  StatusCode createService(const std::string& type,
61  const std::string& name,
62  const InterfaceID& iid,
63  void** ppSvc) const;
64 
65  SmartIF<IService> service(const std::string& name, const bool quiet=false, const bool createIf=true) const;
66 
67  template <typename T>
68  SmartIF<T> service(const std::string& name, const bool quiet=false, const bool createIf=true) const {
69  return service(name,quiet,createIf).as<T>();
70  }
71 
72 private:
73  std::string threadName() const;
74  std::string threadedName(const std::string& name) const;
75  bool isInThread() const;
76  ISvcLocator* serviceLocator() const { return &m_svcLoc; }
77  MsgStream& log() const { return m_msgLog; }
78  const std::string& requesterName() const { return m_requesterName; }
82 };
83 #endif
ISvcLocator * serviceLocator() const
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
an helper to share the implementation of service() among the various kernel base classes ...
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ServiceLocatorHelper(ISvcLocator &svcLoc, const INamedInterface &requester)
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &loggedName, const std::string &requesterName)
STL class.
MsgStream & log() const
Interface ID class.
Definition: IInterface.h:30
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:110
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &requesterName)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
SmartIF< T > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
IInterface compliant class extending IInterface with the name() method.
const std::string & requesterName() const
ServiceLocatorHelper(ISvcLocator &svcLoc, const MsgStream &log, const std::string &requesterName)
#define GAUDI_API
Definition: Kernel.h:107
StatusCode getService(const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const