fw4spl
fwMemory::BufferManager Class Reference

BufferManager implementation. More...

#include <BufferManager.hpp>

+ Inheritance diagram for fwMemory::BufferManager:
+ Collaboration diagram for fwMemory::BufferManager:

Classes

struct  BufferStats
 
struct  StreamInfo
 

Public Types

enum  LoadingModeType { DIRECT, LAZY }
 
typedef void * BufferType
 
typedef const void * ConstBufferType
 
typedef BufferType * BufferPtrType
 
typedef void const *const * ConstBufferPtrType
 
typedef BufferInfo::SizeType SizeType
 
typedef ::fwCom::Signal< void() > UpdatedSignalType
 
typedef std::map< ConstBufferPtrType, BufferInfoBufferInfoMapType
 

Public Member Functions

virtual bool isA (const std::string &type) const override
 
virtual FWMEMORY_API std::shared_future< void > registerBuffer (BufferPtrType bufferPtr)
 Hook called when a new BufferObject is created. More...
 
virtual FWMEMORY_API std::shared_future< void > unregisterBuffer (BufferPtrType bufferPtr)
 Hook called when a BufferObject is destroyed. More...
 
virtual FWMEMORY_API std::shared_future< void > allocateBuffer (BufferPtrType bufferPtr, SizeType size, const ::fwMemory::BufferAllocationPolicy::sptr &policy)
 Hook called when an allocation is requested from a BufferObject. More...
 
virtual FWMEMORY_API std::shared_future< void > setBuffer (BufferPtrType bufferPtr,::fwMemory::BufferManager::BufferType buffer, SizeType size, const ::fwMemory::BufferAllocationPolicy::sptr &policy)
 Hook called when a request is made to set BufferObject's buffer from an external buffer. More...
 
virtual FWMEMORY_API std::shared_future< void > reallocateBuffer (BufferPtrType bufferPtr, SizeType newSize)
 Hook called when a reallocation is requested from a BufferObject. More...
 
virtual FWMEMORY_API std::shared_future< void > destroyBuffer (BufferPtrType bufferPtr)
 Hook called when a destruction is requested from a BufferObject. More...
 
virtual FWMEMORY_API std::shared_future< void > swapBuffer (BufferPtrType bufA, BufferPtrType bufB)
 Hook called when a request to swap two BufferObject contents is made. More...
 
virtual FWMEMORY_API std::shared_future< std::shared_ptr< void > > lockBuffer (ConstBufferPtrType bufferPtr)
 Hook called when a BufferObject is locked. More...
 
virtual FWMEMORY_API std::shared_future< bool > unlockBuffer (ConstBufferPtrType bufferPtr)
 Hook called when a BufferObject lock is released. More...
 
virtual FWMEMORY_API std::shared_future< std::string > toString () const
 returns BufferManager status string
 
std::shared_ptr< UpdatedSignalTypegetUpdatedSignal ()
 Returns a boost::signal emitted when an action has been hooked. More...
 
FWMEMORY_API std::shared_future< BufferInfoMapType > getBufferInfos () const
 Returns the Buffer info map. More...
 
FWMEMORY_API std::shared_future< BufferStatsgetBufferStats () const
 Returns managed buffers statistics.
 
FWMEMORY_API void setDumpPolicy (const std::shared_ptr< ::fwMemory::IPolicy > &policy)
 Sets the dump policy.
 
FWMEMORY_API std::shared_ptr< ::fwMemory::IPolicygetDumpPolicy () const
 Returns the dump policy.
 
FWMEMORY_API std::shared_future< StreamInfogetStreamInfo (const ConstBufferPtrType bufferPtr) const
 Returns stream info.
 
FWMEMORY_API std::shared_future< void > setIStreamFactory (BufferPtrType bufferPtr, const std::shared_ptr< ::fwMemory::stream::in::IFactory > &factory, SizeType size,::fwMemory::FileHolder fsFile,::fwMemory::FileFormatType format, const ::fwMemory::BufferAllocationPolicy::sptr &policy)
 
FWMEMORY_API LoadingModeType getLoadingMode () const
 
FWMEMORY_API void setLoadingMode (LoadingModeType mode)
 
::fwCore::mt::ReadWriteMutexgetMutex () const
 
FWMEMORY_API std::shared_future< bool > dumpBuffer (ConstBufferPtrType bufferPtr)
 Dump/restore a buffer. More...
 
