| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# 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, 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       psvc->addRef();
    00146       return StatusCode::SUCCESS;
    00147     }
    00148     // else
    00149     psvc = 0;
    00150     return StatusCode::FAILURE;
    00151   }
    00152
    00155   template <class T>
    00156   StatusCode service( const std::string& svcType, const std::string& svcName,
    00157                       T*& psvc) const {
    00158     return service(svcType + "/" + svcName, psvc);
    00159   }
    00160   // ==========================================================================
    00189   template <class T>
    00190   Property* declareProperty
    00191   ( const std::string& name              ,
    00192     T&                 property          ,
    00193     const std::string& doc      = "none" ) const
    00194   {
    00195     return m_propertyMgr -> declareProperty ( name , property , doc ) ;
    00196   }
    00197   // ==========================================================================
    00206   Property* declareRemoteProperty
    00207   ( const std::string& name       ,
    00208     IProperty*         rsvc       ,
    00209     const std::string& rname = "" ) const
    00210   {
    00211         return m_propertyMgr -> declareRemoteProperty ( name , rsvc , rname ) ;
    00212   }
    00213   // ==========================================================================
    00217   SmartIF<IAuditorSvc>& auditorSvc() const;
    00218
    00219 protected:
    00221   virtual ~Service();
    00223   IntegerProperty m_outputLevel;
    00225   Gaudi::StateMachine::State    m_state;
    00227   Gaudi::StateMachine::State    m_targetState;
    00228
    00230   int  outputLevel() const { return m_outputLevel.value(); }
    00231
    00232 private:
    00234   std::string   m_name;
    00236   mutable SmartIF<ISvcLocator> m_svcLocator;
    00237   SmartIF<ISvcManager>  m_svcManager;
    00239   PropertyMgr*  m_propertyMgr;
    00240
    00241   void setServiceManager(ISvcManager* ism);
    00242
    00244   mutable SmartIF<IAuditorSvc>  m_pAuditorSvc;
    00245   BooleanProperty       m_auditInit;
    00246   bool                  m_auditorInitialize;
    00247   bool                  m_auditorStart;
    00248   bool                  m_auditorStop;
    00249   bool                  m_auditorFinalize;
    00250   bool                  m_auditorReinitialize;
    00251   bool                  m_auditorRestart;
    00252
    00254   void initOutputLevel(Property& prop);
    00255 };
    00256
    00257 #endif // GAUDIKERNEL_SERVICE_H