fw4spl
AlwaysDump.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 "fwMemory/policy/AlwaysDump.hpp"
8 #include "fwMemory/policy/BarrierDump.hpp"
9 #include "fwMemory/policy/registry/macros.hpp"
10 
11 
12 namespace fwMemory
13 {
14 
15 namespace policy
16 {
17 
18 fwMemoryPolicyRegisterMacro(::fwMemory::policy::AlwaysDump);
19 
20 //------------------------------------------------------------------------------
21 
22 void AlwaysDump::allocationRequest( BufferInfo &info, ::fwMemory::BufferManager::ConstBufferPtrType buffer,
23  BufferInfo::SizeType size )
24 {
25  FwCoreNotUsedMacro(info);
26  FwCoreNotUsedMacro(buffer);
27  FwCoreNotUsedMacro(size);
28  this->apply();
29 }
30 
31 //------------------------------------------------------------------------------
32 
33 void AlwaysDump::setRequest( BufferInfo &info, ::fwMemory::BufferManager::ConstBufferPtrType buffer,
34  BufferInfo::SizeType size )
35 {
36  FwCoreNotUsedMacro(info);
37  FwCoreNotUsedMacro(buffer);
38  FwCoreNotUsedMacro(size);
39  this->apply();
40 }
41 
42 //------------------------------------------------------------------------------
43 
44 void AlwaysDump::reallocateRequest( BufferInfo &info, ::fwMemory::BufferManager::ConstBufferPtrType buffer,
45  BufferInfo::SizeType newSize )
46 {
47  FwCoreNotUsedMacro(info);
48  FwCoreNotUsedMacro(buffer);
49  FwCoreNotUsedMacro(newSize);
50  this->apply();
51 }
52 
53 //------------------------------------------------------------------------------
54 
55 void AlwaysDump::destroyRequest( BufferInfo &info, ::fwMemory::BufferManager::ConstBufferPtrType buffer )
56 {
57  FwCoreNotUsedMacro(info);
58  FwCoreNotUsedMacro(buffer);
59  this->apply();
60 }
61 
62 //------------------------------------------------------------------------------
63 
64 void AlwaysDump::lockRequest( BufferInfo &info, ::fwMemory::BufferManager::ConstBufferPtrType buffer )
65 {
66  FwCoreNotUsedMacro(info);
67  FwCoreNotUsedMacro(buffer);
68  this->apply();
69 }
70 
71 //------------------------------------------------------------------------------
72 
73 void AlwaysDump::unlockRequest( BufferInfo &info, ::fwMemory::BufferManager::ConstBufferPtrType buffer )
74 {
75  FwCoreNotUsedMacro(info);
76  FwCoreNotUsedMacro(buffer);
77  this->apply();
78 }
79 
80 //------------------------------------------------------------------------------
81 
82 void AlwaysDump::dumpSuccess( BufferInfo &info, ::fwMemory::BufferManager::ConstBufferPtrType buffer )
83 {
84  FwCoreNotUsedMacro(info);
85  FwCoreNotUsedMacro(buffer);
86 }
87 
88 //------------------------------------------------------------------------------
89 
90 void AlwaysDump::restoreSuccess( BufferInfo &info, ::fwMemory::BufferManager::ConstBufferPtrType buffer )
91 {
92  FwCoreNotUsedMacro(info);
93  FwCoreNotUsedMacro(buffer);
94 }
95 
96 //------------------------------------------------------------------------------
97 
98 size_t AlwaysDump::dump()
99 {
100  size_t dumped = 0;
101 
102  ::fwMemory::BufferManager::sptr manager = ::fwMemory::BufferManager::getDefault();
103  if(manager)
104  {
105  const ::fwMemory::BufferManager::BufferInfoMapType bufferInfos = manager->getBufferInfos().get();
106 
107  for(const ::fwMemory::BufferManager::BufferInfoMapType::value_type &elt : bufferInfos)
108  {
109  const ::fwMemory::BufferInfo &info = elt.second;
110  if( !( info.size == 0 || info.lockCount() > 0 || !info.loaded ) )
111  {
112  if( manager->dumpBuffer(elt.first).get() )
113  {
114  dumped += elt.second.size;
115  }
116  }
117  }
118  }
119 
120  return dumped;
121 }
122 
123 //------------------------------------------------------------------------------
124 
125 void AlwaysDump::apply()
126 {
127  this->dump();
128 }
129 
130 //------------------------------------------------------------------------------
131 
132 void AlwaysDump::refresh()
133 {
134  this->apply();
135 }
136 
137 //------------------------------------------------------------------------------
138 
139 std::string AlwaysDump::getParam(const std::string &name, bool *ok ) const
140 {
141  FwCoreNotUsedMacro(name);
142  if (ok)
143  {
144  *ok = false;
145  }
146  return "";
147 }
148 
149 //------------------------------------------------------------------------------
150 
151 
152 } // namespace policy
153 
154 } //namespace fwMemory
The namespace fwMemory contains tools to manage memory. Use for dump.
Definition: SReader.hpp:20
static FWMEMORY_API BufferManager::sptr getDefault()
Returns the current BufferManager instance.
Always dump policy.
Definition: AlwaysDump.hpp:28