All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
19 public:
20  ServiceLocatorHelper(ISvcLocator& svcLoc, const INamedInterface& requester):
21  m_svcLoc(svcLoc),
22  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requester.name()), //use requester msg level
23  m_requesterName(requester.name()) {
24  }
26  const std::string& loggedName,
27  const std::string& requesterName):
28  m_svcLoc(svcLoc),
29  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), loggedName), //use requester msg level
30  m_requesterName(requesterName) {
31  }
32  ServiceLocatorHelper(ISvcLocator& svcLoc, const std::string& requesterName):
33  m_svcLoc(svcLoc),
34  m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requesterName), //use requester msg level
35  m_requesterName(requesterName) {
36  }
37 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
39  const MsgStream& log, //use requester msg level
40  const std::string& requesterName):
41  m_svcLoc(svcLoc), m_msgLog(log), m_requesterName(requesterName) {}
42 #endif
43 
44  StatusCode getService(const std::string& name,
45  bool createIf,
46  const InterfaceID& iid,
47  void** ppSvc) const {
48  return (createIf ?
49  createService(name, iid, ppSvc) :
50  locateService(name, iid, ppSvc, true));
51  }
52 
53  StatusCode locateService(const std::string& name,
54  const InterfaceID& iid,
55  void** ppSvc,
56  bool quiet=false) const;
57 
58  StatusCode createService(const std::string& name,
59  const InterfaceID& iid,
60  void** ppSvc) const;
61 
62  StatusCode createService(const std::string& type,
63  const std::string& name,
64  const InterfaceID& iid,
65  void** ppSvc) const;
66 
67  SmartIF<IService> service(const std::string& name, const bool quiet=false, const bool createIf=true) const;
68 
69 private:
70  std::string threadName() const;
71  std::string threadedName(const std::string& name) const;
72  bool isInThread() const;
73  ISvcLocator* serviceLocator() const { return &m_svcLoc; }
74  MsgStream& log() const { return m_msgLog; }
75  const std::string& requesterName() const { return m_requesterName; }
78  std::string m_requesterName;
79 };
80 #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 $Id: ...
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:26
ServiceLocatorHelper(ISvcLocator &svcLoc, const INamedInterface &requester)
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &loggedName, const std::string &requesterName)
MsgStream & log() const
Interface ID class.
Definition: IInterface.h:55
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &requesterName)
string type
Definition: gaudirun.py:126
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
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:108
StatusCode getService(const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const