Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:57:44

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
0012 #define GAUDIKERNEL_ISVCLOCATOR_H 1
0013 
0014 // Include files
0015 #include <GaudiKernel/IInterface.h>
0016 #include <GaudiKernel/ISvcManager.h>
0017 #include <GaudiKernel/SmartIF.h>
0018 #include <GaudiKernel/TypeNameString.h>
0019 
0020 #include <list>
0021 #include <string>
0022 
0023 // Forward class declaration
0024 class IService;
0025 namespace Gaudi::Monitoring {
0026   struct Hub;
0027 }
0028 
0029 namespace Gaudi {
0030   namespace Interfaces {
0031     struct IOptionsSvc;
0032   }
0033 } // namespace Gaudi
0034 #define GAUDI_HAS_IOPTIONS_SVC
0035 
0036 /** @class ISvcLocator ISvcLocator.h GaudiKernel/ISvcLocator.h
0037     The ISvcLocator is the interface implemented by the Service Factory in the
0038     Application Manager to locate services in the framework. Clients use this
0039     interface to locate references to interfaces of services existing in the
0040     application. This operation needs to be done before the service can be used
0041     by the client. Typically "locating the services" is done at the initialization
0042     phase of the clients.
0043 
0044     @author Pere Mato
0045 */
0046 class GAUDI_API ISvcLocator : virtual public IInterface {
0047 public:
0048   /// InterfaceID
0049   DeclareInterfaceID( ISvcLocator, 3, 0 );
0050 
0051 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
0052   /** Get a reference to the service given a service name
0053       @param name Service name
0054       @param svc Returned service pointer
0055   */
0056   [[deprecated( "use ISvcLocator::service<T>(type_name, createIf) -> SmartIF<T>" )]] virtual StatusCode
0057   getService( const Gaudi::Utils::TypeNameString& typeName, IService*& svc, const bool createIf = true ) {
0058     SmartIF<IService>& s = service( typeName, createIf );
0059     svc                  = s.get();
0060     if ( svc ) {
0061       svc->addRef(); // Needed to maintain the correct reference counting.
0062       return StatusCode::SUCCESS;
0063     }
0064     return StatusCode::FAILURE;
0065   }
0066 
0067   /** Get a specific interface pointer given a service name and interface id
0068       @param name Service name
0069       @param iid Interface ID
0070       @param pinterface Returned pointer to the requested interface
0071   */
0072   [[deprecated( "use ISvcLocator::service<T>(type_name, createIf) -> SmartIF<T>" )]] virtual StatusCode
0073   getService( const Gaudi::Utils::TypeNameString& typeName, const InterfaceID& iid, IInterface*& pinterface ) {
0074     auto svc = service( typeName, false );
0075     return svc ? svc->queryInterface( iid, (void**)&pinterface ) : StatusCode::FAILURE;
0076   }
0077 
0078 /** Get a reference to a service and create it if it does not exists
0079     @param name Service name
0080     @param svc Returned service pointer
0081     @param createIf flag to control the creation
0082 */
0083 // virtual StatusCode getService( const Gaudi::Utils::TypeNameString& name,
0084 //                               IService*& svc,
0085 //                               bool createIf ) = 0;
0086 #endif
0087 
0088   /// Return the list of Services
0089   virtual const std::list<IService*>& getServices() const = 0;
0090 
0091   /// Check the existence of a service given a service name
0092   virtual bool existsService( std::string_view name ) const = 0;
0093 
0094 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
0095   /// Templated method to access a service by name.
0096   template <class T>
0097   [[deprecated( "use ISvcLocator::service<T>(type_name, createIf) -> SmartIF<T>" )]] StatusCode
0098   service( const Gaudi::Utils::TypeNameString& name, T*& svc, bool createIf = true ) {
0099     if ( createIf ) {
0100       IService*  s;
0101       StatusCode sc = getService( name, s, true );
0102       if ( !sc.isSuccess() ) return sc; // Must check if initialization was OK!
0103     }
0104     return getService( name, T::interfaceID(), (IInterface*&)svc );
0105   }
0106 
0107   /// Templated method to access a service by type and name.
0108   template <class T>
0109   [[deprecated( "use ISvcLocator::service<T>(type_name, createIf) -> SmartIF<T>" )]] StatusCode
0110   service( std::string_view type, std::string_view name, T*& svc, bool createIf = true ) {
0111     return service( std::string{ type }.append( "/" ).append( name ), svc, createIf );
0112   }
0113 #endif
0114 
0115   /// Returns a smart pointer to a service.
0116   virtual SmartIF<IService>& service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) = 0;
0117 
0118   /// Returns a smart pointer to the requested interface of a service.
0119   template <typename T>
0120   inline SmartIF<T> service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) {
0121     return SmartIF<T>{ service( typeName, createIf ) };
0122   }
0123 
0124   // try to access a different interface of  the _current_ serviceLocator...
0125   template <typename IFace>
0126   SmartIF<IFace> as() {
0127     return SmartIF<IFace>{ this };
0128   }
0129 
0130   /// Direct access to Gaudi::Interfaces::IOptionsSvc implementation.
0131   Gaudi::Interfaces::IOptionsSvc& getOptsSvc();
0132 
0133   Gaudi::Monitoring::Hub& monitoringHub();
0134 };
0135 
0136 #endif // GAUDI_ISVCLOCATOR_H