fw4spl
SDumpPolicy.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 "memory/SDumpPolicy.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <fwMemory/BufferManager.hpp>
12 #include <fwMemory/IPolicy.hpp>
13 
14 #include <fwServices/macros.hpp>
15 
16 #include <vector>
17 
18 namespace memory
19 {
20 
21 fwServicesRegisterMacro( ::fwServices::IController, ::memory::SDumpPolicy, ::fwData::Object );
22 
23 SDumpPolicy::SDumpPolicy()
24 {
25 }
26 
27 SDumpPolicy::~SDumpPolicy()
28 {
29 }
30 
31 //------------------------------------------------------------------------------
32 
34 {
35  typedef ::fwRuntime::ConfigurationElement::sptr ConfigurationType;
36  std::vector < ConfigurationType > config = m_configuration->find("config");
37 
38  if (!config.empty())
39  {
40  std::vector < ConfigurationType > policy = config.at(0)->find("policy");
41  std::vector < ConfigurationType > paramsElement = config.at(0)->find("params");
42 
43  m_policyParams.clear();
44  m_policy = "";
45 
46  if (!policy.empty())
47  {
48  m_policy = policy.at(0)->getValue();
49  }
50 
51  if(!paramsElement.empty())
52  {
53  const ConfigurationType& params = paramsElement.at(0);
54 
55  ::fwRuntime::ConfigurationElement::Container::const_iterator iter;
56 
57  for (iter = params->begin(); iter != params->end(); ++iter)
58  {
59  m_policyParams.push_back( ParametersType::value_type((*iter)->getName(), (*iter)->getValue()));
60  }
61  }
62  }
63 }
64 
65 //------------------------------------------------------------------------------
66 
68 {
69  ::fwMemory::BufferManager::sptr manager = ::fwMemory::BufferManager::getDefault();
70  if (manager)
71  {
72  ::fwMemory::IPolicy::sptr policy = ::fwMemory::policy::registry::get()->create(m_policy);
73 
74  if (policy)
75  {
76  bool success;
77  for(const ParametersType::value_type& param : m_policyParams)
78  {
79  success = policy->setParam(param.first, param.second);
80  OSLM_ERROR_IF( "[" << m_policy << "] Unable to set '"
81  << param.first << "' parameter to " << param.second,
82  !success);
83  OSLM_INFO_IF("Set '" << param.first << "' policy parameter to " << param.second, success);
84  }
85  ::fwCore::mt::WriteLock lock( manager->getMutex() );
86  manager->setDumpPolicy(policy);
87  OSLM_INFO("Set dump policy to : " << m_policy);
88  }
89  OSLM_ERROR_IF("Unable to instantiate '" << m_policy << "' dump policy", !policy);
90  }
91 }
92 
93 //------------------------------------------------------------------------------
94 
96 {
97 }
98 
99 //------------------------------------------------------------------------------
100 
102 {
103 }
104 
105 //------------------------------------------------------------------------------
106 
108 {
109  this->stopping();
110  this->starting();
111 }
112 
113 } // namespace memory
114 
virtual MEMORY_API void configuring() override
Definition: SDumpPolicy.cpp:33
virtual MEMORY_API void swapping() override
Overrides.
static FWMEMORY_API BufferManager::sptr getDefault()
Returns the current BufferManager instance.
#define OSLM_INFO_IF(message, cond)
Definition: spyLog.hpp:256
#define OSLM_INFO(message)
Definition: spyLog.hpp:252
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
virtual MEMORY_API void updating() override
Overrides.
This interface defines control service API. Does nothing particularly, can be considered as a default...
Definition: IController.hpp:23
virtual MEMORY_API void starting() override
Overrides.
Definition: SDumpPolicy.cpp:67
Base class for each data object.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
The namespace memory contains tools to manage memory. It is used for dump. It allows to define the bu...
virtual MEMORY_API void stopping() override
Overrides.
Definition: SDumpPolicy.cpp:95
#define OSLM_ERROR_IF(message, cond)
Definition: spyLog.hpp:278