All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Service.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_SERVICE_H
2 #define GAUDIKERNEL_SERVICE_H
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 #include "GaudiKernel/IService.h"
10 #include "GaudiKernel/IStateful.h"
12 #include "GaudiKernel/Property.h"
15 #include "GaudiKernel/SmartIF.h"
16 #include <Gaudi/PluginService.h>
17 // ============================================================================
18 #include <vector>
19 // ============================================================================
20 // Forward declarations
21 // ============================================================================
22 class IMessageSvc;
23 class ISvcManager;
24 class ServiceManager;
25 // ============================================================================
33 class GAUDI_API Service: public CommonMessaging<implements3<IService, IProperty, IStateful> > {
34 public:
36  const std::string&,
38  friend class ServiceManager;
39 
42  virtual unsigned long release();
43 
45  virtual const std::string& name() const;
46 
47  // State machine implementation
49  virtual StatusCode initialize();
50  virtual StatusCode start();
51  virtual StatusCode stop();
52  virtual StatusCode finalize();
54  virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
55  virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
56  virtual StatusCode reinitialize();
57  virtual StatusCode restart();
58 
60  virtual StatusCode sysInitialize();
62  virtual StatusCode sysStart();
64  virtual StatusCode sysStop();
66  virtual StatusCode sysFinalize();
68  virtual StatusCode sysReinitialize();
70  virtual StatusCode sysRestart();
71 
72  // Default implementations for ISetProperty
73  virtual StatusCode setProperty(const Property& p);
74  virtual StatusCode setProperty( const std::string& s );
75  virtual StatusCode setProperty( const std::string& n, const std::string& v);
76  virtual StatusCode getProperty(Property* p) const;
77  virtual const Property& getProperty( const std::string& name) const;
78  virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
79  virtual const std::vector<Property*>& getProperties( ) const;
80 
121  template <class TYPE>
123  ( const std::string& name ,
124  const TYPE& value )
125  { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
126 
128  Service( const std::string& name, ISvcLocator* svcloc);
131 
135  StatusCode setProperties();
136 
139  template <class T>
140  StatusCode service( const std::string& name, const T*& psvc, bool createIf = true ) const {
141  ISvcLocator& svcLoc = *serviceLocator();
142  SmartIF<T> ptr(
143  ServiceLocatorHelper(svcLoc, *this).service(name, !createIf, // quiet
144  createIf));
145  if (ptr.isValid()) {
146  psvc = ptr.get();
147  const_cast<T*>(psvc)->addRef();
148  return StatusCode::SUCCESS;
149  }
150  // else
151  psvc = 0;
152  return StatusCode::FAILURE;
153  }
154 
155  template <class T>
156  StatusCode service( const std::string& name, T*& psvc, bool createIf = true ) const {
157  ISvcLocator& svcLoc = *serviceLocator();
158  SmartIF<T> ptr(
159  ServiceLocatorHelper(svcLoc, *this).service(name, !createIf, // quiet
160  createIf));
161  if (ptr.isValid()) {
162  psvc = ptr.get();
163  psvc->addRef();
164  return StatusCode::SUCCESS;
165  }
166  // else
167  psvc = 0;
168  return StatusCode::FAILURE;
169  }
170 
173  template <class T>
174  StatusCode service( const std::string& svcType, const std::string& svcName,
175  T*& psvc) const {
176  return service(svcType + "/" + svcName, psvc);
177  }
178  // ==========================================================================
207  template <class T>
208  Property* declareProperty
209  ( const std::string& name ,
210  T& property ,
211  const std::string& doc = "none" ) const
212  {
213  return m_propertyMgr -> declareProperty ( name , property , doc ) ;
214  }
215  // ==========================================================================
224  Property* declareRemoteProperty
225  ( const std::string& name ,
226  IProperty* rsvc ,
227  const std::string& rname = "" ) const
228  {
229  return m_propertyMgr -> declareRemoteProperty ( name , rsvc , rname ) ;
230  }
231  // ==========================================================================
235  SmartIF<IAuditorSvc>& auditorSvc() const;
236 
237 protected:
239  virtual ~Service();
246 
248  int outputLevel() const { return m_outputLevel.value(); }
249 
250 private:
252  std::string m_name;
258 
259  void setServiceManager(ISvcManager* ism);
260 
270 
272  void initOutputLevel(Property& prop);
273 };
274 
275 #ifndef GAUDI_NEW_PLUGIN_SERVICE
276 template <class T>
277 class SvcFactory {
278 public:
279  template <typename S>
280  static typename S::ReturnType create(typename S::Arg1Type a1,
281  typename S::Arg2Type a2) {
282  return new T(a1, a2);
283  }
284 };
285 
286 // Macros to declare component factories
287 #define DECLARE_SERVICE_FACTORY(x) \
288  DECLARE_FACTORY_WITH_CREATOR(x, SvcFactory< x >, Service::Factory)
289 #define DECLARE_NAMED_SERVICE_FACTORY(x, n) \
290  DECLARE_FACTORY_WITH_CREATOR_AND_ID(x, SvcFactory< x >, #n, Service::Factory)
291 #define DECLARE_NAMESPACE_SERVICE_FACTORY(n, x) \
292  DECLARE_SERVICE_FACTORY(n::x)
293 
294 #else
295 
296 // macros to declare factories
297 #define DECLARE_SERVICE_FACTORY(x) DECLARE_COMPONENT(x)
298 #define DECLARE_NAMED_SERVICE_FACTORY(x, n) DECLARE_COMPONENT_WITH_ID(x, #n)
299 #define DECLARE_NAMESPACE_SERVICE_FACTORY(n, x) DECLARE_COMPONENT(n::x)
300 
301 #endif
302 
303 #endif // GAUDIKERNEL_SERVICE_H
The ServiceManager class is in charge of the creation of concrete instances of Services.
virtual StatusCode configure()
Configuration (from OFFLINE to CONFIGURED).
Definition: Service.h:48
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1212
BooleanProperty m_auditInit
Definition: Service.h:263
Gaudi::StateMachine::State m_targetState
Service state.
Definition: Service.h:245
an helper to share the implementation of service() among the various kernel base classes $Id: ...
IntegerProperty m_outputLevel
Service output level.
Definition: Service.h:241
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
bool m_auditorInitialize
Definition: Service.h:264
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:243
SmartIF< IAuditorSvc > m_pAuditorSvc
Auditor Service.
Definition: Service.h:262
virtual SmartIF< ISvcLocator > & serviceLocator() const =0
Needed to locate the message service.
The ISvcManager is the interface implemented by the Service Factory in the Application Manager to sup...
Definition: ISvcManager.h:29
int outputLevel() const
get the Service's output level
Definition: Service.h:248
SmartIF< ISvcLocator > m_svcLocator
Service Locator reference.
Definition: Service.h:254
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
std::string m_name
Service Name.
Definition: Service.h:252
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm, Service, AlgTool).
Definition: StateMachine.h:12
GAUDI_API Property * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
Definition: Property.cpp:349
Property manager helper class.
Definition: PropertyMgr.h:38
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
General service interface definition.
Definition: IService.h:19
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
static S::ReturnType create(typename S::Arg1Type a1, typename S::Arg2Type a2)
Definition: Service.h:280
bool m_auditorFinalize
Definition: Service.h:267
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
bool m_auditorReinitialize
Definition: Service.h:268
virtual StatusCode terminate()
Initialization (from CONFIGURED to OFFLINE).
Definition: Service.h:53
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
Definition: Service.h:54
StatusCode service(const std::string &svcType, const std::string &svcName, T *&psvc) const
Access a service by name and type, creating it if it doesn't already exist.
Definition: Service.h:174
PropertyMgr * m_propertyMgr
Property Manager.
Definition: Service.h:257
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
virtual unsigned long release()=0
Release Interface instance.
bool m_auditorStart
Definition: Service.h:265
Class wrapping the signature for a factory with 2 arguments.
Definition: PluginService.h:86
virtual const std::string & name() const =0
This is needed to avoid ambiguous calls to name()
string s
Definition: gaudirun.py:210
Templated class to add the standard messaging functionalities.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:140
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
Returns a smart pointer to a service.
SmartIF< ISvcManager > m_svcManager
Definition: Service.h:255
virtual Gaudi::StateMachine::State targetFSMState() const
When we are in the middle of a transition, get the state where the transition is leading us...
Definition: Service.h:55
virtual StatusCode restart()
Initialization (from RUNNING to RUNNING, via INITIALIZED).
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:22
Base class for all services.
Definition: Service.h:33
#define GAUDI_API
Definition: Kernel.h:108
Gaudi::PluginService::Factory2< IService *, const std::string &, ISvcLocator * > Factory
Definition: Service.h:37
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Definition: Service.h:156
bool m_auditorRestart
Definition: Service.h:269
bool m_auditorStop
Definition: Service.h:266
tuple start
Definition: IOTest.py:88