| The Gaudi Framework v32r1 (f65d50dc)

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/ISvcLocator.h>
6 #include <GaudiKernel/SmartIF.h>
7 #include <GaudiKernel/StatusCode.h>
8 #include <string>
9
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() )
22 , // use requester msg level
23 m_requesterName( requester.name() ) {}
24 ServiceLocatorHelper( ISvcLocator& svcLoc, const std::string& loggedName, const std::string& requesterName )
25 : m_svcLoc( svcLoc )
26 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), loggedName )
27 , // use requester msg level
28 m_requesterName( requesterName ) {}
29 ServiceLocatorHelper( ISvcLocator& svcLoc, const std::string& requesterName )
30 : m_svcLoc( svcLoc )
31 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
32 , // use requester msg level
33 m_requesterName( requesterName ) {}
34 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
35 ServiceLocatorHelper( ISvcLocator& svcLoc,
36 const MsgStream& log, // use requester msg level
37 const std::string& requesterName )
38 : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName ) {}
39 #endif
40
41 StatusCode getService( const std::string& name, bool createIf, const InterfaceID& iid, void** ppSvc ) const {
42 return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
43 }
44
45 StatusCode locateService( const std::string& name, const InterfaceID& iid, void** ppSvc, bool quiet = false ) const;
46
47 StatusCode createService( const std::string& name, const InterfaceID& iid, void** ppSvc ) const;
48
49 StatusCode createService( const std::string& type, const std::string& name, const InterfaceID& iid,
50 void** ppSvc ) const;
51
52 SmartIF<IService> service( const std::string& name, const bool quiet = false, const bool createIf = true ) const;
53
54 template <typename T>
55 SmartIF<T> service( const std::string& name, const bool quiet = false, const bool createIf = true ) const {
56 return service( name, quiet, createIf ).as<T>();
57 }
58
59 private:
60 ISvcLocator* serviceLocator() const { return &m_svcLoc; }
61 MsgStream& log() const { return m_msgLog; }
62 const std::string& requesterName() const { return m_requesterName; }
63 ISvcLocator& m_svcLoc;
64 mutable MsgStream m_msgLog;
65 std::string m_requesterName;
66 };
67 #endif
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:41
ServiceLocatorHelper::getService
StatusCode getService(const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.h:41
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:62
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:64
std::string
STL class.
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:65
InterfaceID
Interface ID class.
Definition: IInterface.h:29
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &requesterName)
Definition: ServiceLocatorHelper.h:29
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:61
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
gaudirun.type
type
Definition: gaudirun.py:142
SmartIF.h
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:37
IService.h
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:60
ServiceLocatorHelper::service
SmartIF< T > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.h:55
StatusCode.h
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const MsgStream &log, const std::string &requesterName)
Definition: ServiceLocatorHelper.h:35
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:63
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
ISvcLocator.h
Gaudi.Configuration.log
log
Definition: Configuration.py:13