File indexing completed on 2025-03-13 09:10:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
0012 #define GAUDIKERNEL_ISVCLOCATOR_H 1
0013
0014
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
0024 class IService;
0025 namespace Gaudi::Monitoring {
0026 struct Hub;
0027 }
0028
0029 namespace Gaudi {
0030 namespace Interfaces {
0031 struct IOptionsSvc;
0032 }
0033 }
0034 #define GAUDI_HAS_IOPTIONS_SVC
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 class GAUDI_API ISvcLocator : virtual public IInterface {
0047 public:
0048
0049 DeclareInterfaceID( ISvcLocator, 3, 0 );
0050
0051 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
0052
0053
0054
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();
0062 return StatusCode::SUCCESS;
0063 }
0064 return StatusCode::FAILURE;
0065 }
0066
0067
0068
0069
0070
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
0079
0080
0081
0082
0083
0084
0085
0086 #endif
0087
0088
0089 virtual const std::list<IService*>& getServices() const = 0;
0090
0091
0092 virtual bool existsService( std::string_view name ) const = 0;
0093
0094 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
0095
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;
0102 }
0103 return getService( name, T::interfaceID(), (IInterface*&)svc );
0104 }
0105
0106
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
0114 virtual SmartIF<IService>& service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) = 0;
0115
0116
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
0123 template <typename IFace>
0124 SmartIF<IFace> as() {
0125 return SmartIF<IFace>{ this };
0126 }
0127
0128
0129 Gaudi::Interfaces::IOptionsSvc& getOptsSvc();
0130
0131 Gaudi::Monitoring::Hub& monitoringHub();
0132 };
0133
0134 #endif