Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v30r3 (a5ef0a68)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 20 of file ServiceLocatorHelper.h.

21  : m_svcLoc( svcLoc )
22  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
23  , // use requester msg level
24  m_requesterName( requester.name() )
25  {
26  }
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 27 of file ServiceLocatorHelper.h.

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

Definition at line 34 of file ServiceLocatorHelper.h.

35  : m_svcLoc( svcLoc )
36  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
37  , // use requester msg level
38  m_requesterName( requesterName )
39  {
40  }
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const MsgStream log,
const std::string requesterName 
)
inline

Definition at line 42 of file ServiceLocatorHelper.h.

45  : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName )
46  {
47  }

Member Function Documentation

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

Definition at line 22 of file ServiceLocatorHelper.cpp.

23 {
24  auto theSvc = service( name, false, true );
25  if ( !theSvc ) return StatusCode::FAILURE;
26  StatusCode sc = theSvc->queryInterface( iid, ppSvc );
27  if ( !sc.isSuccess() ) {
28  *ppSvc = nullptr;
29  log() << MSG::ERROR << "ServiceLocatorHelper::createService: wrong interface id " << iid << " for service " << name
30  << endmsg;
31  }
32  return sc;
33 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
bool isSuccess() const
Definition: StatusCode.h:287
MsgStream & log() const
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
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:209
StatusCode ServiceLocatorHelper::createService ( const std::string type,
const std::string name,
const InterfaceID iid,
void **  ppSvc 
) const

Definition at line 35 of file ServiceLocatorHelper.cpp.

37 {
38  return createService( type + "/" + name, iid, ppSvc );
39 }
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 50 of file ServiceLocatorHelper.h.

51  {
52  return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
53  }
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.

9 {
10  auto theSvc = service( name, quiet, false );
11  if ( !theSvc ) return StatusCode::FAILURE;
12  StatusCode sc = theSvc->queryInterface( iid, ppSvc );
13  if ( !sc.isSuccess() ) {
14  *ppSvc = nullptr;
15  if ( !quiet )
16  log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service "
17  << name << endmsg;
18  }
19  return sc;
20 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
bool isSuccess() const
Definition: StatusCode.h:287
MsgStream & log() const
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
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:209
MsgStream& ServiceLocatorHelper::log ( ) const
inlineprivate

Definition at line 72 of file ServiceLocatorHelper.h.

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

Definition at line 73 of file ServiceLocatorHelper.h.

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

Definition at line 41 of file ServiceLocatorHelper.cpp.

42 {
43  SmartIF<IService> theSvc = serviceLocator()->service( name, createIf );
44 
45  if ( theSvc ) {
46  if ( !quiet ) {
47  if ( UNLIKELY( log().level() <= MSG::VERBOSE ) )
48  log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name << endmsg;
49  }
50  } else {
51  // if not return an error
52  if ( !quiet ) {
53  log() << MSG::ERROR << "ServiceLocatorHelper::service: can not locate service " << name << endmsg;
54  }
55  }
56  return theSvc;
57 }
ISvcLocator * serviceLocator() const
#define UNLIKELY(x)
Definition: Kernel.h:122
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:79
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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.

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

Definition at line 71 of file ServiceLocatorHelper.h.

71 { return &m_svcLoc; }

Member Data Documentation

MsgStream ServiceLocatorHelper::m_msgLog
mutableprivate

Definition at line 75 of file ServiceLocatorHelper.h.

std::string ServiceLocatorHelper::m_requesterName
private

Definition at line 76 of file ServiceLocatorHelper.h.

ISvcLocator& ServiceLocatorHelper::m_svcLoc
private

Definition at line 74 of file ServiceLocatorHelper.h.


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