| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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