| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# ISvcLocator.h

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/ISvcLocator.h,v 1.15 2006/12/14 12:55:44 hmd Exp $
    00002 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
    00003 #define GAUDIKERNEL_ISVCLOCATOR_H 1
    00004
    00005 // Include files
    00006 #include "GaudiKernel/IInterface.h"
    00007 #include "GaudiKernel/ISvcManager.h"
    00008 #include "GaudiKernel/TypeNameString.h"
    00009 #include "GaudiKernel/SmartIF.h"
    00010 #include <string>
    00011 #include <list>
    00012
    00013 // Forward class declaration
    00014 class IService;
    00015
    00026 class GAUDI_API ISvcLocator: virtual public IInterface {
    00027 public:
    00029   DeclareInterfaceID(ISvcLocator,3,0);
    00030
    00031 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
    00032
    00036   virtual StatusCode getService( const Gaudi::Utils::TypeNameString& typeName,
    00037                                  IService*&  svc, const bool createIf = true) {
    00038     SmartIF<IService> &s = service(typeName, createIf);
    00039     svc = s.get();
    00040     if (svc) {
    00041       svc->addRef(); // Needed to maintain the correct reference counting.
    00042       return StatusCode::SUCCESS;
    00043     }
    00044     return StatusCode::FAILURE;
    00045   }
    00046
    00052   virtual StatusCode getService( const Gaudi::Utils::TypeNameString& typeName,
    00053                                  const InterfaceID& iid,
    00054                                  IInterface*& pinterface ) {
    00055     SmartIF<IService> svc = service(typeName, false);
    00056     if (svc.isValid()) {
    00057       // Service found. So now get the right interface
    00058       return svc->queryInterface(iid, (void**)&pinterface);
    00059     }
    00060     return StatusCode::FAILURE;
    00061   }
    00062
    00068   //virtual StatusCode getService( const Gaudi::Utils::TypeNameString& name,
    00069   //                               IService*& svc,
    00070   //                               bool createIf ) = 0;
    00071 #endif
    00072
    00074   virtual const std::list<IService*> &getServices() const = 0;
    00075
    00077   virtual bool existsService(const std::string& name) const = 0;
    00078
    00079 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
    00081   template <class T>
    00082   StatusCode service( const Gaudi::Utils::TypeNameString& name, T*& svc, bool createIf = true ) {
    00083     if( createIf ) {
    00084       IService* s;
    00085       StatusCode sc = getService( name, s, true);
    00086       if ( !sc.isSuccess() ) return sc;  // Must check if initialization was OK!
    00087     }
    00088     return getService( name, T::interfaceID(), (IInterface*&)svc );
    00089   }
    00090
    00092   template <class T>
    00093   StatusCode service( const std::string& type, const std::string& name,
    00094                       T*& svc, bool createIf = true ) {
    00095     return service(type + "/" + name, svc, createIf);
    00096   }
    00097 #endif
    00098
    00100   virtual SmartIF<IService> &service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true) = 0;
    00101
    00103   template <typename T>
    00104   inline SmartIF<T> service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true) {
    00105     return SmartIF<T>(service(typeName, createIf));
    00106   }
    00107
    00108 };
    00109
    00110
    00111 #endif  // GAUDI_ISVCLOCATOR_H