comparison 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
comparison
equal deleted inserted replaced
1273:88010d8e12cf 1274:b9e2ed59cae4
43 #include <boost/filesystem.hpp> 43 #include <boost/filesystem.hpp>
44 #include <curl/curl.h> 44 #include <curl/curl.h>
45 #include <boost/thread.hpp> 45 #include <boost/thread.hpp>
46 #include <glog/logging.h> 46 #include <glog/logging.h>
47 47
48 #include "DatabaseWrapper.h"
49 #include "../Core/FileStorage/FilesystemStorage.h"
50
48 51
49 #if ORTHANC_JPEG_ENABLED == 1 52 #if ORTHANC_JPEG_ENABLED == 1
50 #include <dcmtk/dcmjpeg/djdecode.h> 53 #include <dcmtk/dcmjpeg/djdecode.h>
51 #endif 54 #endif
52 55
652 655
653 const std::string& Configuration::GetConfigurationAbsolutePath() 656 const std::string& Configuration::GetConfigurationAbsolutePath()
654 { 657 {
655 return configurationAbsolutePath_; 658 return configurationAbsolutePath_;
656 } 659 }
660
661
662 static IDatabaseWrapper* CreateSQLiteWrapper()
663 {
664 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage");
665
666 // Open the database
667 boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath(
668 Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr));
669
670 LOG(WARNING) << "SQLite index directory: " << indexDirectory;
671
672 try
673 {
674 boost::filesystem::create_directories(indexDirectory);
675 }
676 catch (boost::filesystem::filesystem_error)
677 {
678 }
679
680 return new DatabaseWrapper(indexDirectory.string() + "/index");
681 }
682
683
684 namespace
685 {
686 // Anonymous namespace to avoid clashes between compilation modules
687
688 class FilesystemStorageWithoutDicom : public IStorageArea
689 {
690 private:
691 FilesystemStorage storage_;
692
693 public:
694 FilesystemStorageWithoutDicom(const std::string& path) : storage_(path)
695 {
696 }
697
698 virtual void Create(const std::string& uuid,
699 const void* content,
700 size_t size,
701 FileContentType type)
702 {
703 if (type != FileContentType_Dicom)
704 {
705 storage_.Create(uuid, content, size, type);
706 }
707 }
708
709 virtual void Read(std::string& content,
710 const std::string& uuid,
711 FileContentType type)
712 {
713 if (type != FileContentType_Dicom)
714 {
715 storage_.Read(content, uuid, type);
716 }
717 else
718 {
719 throw OrthancException(ErrorCode_UnknownResource);
720 }
721 }
722
723 virtual void Remove(const std::string& uuid,
724 FileContentType type)
725 {
726 if (type != FileContentType_Dicom)
727 {
728 storage_.Remove(uuid, type);
729 }
730 }
731 };
732 }
733
734
735 static IStorageArea* CreateFilesystemStorage()
736 {
737 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage");
738
739 boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr);
740 LOG(WARNING) << "Storage directory: " << storageDirectory;
741
742 if (Configuration::GetGlobalBoolParameter("StoreDicom", true))
743 {
744 return new FilesystemStorage(storageDirectory.string());
745 }
746 else
747 {
748 LOG(WARNING) << "The DICOM files will not be stored, Orthanc running in index-only mode";
749 return new FilesystemStorageWithoutDicom(storageDirectory.string());
750 }
751 }
752
753
754 IDatabaseWrapper* Configuration::CreateDatabaseWrapper()
755 {
756 return CreateSQLiteWrapper();
757 }
758
759
760 IStorageArea* Configuration::CreateStorageArea()
761 {
762 return CreateFilesystemStorage();
763 }
657 } 764 }