# HG changeset patch # User Sebastien Jodogne # Date 1421857973 -3600 # Node ID b9e2ed59cae44e6c044f50eb22b7d9905af92150 # Parent 88010d8e12cf0cfda8ee88ba810fd97448cccbf8 refactoring diff -r 88010d8e12cf -r b9e2ed59cae4 NEWS --- a/NEWS Mon Jan 19 16:08:58 2015 +0100 +++ b/NEWS Wed Jan 21 17:32:53 2015 +0100 @@ -8,6 +8,7 @@ * Instances without PatientID are now allowed * Support of Tudor DICOM in Query/Retrieve * Fix issue 25 (AET with underscore not allowed) +* Code refactorings Plugins ------- diff -r 88010d8e12cf -r b9e2ed59cae4 OrthancServer/OrthancInitialization.cpp --- 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 #include +#include "DatabaseWrapper.h" +#include "../Core/FileStorage/FilesystemStorage.h" + #if ORTHANC_JPEG_ENABLED == 1 #include @@ -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(); + } } diff -r 88010d8e12cf -r b9e2ed59cae4 OrthancServer/OrthancInitialization.h --- a/OrthancServer/OrthancInitialization.h Mon Jan 19 16:08:58 2015 +0100 +++ b/OrthancServer/OrthancInitialization.h Wed Jan 21 17:32:53 2015 +0100 @@ -40,6 +40,8 @@ #include "DicomProtocol/RemoteModalityParameters.h" #include "ServerEnumerations.h" #include "OrthancPeerParameters.h" +#include "IDatabaseWrapper.h" +#include "../Core/FileStorage/IStorageArea.h" namespace Orthanc { @@ -102,5 +104,9 @@ static void RemovePeer(const std::string& symbolicName); static const std::string& GetConfigurationAbsolutePath(); + + static IDatabaseWrapper* CreateDatabaseWrapper(); + + static IStorageArea* CreateStorageArea(); }; } diff -r 88010d8e12cf -r b9e2ed59cae4 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Mon Jan 19 16:08:58 2015 +0100 +++ b/OrthancServer/main.cpp Wed Jan 21 17:32:53 2015 +0100 @@ -38,7 +38,6 @@ #include #include "../Core/Uuid.h" -#include "../Core/FileStorage/FilesystemStorage.h" #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" #include "../Core/HttpServer/FilesystemHttpHandler.h" #include "../Core/Lua/LuaFunctionCall.h" @@ -50,7 +49,6 @@ #include "OrthancFindRequestHandler.h" #include "OrthancMoveRequestHandler.h" #include "ServerToolbox.h" -#include "DatabaseWrapper.h" #include "../Plugins/Engine/PluginsManager.h" #include "../Plugins/Engine/OrthancPlugins.h" @@ -383,71 +381,10 @@ -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 bool StartOrthanc() { - std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); - - - // Open the database - boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath( - Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr)); - std::auto_ptr database; - try - { - boost::filesystem::create_directories(indexDirectory); - } - catch (boost::filesystem::filesystem_error) - { - } - - database.reset(new DatabaseWrapper(indexDirectory.string() + "/index")); + database.reset(Configuration::CreateDatabaseWrapper()); // "storage" must be declared BEFORE "ServerContext context", to @@ -456,8 +393,6 @@ ServerContext context(*database); - LOG(WARNING) << "Index directory: " << indexDirectory; - context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); @@ -553,17 +488,7 @@ else #endif { - boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr); - LOG(WARNING) << "Storage directory: " << storageDirectory; - if (Configuration::GetGlobalBoolParameter("StoreDicom", true)) - { - storage.reset(new FilesystemStorage(storageDirectory.string())); - } - else - { - LOG(WARNING) << "The DICOM files will not be stored, Orthanc running in index-only mode"; - storage.reset(new FilesystemStorageWithoutDicom(storageDirectory.string())); - } + storage.reset(Configuration::CreateStorageArea()); } context.SetStorageArea(*storage);