The Gaudi Framework  v33r0 (d5ea422b)
ServiceLocatorHelper Class Reference

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

#include <GaudiKernel/ServiceLocatorHelper.h>

Collaboration diagram for ServiceLocatorHelper:

Public Member Functions

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

Private Member Functions

ISvcLocatorserviceLocator () const
 
MsgStreamlog () const
 
const std::stringrequesterName () 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 27 of file ServiceLocatorHelper.h.

Constructor & Destructor Documentation

◆ ServiceLocatorHelper() [1/4]

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

Definition at line 29 of file ServiceLocatorHelper.h.

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

◆ ServiceLocatorHelper() [2/4]

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

Definition at line 34 of file ServiceLocatorHelper.h.

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

◆ ServiceLocatorHelper() [3/4]

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

Definition at line 39 of file ServiceLocatorHelper.h.

40  : m_svcLoc( svcLoc )
42  , // use requester msg level
const std::string & requesterName() const

◆ ServiceLocatorHelper() [4/4]

ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const MsgStream log,
const std::string requesterName 
)
inline

Definition at line 45 of file ServiceLocatorHelper.h.

48  : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName ) {}
const std::string & requesterName() const
MsgStream & log() const

Member Function Documentation

◆ createService() [1/2]

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

Definition at line 31 of file ServiceLocatorHelper.cpp.

31  {
32  auto theSvc = service( name, false, true );
33  if ( !theSvc ) return StatusCode::FAILURE;
34  StatusCode sc = theSvc->queryInterface( iid, ppSvc );
35  if ( !sc.isSuccess() ) {
36  *ppSvc = nullptr;
37  log() << MSG::ERROR << "ServiceLocatorHelper::createService: wrong interface id " << iid << " for service " << name
38  << endmsg;
39  }
40  return sc;
41 }
MsgStream & log() const
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
bool isSuccess() const
Definition: StatusCode.h:361
constexpr static const auto FAILURE
Definition: StatusCode.h:97
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ createService() [2/2]

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

Definition at line 43 of file ServiceLocatorHelper.cpp.

44  {
45  return createService( type + "/" + name, iid, ppSvc );
46 }
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const

◆ getService()

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

Definition at line 51 of file ServiceLocatorHelper.h.

51  {
52  return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
53  }
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
StatusCode locateService(const std::string &name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const

◆ locateService()

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

Definition at line 17 of file ServiceLocatorHelper.cpp.

18  {
19  auto theSvc = service( name, quiet, false );
20  if ( !theSvc ) return StatusCode::FAILURE;
21  StatusCode sc = theSvc->queryInterface( iid, ppSvc );
22  if ( !sc.isSuccess() ) {
23  *ppSvc = nullptr;
24  if ( !quiet )
25  log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service "
26  << name << endmsg;
27  }
28  return sc;
29 }
MsgStream & log() const
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
bool isSuccess() const
Definition: StatusCode.h:361
constexpr static const auto FAILURE
Definition: StatusCode.h:97
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ log()

MsgStream& ServiceLocatorHelper::log ( ) const
inlineprivate

Definition at line 71 of file ServiceLocatorHelper.h.

71 { return m_msgLog; }

◆ requesterName()

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

Definition at line 72 of file ServiceLocatorHelper.h.

72 { return m_requesterName; }

◆ service() [1/2]

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

Definition at line 48 of file ServiceLocatorHelper.cpp.

49  {
50  SmartIF<IService> theSvc = serviceLocator()->service( name, createIf );
51 
52  if ( theSvc ) {
53  if ( !quiet ) {
54  if ( UNLIKELY( log().level() <= MSG::VERBOSE ) )
55  log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name << endmsg;
56  }
57  } else {
58  // if not return an error
59  if ( !quiet ) { log() << MSG::ERROR << "ServiceLocatorHelper::service: can not locate service " << name << endmsg; }
60  }
61  return theSvc;
62 }
#define UNLIKELY(x)
Definition: Kernel.h:106
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:86
MsgStream & log() const
ISvcLocator * serviceLocator() const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ service() [2/2]

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

Definition at line 65 of file ServiceLocatorHelper.h.

65  {
66  return service( name, quiet, createIf ).as<T>();
67  }
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:117
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const

◆ serviceLocator()

ISvcLocator* ServiceLocatorHelper::serviceLocator ( ) const
inlineprivate

Definition at line 70 of file ServiceLocatorHelper.h.

70 { return &m_svcLoc; }

Member Data Documentation

◆ m_msgLog

MsgStream ServiceLocatorHelper::m_msgLog
mutableprivate

Definition at line 74 of file ServiceLocatorHelper.h.

◆ m_requesterName

std::string ServiceLocatorHelper::m_requesterName
private

Definition at line 75 of file ServiceLocatorHelper.h.

◆ m_svcLoc

ISvcLocator& ServiceLocatorHelper::m_svcLoc
private

Definition at line 73 of file ServiceLocatorHelper.h.


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