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:
35 #ifndef __REFLEX__
37  const std::string&,
39 #endif
40  friend class ServiceManager;
41 
44  virtual unsigned long release();
45 
47  virtual const std::string& name() const;
48 
49  // State machine implementation
51  virtual StatusCode initialize();
52  virtual StatusCode start();
53  virtual StatusCode stop();
54  virtual StatusCode finalize();
56  virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
57  virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
58  virtual StatusCode reinitialize();
59  virtual StatusCode restart();
60 
62  virtual StatusCode sysInitialize();
64  virtual StatusCode sysStart();
66  virtual StatusCode sysStop();
68  virtual StatusCode sysFinalize();
70  virtual StatusCode sysReinitialize();
72  virtual StatusCode sysRestart();
73 
74  // Default implementations for ISetProperty
75  virtual StatusCode setProperty(const Property& p);
76  virtual StatusCode setProperty( const std::string& s );
77  virtual StatusCode setProperty( const std::string& n, const std::string& v);
78  virtual StatusCode getProperty(Property* p) const;
79  virtual const Property& getProperty( const std::string& name) const;
80  virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
81  virtual const std::vector<Property*>& getProperties( ) const;
82 
123  template <class TYPE>
125  ( const std::string& name ,
126  const TYPE& value )
127  { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
128 
130  Service( const std::string& name, ISvcLocator* svcloc);
133 
137  StatusCode setProperties();
138 
141  template <class T>
142  StatusCode service( const std::string& name, const T*& psvc, bool createIf = true ) const {
143  ISvcLocator& svcLoc = *serviceLocator();
144  SmartIF<T> ptr(
145  ServiceLocatorHelper(svcLoc, *this).service(name, !createIf, // quiet
146  createIf));
147  if (ptr.isValid()) {
148  psvc = ptr.get();
149  const_cast<T*>(psvc)->addRef();
150  return StatusCode::SUCCESS;
151  }
152  // else
153  psvc = 0;
154  return StatusCode::FAILURE;
155  }
156 
157  template <class T>
158  StatusCode service( const std::string& name, T*& psvc, bool createIf = true ) const {
159  ISvcLocator& svcLoc = *serviceLocator();
160  SmartIF<T> ptr(
161  ServiceLocatorHelper(svcLoc, *this).service(name, !createIf, // quiet
162  createIf));
163  if (ptr.isValid()) {
164  psvc = ptr.get();
165  psvc->addRef();
166  return StatusCode::SUCCESS;
167  }
168  // else
169  psvc = 0;
170  return StatusCode::FAILURE;
171  }
172 
175  template <class T>
176  StatusCode service( const std::string& svcType, const std::string& svcName,
177  T*& psvc) const {
178  return service(svcType + "/" + svcName, psvc);
179  }
180  // ==========================================================================
209  template <class T>
210  Property* declareProperty
211  ( const std::string& name ,
212  T& property ,
213  const std::string& doc = "none" ) const
214  {
215  return m_propertyMgr -> declareProperty ( name , property , doc ) ;
216  }
217  // ==========================================================================
226  Property* declareRemoteProperty
227  ( const std::string& name ,
228  IProperty* rsvc ,
229  const std::string& rname = "" ) const
230  {
231  return m_propertyMgr -> declareRemoteProperty ( name , rsvc , rname ) ;
232  }
233  // ==========================================================================
237  SmartIF<IAuditorSvc>& auditorSvc() const;
238 
239 protected:
241  virtual ~Service();
248 
250  int outputLevel() const { return m_outputLevel.value(); }
251 
252 private:
254  std::string m_name;
260 
261  void setServiceManager(ISvcManager* ism);
262 
272 
274  void initOutputLevel(Property& prop);
275 };
276 
277 #ifndef GAUDI_NEW_PLUGIN_SERVICE
278 template <class T>
279 class SvcFactory {
280 public:
281 #ifndef __REFLEX__
282  template <typename S, typename... Args>
283  static typename S::ReturnType create(Args... args) {
284  return new T(args...);
285  }
286 #endif
287 };
288 
289 // Macros to declare component factories
290 #define DECLARE_SERVICE_FACTORY(x) \
291  DECLARE_FACTORY_WITH_CREATOR(x, SvcFactory< x >, Service::Factory)
292 #define DECLARE_NAMED_SERVICE_FACTORY(x, n) \
293  DECLARE_FACTORY_WITH_CREATOR_AND_ID(x, SvcFactory< x >, #n, Service::Factory)
294 #define DECLARE_NAMESPACE_SERVICE_FACTORY(n, x) \
295  DECLARE_SERVICE_FACTORY(n::x)
296 
297 #else
298 
299 // macros to declare factories
300 #define DECLARE_SERVICE_FACTORY(x) DECLARE_COMPONENT(x)
301 #define DECLARE_NAMED_SERVICE_FACTORY(x, n) DECLARE_COMPONENT_WITH_ID(x, #n)
302 #define DECLARE_NAMESPACE_SERVICE_FACTORY(n, x) DECLARE_COMPONENT(n::x)
303 
304 #endif
305 
306 #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:50
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:265
Gaudi::StateMachine::State m_targetState
Service state.
Definition: Service.h:247
an helper to share the implementation of service() among the various kernel base classes $Id: ...
IntegerProperty m_outputLevel
Service output level.
Definition: Service.h:243
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:266
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:245
SmartIF< IAuditorSvc > m_pAuditorSvc
Auditor Service.
Definition: Service.h:264
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:250
SmartIF< ISvcLocator > m_svcLocator
Service Locator reference.
Definition: Service.h:256
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
std::string m_name
Service Name.
Definition: Service.h:254
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
static S::ReturnType create(Args...args)
Definition: Service.h:283
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
bool m_auditorFinalize
Definition: Service.h:269
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
bool m_auditorReinitialize
Definition: Service.h:270
virtual StatusCode terminate()
Initialization (from CONFIGURED to OFFLINE).
Definition: Service.h:55
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
Definition: Service.h:56
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:176
PropertyMgr * m_propertyMgr
Property Manager.
Definition: Service.h:259
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
virtual unsigned long release()=0
Release Interface instance.
list args
Definition: gaudirun.py:254
bool m_auditorStart
Definition: Service.h:267
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:47
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:142
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:257
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:57
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::Factory< IService *, const std::string &, ISvcLocator * > Factory
Definition: Service.h:38
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Definition: Service.h:158
bool m_auditorRestart
Definition: Service.h:271
bool m_auditorStop
Definition: Service.h:268
tuple start
Definition: IOTest.py:88