00001
00002 #ifndef GAUDIKERNEL_SERVICE_H
00003 #define GAUDIKERNEL_SERVICE_H
00004
00005
00006 #include "GaudiKernel/IService.h"
00007 #include "GaudiKernel/IProperty.h"
00008 #include "GaudiKernel/PropertyMgr.h"
00009
00010 #include <vector>
00011
00012
00013 class ISvcLocator;
00014 class IMessageSvc;
00015 class IJobOptions;
00016
00023 class Service : public virtual IService,
00024 public virtual IProperty {
00025 public:
00027 enum State { OFFLINE, INITIALIZED };
00028
00033 virtual StatusCode queryInterface(const IID& riid, void** ppvUnknown);
00034
00036 virtual unsigned long addRef();
00037
00039 virtual unsigned long release();
00040
00042 virtual const std::string& name() const;
00044 virtual const IID& type() const;
00046 State state( ) const { return m_state; }
00048 virtual StatusCode initialize();
00050 virtual StatusCode finalize();
00051
00052
00053 virtual StatusCode setProperty(const Property& p);
00054 virtual StatusCode setProperty( std::istream& s );
00055 virtual StatusCode setProperty( const std::string& n, const std::string& v);
00056 virtual StatusCode getProperty(Property* p) const;
00057 virtual const Property& getProperty( const std::string& name) const;
00058 virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
00059 virtual const std::vector<Property*>& getProperties( ) const;
00060
00062 Service( const std::string& name, ISvcLocator* svcloc);
00064 ISvcLocator* serviceLocator() const;
00066 IMessageSvc* msgSvc();
00067 IMessageSvc* msgSvc() const;
00068
00069 IMessageSvc* messageService();
00070 IMessageSvc* messageService() const;
00071
00072
00076 StatusCode setProperties();
00077
00080 template <class T>
00081 StatusCode service( const std::string& name, T*& svc, bool createIf = false ) const {
00082 IService* theSvc;
00083 StatusCode sc = serviceLocator()->getService( name, theSvc, createIf );
00084 if ( sc.isSuccess() ) {
00085 return theSvc->queryInterface(T::interfaceID(), (void**)&svc);
00086 }
00087 svc = 0;
00088 return sc;
00089 }
00090
00092 template <class T>
00093 StatusCode declareProperty( const std::string& name, T& property ) const {
00094 m_propertyMgr->declareProperty(name, property);
00095 return StatusCode::SUCCESS;
00096 }
00097
00098 protected:
00100 virtual ~Service();
00102 int m_outputLevel;
00103 private:
00105 std::string m_name;
00107 unsigned long m_refCount;
00109 ISvcLocator* m_svcLocator;
00111 IMessageSvc* m_messageSvc;
00113 IJobOptions* m_jobOptions;
00115 State m_state;
00117 PropertyMgr* m_propertyMgr;
00118 };
00119
00120 #endif // GAUDIKERNEL_SERVICE_H