fw4spl
ActiveWorkers.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWSERVICES_REGISTRY_ACTIVEWORKERS_HPP__
8 #define __FWSERVICES_REGISTRY_ACTIVEWORKERS_HPP__
9 
10 #include "fwServices/config.hpp"
11 
12 #include <fwCore/mt/types.hpp>
13 
14 #include <fwThread/Worker.hpp>
15 
16 namespace fwServices
17 {
18 namespace registry
19 {
20 
24 class FWSERVICES_CLASS_API ActiveWorkers : public ::fwCore::BaseObject
25 {
26 
27 public:
28 
30  (()),
31  std::make_shared< ActiveWorkers >);
32 
33  typedef std::string WorkerKeyType;
34 
35  typedef std::map< WorkerKeyType, ::fwThread::Worker::sptr > WorkerMapType;
36 
38  FWSERVICES_API static const std::string s_DEFAULT_WORKER;
39 
41  FWSERVICES_API ActiveWorkers();
42 
44  FWSERVICES_API virtual ~ActiveWorkers();
45 
50  FWSERVICES_API ::fwThread::Worker::sptr getWorker( const WorkerKeyType& key ) const;
51 
53  FWSERVICES_API static void setDefaultWorker( ::fwThread::Worker::sptr worker );
54 
59  static FWSERVICES_API ::fwThread::Worker::sptr getDefaultWorker();
60 
65  FWSERVICES_API void addWorker( const WorkerKeyType& key, ::fwThread::Worker::sptr worker );
66 
71  FWSERVICES_API void initRegistry();
72 
77  FWSERVICES_API void clearRegistry();
78 
80  FWSERVICES_API static ActiveWorkers::sptr getDefault();
81 
82 protected:
83 
85  WorkerMapType m_workers;
86 
88  mutable ::fwCore::mt::ReadWriteMutex m_registryMutex;
89 
91  static ActiveWorkers::sptr s_currentActiveWorkers;
92 
93 };
94 
95 } // namespace registry
96 } // namespace fwServices
97 
98 #endif // __FWSERVICES_REGISTRY_ACTIVEWORKERS_HPP__
static ActiveWorkers::sptr s_currentActiveWorkers
The global instance of the active referenced workers.
Contains fwAtomsFilter::registry details.
WorkerMapType m_workers
Association key <=> worker.
Base class for all FW4SPL&#39;s classes.
Definition: BaseObject.hpp:22
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
This class to register active worker in the system, creates a default worker.
static FWSERVICES_API const std::string s_DEFAULT_WORKER
Key of default worker in registry, created and registered by initRegistry method. ...
mutable::fwCore::mt::ReadWriteMutex m_registryMutex
Used to protect the registry access.
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.