fw4spl
ActiveWorkers.cpp
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 #include "fwServices/registry/ActiveWorkers.hpp"
8 
9 #include "fwCore/util/LazyInstantiator.hpp"
10 
11 namespace fwServices
12 {
13 namespace registry
14 {
15 
16 //-----------------------------------------------------------------------------
17 
18 const std::string ActiveWorkers::s_DEFAULT_WORKER = "DEFAULT_WORKER";
19 
20 //-----------------------------------------------------------------------------
21 
23 {
24 }
25 
26 //-----------------------------------------------------------------------------
27 
29 {
30 }
31 
32 //-----------------------------------------------------------------------------
33 
34 ActiveWorkers::sptr ActiveWorkers::getDefault()
35 {
36  return ::fwCore::util::LazyInstantiator< ActiveWorkers >::getInstance();
37 }
38 
39 //-----------------------------------------------------------------------------
40 
41 ::fwThread::Worker::sptr ActiveWorkers::getWorker( const WorkerKeyType& key ) const
42 {
44 
45  WorkerMapType::const_iterator it = m_workers.find(key);
46 
47  if( it != m_workers.end() )
48  {
49  return it->second;
50  }
51 
52  return ::fwThread::Worker::sptr();
53 }
54 
55 //-----------------------------------------------------------------------------
56 
57 void ActiveWorkers::setDefaultWorker(fwThread::Worker::sptr worker)
58 {
61 }
62 
63 //-----------------------------------------------------------------------------
64 
65 ::fwThread::Worker::sptr ActiveWorkers::getDefaultWorker()
66 {
68 }
69 
70 //-----------------------------------------------------------------------------
71 
72 void ActiveWorkers::addWorker( const WorkerKeyType& key, ::fwThread::Worker::sptr worker )
73 {
75  m_workers.insert( WorkerMapType::value_type(key, worker) );
76 }
77 
78 //-----------------------------------------------------------------------------
79 
81 {
82  this->addWorker( s_DEFAULT_WORKER, ::fwThread::Worker::New() );
83 }
84 
85 //-----------------------------------------------------------------------------
86 
88 {
90  m_workers.clear();
91 }
92 
93 //-----------------------------------------------------------------------------
94 
95 } // namespace registry
96 } // namespace fwServices
97 
FWSERVICES_API ActiveWorkers()
Constructor, does nothing.
Contains fwAtomsFilter::registry details.
WorkerMapType m_workers
Association key <=> worker.
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
virtual FWSERVICES_API ~ActiveWorkers()
Destructor, does nothing.
FWSERVICES_API void clearRegistry()
Unregisters all registered workers, s_DEFAULT_WORKER also.
static FWSERVICES_API void setDefaultWorker(::fwThread::Worker::sptr worker)
Register the default active 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.
FWSERVICES_API void addWorker(const WorkerKeyType &key,::fwThread::Worker::sptr worker)
Registers a worker.
FWSERVICES_API void initRegistry()
Initializes registry, creates and registers the default worker.
static FWSERVICES_API ActiveWorkers::sptr getDefault()
Returns an instance of ActiveWorkers.
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.
FWSERVICES_API::fwThread::Worker::sptr getWorker(const WorkerKeyType &key) const
Get a worker registered with key, if the key does not exist a null sptr is returned.