| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ServiceLocatorHelper.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_SERVICELOCATORHELPER_H
2 #define GAUDIKERNEL_SERVICELOCATORHELPER_H
3
4 #include <string>
5 #include <GaudiKernel/StatusCode.h>
6 #include <GaudiKernel/SmartIF.h>
7 #include <GaudiKernel/IService.h>
8
9 class ISvcLocator;
10 class InterfaceID;
11 class MsgStream;
12
17 class GAUDI_API ServiceLocatorHelper {
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 }
24 ServiceLocatorHelper(ISvcLocator& svcLoc,
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)
37 ServiceLocatorHelper(ISvcLocator& svcLoc,
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
43 StatusCode getService(const std::string& name,
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; }
79 ISvcLocator& m_svcLoc;
80 mutable MsgStream m_msgLog;
81 std::string m_requesterName;
82 };
83 #endif
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:76
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
ServiceLocatorHelper
an helper to share the implementation of service() among the various kernel base classes ...
Definition: ServiceLocatorHelper.h:17
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:14
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const INamedInterface &requester)
Definition: ServiceLocatorHelper.h:19
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &loggedName, const std::string &requesterName)
Definition: ServiceLocatorHelper.h:24
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:80
std::string
STL class.
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:81
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:77
InterfaceID
Interface ID class.
Definition: IInterface.h:30
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &requesterName)
Definition: ServiceLocatorHelper.h:31
gaudirun.type
string type
Definition: gaudirun.py:151
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
SmartIF.h
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
ServiceLocatorHelper::service
SmartIF< T > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.h:68
IService.h
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
StatusCode.h
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:78
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const MsgStream &log, const std::string &requesterName)
Definition: ServiceLocatorHelper.h:37
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:79
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
ServiceLocatorHelper::getService
StatusCode getService(const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.h:43