FWMEMORY_API std::shared_future< bool > restoreBuffer (ConstBufferPtrType bufferPtr)
 Dump/restore a buffer. More...
 
FWMEMORY_API std::shared_future< bool > writeBuffer (ConstBufferType buffer, SizeType size,::boost::filesystem::path &path)
 Write/read a buffer. More...
 
FWMEMORY_API std::shared_future< bool > readBuffer (BufferType buffer, SizeType size,::boost::filesystem::path &path)
 Write/read a buffer. More...
 
- Public Member Functions inherited from fwCore::BaseObject
virtual const std::string & getLeafClassname () const
 return object's classname without its namespace, i.e. BaseObject
 

Static Public Member Functions

static bool isTypeOf (const std::string &type)
 
static FWMEMORY_API BufferStats computeBufferStats (const BufferInfoMapType &bufferInfo)
 
static FWMEMORY_API BufferManager::sptr getDefault ()
 Returns the current BufferManager instance. More...
 
- Static Public Member Functions inherited from fwCore::BaseObject
static bool isTypeOf (const std::string &type)
 
static const std::string & leafClassname ()
 return object's classname without its namespace, i.e. BaseObject
 
static const std::string & classname ()
 return object's classname without its namespace, i.e. BaseObject
 

Protected Member Functions

virtual void registerBufferImpl (BufferPtrType bufferPtr)
 BufferManager'a Implementation.
 
virtual void unregisterBufferImpl (BufferPtrType bufferPtr)
 BufferManager'a Implementation.
 
virtual void allocateBufferImpl (BufferPtrType bufferPtr, SizeType size, const ::fwMemory::BufferAllocationPolicy::sptr &policy)
 BufferManager'a Implementation.
 
virtual void setBufferImpl (BufferPtrType bufferPtr,::fwMemory::BufferManager::BufferType buffer, SizeType size, const ::fwMemory::BufferAllocationPolicy::sptr &policy)
 BufferManager'a Implementation.
 
virtual void reallocateBufferImpl (BufferPtrType bufferPtr, SizeType newSize)
 BufferManager'a Implementation.
 
virtual void destroyBufferImpl (BufferPtrType bufferPtr)
 BufferManager'a Implementation.
 
virtual void swapBufferImpl (BufferPtrType bufA, BufferPtrType bufB)
 BufferManager'a Implementation.
 
virtual std::shared_ptr< void > lockBufferImpl (ConstBufferPtrType bufferPtr)
 BufferManager'a Implementation.
 
virtual bool unlockBufferImpl (ConstBufferPtrType bufferPtr)
 BufferManager'a Implementation.
 
virtual std::string toStringImpl () const
 BufferManager'a Implementation.
 
bool dumpBufferImpl (ConstBufferPtrType buffer)
 BufferManager'a Implementation.
 
bool restoreBufferImpl (ConstBufferPtrType buffer)
 BufferManager'a Implementation.
 
bool writeBufferImpl (ConstBufferType buffer, SizeType size,::boost::filesystem::path &path)
 BufferManager'a Implementation.
 
bool readBufferImpl (BufferType buffer, SizeType size,::boost::filesystem::path &path)
 BufferManager'a Implementation.
 
BufferInfoMapType getBufferInfosImpl () const
 BufferManager'a Implementation.
 
StreamInfo getStreamInfoImpl (const ConstBufferPtrType bufferPtr) const
 BufferManager'a Implementation.
 
void setIStreamFactoryImpl (BufferPtrType bufferPtr, const std::shared_ptr< ::fwMemory::stream::in::IFactory > &factory, SizeType size,::fwMemory::FileHolder fsFile,::fwMemory::FileFormatType format, const ::fwMemory::BufferAllocationPolicy::sptr &policy)
 BufferManager'a Implementation.
 
FWMEMORY_API bool dumpBuffer (BufferInfo &info, BufferPtrType bufferPtr)
 Dump/restore a buffer. More...
 
FWMEMORY_API bool restoreBuffer (BufferInfo &info, BufferPtrType bufferPtr, SizeType size=0)
 Dump/restore a buffer. More...
 

Protected Attributes

std::shared_ptr< UpdatedSignalTypem_updatedSig
 
::fwCore::LogicStamp m_lastAccess
 
BufferInfoMapType m_bufferInfos
 
