7 #ifndef __FWMEMORY_BUFFERMANAGER_HPP__ 8 #define __FWMEMORY_BUFFERMANAGER_HPP__ 10 #include "fwMemory/BufferInfo.hpp" 11 #include "fwMemory/config.hpp" 12 #include "fwMemory/FileHolder.hpp" 14 #include <fwCom/Signal.hpp> 16 #include <fwCore/base.hpp> 17 #include <fwCore/BaseObject.hpp> 18 #include <fwCore/mt/types.hpp> 20 #include <boost/filesystem/path.hpp> 66 typedef void* BufferType;
67 typedef const void* ConstBufferType;
68 typedef BufferType* BufferPtrType;
69 typedef void const*
const* ConstBufferPtrType;
71 typedef BufferInfo::SizeType SizeType;
75 typedef std::map< ConstBufferPtrType, BufferInfo > BufferInfoMapType;
92 SizeType totalManaged;
98 SPTR(std::istream) stream;
112 FWMEMORY_API
virtual std::shared_future<void> registerBuffer(BufferPtrType bufferPtr);
119 FWMEMORY_API
virtual std::shared_future<void> unregisterBuffer(BufferPtrType bufferPtr);
128 FWMEMORY_API
virtual std::shared_future<void> allocateBuffer(BufferPtrType bufferPtr, SizeType size,
129 const ::fwMemory::BufferAllocationPolicy::sptr& policy);
139 FWMEMORY_API
virtual std::shared_future<void> setBuffer(BufferPtrType bufferPtr,
140 ::fwMemory::BufferManager::BufferType buffer,
142 const ::fwMemory::BufferAllocationPolicy::sptr& policy);
150 FWMEMORY_API
virtual std::shared_future<void> reallocateBuffer(BufferPtrType bufferPtr, SizeType newSize);
157 FWMEMORY_API
virtual std::shared_future<void> destroyBuffer(BufferPtrType bufferPtr);
165 FWMEMORY_API
virtual std::shared_future<void> swapBuffer(BufferPtrType bufA, BufferPtrType bufB);
174 FWMEMORY_API
virtual std::shared_future<SPTR(void)> lockBuffer(ConstBufferPtrType bufferPtr);
183 FWMEMORY_API
virtual std::shared_future<bool> unlockBuffer(ConstBufferPtrType bufferPtr);
188 FWMEMORY_API
virtual std::shared_future<std::string> toString()
const;
199 FWMEMORY_API std::shared_future<bool> dumpBuffer(ConstBufferPtrType bufferPtr);
200 FWMEMORY_API std::shared_future<bool> restoreBuffer(ConstBufferPtrType bufferPtr);
214 FWMEMORY_API std::shared_future<bool> writeBuffer(ConstBufferType buffer, SizeType size,
215 ::boost::filesystem::path& path);
216 FWMEMORY_API std::shared_future<bool> readBuffer(BufferType buffer, SizeType size,
217 ::boost::filesystem::path& path);
225 SPTR(UpdatedSignalType) getUpdatedSignal(){
234 FWMEMORY_API std::shared_future<BufferInfoMapType> getBufferInfos()
const;
239 FWMEMORY_API std::shared_future<BufferStats> getBufferStats()
const;
240 FWMEMORY_API
static BufferStats computeBufferStats(
const BufferInfoMapType& bufferInfo);
255 FWMEMORY_API std::shared_future<StreamInfo> getStreamInfo(
const ConstBufferPtrType bufferPtr)
const;
257 FWMEMORY_API std::shared_future<void> setIStreamFactory(BufferPtrType bufferPtr,
261 ::fwMemory::FileFormatType format,
262 const ::fwMemory::BufferAllocationPolicy::sptr& policy
265 FWMEMORY_API LoadingModeType getLoadingMode()
const;
266 FWMEMORY_API
void setLoadingMode(LoadingModeType mode);
272 FWMEMORY_API
static BufferManager::sptr getDefault();
283 virtual void registerBufferImpl(BufferPtrType bufferPtr);
284 virtual void unregisterBufferImpl(BufferPtrType bufferPtr);
285 virtual void allocateBufferImpl(BufferPtrType bufferPtr, SizeType size,
286 const ::fwMemory::BufferAllocationPolicy::sptr& policy);
287 virtual void setBufferImpl(BufferPtrType bufferPtr, ::fwMemory::BufferManager::BufferType buffer, SizeType size,
288 const ::fwMemory::BufferAllocationPolicy::sptr& policy);
289 virtual void reallocateBufferImpl(BufferPtrType bufferPtr, SizeType newSize);
290 virtual void destroyBufferImpl(BufferPtrType bufferPtr);
291 virtual void swapBufferImpl(BufferPtrType bufA, BufferPtrType bufB);
292 virtual SPTR(
void) lockBufferImpl(ConstBufferPtrType bufferPtr);
293 virtual bool unlockBufferImpl(ConstBufferPtrType bufferPtr);
294 virtual std::string toStringImpl()
const;
295 bool dumpBufferImpl(ConstBufferPtrType buffer);
296 bool restoreBufferImpl(ConstBufferPtrType buffer);
297 bool writeBufferImpl(ConstBufferType buffer, SizeType size, ::boost::filesystem::path& path);
298 bool readBufferImpl(BufferType buffer, SizeType size, ::boost::filesystem::path& path);
299 BufferInfoMapType getBufferInfosImpl()
const;
300 StreamInfo getStreamInfoImpl(
const ConstBufferPtrType bufferPtr)
const;
301 void setIStreamFactoryImpl(BufferPtrType bufferPtr,
305 ::fwMemory::FileFormatType format,
306 const ::fwMemory::BufferAllocationPolicy::sptr& policy
315 FWMEMORY_API
bool dumpBuffer(
BufferInfo& info, BufferPtrType bufferPtr);
316 FWMEMORY_API
bool restoreBuffer(
BufferInfo& info, BufferPtrType bufferPtr, SizeType size = 0);
319 SPTR(UpdatedSignalType) m_updatedSig;
322 BufferInfoMapType m_bufferInfos;
326 LoadingModeType m_loadingMode;
::fwMemory::FileFormatType format
format of the dumped file
#define fwCoreNonInstanciableClassDefinitionsMacro(_classinfo_)
Generate common code for Non Instanciable classes (Interfaces, Abstract classes, ...)
Base class for all FW4SPL's classes.
::boost::shared_mutex ReadWriteMutex
Defines a single writer, multiple readers mutex.
The namespace fwMemory contains tools to manage memory. Use for dump.
Contains fwAtomsFilter::factory utilities.
bool userStream
true if stream has been set by the user
mutable::fwCore::mt::ReadWriteMutex m_mutex
Mutex to protect concurrent access in BufferManager.
BufferManager implementation.
#define fwCoreAllowSharedFromThis()
Generate getSptr and getConstSptr methods.
Provides a Logical timestamp system.
This class creates and manages a task loop. The default implementation create a loop in a new thread...
This namespace fwThread provides few tools to execute asynchronous tasks on different threads...
Defines the memory dump policy interface.
::fwMemory::FileHolder fsFile
path of the file containing the dumped buffer