Mercurial > hg > orthanc
changeset 1134:ba9fd42284d0
preparing storage plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Sep 2014 12:53:49 +0200 |
parents | 382e162c074c |
children | 67c3c1e4a6e0 |
files | Core/FileStorage/CompressedFileStorageAccessor.cpp Core/FileStorage/CompressedFileStorageAccessor.h OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/main.cpp UnitTestsSources/ServerIndexTests.cpp |
diffstat | 6 files changed, 63 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/FileStorage/CompressedFileStorageAccessor.cpp Tue Sep 09 10:45:14 2014 +0200 +++ b/Core/FileStorage/CompressedFileStorageAccessor.cpp Tue Sep 09 12:53:49 2014 +0200 @@ -56,7 +56,7 @@ { case CompressionType_None: { - std::string uuid = storage_.Create(data, size, type); + std::string uuid = GetStorageArea().Create(data, size, type); return FileInfo(uuid, type, size, md5); } @@ -75,11 +75,11 @@ std::string uuid; if (compressed.size() > 0) { - uuid = storage_.Create(&compressed[0], compressed.size(), type); + uuid = GetStorageArea().Create(&compressed[0], compressed.size(), type); } else { - uuid = storage_.Create(NULL, 0, type); + uuid = GetStorageArea().Create(NULL, 0, type); } return FileInfo(uuid, type, size, md5, @@ -91,12 +91,32 @@ } } + + CompressedFileStorageAccessor::CompressedFileStorageAccessor() : + storage_(NULL), + compressionType_(CompressionType_None) + { + } + + CompressedFileStorageAccessor::CompressedFileStorageAccessor(IStorageArea& storage) : - storage_(storage) + storage_(&storage), + compressionType_(CompressionType_None) { - compressionType_ = CompressionType_None; } + + IStorageArea& CompressedFileStorageAccessor::GetStorageArea() + { + if (storage_ == NULL) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + + return *storage_; + } + + void CompressedFileStorageAccessor::Read(std::string& content, const std::string& uuid, FileContentType type) @@ -104,13 +124,13 @@ switch (compressionType_) { case CompressionType_None: - storage_.Read(content, uuid, type); + GetStorageArea().Read(content, uuid, type); break; case CompressionType_Zlib: { std::string compressed; - storage_.Read(compressed, uuid, type); + GetStorageArea().Read(compressed, uuid, type); zlib_.Uncompress(content, compressed); break; } @@ -127,14 +147,14 @@ { case CompressionType_None: { - FileStorageAccessor uncompressedAccessor(storage_); + FileStorageAccessor uncompressedAccessor(GetStorageArea()); return uncompressedAccessor.ConstructHttpFileSender(uuid, type); } case CompressionType_Zlib: { std::string compressed; - storage_.Read(compressed, uuid, type); + GetStorageArea().Read(compressed, uuid, type); std::auto_ptr<BufferHttpSender> sender(new BufferHttpSender); zlib_.Uncompress(sender->GetBuffer(), compressed); @@ -146,4 +166,11 @@ throw OrthancException(ErrorCode_NotImplemented); } } + + + void CompressedFileStorageAccessor::Remove(const std::string& uuid, + FileContentType type) + { + GetStorageArea().Remove(uuid, type); + } }
--- a/Core/FileStorage/CompressedFileStorageAccessor.h Tue Sep 09 10:45:14 2014 +0200 +++ b/Core/FileStorage/CompressedFileStorageAccessor.h Tue Sep 09 12:53:49 2014 +0200 @@ -41,7 +41,7 @@ class CompressedFileStorageAccessor : public StorageAccessor { private: - IStorageArea& storage_; + IStorageArea* storage_; ZlibCompressor zlib_; CompressionType compressionType_; @@ -51,8 +51,22 @@ FileContentType type); public: + CompressedFileStorageAccessor(); + CompressedFileStorageAccessor(IStorageArea& storage); + void SetStorageArea(IStorageArea& storage) + { + storage_ = &storage; + } + + bool HasStorageArea() const + { + return storage_ != NULL; + } + + IStorageArea& GetStorageArea(); + void SetCompressionForNextOperations(CompressionType compression) { compressionType_ = compression; @@ -71,9 +85,6 @@ FileContentType type); virtual void Remove(const std::string& uuid, - FileContentType type) - { - storage_.Remove(uuid, type); - } + FileContentType type); }; }
--- a/OrthancServer/ServerContext.cpp Tue Sep 09 10:45:14 2014 +0200 +++ b/OrthancServer/ServerContext.cpp Tue Sep 09 12:53:49 2014 +0200 @@ -71,10 +71,8 @@ namespace Orthanc { - ServerContext::ServerContext(IStorageArea& storage, - const boost::filesystem::path& indexPath) : + ServerContext::ServerContext(const boost::filesystem::path& indexPath) : index_(*this, indexPath.string()), - accessor_(storage), compressionEnabled_(false), provider_(*this), dicomCache_(provider_, DICOM_CACHE_SIZE),
--- a/OrthancServer/ServerContext.h Tue Sep 09 10:45:14 2014 +0200 +++ b/OrthancServer/ServerContext.h Tue Sep 09 12:53:49 2014 +0200 @@ -134,8 +134,12 @@ }; - ServerContext(IStorageArea& storage, - const boost::filesystem::path& indexPath); + ServerContext(const boost::filesystem::path& indexPath); + + void SetStorageArea(IStorageArea& storage) + { + accessor_.SetStorageArea(storage); + } ServerIndex& GetIndex() {
--- a/OrthancServer/main.cpp Tue Sep 09 10:45:14 2014 +0200 +++ b/OrthancServer/main.cpp Tue Sep 09 12:53:49 2014 +0200 @@ -376,7 +376,8 @@ FilesystemStorage storage(storageDirectory.string()); //FilesystemStorageWithoutDicom storage(storageDirectory.string()); - ServerContext context(storage, indexDirectory); + ServerContext context(indexDirectory); + context.SetStorageArea(storage); LOG(WARNING) << "Storage directory: " << storageDirectory; LOG(WARNING) << "Index directory: " << indexDirectory;
--- a/UnitTestsSources/ServerIndexTests.cpp Tue Sep 09 10:45:14 2014 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Tue Sep 09 12:53:49 2014 +0200 @@ -573,7 +573,8 @@ Toolbox::RemoveFile(path + "/index"); FilesystemStorage storage(path); - ServerContext context(storage, ":memory:"); // The SQLite DB is in memory + ServerContext context(":memory:"); // The SQLite DB is in memory + context.SetStorageArea(storage); ServerIndex& index = context.GetIndex(); index.SetMaximumStorageSize(10);