The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
ServiceLocatorHelper Class Reference

an helper to share the implementation of service() among the various kernel base classes More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/ServiceLocatorHelper.h>

Collaboration diagram for ServiceLocatorHelper:

Public Member Functions

 ServiceLocatorHelper (ISvcLocator &svcLoc, const INamedInterface &requester)
 
 ServiceLocatorHelper (ISvcLocator &svcLoc, std::string loggedName, std::string requesterName)
 
 ServiceLocatorHelper (ISvcLocator &svcLoc, std::string requesterName)
 
StatusCode getService (std::string_view name, bool createIf, const InterfaceID &iid, void **ppSvc) const
 
StatusCode locateService (std::string_view name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
 
StatusCode createService (std::string_view name, const InterfaceID &iid, void **ppSvc) const
 
StatusCode createService (std::string_view type, std::string_view name, const InterfaceID &iid, void **ppSvc) const
 
SmartIF< IServiceservice (std::string_view name, const bool quiet=false, const bool createIf=true) const
 
template<typename T>
SmartIF< T > service (std::string_view name, const bool quiet=false, const bool createIf=true) const
 

Private Member Functions

ISvcLocatorserviceLocator () const
 
MsgStreamlog () const
 
const std::string & requesterName () const
 

Private Attributes

ISvcLocatorm_svcLoc
 
MsgStream m_msgLog
 
std::string m_requesterName
 

Detailed Description

an helper to share the implementation of service() among the various kernel base classes

Definition at line 26 of file ServiceLocatorHelper.h.

Constructor & Destructor Documentation

◆ ServiceLocatorHelper() [1/3]

ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator & svcLoc,
const INamedInterface & requester )
inline

Definition at line 28 of file ServiceLocatorHelper.h.

29 : m_svcLoc( svcLoc )
30 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
31 , // use requester msg level
32 m_requesterName( requester.name() ) {}
virtual const std::string & name() const =0
Retrieve the name of the instance.

◆ ServiceLocatorHelper() [2/3]

ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator & svcLoc,
std::string loggedName,
std::string requesterName )
inline

Definition at line 33 of file ServiceLocatorHelper.h.

34 : m_svcLoc( svcLoc )
35 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), std::move( loggedName ) )
36 , // use requester msg level
37 m_requesterName( std::move( requesterName ) ) {}
const std::string & requesterName() const

◆ ServiceLocatorHelper() [3/3]

ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator & svcLoc,
std::string requesterName )
inline

Definition at line 38 of file ServiceLocatorHelper.h.

39 : m_svcLoc( svcLoc )
40 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
41 , // use requester msg level
42 m_requesterName( std::move( requesterName ) ) {}

Member Function Documentation

◆ createService() [1/2]

StatusCode ServiceLocatorHelper::createService ( std::string_view name,
const InterfaceID & iid,
void ** ppSvc ) const

Definition at line 33 of file ServiceLocatorHelper.cpp.

33 {
34 auto theSvc = service( name, false, true );
35 if ( !theSvc ) return StatusCode::FAILURE;
36 StatusCode sc = theSvc->queryInterface( iid, ppSvc );
37 if ( !sc.isSuccess() ) {
38 *ppSvc = nullptr;
39 log() << MSG::ERROR << "ServiceLocatorHelper::createService: wrong interface id " << iid << " for service " << name
40 << endmsg;
41 }
42 return sc;
43}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & log() const
SmartIF< IService > service(std::string_view name, const bool quiet=false, const bool createIf=true) const
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto FAILURE
Definition StatusCode.h:100
@ ERROR
Definition IMessageSvc.h:22

◆ createService() [2/2]

StatusCode ServiceLocatorHelper::createService ( std::string_view type,
std::string_view name,
const InterfaceID & iid,
void ** ppSvc ) const

Definition at line 45 of file ServiceLocatorHelper.cpp.

46 {
47 return createService( fmt::format( "{}/{}", type, name ), iid, ppSvc );
48}
StatusCode createService(std::string_view name, const InterfaceID &iid, void **ppSvc) const

◆ getService()

StatusCode ServiceLocatorHelper::getService ( std::string_view name,
bool createIf,
const InterfaceID & iid,
void ** ppSvc ) const
inline

Definition at line 44 of file ServiceLocatorHelper.h.

44 {
45 return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
46 }
StatusCode locateService(std::string_view name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const

◆ locateService()

StatusCode ServiceLocatorHelper::locateService ( std::string_view name,
const InterfaceID & iid,
void ** ppSvc,
bool quiet = false ) const

Definition at line 19 of file ServiceLocatorHelper.cpp.

20 {
21 auto theSvc = service( name, quiet, false );
22 if ( !theSvc ) return StatusCode::FAILURE;
23 StatusCode sc = theSvc->queryInterface( iid, ppSvc );
24 if ( !sc.isSuccess() ) {
25 *ppSvc = nullptr;
26 if ( !quiet )
27 log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service "
28 << name << endmsg;
29 }
30 return sc;
31}

◆ log()

MsgStream & ServiceLocatorHelper::log ( ) const
inlineprivate

Definition at line 63 of file ServiceLocatorHelper.h.

63{ return m_msgLog; }

◆ requesterName()

const std::string & ServiceLocatorHelper::requesterName ( ) const
inlineprivate

Definition at line 64 of file ServiceLocatorHelper.h.

64{ return m_requesterName; }

◆ service() [1/2]

SmartIF< IService > ServiceLocatorHelper::service ( std::string_view name,
const bool quiet = false,
const bool createIf = true ) const

Definition at line 50 of file ServiceLocatorHelper.cpp.

50 {
51 SmartIF<IService> theSvc = serviceLocator()->service( name, createIf );
52
53 if ( theSvc ) {
54 if ( !quiet ) {
55 if ( log().level() <= MSG::VERBOSE )
56 log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name << endmsg;
57 }
58 } else {
59 // if not return an error
60 if ( !quiet ) { log() << MSG::ERROR << "ServiceLocatorHelper::service: can not locate service " << name << endmsg; }
61 }
62 return theSvc;
63}
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
ISvcLocator * serviceLocator() const
@ VERBOSE
Definition IMessageSvc.h:22

◆ service() [2/2]

template<typename T>
SmartIF< T > ServiceLocatorHelper::service ( std::string_view name,
const bool quiet = false,
const bool createIf = true ) const
inline

Definition at line 57 of file ServiceLocatorHelper.h.

57 {
58 return service( name, quiet, createIf ).as<T>();
59 }
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition SmartIF.h:110

◆ serviceLocator()

ISvcLocator * ServiceLocatorHelper::serviceLocator ( ) const
inlineprivate

Definition at line 62 of file ServiceLocatorHelper.h.

62{ return &m_svcLoc; }

Member Data Documentation

◆ m_msgLog

MsgStream ServiceLocatorHelper::m_msgLog
mutableprivate

Definition at line 66 of file ServiceLocatorHelper.h.

◆ m_requesterName

std::string ServiceLocatorHelper::m_requesterName
private

Definition at line 67 of file ServiceLocatorHelper.h.

◆ m_svcLoc

ISvcLocator& ServiceLocatorHelper::m_svcLoc
private

Definition at line 65 of file ServiceLocatorHelper.h.


The documentation for this class was generated from the following files: