All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ISvcLocator.h
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/ISvcLocator.h,v 1.15 2006/12/14 12:55:44 hmd Exp $
2 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
3 #define GAUDIKERNEL_ISVCLOCATOR_H 1
4 
5 // Include files
9 #include "GaudiKernel/SmartIF.h"
10 #include <string>
11 #include <list>
12 
13 // Forward class declaration
14 class IService;
15 
26 class GAUDI_API ISvcLocator: virtual public IInterface {
27 public:
30 
31 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
32 
37  IService*& svc, const bool createIf = true) {
38  SmartIF<IService> &s = service(typeName, createIf);
39  svc = s.get();
40  if (svc) {
41  svc->addRef(); // Needed to maintain the correct reference counting.
42  return StatusCode::SUCCESS;
43  }
44  return StatusCode::FAILURE;
45  }
46 
53  const InterfaceID& iid,
54  IInterface*& pinterface ) {
55  SmartIF<IService> svc = service(typeName, false);
56  if (svc.isValid()) {
57  // Service found. So now get the right interface
58  return svc->queryInterface(iid, (void**)&pinterface);
59  }
60  return StatusCode::FAILURE;
61  }
62 
68  //virtual StatusCode getService( const Gaudi::Utils::TypeNameString& name,
69  // IService*& svc,
70  // bool createIf ) = 0;
71 #endif
72 
74  virtual const std::list<IService*> &getServices() const = 0;
75 
77  virtual bool existsService(const std::string& name) const = 0;
78 
79 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
80  template <class T>
82  StatusCode service( const Gaudi::Utils::TypeNameString& name, T*& svc, bool createIf = true ) {
83  if( createIf ) {
84  IService* s;
85  StatusCode sc = getService( name, s, true);
86  if ( !sc.isSuccess() ) return sc; // Must check if initialization was OK!
87  }
88  return getService( name, T::interfaceID(), (IInterface*&)svc );
89  }
90 
92  template <class T>
93  StatusCode service( const std::string& type, const std::string& name,
94  T*& svc, bool createIf = true ) {
95  return service(type + "/" + name, svc, createIf);
96  }
97 #endif
98 
100  virtual SmartIF<IService> &service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true) = 0;
101 
103  template <typename T>
104  inline SmartIF<T> service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true) {
105  return SmartIF<T>(service(typeName, createIf));
106  }
107 
108 };
109 
110 
111 #endif // GAUDI_ISVCLOCATOR_H
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:62
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:104
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:93
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:164
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:82
Interface ID class.
Definition: IInterface.h:55
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
string type
Definition: gaudirun.py:126
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
General service interface definition.
Definition: IService.h:19
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Definition of the basic interface.
Definition: IInterface.h:160
#define DeclareInterfaceID(name, major, minor)
Macro to declare the interface ID when using the new mechanism of extending and implementing interfac...
Definition: IInterface.h:23
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
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
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:52
string s
Definition: gaudirun.py:210
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:22
#define GAUDI_API
Definition: Kernel.h:108