comparison OrthancServer/main.cpp @ 1135:67c3c1e4a6e0

index-only mode, and custom storage area with plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Sep 2014 15:55:43 +0200
parents ba9fd42284d0
children 3db41779d8f9
comparison
equal deleted inserted replaced
1134:ba9fd42284d0 1135:67c3c1e4a6e0
324 public: 324 public:
325 FilesystemStorageWithoutDicom(const std::string& path) : storage_(path) 325 FilesystemStorageWithoutDicom(const std::string& path) : storage_(path)
326 { 326 {
327 } 327 }
328 328
329 virtual std::string Create(const void* content, 329 virtual void Create(const std::string& uuid,
330 size_t size, 330 const void* content,
331 FileContentType type) 331 size_t size,
332 FileContentType type)
332 { 333 {
333 if (type != FileContentType_Dicom) 334 if (type != FileContentType_Dicom)
334 { 335 {
335 return storage_.Create(content, size, type); 336 storage_.Create(uuid, content, size, type);
336 }
337 else
338 {
339 return Toolbox::GenerateUuid();
340 } 337 }
341 } 338 }
342 339
343 virtual void Read(std::string& content, 340 virtual void Read(std::string& content,
344 const std::string& uuid, 341 const std::string& uuid,
366 363
367 364
368 static bool StartOrthanc() 365 static bool StartOrthanc()
369 { 366 {
370 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); 367 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage");
371 boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr);
372 boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath( 368 boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath(
373 Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr)); 369 Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr));
374 370
375 // TODO HERE 371 // "storage" must be declared BEFORE "ServerContext context", to
376 FilesystemStorage storage(storageDirectory.string()); 372 // avoid mess in the invokation order of the destructors.
377 //FilesystemStorageWithoutDicom storage(storageDirectory.string()); 373 std::auto_ptr<IStorageArea> storage;
378
379 ServerContext context(indexDirectory); 374 ServerContext context(indexDirectory);
380 context.SetStorageArea(storage); 375
381
382 LOG(WARNING) << "Storage directory: " << storageDirectory;
383 LOG(WARNING) << "Index directory: " << indexDirectory; 376 LOG(WARNING) << "Index directory: " << indexDirectory;
384 377
385 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); 378 context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false));
386 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); 379 context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true));
387 380
463 httpServer.RegisterHandler(staticResources); 456 httpServer.RegisterHandler(staticResources);
464 httpServer.RegisterHandler(restApi); 457 httpServer.RegisterHandler(restApi);
465 orthancPlugins.SetOrthancRestApi(restApi); 458 orthancPlugins.SetOrthancRestApi(restApi);
466 context.SetOrthancPlugins(orthancPlugins); 459 context.SetOrthancPlugins(orthancPlugins);
467 460
461
462 // Prepare the storage area
463 if (orthancPlugins.HasStorageArea())
464 {
465 LOG(WARNING) << "Using a custom storage area from plugins";
466 storage.reset(orthancPlugins.GetStorageArea());
467 }
468 else
469 {
470 boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr);
471 LOG(WARNING) << "Storage directory: " << storageDirectory;
472 if (Configuration::GetGlobalBoolParameter("StoreDicom", true))
473 {
474 storage.reset(new FilesystemStorage(storageDirectory.string()));
475 }
476 else
477 {
478 LOG(WARNING) << "The DICOM files will not be stored, Orthanc running in index-only mode";
479 storage.reset(new FilesystemStorageWithoutDicom(storageDirectory.string()));
480 }
481 }
482
483 context.SetStorageArea(*storage);
484
485
468 // GO !!! Start the requested servers 486 // GO !!! Start the requested servers
469 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true)) 487 if (Configuration::GetGlobalBoolParameter("HttpServerEnabled", true))
470 { 488 {
471 httpServer.Start(); 489 httpServer.Start();
472 LOG(WARNING) << "HTTP server listening on port: " << httpServer.GetPortNumber(); 490 LOG(WARNING) << "HTTP server listening on port: " << httpServer.GetPortNumber();