The Gaudi Framework  v31r0 (aeb156f0)
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 17 of file ServiceLocatorHelper.h.

Constructor & Destructor Documentation

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

Definition at line 19 of file ServiceLocatorHelper.h.

20  : m_svcLoc( svcLoc )
21  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
22  , // use requester msg level
23  m_requesterName( requester.name() ) {}
virtual const std::string & name() const =0
Retrieve the name of the instance.
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const std::string loggedName,
const std::string requesterName 
)
inline

Definition at line 24 of file ServiceLocatorHelper.h.

25  : m_svcLoc( svcLoc )
26  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), loggedName )
27  , // use requester msg level
28  m_requesterName( requesterName ) {}
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const std::string requesterName 
)
inline

Definition at line 29 of file ServiceLocatorHelper.h.

30  : m_svcLoc( svcLoc )
31  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
32  , // use requester msg level
33  m_requesterName( requesterName ) {}
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const MsgStream log,
const std::string requesterName 
)
inline

Definition at line 35 of file ServiceLocatorHelper.h.

38  : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName ) {}

Member Function Documentation

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

Definition at line 21 of file ServiceLocatorHelper.cpp.

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

Definition at line 33 of file ServiceLocatorHelper.cpp.

34  {
35  return createService( type + "/" + name, iid, ppSvc );
36 }
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
StatusCode ServiceLocatorHelper::getService ( const std::string name,
bool  createIf,
const InterfaceID iid,
void **  ppSvc 
) const
inline

Definition at line 41 of file ServiceLocatorHelper.h.

41  {
42  return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
43  }
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 ServiceLocatorHelper::locateService ( const std::string name,
const InterfaceID iid,
void **  ppSvc,
bool  quiet = false 
) const

Definition at line 7 of file ServiceLocatorHelper.cpp.

8  {
9  auto theSvc = service( name, quiet, false );
10  if ( !theSvc ) return StatusCode::FAILURE;
11  StatusCode sc = theSvc->queryInterface( iid, ppSvc );
12  if ( !sc.isSuccess() ) {
13  *ppSvc = nullptr;
14  if ( !quiet )
15  log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service "
16  << name << endmsg;
17  }
18  return sc;
19 }
bool isSuccess() const
Definition: StatusCode.h:267
MsgStream & log() const
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
constexpr static const auto FAILURE
Definition: StatusCode.h:86
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
MsgStream& ServiceLocatorHelper::log ( ) const
inlineprivate

Definition at line 61 of file ServiceLocatorHelper.h.

61 { return m_msgLog; }
const std::string& ServiceLocatorHelper::requesterName ( ) const
inlineprivate

Definition at line 62 of file ServiceLocatorHelper.h.

62 { return m_requesterName; }
SmartIF< IService > ServiceLocatorHelper::service ( const std::string name,
const bool  quiet = false,
const bool  createIf = true 
) const

Definition at line 38 of file ServiceLocatorHelper.cpp.

39  {
40  SmartIF<IService> theSvc = serviceLocator()->service( name, createIf );
41 
42  if ( theSvc ) {
43  if ( !quiet ) {
44  if ( UNLIKELY( log().level() <= MSG::VERBOSE ) )
45  log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name << endmsg;
46  }
47  } else {
48  // if not return an error
49  if ( !quiet ) { log() << MSG::ERROR << "ServiceLocatorHelper::service: can not locate service " << name << endmsg; }
50  }
51  return theSvc;
52 }
ISvcLocator * serviceLocator() const
#define UNLIKELY(x)
Definition: Kernel.h:89
MsgStream & log() const
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
template<typename T >
SmartIF<T> ServiceLocatorHelper::service ( const std::string name,
const bool  quiet = false,
const bool  createIf = true 
) const
inline

Definition at line 55 of file ServiceLocatorHelper.h.

55  {
56  return service( name, quiet, createIf ).as<T>();
57  }
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:107
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
ISvcLocator* ServiceLocatorHelper::serviceLocator ( ) const
inlineprivate

Definition at line 60 of file ServiceLocatorHelper.h.

60 { return &m_svcLoc; }

Member Data Documentation

MsgStream ServiceLocatorHelper::m_msgLog
mutableprivate

Definition at line 64 of file ServiceLocatorHelper.h.

std::string ServiceLocatorHelper::m_requesterName
private

Definition at line 65 of file ServiceLocatorHelper.h.

ISvcLocator& ServiceLocatorHelper::m_svcLoc
private

Definition at line 63 of file ServiceLocatorHelper.h.


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