Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 4845:02d77189d8ba received-instance-callback
added ReceivedInstanceCallback + sample C++ plugin
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 09 Dec 2021 17:22:40 +0100 |
parents | 7053502fbf97 |
children | 8b51d65584f0 |
comparison
equal
deleted
inserted
replaced
4844:55e8fb8e8028 | 4845:02d77189d8ba |
---|---|
45 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h" | 45 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h" |
46 #include "../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h" | 46 #include "../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h" |
47 #include "../../OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h" | 47 #include "../../OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h" |
48 #include "../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h" | 48 #include "../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h" |
49 #include "../../OrthancFramework/Sources/Logging.h" | 49 #include "../../OrthancFramework/Sources/Logging.h" |
50 #include "../../OrthancFramework/Sources/MallocMemoryBuffer.h" | |
50 #include "../../OrthancFramework/Sources/MetricsRegistry.h" | 51 #include "../../OrthancFramework/Sources/MetricsRegistry.h" |
51 #include "../Plugins/Engine/OrthancPlugins.h" | 52 #include "../Plugins/Engine/OrthancPlugins.h" |
52 | 53 |
53 #include "OrthancConfiguration.h" | 54 #include "OrthancConfiguration.h" |
54 #include "OrthancRestApi/OrthancRestApi.h" | 55 #include "OrthancRestApi/OrthancRestApi.h" |
692 } | 693 } |
693 } | 694 } |
694 | 695 |
695 | 696 |
696 ServerContext::StoreResult ServerContext::Store(std::string& resultPublicId, | 697 ServerContext::StoreResult ServerContext::Store(std::string& resultPublicId, |
697 DicomInstanceToStore& dicom, | 698 DicomInstanceToStore& receivedDicom, |
698 StoreInstanceMode mode) | 699 StoreInstanceMode mode) |
699 { | 700 { |
701 DicomInstanceToStore* dicom = &receivedDicom; | |
702 std::unique_ptr<DicomInstanceToStore> modifiedDicom; | |
703 | |
704 void* modifiedDicomBuffer = NULL; | |
705 size_t modifiedDicomBufferSize = 0; | |
706 | |
707 std::unique_ptr<MallocMemoryBuffer> raii(new MallocMemoryBuffer); | |
708 | |
709 #if ORTHANC_ENABLE_PLUGINS == 1 | |
710 if (HasPlugins()) | |
711 { | |
712 | |
713 bool store = GetPlugins().ApplyReceivedInstanceCallbacks(receivedDicom.GetBufferData(), | |
714 receivedDicom.GetBufferSize(), | |
715 &modifiedDicomBuffer, | |
716 modifiedDicomBufferSize); | |
717 raii->Assign(modifiedDicomBuffer, modifiedDicomBufferSize, ::free); | |
718 | |
719 if (!store) | |
720 { | |
721 StoreResult result; | |
722 result.SetStatus(StoreStatus_FilteredOut); | |
723 return result; | |
724 } | |
725 | |
726 if (modifiedDicomBufferSize > 0 && modifiedDicomBuffer != NULL) | |
727 { | |
728 modifiedDicom.reset(DicomInstanceToStore::CreateFromBuffer(modifiedDicomBuffer, modifiedDicomBufferSize)); | |
729 modifiedDicom->SetOrigin(dicom->GetOrigin()); | |
730 dicom = modifiedDicom.get(); | |
731 } | |
732 } | |
733 #endif | |
734 | |
700 if (!isIngestTranscoding_) | 735 if (!isIngestTranscoding_) |
701 { | 736 { |
702 // No automated transcoding. This was the only path in Orthanc <= 1.6.1. | 737 // No automated transcoding. This was the only path in Orthanc <= 1.6.1. |
703 return StoreAfterTranscoding(resultPublicId, dicom, mode); | 738 return StoreAfterTranscoding(resultPublicId, *dicom, mode); |
704 } | 739 } |
705 else | 740 else |
706 { | 741 { |
707 // Automated transcoding of incoming DICOM instance | 742 // Automated transcoding of incoming DICOM instance |
708 | 743 |
709 bool transcode = false; | 744 bool transcode = false; |
710 | 745 |
711 DicomTransferSyntax sourceSyntax; | 746 DicomTransferSyntax sourceSyntax; |
712 if (!dicom.LookupTransferSyntax(sourceSyntax) || | 747 if (!dicom->LookupTransferSyntax(sourceSyntax) || |
713 sourceSyntax == ingestTransferSyntax_) | 748 sourceSyntax == ingestTransferSyntax_) |
714 { | 749 { |
715 // Don't transcode if the incoming DICOM is already in the proper transfer syntax | 750 // Don't transcode if the incoming DICOM is already in the proper transfer syntax |
716 transcode = false; | 751 transcode = false; |
717 } | 752 } |
734 } | 769 } |
735 | 770 |
736 if (!transcode) | 771 if (!transcode) |
737 { | 772 { |
738 // No transcoding | 773 // No transcoding |
739 return StoreAfterTranscoding(resultPublicId, dicom, mode); | 774 return StoreAfterTranscoding(resultPublicId, *dicom, mode); |
740 } | 775 } |
741 else | 776 else |
742 { | 777 { |
743 // Trancoding | 778 // Trancoding |
744 std::set<DicomTransferSyntax> syntaxes; | 779 std::set<DicomTransferSyntax> syntaxes; |
745 syntaxes.insert(ingestTransferSyntax_); | 780 syntaxes.insert(ingestTransferSyntax_); |
746 | 781 |
747 IDicomTranscoder::DicomImage source; | 782 IDicomTranscoder::DicomImage source; |
748 source.SetExternalBuffer(dicom.GetBufferData(), dicom.GetBufferSize()); | 783 source.SetExternalBuffer(dicom->GetBufferData(), dicom->GetBufferSize()); |
749 | 784 |
750 IDicomTranscoder::DicomImage transcoded; | 785 IDicomTranscoder::DicomImage transcoded; |
751 if (Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) | 786 if (Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) |
752 { | 787 { |
753 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); | 788 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); |
754 | 789 |
755 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*tmp)); | 790 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*tmp)); |
756 toStore->SetOrigin(dicom.GetOrigin()); | 791 toStore->SetOrigin(dicom->GetOrigin()); |
757 | 792 |
758 StoreResult result = StoreAfterTranscoding(resultPublicId, *toStore, mode); | 793 StoreResult result = StoreAfterTranscoding(resultPublicId, *toStore, mode); |
759 assert(resultPublicId == tmp->GetHasher().HashInstance()); | 794 assert(resultPublicId == tmp->GetHasher().HashInstance()); |
760 | 795 |
761 return result; | 796 return result; |
762 } | 797 } |
763 else | 798 else |
764 { | 799 { |
765 // Cannot transcode => store the original file | 800 // Cannot transcode => store the original file |
766 return StoreAfterTranscoding(resultPublicId, dicom, mode); | 801 return StoreAfterTranscoding(resultPublicId, *dicom, mode); |
767 } | 802 } |
768 } | 803 } |
769 } | 804 } |
770 } | 805 } |
771 | 806 |