| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/ServiceLocatorHelper.h"
9 #include "GaudiKernel/IProperty.h"
10 #include "GaudiKernel/IStateful.h"
11 #include "GaudiKernel/PropertyMgr.h"
12 #include "GaudiKernel/Property.h"
13 #include "GaudiKernel/IAuditorSvc.h"
14 #include "GaudiKernel/CommonMessaging.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 typedef Gaudi::PluginService::Factory2<IService*,
36 const std::string&,
37 ISvcLocator*> Factory;
38 friend class ServiceManager;
39
42 virtual unsigned long release();
43
45 virtual const std::string& name() const;
46
47 // State machine implementation
48 virtual StatusCode configure() { return StatusCode::SUCCESS; }
49 virtual StatusCode initialize();
50 virtual StatusCode start();
51 virtual StatusCode stop();
52 virtual StatusCode finalize();
53 virtual StatusCode terminate() { return StatusCode::SUCCESS; }
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>
122 StatusCode setProperty
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);
130 SmartIF<ISvcLocator>& serviceLocator() const;
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();
241 IntegerProperty m_outputLevel;
243 Gaudi::StateMachine::State m_state;
245 Gaudi::StateMachine::State m_targetState;
246
248 int outputLevel() const { return m_outputLevel.value(); }
249
250 private:
252 std::string m_name;
254 mutable SmartIF<ISvcLocator> m_svcLocator;
255 SmartIF<ISvcManager> m_svcManager;
257 PropertyMgr* m_propertyMgr;
258
259 void setServiceManager(ISvcManager* ism);
260
262 mutable SmartIF<IAuditorSvc> m_pAuditorSvc;
263 BooleanProperty m_auditInit;
264 bool m_auditorInitialize;
265 bool m_auditorStart;
266 bool m_auditorStop;
267 bool m_auditorFinalize;
268 bool m_auditorReinitialize;
269 bool m_auditorRestart;
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