File indexing completed on 2025-01-18 09:57:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIKERNEL_SERVICELOCATORHELPER_H
0012 #define GAUDIKERNEL_SERVICELOCATORHELPER_H
0013
0014 #include <GaudiKernel/IService.h>
0015 #include <GaudiKernel/ISvcLocator.h>
0016 #include <GaudiKernel/SmartIF.h>
0017 #include <GaudiKernel/StatusCode.h>
0018 #include <string>
0019
0020 class InterfaceID;
0021 class MsgStream;
0022
0023
0024
0025
0026
0027 class GAUDI_API ServiceLocatorHelper {
0028 public:
0029 ServiceLocatorHelper( ISvcLocator& svcLoc, const INamedInterface& requester )
0030 : m_svcLoc( svcLoc )
0031 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
0032 ,
0033 m_requesterName( requester.name() ) {}
0034 ServiceLocatorHelper( ISvcLocator& svcLoc, std::string loggedName, std::string requesterName )
0035 : m_svcLoc( svcLoc )
0036 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), std::move( loggedName ) )
0037 ,
0038 m_requesterName( std::move( requesterName ) ) {}
0039 ServiceLocatorHelper( ISvcLocator& svcLoc, std::string requesterName )
0040 : m_svcLoc( svcLoc )
0041 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
0042 ,
0043 m_requesterName( std::move( requesterName ) ) {}
0044 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
0045 ServiceLocatorHelper( ISvcLocator& svcLoc,
0046 const MsgStream& log,
0047 std::string requesterName )
0048 : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( std::move( requesterName ) ) {}
0049 #endif
0050
0051 StatusCode getService( std::string_view name, bool createIf, const InterfaceID& iid, void** ppSvc ) const {
0052 return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
0053 }
0054
0055 StatusCode locateService( std::string_view name, const InterfaceID& iid, void** ppSvc, bool quiet = false ) const;
0056
0057 StatusCode createService( std::string_view name, const InterfaceID& iid, void** ppSvc ) const;
0058
0059 StatusCode createService( std::string_view type, std::string_view name, const InterfaceID& iid, void** ppSvc ) const;
0060
0061 SmartIF<IService> service( std::string_view name, const bool quiet = false, const bool createIf = true ) const;
0062
0063 template <typename T>
0064 SmartIF<T> service( std::string_view name, const bool quiet = false, const bool createIf = true ) const {
0065 return service( name, quiet, createIf ).as<T>();
0066 }
0067
0068 private:
0069 ISvcLocator* serviceLocator() const { return &m_svcLoc; }
0070 MsgStream& log() const { return m_msgLog; }
0071 const std::string& requesterName() const { return m_requesterName; }
0072 ISvcLocator& m_svcLoc;
0073 mutable MsgStream m_msgLog;
0074 std::string m_requesterName;
0075 };
0076 #endif