| The Gaudi Framework v29r1 (5cd95fa2)

- 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 <GaudiKernel/IService.h>
5 #include <GaudiKernel/SmartIF.h>
6 #include <GaudiKernel/StatusCode.h>
7 #include <string>
8
9 class ISvcLocator;
10 class InterfaceID;
11 class MsgStream;
12
17 class GAUDI_API ServiceLocatorHelper
18 {
19 public:
20 ServiceLocatorHelper( ISvcLocator& svcLoc, const INamedInterface& requester )
21 : m_svcLoc( svcLoc )
22 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
23 , // use requester msg level
24 m_requesterName( requester.name() )
25 {
26 }
27 ServiceLocatorHelper( ISvcLocator& svcLoc, const std::string& loggedName, const std::string& requesterName )
28 : m_svcLoc( svcLoc )
29 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), loggedName )
30 , // use requester msg level
31 m_requesterName( requesterName )
32 {
33 }
34 ServiceLocatorHelper( ISvcLocator& svcLoc, const std::string& requesterName )
35 : m_svcLoc( svcLoc )
36 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
37 , // use requester msg level
38 m_requesterName( requesterName )
39 {
40 }
41 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
42 ServiceLocatorHelper( ISvcLocator& svcLoc,
43 const MsgStream& log, // use requester msg level
44 const std::string& requesterName )
45 : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName )
46 {
47 }
48 #endif
49
50 StatusCode getService( const std::string& name, bool createIf, const InterfaceID& iid, void** ppSvc ) const
51 {
52 return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
53 }
54
55 StatusCode locateService( const std::string& name, const InterfaceID& iid, void** ppSvc, bool quiet = false ) const;
56
57 StatusCode createService( const std::string& name, const InterfaceID& iid, void** ppSvc ) const;
58
59 StatusCode createService( const std::string& type, const std::string& name, const InterfaceID& iid,
60 void** ppSvc ) const;
61
62 SmartIF<IService> service( const std::string& name, const bool quiet = false, const bool createIf = true ) const;
63
64 template <typename T>
65 SmartIF<T> service( const std::string& name, const bool quiet = false, const bool createIf = true ) const
66 {
67 return service( name, quiet, createIf ).as<T>();
68 }
69
70 private:
71 std::string threadName() const;
72 std::string threadedName( const std::string& name ) const;
73 bool isInThread() const;
74 ISvcLocator* serviceLocator() const { return &m_svcLoc; }
75 MsgStream& log() const { return m_msgLog; }
76 const std::string& requesterName() const { return m_requesterName; }
77 ISvcLocator& m_svcLoc;
78 mutable MsgStream m_msgLog;
79 std::string m_requesterName;
80 };
81 #endif
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:74
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:15
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:32
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const INamedInterface &requester)
Definition: ServiceLocatorHelper.h:20
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &loggedName, const std::string &requesterName)
Definition: ServiceLocatorHelper.h:27
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:78
std::string
STL class.
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:79
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:75
InterfaceID
Interface ID class.
Definition: IInterface.h:29
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:115
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &requesterName)
Definition: ServiceLocatorHelper.h:34
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
gaudirun.type
type
Definition: gaudirun.py:133
SmartIF.h
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:38
ServiceLocatorHelper::service
SmartIF< T > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.h:65
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:76
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const MsgStream &log, const std::string &requesterName)
Definition: ServiceLocatorHelper.h:42
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:77
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
ServiceLocatorHelper::getService
StatusCode getService(const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.h:50
Gaudi.Configuration.log
log
Definition: Configuration.py:13