fw4spl
BarrierDump.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 __FWMEMORY_POLICY_BARRIERDUMP_HPP__
8 #define __FWMEMORY_POLICY_BARRIERDUMP_HPP__
9 
10 #include "fwMemory/BufferInfo.hpp"
11 #include "fwMemory/BufferManager.hpp"
12 #include "fwMemory/config.hpp"
13 #include "fwMemory/IPolicy.hpp"
14 #include "fwMemory/policy/factory/new.hpp"
15 
16 #include <fwCore/base.hpp>
17 
18 namespace fwMemory
19 {
20 
21 namespace policy
22 {
23 
30 class FWMEMORY_CLASS_API BarrierDump : public ::fwMemory::IPolicy
31 {
32 public:
34  (()),
35  ::fwMemory::policy::factory::New< BarrierDump >)
36  FWMEMORY_API BarrierDump();
37 
38  FWMEMORY_API virtual void allocationRequest( BufferInfo& info,
39  ::fwMemory::BufferManager::ConstBufferPtrType buffer,
40  BufferInfo::SizeType size ) override;
41 
42  FWMEMORY_API virtual void setRequest( BufferInfo& info,
43  ::fwMemory::BufferManager::ConstBufferPtrType buffer,
44  BufferInfo::SizeType size ) override;
45 
46  FWMEMORY_API virtual void reallocateRequest( BufferInfo& info,
47  ::fwMemory::BufferManager::ConstBufferPtrType buffer,
48  BufferInfo::SizeType newSize ) override;
49 
50  FWMEMORY_API virtual void destroyRequest( BufferInfo& info,
51  ::fwMemory::BufferManager::ConstBufferPtrType buffer ) override;
52 
53  FWMEMORY_API virtual void lockRequest( BufferInfo& info,
54  ::fwMemory::BufferManager::ConstBufferPtrType buffer ) override;
55  FWMEMORY_API virtual void unlockRequest( BufferInfo& info,
56  ::fwMemory::BufferManager::ConstBufferPtrType buffer ) override;
57 
58  FWMEMORY_API virtual void dumpSuccess( BufferInfo& info,
59  ::fwMemory::BufferManager::ConstBufferPtrType buffer ) override;
60  FWMEMORY_API virtual void restoreSuccess( BufferInfo& info,
61  ::fwMemory::BufferManager::ConstBufferPtrType buffer ) override;
62 
63  FWMEMORY_API virtual void refresh() override;
64 
65  //------------------------------------------------------------------------------
66 
67  void setBarrier( size_t barrier )
68  {
69  m_barrier = barrier;
70  }
71  //------------------------------------------------------------------------------
72 
73  size_t getBarrier() const
74  {
75  return m_barrier;
76  }
77 
78  FWMEMORY_API virtual std::string getParam(const std::string& name, bool* ok = NULL ) const override;
79  FWMEMORY_API bool setParam(const std::string& name, const std::string& value) override;
80  FWMEMORY_API const fwMemory::IPolicy::ParamNamesType& getParamNames() const override;
81 
82 protected:
83 
84  FWMEMORY_API size_t getTotalAlive() const;
85  FWMEMORY_API bool isBarrierCrossed() const;
86 
87  FWMEMORY_API size_t dump(size_t nbOfBytes);
88 
89  FWMEMORY_API void apply();
90 
91  size_t m_totalAllocated;
92  size_t m_totalDumped;
93  size_t m_barrier;
94 };
95 
96 } // namespace policy
97 
98 } // namespace fwMemory
99 
100 #endif // __FWMEMORY_POLICY_BARRIERDUMP_HPP__
101 
The namespace fwMemory contains tools to manage memory. Use for dump.
Definition: SReader.hpp:20
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
BufferManager implementation.
Barrier dump policy.
Definition: BarrierDump.hpp:30
Defines the memory dump policy interface.
Definition: IPolicy.hpp:23