Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Service.cpp

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiKernel/src/Lib/Service.cpp,v 1.1.1.1 2001/04/18 18:14:18 tlindner Exp $
00002 //====================================================================
00003 //      Service.cpp
00004 //--------------------------------------------------------------------
00005 //
00006 //      Package    : System ( The LHCb Offline System)
00007 //
00008 //  Description: Common ancestror for all "Service" 
00009 //
00010 //      Author     : P. Mato
00011 //  History    :
00012 // +---------+----------------------------------------------+---------
00013 // |    Date |                 Comment                      | Who     
00014 // +---------+----------------------------------------------+---------
00015 // | 29/10/98| Initial version                              | PM
00016 // | 13/11/98| Conform to standard interface                | MF/PM
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 //--- IInterface::addRef
00028 unsigned long Service::addRef()   {
00029   m_refCount++;
00030   return m_refCount;
00031 }
00032 
00033 //--- IInterface::release
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 //--- IInterface::queryInterface
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 //--- IService::initialize
00062 StatusCode Service::initialize() {
00063   StatusCode status;
00064   // Initialize it only if was not done
00065   if( m_state != OFFLINE ) {
00066     m_messageSvc->reportMessage(m_name, MSG::WARNING, "Service already initialized");
00067     return StatusCode::FAILURE;
00068   }
00069   // Get a reference to the Message Service
00070   status = m_svcLocator->getService("MessageSvc", IID_IMessageSvc, (IInterface*&)m_messageSvc);
00071   if( status.isFailure() ) return status;
00072 
00073   // Set the Algorithm's properties
00074   setProperties();
00075 
00076   // Check current outputLevel to evetually inform the MessageSvc
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 //--- IService::initialize
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 //  m_jobOptions->release();
00095   m_jobOptions = 0;
00096 
00097   return StatusCode::SUCCESS;
00098 }
00099 
00100 //--- IService::getServiceName
00101 const std::string& Service::name()   const {
00102   return m_name;
00103 }
00104 
00105 //--- IService::getSeriviceType
00106 const IID& Service::type()  const {
00107   return IID_IService;
00108 }
00109 
00110 //--- Retrieve pointer to service locator
00111 ISvcLocator* Service::serviceLocator() const {
00112   return m_svcLocator;
00113 }
00114 
00115 //--- Retrieve pointer to message service
00116 IMessageSvc* Service::msgSvc()    {
00117   return m_messageSvc;
00118 }
00119 IMessageSvc* Service::msgSvc()  const  {
00120   return m_messageSvc;
00121 }
00122 // Obsoleted name, kept due to the backwards compatibility
00123 IMessageSvc* Service::messageService()    {
00124   return m_messageSvc;
00125 }
00126 IMessageSvc* Service::messageService()  const  {
00127   return m_messageSvc;
00128 }
00129 
00130 // IProperty implementation
00131 // Delegate to the Property manager
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 // Use the job options service to set declared properties
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 //--- Local methods
00174 // Standard Constructor
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   // Declare common Service properties with their defaults
00185   declareProperty( "OutputLevel", m_outputLevel = MSG::NIL);
00186 }
00187 
00188 // Standard Destructor
00189 Service::~Service() {
00190   delete m_propertyMgr;
00191 }

Generated at Wed Nov 21 12:22:05 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000