The Gaudi Framework  v30r3 (a5ef0a68)
ISvcLocator.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
2 #define GAUDIKERNEL_ISVCLOCATOR_H 1
3 
4 // Include files
7 #include "GaudiKernel/SmartIF.h"
9 #include <list>
10 #include <string>
11 
12 // Forward class declaration
13 class IService;
14 
25 class GAUDI_API ISvcLocator : virtual public IInterface
26 {
27 public:
30 
31 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
32 
37  const bool createIf = true )
38  {
39  SmartIF<IService>& s = service( typeName, createIf );
40  svc = s.get();
41  if ( svc ) {
42  svc->addRef(); // Needed to maintain the correct reference counting.
43  return StatusCode::SUCCESS;
44  }
45  return StatusCode::FAILURE;
46  }
47 
54  IInterface*& pinterface )
55  {
56  auto svc = service( typeName, false );
57  return svc ? svc->queryInterface( iid, (void**)&pinterface ) : StatusCode::FAILURE;
58  }
59 
65 // virtual StatusCode getService( const Gaudi::Utils::TypeNameString& name,
66 // IService*& svc,
67 // bool createIf ) = 0;
68 #endif
69 
71  virtual const std::list<IService*>& getServices() const = 0;
72 
74  virtual bool existsService( const std::string& name ) const = 0;
75 
76 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
77  template <class T>
79  StatusCode service( const Gaudi::Utils::TypeNameString& name, T*& svc, bool createIf = true )
80  {
81  if ( createIf ) {
82  IService* s;
83  StatusCode sc = getService( name, s, true );
84  if ( !sc.isSuccess() ) return sc; // Must check if initialization was OK!
85  }
86  return getService( name, T::interfaceID(), (IInterface*&)svc );
87  }
88 
90  template <class T>
91  StatusCode service( const std::string& type, const std::string& name, T*& svc, bool createIf = true )
92  {
93  return service( type + "/" + name, svc, createIf );
94  }
95 #endif
96 
98  virtual SmartIF<IService>& service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) = 0;
99 
101  template <typename T>
102  inline SmartIF<T> service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true )
103  {
104  return SmartIF<T>{service( typeName, createIf )};
105  }
106 
107  // try to access a different interface of the _current_ serviceLocator...
108  template <typename IFace>
110  {
111  return SmartIF<IFace>{this};
112  }
113 };
114 
115 #endif // GAUDI_ISVCLOCATOR_H
constexpr static const auto FAILURE
Definition: StatusCode.h:88
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
bool isSuccess() const
Definition: StatusCode.h:287
SmartIF< T > service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
Returns a smart pointer to the requested interface of a service.
Definition: ISvcLocator.h:102
StatusCode service(const std::string &type, const std::string &name, T *&svc, bool createIf=true)
Templated method to access a service by type and name.
Definition: ISvcLocator.h:91
SmartIF< IFace > as()
Definition: ISvcLocator.h:109
STL class.
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
Interface ID class.
Definition: IInterface.h:29
Helper class to parse a string of format "type/name".
General service interface definition.
Definition: IService.h:18
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
#define DeclareInterfaceID(iface, major, minor)
Macro to declare the interface ID when using the new mechanism of extending and implementing interfac...
Definition: IInterface.h:13
Definition of the basic interface.
Definition: IInterface.h:277
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:36
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
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.
Definition: ISvcLocator.h:53
string s
Definition: gaudirun.py:253
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:23
#define GAUDI_API
Definition: Kernel.h:104
IInterface *PyHelper() getService(IInterface *app, char *name)
Definition: Bootstrap.cpp:238
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:281