std::shared_ptr< ::fwMemory::IPolicym_dumpPolicy
 
LoadingModeType m_loadingMode
 
std::shared_ptr< fwThread::Workerm_worker
 
mutable::fwCore::mt::ReadWriteMutex m_mutex
 Mutex to protect concurrent access in BufferManager.
 

Demangling methods

virtual const std::string & getClassname () const override
 return full object's classname with its namespace, i.e. fwCore::BaseObject
 
static const std::string & classname ()
 return full object's classname with its namespace, i.e. fwCore::BaseObject
 

Detailed Description

BufferManager implementation.

This implementation purpose is to manage memory load, freeing memory and restoring freed buffers as needed.

A dump policy is used to trigger memory freeing process. The restore process is always triggers when a lock is requested on a dumped buffer.

Definition at line 62 of file BufferManager.hpp.

Member Function Documentation

std::shared_future< void > fwMemory::BufferManager::allocateBuffer ( BufferManager::BufferPtrType  bufferPtr,
SizeType  size,
const ::fwMemory::BufferAllocationPolicy::sptr &  policy 
)
virtual

Hook called when an allocation is requested from a BufferObject.

Parameters
bufferPtrBufferObject's buffer pointer
sizerequested size for allocation
policyBufferObject's allocation policy

Definition at line 99 of file BufferManager.cpp.

References allocateBufferImpl().

+ Here is the call graph for this function:

std::shared_future< void > fwMemory::BufferManager::destroyBuffer ( BufferManager::BufferPtrType  bufferPtr)
virtual

Hook called when a destruction is requested from a BufferObject.

Parameters
bufferPtrBufferObject's buffer pointer

Definition at line 226 of file BufferManager.cpp.

References destroyBufferImpl().

+ Here is the call graph for this function:

std::shared_future< bool > fwMemory::BufferManager::dumpBuffer ( BufferManager::ConstBufferPtrType  bufferPtr)

Dump/restore a buffer.

Keeps up to date buffer's information

Parameters
bufferPtrBuffer to dump/restore
Returns
true on success

Definition at line 362 of file BufferManager.cpp.

References dumpBufferImpl().

Referenced by dumpBufferImpl().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool fwMemory::BufferManager::dumpBuffer ( BufferInfo info,
BufferManager::BufferPtrType  bufferPtr 
)
protected

Dump/restore a buffer.

Used by public dump/restoreBuffer methods

Definition at line 378 of file BufferManager.cpp.

References fwTools::System::getTemporaryFolder(), fwMemory::BufferInfo::loaded, OSLM_TRACE, and writeBufferImpl().

+ Here is the call graph for this function:

std::shared_future< BufferManager::BufferInfoMapType > fwMemory::BufferManager::getBufferInfos ( ) const

Returns the Buffer info map.

Returns

Definition at line 577 of file BufferManager.cpp.

References getBufferInfosImpl().

+ Here is the call graph for this function:

BufferManager::sptr fwMemory::BufferManager::getDefault ( )
static

Returns the current BufferManager instance.

Note
This method is thread-safe.

Definition at line 40 of file BufferManager.cpp.

Referenced by monitorQt::DumpEditor::changeStatus(), fwDcmtkIO::reader::ImageStorageReader::read(), memory::Plugin::start(), memory::SDumpPolicy::starting(), monitorQt::DumpEditor::starting(), monitor::action::SDumpAll::updating(), and monitor::action::MemoryInfo::updating().

+ Here is the caller graph for this function:

std::shared_ptr< UpdatedSignalType > fwMemory::BufferManager::getUpdatedSignal ( )
inline

Returns a boost::signal emitted when an action has been hooked.

Returns

Definition at line 225 of file BufferManager.hpp.

References SPTR.

std::shared_future< std::shared_ptr< void > > fwMemory::BufferManager::lockBuffer ( BufferManager::ConstBufferPtrType  bufferPtr)
virtual

Hook called when a BufferObject is locked.

Parameters
bufferPtrBufferObject's buffer pointer
Returns
false if the BufferManager supported the action

Definition at line 316 of file BufferManager.cpp.

References lockBufferImpl(), and SPTR.

+ Here is the call graph for this function:

std::shared_future< bool > fwMemory::BufferManager::readBuffer ( BufferManager::BufferType  buffer,
SizeType  size,
::boost::filesystem::path &  path 
)

Write/read a buffer.

The buffer is written/read in a raw format

