2015-04-15 19:05:58 +02:00
|
|
|
#include "CachedBlock.h"
|
2015-04-16 14:10:44 +02:00
|
|
|
#include "CachingBlockStore.h"
|
2015-04-15 19:05:58 +02:00
|
|
|
|
2015-04-15 20:39:58 +02:00
|
|
|
using std::unique_ptr;
|
2015-04-15 19:05:58 +02:00
|
|
|
using std::make_unique;
|
|
|
|
|
|
|
|
namespace blockstore {
|
2015-04-16 14:10:44 +02:00
|
|
|
namespace caching {
|
2015-04-15 19:05:58 +02:00
|
|
|
|
2015-04-16 14:10:44 +02:00
|
|
|
CachedBlock::CachedBlock(std::unique_ptr<Block> baseBlock, CachingBlockStore *blockStore)
|
2015-04-15 19:05:58 +02:00
|
|
|
:Block(baseBlock->key()),
|
|
|
|
_blockStore(blockStore),
|
|
|
|
_baseBlock(std::move(baseBlock)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CachedBlock::~CachedBlock() {
|
2015-04-15 20:39:58 +02:00
|
|
|
if (_baseBlock.get() != nullptr) {
|
|
|
|
_blockStore->release(std::move(_baseBlock));
|
|
|
|
}
|
2015-04-15 19:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const void *CachedBlock::data() const {
|
|
|
|
return _baseBlock->data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CachedBlock::write(const void *source, uint64_t offset, uint64_t size) {
|
|
|
|
return _baseBlock->write(source, offset, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CachedBlock::flush() {
|
|
|
|
return _baseBlock->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CachedBlock::size() const {
|
|
|
|
return _baseBlock->size();
|
|
|
|
}
|
|
|
|
|
2015-04-15 20:39:58 +02:00
|
|
|
unique_ptr<Block> CachedBlock::releaseBlock() {
|
|
|
|
return std::move(_baseBlock);
|
|
|
|
}
|
|
|
|
|
2015-04-15 19:05:58 +02:00
|
|
|
}
|
|
|
|
}
|