The Gaudi Framework  v33r1 (b1225454)
ISvcLocator Class Referenceabstract

The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to locate services in the framework. More...

#include <GaudiKernel/ISvcLocator.h>

Inheritance diagram for ISvcLocator:
Collaboration diagram for ISvcLocator:

Public Member Functions

 DeclareInterfaceID (ISvcLocator, 3, 0)
 InterfaceID. More...
 
virtual StatusCode getService (const Gaudi::Utils::TypeNameString &typeName, IService *&svc, const bool createIf=true)
 Get a reference to the service given a service name. More...
 
virtual StatusCode getService (const Gaudi::Utils::TypeNameString &typeName, const InterfaceID &iid, IInterface *&pinterface)
 Get a specific interface pointer given a service name and interface id. More...
 
virtual const std::list< IService * > & getServices () const =0
 Get a reference to a service and create it if it does not exists. More...
 
virtual bool existsService (std::string_view name) const =0
 Check the existence of a service given a service name. More...
 
template<class T >
StatusCode service (const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
 Templated method to access a service by name. More...
 
template<class T >
StatusCode service (std::string_view type, std::string_view name, T *&svc, bool createIf=true)
 Templated method to access a service by type and name. More...
 
virtual SmartIF< IService > & service (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
 Returns a smart pointer to a service. More...
 
template<typename T >
SmartIF< T > service (const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
 Returns a smart pointer to the requested interface of a service. More...
 
template<typename IFace >
SmartIF< IFace > as ()
 
- Public Member Functions inherited from IInterface
virtual void * i_cast (const InterfaceID &) const =0
 main cast function More...
 
virtual std::vector< std::stringgetInterfaceNames () const =0
 Returns a vector of strings containing the names of all the implemented interfaces. More...
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long release ()=0
 Release Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance. More...
 
virtual ~IInterface ()=default
 Virtual destructor. More...
 

Additional Inherited Members

- Public Types inherited from IInterface
enum  Status : StatusCode::code_t {
  Status::FAILURE = 0, Status::SUCCESS = 1, Status::NO_INTERFACE, Status::VERSMISMATCH,
  Status::LAST_ERROR
}
 Return status. More...
 
using iid = Gaudi::InterfaceId< IInterface, 0, 0 >
 Interface ID. More...
 
using ext_iids = Gaudi::interface_list< iid >
 Extra interfaces. More...
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 

Detailed Description

The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to locate services in the framework.

Clients use this interface to locate references to interfaces of services existing in the application. This operation needs to be done before the service can be used by the client. Typically "locating the services" is done at the initialization phase of the clients.

Author
Pere Mato

Definition at line 35 of file ISvcLocator.h.

Member Function Documentation

◆ as()

template<typename IFace >
SmartIF<IFace> ISvcLocator::as ( )
inline

Definition at line 113 of file ISvcLocator.h.

113  {
114  return SmartIF<IFace>{this};
115  }
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:25

◆ DeclareInterfaceID()

ISvcLocator::DeclareInterfaceID ( ISvcLocator  ,
,
 
)

◆ existsService()

virtual bool ISvcLocator::existsService ( std::string_view  name) const
pure virtual

Check the existence of a service given a service name.

◆ getService() [1/2]

virtual StatusCode ISvcLocator::getService ( const Gaudi::Utils::TypeNameString typeName,
IService *&  svc,
const bool  createIf = true 
)
inlinevirtual

Get a reference to the service given a service name.

Parameters
nameService name
svcReturned service pointer

Definition at line 45 of file ISvcLocator.h.

46  {
47  SmartIF<IService>& s = service( typeName, createIf );
48  svc = s.get();
49  if ( svc ) {
50  svc->addRef(); // Needed to maintain the correct reference counting.
51  return StatusCode::SUCCESS;
52  }
53  return StatusCode::FAILURE;
54  }
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:86
string s
Definition: gaudirun.py:328
constexpr static const auto FAILURE
Definition: StatusCode.h:101
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:31

◆ getService() [2/2]

virtual StatusCode ISvcLocator::getService ( const Gaudi::Utils::TypeNameString typeName,
const InterfaceID iid,
IInterface *&  pinterface 
)
inlinevirtual

Get a specific interface pointer given a service name and interface id.

Parameters
nameService name
iidInterface ID
pinterfaceReturned pointer to the requested interface

Definition at line 61 of file ISvcLocator.h.

62  {
63  auto svc = service( typeName, false );
64  return svc ? svc->queryInterface( iid, (void**)&pinterface ) : StatusCode::FAILURE;
65  }
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:86
constexpr static const auto FAILURE
Definition: StatusCode.h:101
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:31
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:257

◆ getServices()

virtual const std::list<IService*>& ISvcLocator::getServices ( ) const
pure virtual

Get a reference to a service and create it if it does not exists.

Parameters
nameService name
svcReturned service pointer
createIfflag to control the creationReturn the list of Services

◆ service() [1/4]

template<class T >
StatusCode ISvcLocator::service ( const Gaudi::Utils::TypeNameString name,
T *&  svc,
bool  createIf = true 
)
inline

Templated method to access a service by name.

Definition at line 86 of file ISvcLocator.h.

86  {
87  if ( createIf ) {
88  IService* s;
89  StatusCode sc = getService( name, s, true );
90  if ( !sc.isSuccess() ) return sc; // Must check if initialization was OK!
91  }
92  return getService( name, T::interfaceID(), (IInterface*&)svc );
93  }
General service interface definition.
Definition: IService.h:28
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
virtual StatusCode getService(const Gaudi::Utils::TypeNameString &typeName, IService *&svc, const bool createIf=true)
Get a reference to the service given a service name.
Definition: ISvcLocator.h:45
bool isSuccess() const
Definition: StatusCode.h:365
string s
Definition: gaudirun.py:328

◆ service() [2/4]

template<class T >
StatusCode ISvcLocator::service ( std::string_view  type,
std::string_view  name,
T *&  svc,
bool  createIf = true 
)
inline

Templated method to access a service by type and name.

Definition at line 97 of file ISvcLocator.h.

97  {
98  return service( std::string{type}.append( "/" ).append( name ), svc, createIf );
99  }
STL class.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:86

◆ service() [3/4]

virtual SmartIF<IService>& ISvcLocator::service ( const Gaudi::Utils::TypeNameString typeName,
const bool  createIf = true 
)
pure virtual

Returns a smart pointer to a service.

◆ service() [4/4]

template<typename T >
SmartIF<T> ISvcLocator::service ( const Gaudi::Utils::TypeNameString typeName,
const bool  createIf = true 
)
inline

Returns a smart pointer to the requested interface of a service.

Definition at line 107 of file ISvcLocator.h.

107  {
108  return SmartIF<T>{service( typeName, createIf )};
109  }
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:25
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:86
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:31

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