Parameters
bufferBuffer to write/read
sizeBuffer's size
pathfile to write/read
Returns
true on success

Definition at line 497 of file BufferManager.cpp.

References readBufferImpl().

+ Here is the call graph for this function:

std::shared_future< void > fwMemory::BufferManager::reallocateBuffer ( BufferManager::BufferPtrType  bufferPtr,
SizeType  newSize 
)
virtual

Hook called when a reallocation is requested from a BufferObject.

Parameters
bufferPtrBufferObject's buffer pointer
newSizerequested size for reallocation

Definition at line 183 of file BufferManager.cpp.

References reallocateBufferImpl().

+ Here is the call graph for this function:

std::shared_future< void > fwMemory::BufferManager::registerBuffer ( BufferManager::BufferPtrType  bufferPtr)
virtual

Hook called when a new BufferObject is created.

Parameters
bufferPtrBufferObject's buffer pointer.

Definition at line 65 of file BufferManager.cpp.

References registerBufferImpl().

+ Here is the call graph for this function:

std::shared_future< bool > fwMemory::BufferManager::restoreBuffer ( BufferManager::ConstBufferPtrType  bufferPtr)

Dump/restore a buffer.

Keeps up to date buffer's information

Parameters
bufferPtrBuffer to dump/restore
Returns
true on success

Definition at line 411 of file BufferManager.cpp.

References restoreBufferImpl().

Referenced by reallocateBufferImpl(), restoreBufferImpl(), and setIStreamFactoryImpl().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool fwMemory::BufferManager::restoreBuffer ( BufferInfo info,
BufferManager::BufferPtrType  bufferPtr,
BufferManager::SizeType  allocSize = 0 
)
protected

Dump/restore a buffer.

Used by public dump/restoreBuffer methods

Definition at line 427 of file BufferManager.cpp.

References fwMemory::BufferInfo::loaded, fwCore::LogicStamp::modified(), OSLM_TRACE, and SPTR.

+ Here is the call graph for this function:

std::shared_future< void > fwMemory::BufferManager::setBuffer ( BufferManager::BufferPtrType  bufferPtr,
::fwMemory::BufferManager::BufferType  buffer,
SizeType  size,
const ::fwMemory::BufferAllocationPolicy::sptr &  policy 
)
virtual

Hook called when a request is made to set BufferObject's buffer from an external buffer.

Parameters
bufferPtrBufferObject's buffer pointer
buffernew buffer
sizerequested size for allocation
policyBufferObject's allocation policy

Definition at line 142 of file BufferManager.cpp.

References setBufferImpl().

+ Here is the call graph for this function:

std::shared_future< void > fwMemory::BufferManager::swapBuffer ( BufferManager::BufferPtrType  bufA,
BufferManager::BufferPtrType  bufB 
)
virtual

Hook called when a request to swap two BufferObject contents is made.

Parameters
bufAFirst BufferObject's buffer
bufBSecond BufferObject's buffer

Definition at line 252 of file BufferManager.cpp.

References swapBufferImpl().

+ Here is the call graph for this function:

std::shared_future< bool > fwMemory::BufferManager::unlockBuffer ( BufferManager::ConstBufferPtrType  bufferPtr)
virtual

Hook called when a BufferObject lock is released.

Parameters
bufferPtrBufferObject's buffer pointer
Returns
false if the BufferManager supported the action

Definition at line 344 of file BufferManager.cpp.

References unlockBufferImpl().

+ Here is the call graph for this function:

std::shared_future< void > fwMemory::BufferManager::unregisterBuffer ( BufferManager::BufferPtrType  bufferPtr)
virtual

Hook called when a BufferObject is destroyed.

Parameters
bufferPtrBufferObject's buffer pointer.

Definition at line 80 of file BufferManager.cpp.

References unregisterBufferImpl().

+ Here is the call graph for this function:

std::shared_future< bool > fwMemory::BufferManager::writeBuffer ( BufferManager::ConstBufferType  buffer,
SizeType  size,
::boost::filesystem::path &  path 
)

Write/read a buffer.

The buffer is written/read in a raw format

Parameters
bufferBuffer to write/read
sizeBuffer's size
pathfile to write/read
Returns
true on success

Definition at line 475 of file BufferManager.cpp.

References writeBufferImpl().

+ Here is the call graph for this function:


The documentation for this class was generated from the following files: