comparison OrthancServer/Sources/ServerContext.cpp @ 4913:c1b19f95e166

fix signature of OrthancPluginReceivedInstanceCallback for ABI compatibility
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Feb 2022 22:12:43 +0100
parents ea5f1c6ed07e
children 676e03e69703
comparison
equal deleted inserted replaced
4912:45d6ce72a84e 4913:c1b19f95e166
685 ServerContext::StoreResult ServerContext::Store(std::string& resultPublicId, 685 ServerContext::StoreResult ServerContext::Store(std::string& resultPublicId,
686 DicomInstanceToStore& receivedDicom, 686 DicomInstanceToStore& receivedDicom,
687 StoreInstanceMode mode) 687 StoreInstanceMode mode)
688 { 688 {
689 DicomInstanceToStore* dicom = &receivedDicom; 689 DicomInstanceToStore* dicom = &receivedDicom;
690
691 // WARNING: The scope of "modifiedBuffer" and "modifiedDicom" must
692 // be the same as that of "dicom"
693 MallocMemoryBuffer modifiedBuffer;
690 std::unique_ptr<DicomInstanceToStore> modifiedDicom; 694 std::unique_ptr<DicomInstanceToStore> modifiedDicom;
691
692 std::unique_ptr<MallocMemoryBuffer> raii(new MallocMemoryBuffer);
693 695
694 #if ORTHANC_ENABLE_PLUGINS == 1 696 #if ORTHANC_ENABLE_PLUGINS == 1
695 if (HasPlugins()) 697 if (HasPlugins())
696 { 698 {
697 void* modifiedDicomBuffer = NULL; 699 // New in Orthanc 1.10.0
698 size_t modifiedDicomBufferSize = 0; 700
699 701 OrthancPluginReceivedInstanceCallbackResult action = GetPlugins().ApplyReceivedInstanceCallbacks(
700 bool store = GetPlugins().ApplyReceivedInstanceCallbacks(receivedDicom.GetBufferData(), 702 modifiedBuffer, receivedDicom.GetBufferData(), receivedDicom.GetBufferSize());
701 receivedDicom.GetBufferSize(), 703
702 &modifiedDicomBuffer, 704 switch (action)
703 modifiedDicomBufferSize); 705 {
704 raii->Assign(modifiedDicomBuffer, modifiedDicomBufferSize, ::free); 706 case OrthancPluginReceivedInstanceCallbackResult_Discard:
705 707 {
706 if (!store) 708 CLOG(INFO, PLUGINS) << "A plugin has discarded the instance in its ReceivedInstanceCallback";
707 { 709 StoreResult result;
708 StoreResult result; 710 result.SetStatus(StoreStatus_FilteredOut);
709 result.SetStatus(StoreStatus_FilteredOut); 711 return result;
710 return result; 712 }
711 } 713
712 714 case OrthancPluginReceivedInstanceCallbackResult_KeepAsIs:
713 if (modifiedDicomBufferSize > 0 && modifiedDicomBuffer != NULL) 715 break;
714 { 716
715 modifiedDicom.reset(DicomInstanceToStore::CreateFromBuffer(modifiedDicomBuffer, modifiedDicomBufferSize)); 717 case OrthancPluginReceivedInstanceCallbackResult_Modify:
716 modifiedDicom->SetOrigin(dicom->GetOrigin()); 718 if (modifiedBuffer.GetSize() > 0 &&
717 dicom = modifiedDicom.get(); 719 modifiedBuffer.GetData() != NULL)
720 {
721 CLOG(INFO, PLUGINS) << "A plugin has modified the instance in its ReceivedInstanceCallback";
722 modifiedDicom.reset(DicomInstanceToStore::CreateFromBuffer(modifiedBuffer.GetData(), modifiedBuffer.GetSize()));
723 modifiedDicom->SetOrigin(dicom->GetOrigin());
724 dicom = modifiedDicom.get();
725 }
726 else
727 {
728 throw OrthancException(ErrorCode_Plugin, "The ReceivedInstanceCallback plugin is not returning a modified buffer while it has modified the instance");
729 }
730 break;
731
732 default:
733 throw OrthancException(ErrorCode_Plugin, "The ReceivedInstanceCallback has returned an invalid value");
718 } 734 }
719 } 735 }
720 #endif 736 #endif
721 737
722 if (!isIngestTranscoding_) 738 if (!isIngestTranscoding_)