00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "GaudiKernel/Service.h"
00022 #include "GaudiKernel/PropertyMgr.h"
00023 #include "GaudiKernel/IMessageSvc.h"
00024 #include "GaudiKernel/ISvcLocator.h"
00025 #include "GaudiKernel/IJobOptionsSvc.h"
00026
00027
00028 unsigned long Service::addRef() {
00029 m_refCount++;
00030 return m_refCount;
00031 }
00032
00033
00034 unsigned long Service::release() {
00035 unsigned long count = --m_refCount;
00036 if( count <= 0) {
00037 delete this;
00038 }
00039 return count;
00040 }
00041
00042
00043 StatusCode Service::queryInterface(const IID& riid, void** ppvInterface) {
00044 if ( IID_IInterface.versionMatch(riid) ) {
00045 *ppvInterface = (IInterface*)this;
00046 }
00047 else if ( IID_IService.versionMatch(riid) ) {
00048 *ppvInterface = (IService*)this;
00049 }
00050 else if ( IID_IProperty.versionMatch(riid) ) {
00051 *ppvInterface = (IProperty*)this;
00052 }
00053 else {
00054 return NO_INTERFACE;
00055 }
00056 addRef();
00057 return SUCCESS;
00058 }
00059
00060
00061
00062 StatusCode Service::initialize() {
00063 StatusCode status;
00064
00065 if( m_state != OFFLINE ) {
00066 m_messageSvc->reportMessage(m_name, MSG::WARNING, "Service already initialized");
00067 return StatusCode::FAILURE;
00068 }
00069
00070 status = m_svcLocator->getService("MessageSvc", IID_IMessageSvc, (IInterface*&)m_messageSvc);
00071 if( status.isFailure() ) return status;
00072
00073
00074 setProperties();
00075
00076
00077 if( m_outputLevel != MSG::NIL ) {
00078 m_messageSvc->setOutputLevel( name(), m_outputLevel );
00079 }
00080
00081 m_state = INITIALIZED;
00082 m_messageSvc->reportMessage(m_name, MSG::INFO, "Service initialized successfully");
00083 return StatusCode::SUCCESS;
00084 }
00085
00086
00087 StatusCode Service::finalize() {
00088 if( m_state != INITIALIZED ) {
00089 m_messageSvc->reportMessage(m_name, MSG::WARNING, "Service already offline");
00090 return StatusCode::FAILURE;
00091 }
00092 m_messageSvc->release();
00093 m_messageSvc = 0;
00094
00095 m_jobOptions = 0;
00096
00097 return StatusCode::SUCCESS;
00098 }
00099
00100
00101 const std::string& Service::name() const {
00102 return m_name;
00103 }
00104
00105
00106 const IID& Service::type() const {
00107 return IID_IService;
00108 }
00109
00110
00111 ISvcLocator* Service::serviceLocator() const {
00112 return m_svcLocator;
00113 }
00114
00115
00116 IMessageSvc* Service::msgSvc() {
00117 return m_messageSvc;
00118 }
00119 IMessageSvc* Service::msgSvc() const {
00120 return m_messageSvc;
00121 }
00122
00123 IMessageSvc* Service::messageService() {
00124 return m_messageSvc;
00125 }
00126 IMessageSvc* Service::messageService() const {
00127 return m_messageSvc;
00128 }
00129
00130
00131
00132 StatusCode Service::setProperty(const Property& p) {
00133 return m_propertyMgr->setProperty(p);
00134 }
00135
00136 StatusCode Service::setProperty(std::istream& s) {
00137 return m_propertyMgr->setProperty(s);
00138 }
00139
00140 StatusCode Service::setProperty(const std::string& n, const std::string& v) {
00141 return m_propertyMgr->setProperty(n,v);
00142 }
00143
00144 StatusCode Service::getProperty(Property* p) const {
00145 return m_propertyMgr->getProperty(p);
00146 }
00147
00148 const Property& Service::getProperty(const std::string& n) const {
00149 return m_propertyMgr->getProperty(n);
00150 }
00151
00152 StatusCode Service::getProperty(const std::string& n, std::string& v ) const {
00153 return m_propertyMgr->getProperty(n,v);
00154 }
00155
00156 const std::vector<Property*>& Service::getProperties() const {
00157 return m_propertyMgr->getProperties();
00158 }
00159
00160
00161 StatusCode Service::setProperties() {
00162 IJobOptionsSvc* jos;
00163 StatusCode sc = m_svcLocator->getService( "JobOptionsSvc", IID_IJobOptionsSvc,
00164 (IInterface*&) jos);
00165 if( !sc.isSuccess() ) return StatusCode::FAILURE;
00166
00167 jos->setMyProperties( name(), this );
00168
00169 return StatusCode::SUCCESS;
00170 }
00171
00172
00173
00174
00175 Service::Service( const std::string& name, ISvcLocator* svcloc) {
00176 m_name = name;
00177 m_refCount = 0;
00178 m_svcLocator = svcloc;
00179 m_messageSvc = 0;
00180 m_jobOptions = 0;
00181 m_state = OFFLINE;
00182 m_propertyMgr = new PropertyMgr();
00183
00184
00185 declareProperty( "OutputLevel", m_outputLevel = MSG::NIL);
00186 }
00187
00188
00189 Service::~Service() {
00190 delete m_propertyMgr;
00191 }