| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

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>
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
18 class GAUDI_API ServiceLocatorHelper {
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 }
25 ServiceLocatorHelper(ISvcLocator& svcLoc,
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)
38 ServiceLocatorHelper(ISvcLocator& svcLoc,
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; }
76 ISvcLocator& m_svcLoc;
77 mutable MsgStream m_msgLog;
78 std::string m_requesterName;
79 };
80 #endif