![]() |
|
|
Generated: 8 Jan 2009 |
00001 // $Id: Service.h,v 1.23 2008/06/02 14:20:37 marcocle Exp $ 00002 // ============================================================================ 00003 #ifndef GAUDIKERNEL_SERVICE_H 00004 #define GAUDIKERNEL_SERVICE_H 00005 // ============================================================================ 00006 // Include files 00007 // ============================================================================ 00008 #include "GaudiKernel/IService.h" 00009 #include "GaudiKernel/ISvcLocator.h" 00010 #include "GaudiKernel/IProperty.h" 00011 #include "GaudiKernel/IStateful.h" 00012 #include "GaudiKernel/PropertyMgr.h" 00013 #include "GaudiKernel/Property.h" 00014 #include "GaudiKernel/IAuditorSvc.h" 00015 // ============================================================================ 00016 #include <vector> 00017 // ============================================================================ 00018 // Forward delarations 00019 // ============================================================================ 00020 class IMessageSvc; 00021 class ISvcManager; 00022 class ServiceManager; 00023 // ============================================================================ 00030 class Service : public virtual IService, 00031 public virtual IProperty, 00032 public virtual IStateful { 00033 public: 00034 friend class ServiceManager; 00039 virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvUnknown); 00040 00042 virtual unsigned long addRef(); 00043 00045 virtual unsigned long release(); 00046 00048 virtual const std::string& name() const; 00050 virtual const InterfaceID& type() const; 00051 00052 // State machine implementation 00053 virtual StatusCode configure() { return StatusCode::SUCCESS; } 00054 virtual StatusCode initialize(); 00055 virtual StatusCode start(); 00056 virtual StatusCode stop(); 00057 virtual StatusCode finalize(); 00058 virtual StatusCode terminate() { return StatusCode::SUCCESS; } 00059 virtual Gaudi::StateMachine::State FSMState() const { return m_state; } 00060 virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; } 00061 virtual StatusCode reinitialize(); 00062 virtual StatusCode restart(); 00063 00065 virtual StatusCode sysInitialize(); 00067 virtual StatusCode sysStart(); 00069 virtual StatusCode sysStop(); 00071 virtual StatusCode sysFinalize(); 00073 virtual StatusCode sysReinitialize(); 00075 virtual StatusCode sysRestart(); 00076 00077 // Default implementations for ISetProperty 00078 virtual StatusCode setProperty(const Property& p); 00079 virtual StatusCode setProperty( const std::string& s ); 00080 virtual StatusCode setProperty( const std::string& n, const std::string& v); 00081 virtual StatusCode getProperty(Property* p) const; 00082 virtual const Property& getProperty( const std::string& name) const; 00083 virtual StatusCode getProperty( const std::string& n, std::string& v ) const; 00084 virtual const std::vector<Property*>& getProperties( ) const; 00085 00126 template <class TYPE> 00127 StatusCode setProperty 00128 ( const std::string& name , 00129 const TYPE& value ) 00130 { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; } 00131 00133 Service( const std::string& name, ISvcLocator* svcloc); 00135 ISvcLocator* serviceLocator() const; 00137 IMessageSvc* msgSvc(); 00138 IMessageSvc* msgSvc() const; 00139 // Obsoleted name, kept due to the backwards compatibility 00140 IMessageSvc* messageService(); 00141 IMessageSvc* messageService() const; 00142 00143 00147 StatusCode setProperties(); 00148 00151 template <class T> 00152 StatusCode service( const std::string& name, T*& psvc, bool createIf = true ) const { 00153 return service_i(name, createIf, T::interfaceID(), (void**)&psvc); 00154 } 00155 00158 template <class T> 00159 StatusCode service( const std::string& svcType, const std::string& svcName, 00160 T*& psvc) const { 00161 return service_i(svcType, svcName, T::interfaceID(), (void**)&psvc); 00162 } 00163 // ========================================================================== 00192 template <class T> 00193 Property* declareProperty 00194 ( const std::string& name , 00195 T& property , 00196 const std::string& doc = "none" ) const 00197 { 00198 return m_propertyMgr -> declareProperty ( name , property , doc ) ; 00199 } 00200 // ========================================================================== 00209 Property* declareRemoteProperty 00210 ( const std::string& name , 00211 IProperty* rsvc , 00212 const std::string& rname = "" ) const 00213 { 00214 return m_propertyMgr -> declareRemoteProperty ( name , rsvc , rname ) ; 00215 } 00216 // ========================================================================== 00220 IAuditorSvc* auditorSvc() const; 00221 00222 protected: 00224 virtual ~Service(); 00226 IntegerProperty m_outputLevel; 00228 Gaudi::StateMachine::State m_state; 00230 Gaudi::StateMachine::State m_targetState; 00232 mutable IMessageSvc* m_messageSvc; 00233 00235 int outputLevel() const { return m_outputLevel.value(); } 00236 00237 private: 00239 std::string m_name; 00241 unsigned long m_refCount; 00243 ISvcLocator* m_svcLocator; 00244 ISvcManager* m_svcManager; 00246 PropertyMgr* m_propertyMgr; 00248 StatusCode service_i(const std::string& svcName, 00249 bool createIf, 00250 const InterfaceID& iid, 00251 void** ppSvc) const; 00252 StatusCode service_i(const std::string& svcType, 00253 const std::string& svcName, 00254 const InterfaceID& iid, 00255 void** ppSvc) const; 00256 void setServiceManager(ISvcManager*); 00257 00259 mutable IAuditorSvc* m_pAuditorSvc; 00260 BooleanProperty m_auditInit; 00261 bool m_auditorInitialize; 00262 bool m_auditorStart; 00263 bool m_auditorStop; 00264 bool m_auditorFinalize; 00265 bool m_auditorReinitialize; 00266 bool m_auditorRestart; 00267 00269 void initOutputLevel(Property& prop); 00270 }; 00271 00272 #endif // GAUDIKERNEL_SERVICE_H