| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# Service.h

Go to the documentation of this file.

    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/ServiceLocatorHelper.h"
    00011 #include "GaudiKernel/IProperty.h"
    00012 #include "GaudiKernel/IStateful.h"
    00013 #include "GaudiKernel/PropertyMgr.h"
    00014 #include "GaudiKernel/Property.h"
    00015 #include "GaudiKernel/IAuditorSvc.h"
    00016 #include "GaudiKernel/CommonMessaging.h"
    00017 #include "GaudiKernel/SmartIF.h"
    00018 // ============================================================================
    00019 #include <vector>
    00020 // ============================================================================
    00021 // Forward declarations
    00022 // ============================================================================
    00023 class IMessageSvc;
    00024 class ISvcManager;
    00025 class ServiceManager;
    00026 // ============================================================================
    00034 class GAUDI_API Service: public CommonMessaging<implements3<IService, IProperty, IStateful> > {
    00035 public:
    00036   friend class ServiceManager;
    00037
    00040   virtual unsigned long release();
    00041
    00043   virtual const std::string& name() const;
    00044
    00045   // State machine implementation
    00046   virtual StatusCode configure() { return StatusCode::SUCCESS; }
    00047   virtual StatusCode initialize();
    00048   virtual StatusCode start();
    00049   virtual StatusCode stop();
    00050   virtual StatusCode finalize();
    00051   virtual StatusCode terminate() { return StatusCode::SUCCESS; }
    00052   virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
    00053   virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
    00054   virtual StatusCode reinitialize();
    00055   virtual StatusCode restart();
    00056
    00058   virtual StatusCode sysInitialize();
    00060   virtual StatusCode sysStart();
    00062   virtual StatusCode sysStop();
    00064   virtual StatusCode sysFinalize();
    00066   virtual StatusCode sysReinitialize();
    00068   virtual StatusCode sysRestart();
    00069
    00070   // Default implementations for ISetProperty
    00071   virtual StatusCode setProperty(const Property& p);
    00072   virtual StatusCode setProperty( const std::string& s );
    00073   virtual StatusCode setProperty( const std::string& n, const std::string& v);
    00074   virtual StatusCode getProperty(Property* p) const;
    00075   virtual const Property& getProperty( const std::string& name) const;
    00076   virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
    00077   virtual const std::vector<Property*>& getProperties( ) const;
    00078
    00119   template <class TYPE>
    00120   StatusCode setProperty
    00121   ( const std::string& name  ,
    00122     const TYPE&        value )
    00123   { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
    00124
    00126   Service( const std::string& name, ISvcLocator* svcloc);
    00128   SmartIF<ISvcLocator>& serviceLocator() const;
    00129
    00133   StatusCode setProperties();
    00134
    00137   template <class T>
    00138   StatusCode service( const std::string& name, const T*& psvc, bool createIf = true ) const {
    00139     ISvcLocator& svcLoc = *serviceLocator();
    00140     SmartIF<T> ptr(
    00141       ServiceLocatorHelper(svcLoc, *this).service(name, !createIf, // quiet
    00142                                                   createIf));
    00143     if (ptr.isValid()) {
    00144       psvc = ptr.get();
    00145       const_cast<T*>(psvc)->addRef();
    00146       return StatusCode::SUCCESS;
    00147     }
    00148     // else
    00149     psvc = 0;
    00150     return StatusCode::FAILURE;
    00151   }
    00152
    00153   template <class T>
    00154   StatusCode service( const std::string& name, T*& psvc, bool createIf = true ) const {
    00155     ISvcLocator& svcLoc = *serviceLocator();
    00156     SmartIF<T> ptr(
    00157       ServiceLocatorHelper(svcLoc, *this).service(name, !createIf, // quiet
    00158                                                   createIf));
    00159     if (ptr.isValid()) {
    00160       psvc = ptr.get();
    00161       psvc->addRef();
    00162       return StatusCode::SUCCESS;
    00163     }
    00164     // else
    00165     psvc = 0;
    00166     return StatusCode::FAILURE;
    00167   }
    00168
    00171   template <class T>
    00172   StatusCode service( const std::string& svcType, const std::string& svcName,
    00173                       T*& psvc) const {
    00174     return service(svcType + "/" + svcName, psvc);
    00175   }
    00176   // ==========================================================================
    00205   template <class T>
    00206   Property* declareProperty
    00207   ( const std::string& name              ,
    00208     T&                 property          ,
    00209     const std::string& doc      = "none" ) const
    00210   {
    00211     return m_propertyMgr -> declareProperty ( name , property , doc ) ;
    00212   }
    00213   // ==========================================================================
    00222   Property* declareRemoteProperty
    00223   ( const std::string& name       ,
    00224     IProperty*         rsvc       ,
    00225     const std::string& rname = "" ) const
    00226   {
    00227         return m_propertyMgr -> declareRemoteProperty ( name , rsvc , rname ) ;
    00228   }
    00229   // ==========================================================================
    00233   SmartIF<IAuditorSvc>& auditorSvc() const;
    00234
    00235 protected:
    00237   virtual ~Service();
    00239   IntegerProperty m_outputLevel;
    00241   Gaudi::StateMachine::State    m_state;
    00243   Gaudi::StateMachine::State    m_targetState;
    00244
    00246   int  outputLevel() const { return m_outputLevel.value(); }
    00247
    00248 private:
    00250   std::string   m_name;
    00252   mutable SmartIF<ISvcLocator> m_svcLocator;
    00253   SmartIF<ISvcManager>  m_svcManager;
    00255   PropertyMgr*  m_propertyMgr;
    00256
    00257   void setServiceManager(ISvcManager* ism);
    00258
    00260   mutable SmartIF<IAuditorSvc>  m_pAuditorSvc;
    00261   BooleanProperty       m_auditInit;
    00262   bool                  m_auditorInitialize;
    00263   bool                  m_auditorStart;
    00264   bool                  m_auditorStop;
    00265   bool                  m_auditorFinalize;
    00266   bool                  m_auditorReinitialize;
    00267   bool                  m_auditorRestart;
    00268
    00270   void initOutputLevel(Property& prop);
    00271 };
    00272
    00273 #endif // GAUDIKERNEL_SERVICE_H