Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 1274:b9e2ed59cae4
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 21 Jan 2015 17:32:53 +0100 |
parents | 2ffe07abd9d8 |
children | d6a65dc6d0ac |
comparison
equal
deleted
inserted
replaced
1273:88010d8e12cf | 1274:b9e2ed59cae4 |
---|---|
36 #include <fstream> | 36 #include <fstream> |
37 #include <glog/logging.h> | 37 #include <glog/logging.h> |
38 #include <boost/algorithm/string/predicate.hpp> | 38 #include <boost/algorithm/string/predicate.hpp> |
39 | 39 |
40 #include "../Core/Uuid.h" | 40 #include "../Core/Uuid.h" |
41 #include "../Core/FileStorage/FilesystemStorage.h" | |
42 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" | 41 #include "../Core/HttpServer/EmbeddedResourceHttpHandler.h" |
43 #include "../Core/HttpServer/FilesystemHttpHandler.h" | 42 #include "../Core/HttpServer/FilesystemHttpHandler.h" |
44 #include "../Core/Lua/LuaFunctionCall.h" | 43 #include "../Core/Lua/LuaFunctionCall.h" |
45 #include "../Core/DicomFormat/DicomArray.h" | 44 #include "../Core/DicomFormat/DicomArray.h" |
46 #include "DicomProtocol/DicomServer.h" | 45 #include "DicomProtocol/DicomServer.h" |
48 #include "OrthancInitialization.h" | 47 #include "OrthancInitialization.h" |
49 #include "ServerContext.h" | 48 #include "ServerContext.h" |
50 #include "OrthancFindRequestHandler.h" | 49 #include "OrthancFindRequestHandler.h" |
51 #include "OrthancMoveRequestHandler.h" | 50 #include "OrthancMoveRequestHandler.h" |
52 #include "ServerToolbox.h" | 51 #include "ServerToolbox.h" |
53 #include "DatabaseWrapper.h" | |
54 #include "../Plugins/Engine/PluginsManager.h" | 52 #include "../Plugins/Engine/PluginsManager.h" |
55 #include "../Plugins/Engine/OrthancPlugins.h" | 53 #include "../Plugins/Engine/OrthancPlugins.h" |
56 | 54 |
57 using namespace Orthanc; | 55 using namespace Orthanc; |
58 | 56 |
381 } | 379 } |
382 } | 380 } |
383 | 381 |
384 | 382 |
385 | 383 |
386 class FilesystemStorageWithoutDicom : public IStorageArea | |
387 { | |
388 private: | |
389 FilesystemStorage storage_; | |
390 | |
391 public: | |
392 FilesystemStorageWithoutDicom(const std::string& path) : storage_(path) | |
393 { | |
394 } | |
395 | |
396 virtual void Create(const std::string& uuid, | |
397 const void* content, | |
398 size_t size, | |
399 FileContentType type) | |
400 { | |
401 if (type != FileContentType_Dicom) | |
402 { | |
403 storage_.Create(uuid, content, size, type); | |
404 } | |
405 } | |
406 | |
407 virtual void Read(std::string& content, | |
408 const std::string& uuid, | |
409 FileContentType type) | |
410 { | |
411 if (type != FileContentType_Dicom) | |
412 { | |
413 storage_.Read(content, uuid, type); | |
414 } | |
415 else | |
416 { | |
417 throw OrthancException(ErrorCode_UnknownResource); | |
418 } | |
419 } | |
420 | |
421 virtual void Remove(const std::string& uuid, | |
422 FileContentType type) | |
423 { | |
424 if (type != FileContentType_Dicom) | |
425 { | |
426 storage_.Remove(uuid, type); | |
427 } | |
428 } | |
429 }; | |
430 | |
431 | |
432 static bool StartOrthanc() | 384 static bool StartOrthanc() |
433 { | 385 { |
434 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); | |
435 | |
436 | |
437 // Open the database | |
438 boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath( | |
439 Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr)); | |
440 | |
441 std::auto_ptr<IDatabaseWrapper> database; | 386 std::auto_ptr<IDatabaseWrapper> database; |
442 try | 387 database.reset(Configuration::CreateDatabaseWrapper()); |
443 { | |
444 boost::filesystem::create_directories(indexDirectory); | |
445 } | |
446 catch (boost::filesystem::filesystem_error) | |
447 { | |
448 } | |
449 | |
450 database.reset(new DatabaseWrapper(indexDirectory.string() + "/index")); | |
451 | 388 |
452 | 389 |
453 // "storage" must be declared BEFORE "ServerContext context", to | 390 // "storage" must be declared BEFORE "ServerContext context", to |
454 // avoid mess in the invokation order of the destructors. | 391 // avoid mess in the invokation order of the destructors. |
455 std::auto_ptr<IStorageArea> storage; | 392 std::auto_ptr<IStorageArea> storage; |
456 | 393 |
457 ServerContext context(*database); | 394 ServerContext context(*database); |
458 | |
459 LOG(WARNING) << "Index directory: " << indexDirectory; | |
460 | 395 |
461 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); | 396 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); |
462 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); | 397 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); |
463 | 398 |
464 LoadLuaScripts(context); | 399 LoadLuaScripts(context); |
551 storage.reset(orthancPlugins.GetStorageArea()); | 486 storage.reset(orthancPlugins.GetStorageArea()); |
552 } | 487 } |
553 else | 488 else |
554 #endif | 489 #endif |
555 { | 490 { |
556 boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr); | 491 storage.reset(Configuration::CreateStorageArea()); |
557 LOG(WARNING) << "Storage directory: " << storageDirectory; | |
558 if (Configuration::GetGlobalBoolParameter("StoreDicom", true)) | |
559 { | |
560 storage.reset(new FilesystemStorage(storageDirectory.string())); | |
561 } | |
562 else | |
563 { | |
564 LOG(WARNING) << "The DICOM files will not be stored, Orthanc running in index-only mode"; | |
565 storage.reset(new FilesystemStorageWithoutDicom(storageDirectory.string())); | |
566 } | |
567 } | 492 } |
568 | 493 |
569 context.SetStorageArea(*storage); | 494 context.SetStorageArea(*storage); |
570 | 495 |
571 | 496 |