Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:10:00

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 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   virtual StatusCode getService( const Gaudi::Utils::TypeNameString& typeName, IService*& svc,
0057                                  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   virtual StatusCode getService( const Gaudi::Utils::TypeNameString& typeName, const InterfaceID& iid,
0073                                  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   StatusCode service( const Gaudi::Utils::TypeNameString& name, T*& svc, bool createIf = true ) {
0098     if ( createIf ) {
0099       IService*  s;
0100       StatusCode sc = getService( name, s, true );
0101       if ( !sc.isSuccess() ) return sc; // Must check if initialization was OK!
0102     }
0103     return getService( name, T::interfaceID(), (IInterface*&)svc );
0104   }
0105 
0106   /// Templated method to access a service by type and name.
0107   template <class T>
0108   StatusCode service( std::string_view type, std::string_view name, T*& svc, bool createIf = true ) {
0109     return service( std::string{ type }.append( "/" ).append( name ), svc, createIf );
0110   }
0111 #endif
0112 
0113   /// Returns a smart pointer to a service.
0114   virtual SmartIF<IService>& service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) = 0;
0115 
0116   /// Returns a smart pointer to the requested interface of a service.
0117   template <typename T>
0118   inline SmartIF<T> service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) {
0119     return SmartIF<T>{ service( typeName, createIf ) };
0120   }
0121 
0122   // try to access a different interface of  the _current_ serviceLocator...
0123   template <typename IFace>
0124   SmartIF<IFace> as() {
0125     return SmartIF<IFace>{ this };
0126   }
0127 
0128   /// Direct access to Gaudi::Interfaces::IOptionsSvc implementation.
0129   Gaudi::Interfaces::IOptionsSvc& getOptsSvc();
0130 
0131   Gaudi::Monitoring::Hub& monitoringHub();
0132 };
0133 
0134 #endif // GAUDI_ISVCLOCATOR_H