comparison OrthancServer/Plugins/Samples/AdvancedStorage/Plugin.cpp @ 5807:8279eaab0d1d attach-custom-data

merged default -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 11:39:52 +0200
parents 79f98ee4f04b
children 63c025cf6958
comparison
equal deleted inserted replaced
5085:79f98ee4f04b 5807:8279eaab0d1d
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **/ 20 **/
21 21
22 #define ORTHANC_PLUGIN_NAME "advanced-storage"
22 23
23 #include "../../../../OrthancFramework/Sources/Compatibility.h" 24 #include "../../../../OrthancFramework/Sources/Compatibility.h"
24 #include "../../../../OrthancFramework/Sources/OrthancException.h" 25 #include "../../../../OrthancFramework/Sources/OrthancException.h"
25 #include "../../../../OrthancFramework/Sources/SystemToolbox.h" 26 #include "../../../../OrthancFramework/Sources/SystemToolbox.h"
26 #include "../../../../OrthancFramework/Sources/Toolbox.h" 27 #include "../../../../OrthancFramework/Sources/Toolbox.h"
377 OrthancPluginContentType type, 378 OrthancPluginContentType type,
378 bool isCompressed) 379 bool isCompressed)
379 { 380 {
380 try 381 try
381 { 382 {
382 OrthancPlugins::LogInfo(std::string("Creating attachment \"") + uuid + "\""); 383 LOG(INFO) << "Creating attachment \"" << uuid << "\"";
383 384
384 //TODO_CUSTOM_DATA: get tags from the Rest API... 385 //TODO_CUSTOM_DATA: get tags from the Rest API...
385 Json::Value tags; 386 Json::Value tags;
386 387
387 return StorageCreate(customData, uuid, tags, content, size, type, isCompressed); 388 return StorageCreate(customData, uuid, tags, content, size, type, isCompressed);
407 408
408 LOG(INFO) << "Advanced Storage - Reading whole attachment \"" << uuid << "\" of type " << static_cast<int>(type) << " (path = " + path + ")"; 409 LOG(INFO) << "Advanced Storage - Reading whole attachment \"" << uuid << "\" of type " << static_cast<int>(type) << " (path = " + path + ")";
409 410
410 if (!Orthanc::SystemToolbox::IsRegularFile(path)) 411 if (!Orthanc::SystemToolbox::IsRegularFile(path))
411 { 412 {
412 OrthancPlugins::LogError(std::string("The path does not point to a regular file: ") + path); 413 LOG(ERROR) << "The path does not point to a regular file: " << path;
413 return OrthancPluginErrorCode_InexistentFile; 414 return OrthancPluginErrorCode_InexistentFile;
414 } 415 }
415 416
416 try 417 try
417 { 418 {
418 fs::ifstream f; 419 fs::ifstream f;
419 f.open(path, std::ifstream::in | std::ifstream::binary); 420 f.open(path, std::ifstream::in | std::ifstream::binary);
420 if (!f.good()) 421 if (!f.good())
421 { 422 {
422 OrthancPlugins::LogError(std::string("The path does not point to a regular file: ") + path); 423 LOG(ERROR) << "The path does not point to a regular file: " << path;
423 return OrthancPluginErrorCode_InexistentFile; 424 return OrthancPluginErrorCode_InexistentFile;
424 } 425 }
425 426
426 // get file size 427 // get file size
427 f.seekg(0, std::ios::end); 428 f.seekg(0, std::ios::end);
429 f.seekg(0, std::ios::beg); 430 f.seekg(0, std::ios::beg);
430 431
431 // The ReadWhole must allocate the buffer itself 432 // The ReadWhole must allocate the buffer itself
432 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, fileSize) != OrthancPluginErrorCode_Success) 433 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, fileSize) != OrthancPluginErrorCode_Success)
433 { 434 {
434 OrthancPlugins::LogError(std::string("Unable to allocate memory to read file: ") + path); 435 LOG(ERROR) << "Unable to allocate memory to read file: " << path;
435 return OrthancPluginErrorCode_NotEnoughMemory; 436 return OrthancPluginErrorCode_NotEnoughMemory;
436 } 437 }
437 438
438 if (fileSize != 0) 439 if (fileSize != 0)
439 { 440 {
442 443
443 f.close(); 444 f.close();
444 } 445 }
445 catch (...) 446 catch (...)
446 { 447 {
447 OrthancPlugins::LogError(std::string("Unexpected error while reading: ") + path); 448 LOG(ERROR) << "Unexpected error while reading: " << path;
448 return OrthancPluginErrorCode_StorageAreaPlugin; 449 return OrthancPluginErrorCode_StorageAreaPlugin;
449 } 450 }
450 451
451 return OrthancPluginErrorCode_Success; 452 return OrthancPluginErrorCode_Success;
452 } 453 }
462 463
463 LOG(INFO) << "Advanced Storage - Reading range of attachment \"" << uuid << "\" of type " << static_cast<int>(type) << " (path = " + path + ")"; 464 LOG(INFO) << "Advanced Storage - Reading range of attachment \"" << uuid << "\" of type " << static_cast<int>(type) << " (path = " + path + ")";
464 465
465 if (!Orthanc::SystemToolbox::IsRegularFile(path)) 466 if (!Orthanc::SystemToolbox::IsRegularFile(path))
466 { 467 {
467 OrthancPlugins::LogError(std::string("The path does not point to a regular file: ") + path); 468 LOG(ERROR) << "The path does not point to a regular file: " << path;
468 return OrthancPluginErrorCode_InexistentFile; 469 return OrthancPluginErrorCode_InexistentFile;
469 } 470 }
470 471
471 try 472 try
472 { 473 {
473 fs::ifstream f; 474 fs::ifstream f;
474 f.open(path, std::ifstream::in | std::ifstream::binary); 475 f.open(path, std::ifstream::in | std::ifstream::binary);
475 if (!f.good()) 476 if (!f.good())
476 { 477 {
477 OrthancPlugins::LogError(std::string("The path does not point to a regular file: ") + path); 478 LOG(ERROR) << "The path does not point to a regular file: " << path;
478 return OrthancPluginErrorCode_InexistentFile; 479 return OrthancPluginErrorCode_InexistentFile;
479 } 480 }
480 481
481 f.seekg(rangeStart, std::ios::beg); 482 f.seekg(rangeStart, std::ios::beg);
482 483
485 486
486 f.close(); 487 f.close();
487 } 488 }
488 catch (...) 489 catch (...)
489 { 490 {
490 OrthancPlugins::LogError(std::string("Unexpected error while reading: ") + path); 491 LOG(ERROR) << "Unexpected error while reading: " << path;
491 return OrthancPluginErrorCode_StorageAreaPlugin; 492 return OrthancPluginErrorCode_StorageAreaPlugin;
492 } 493 }
493 494
494 return OrthancPluginErrorCode_Success; 495 return OrthancPluginErrorCode_Success;
495 } 496 }
547 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, 548 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
548 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); 549 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
549 return -1; 550 return -1;
550 } 551 }
551 552
552 OrthancPlugins::LogWarning("AdvancedStorage plugin is initializing"); 553 LOG(WARNING) << "AdvancedStorage plugin is initializing";
553 OrthancPluginSetDescription(context, "Provides alternative layout for your storage."); 554 OrthancPluginSetDescription2(context, ORTHANC_PLUGIN_NAME, "Provides alternative layout for your storage.");
554 555
555 OrthancPlugins::OrthancConfiguration orthancConfiguration; 556 OrthancPlugins::OrthancConfiguration orthancConfiguration;
556 557
557 OrthancPlugins::OrthancConfiguration advancedStorage; 558 OrthancPlugins::OrthancConfiguration advancedStorage;
558 orthancConfiguration.GetSection(advancedStorage, "AdvancedStorage"); 559 orthancConfiguration.GetSection(advancedStorage, "AdvancedStorage");
671 672
672 OrthancPluginRegisterStorageArea3(context, StorageCreateInstance, StorageCreateAttachment, StorageReadWhole, StorageReadRange, StorageRemove); 673 OrthancPluginRegisterStorageArea3(context, StorageCreateInstance, StorageCreateAttachment, StorageReadWhole, StorageReadRange, StorageRemove);
673 } 674 }
674 else 675 else
675 { 676 {
676 OrthancPlugins::LogWarning("AdvancedStorage plugin is disabled by the configuration file"); 677 LOG(WARNING) << "AdvancedStorage plugin is disabled by the configuration file";
677 } 678 }
678 679
679 return 0; 680 return 0;
680 } 681 }
681 682
682 683
683 ORTHANC_PLUGINS_API void OrthancPluginFinalize() 684 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
684 { 685 {
685 OrthancPlugins::LogWarning("AdvancedStorage plugin is finalizing"); 686 LOG(WARNING) << "AdvancedStorage plugin is finalizing";
686 } 687 }
687 688
688 689
689 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() 690 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
690 { 691 {
691 return "advanced-storage"; 692 return ORTHANC_PLUGIN_NAME;
692 } 693 }
693 694
694 695
695 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() 696 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
696 { 697 {
697 return ORTHANC_PLUGIN_VERSION; 698 return ADVANCED_STORAGE_VERSION;
698 } 699 }
699 } 700 }