The Gaudi Framework  v30r3 (a5ef0a68)
ServiceLocatorHelper.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_SERVICELOCATORHELPER_H
2 #define GAUDIKERNEL_SERVICELOCATORHELPER_H
3 
4 #include <GaudiKernel/IService.h>
6 #include <GaudiKernel/SmartIF.h>
8 #include <string>
9 
10 class InterfaceID;
11 class MsgStream;
12 
18 {
19 public:
20  ServiceLocatorHelper( ISvcLocator& svcLoc, const INamedInterface& requester )
21  : m_svcLoc( svcLoc )
22  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
23  , // use requester msg level
24  m_requesterName( requester.name() )
25  {
26  }
27  ServiceLocatorHelper( ISvcLocator& svcLoc, const std::string& loggedName, const std::string& requesterName )
28  : m_svcLoc( svcLoc )
29  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), loggedName )
30  , // use requester msg level
31  m_requesterName( requesterName )
32  {
33  }
34  ServiceLocatorHelper( ISvcLocator& svcLoc, const std::string& requesterName )
35  : m_svcLoc( svcLoc )
36  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
37  , // use requester msg level
38  m_requesterName( requesterName )
39  {
40  }
41 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
43  const MsgStream& log, // use requester msg level
44  const std::string& requesterName )
45  : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName )
46  {
47  }
48 #endif
49 
50  StatusCode getService( const std::string& name, bool createIf, const InterfaceID& iid, void** ppSvc ) const
51  {
52  return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
53  }
54 
55  StatusCode locateService( const std::string& name, const InterfaceID& iid, void** ppSvc, bool quiet = false ) const;
56 
57  StatusCode createService( const std::string& name, const InterfaceID& iid, void** ppSvc ) const;
58 
59  StatusCode createService( const std::string& type, const std::string& name, const InterfaceID& iid,
60  void** ppSvc ) const;
61 
62  SmartIF<IService> service( const std::string& name, const bool quiet = false, const bool createIf = true ) const;
63 
64  template <typename T>
65  SmartIF<T> service( const std::string& name, const bool quiet = false, const bool createIf = true ) const
66  {
67  return service( name, quiet, createIf ).as<T>();
68  }
69 
70 private:
71  ISvcLocator* serviceLocator() const { return &m_svcLoc; }
72  MsgStream& log() const { return m_msgLog; }
73  const std::string& requesterName() const { return m_requesterName; }
77 };
78 #endif
ISvcLocator * serviceLocator() const
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
an helper to share the implementation of service() among the various kernel base classes ...
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ServiceLocatorHelper(ISvcLocator &svcLoc, const INamedInterface &requester)
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &loggedName, const std::string &requesterName)
STL class.
MsgStream & log() const
Interface ID class.
Definition: IInterface.h:29
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:115
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &requesterName)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:38
SmartIF< T > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
IInterface compliant class extending IInterface with the name() method.
const std::string & requesterName() const
ServiceLocatorHelper(ISvcLocator &svcLoc, const MsgStream &log, const std::string &requesterName)
#define GAUDI_API
Definition: Kernel.h:104
StatusCode getService(const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const