Mercurial > hg > orthanc
diff OrthancServer/OrthancInitialization.cpp @ 1274:b9e2ed59cae4
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 21 Jan 2015 17:32:53 +0100 |
parents | 0479d02c6778 |
children | 4287285709d1 |
line wrap: on
line diff
--- a/OrthancServer/OrthancInitialization.cpp Mon Jan 19 16:08:58 2015 +0100 +++ b/OrthancServer/OrthancInitialization.cpp Wed Jan 21 17:32:53 2015 +0100 @@ -45,6 +45,9 @@ #include <boost/thread.hpp> #include <glog/logging.h> +#include "DatabaseWrapper.h" +#include "../Core/FileStorage/FilesystemStorage.h" + #if ORTHANC_JPEG_ENABLED == 1 #include <dcmtk/dcmjpeg/djdecode.h> @@ -654,4 +657,108 @@ { return configurationAbsolutePath_; } + + + static IDatabaseWrapper* CreateSQLiteWrapper() + { + std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); + + // Open the database + boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath( + Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr)); + + LOG(WARNING) << "SQLite index directory: " << indexDirectory; + + try + { + boost::filesystem::create_directories(indexDirectory); + } + catch (boost::filesystem::filesystem_error) + { + } + + return new DatabaseWrapper(indexDirectory.string() + "/index"); + } + + + namespace + { + // Anonymous namespace to avoid clashes between compilation modules + + class FilesystemStorageWithoutDicom : public IStorageArea + { + private: + FilesystemStorage storage_; + + public: + FilesystemStorageWithoutDicom(const std::string& path) : storage_(path) + { + } + + virtual void Create(const std::string& uuid, + const void* content, + size_t size, + FileContentType type) + { + if (type != FileContentType_Dicom) + { + storage_.Create(uuid, content, size, type); + } + } + + virtual void Read(std::string& content, + const std::string& uuid, + FileContentType type) + { + if (type != FileContentType_Dicom) + { + storage_.Read(content, uuid, type); + } + else + { + throw OrthancException(ErrorCode_UnknownResource); + } + } + + virtual void Remove(const std::string& uuid, + FileContentType type) + { + if (type != FileContentType_Dicom) + { + storage_.Remove(uuid, type); + } + } + }; + } + + + static IStorageArea* CreateFilesystemStorage() + { + std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); + + boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr); + LOG(WARNING) << "Storage directory: " << storageDirectory; + + if (Configuration::GetGlobalBoolParameter("StoreDicom", true)) + { + return new FilesystemStorage(storageDirectory.string()); + } + else + { + LOG(WARNING) << "The DICOM files will not be stored, Orthanc running in index-only mode"; + return new FilesystemStorageWithoutDicom(storageDirectory.string()); + } + } + + + IDatabaseWrapper* Configuration::CreateDatabaseWrapper() + { + return CreateSQLiteWrapper(); + } + + + IStorageArea* Configuration::CreateStorageArea() + { + return CreateFilesystemStorage(); + } }