annotate OrthancServer/Plugins/Samples/Sanitizer/Plugin.cpp @ 4915:189ae9a37e01

reorder arguments to put the target as first argument (convention)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 Feb 2022 22:18:54 +0100
parents 4b10cbf3ccc8
children 676e03e69703
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4845
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 /**
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4849
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4849
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4845
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 *
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
11 * License, or (at your option) any later version.
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
12 *
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 * General Public License for more details.
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 *
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
20 **/
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
21
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
22
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
23 #include "../../../../OrthancFramework/Sources/Compatibility.h"
4849
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
24 #include "../../../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
25 #include "../../../../OrthancFramework/Sources/OrthancFramework.h"
4845
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
26 #include "../Common/OrthancPluginCppWrapper.h"
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
27
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 #include <boost/filesystem.hpp>
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 #include <json/value.h>
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 #include <string.h>
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 #include <iostream>
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
32
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
33
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
34
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
35
4915
189ae9a37e01 reorder arguments to put the target as first argument (convention)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4914
diff changeset
36 OrthancPluginReceivedInstanceCallbackResult ReceivedInstanceCallback(OrthancPluginMemoryBuffer64* modifiedDicomBuffer,
189ae9a37e01 reorder arguments to put the target as first argument (convention)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4914
diff changeset
37 const void* receivedDicomBuffer,
189ae9a37e01 reorder arguments to put the target as first argument (convention)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4914
diff changeset
38 uint64_t receivedDicomBufferSize)
4845
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 {
4849
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
40 Orthanc::ParsedDicomFile dicom(receivedDicomBuffer, receivedDicomBufferSize);
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
41 std::string institutionName = "My institution";
4845
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
42
4849
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
43 dicom.Replace(Orthanc::DICOM_TAG_INSTITUTION_NAME, institutionName, false, Orthanc::DicomReplaceMode_InsertIfAbsent, "");
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
44
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
45 std::string modifiedDicom;
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
46 dicom.SaveToMemoryBuffer(modifiedDicom);
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
47
4913
c1b19f95e166 fix signature of OrthancPluginReceivedInstanceCallback for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4912
diff changeset
48 OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), modifiedDicomBuffer, modifiedDicom.size());
c1b19f95e166 fix signature of OrthancPluginReceivedInstanceCallback for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4912
diff changeset
49 memcpy(modifiedDicomBuffer->data, modifiedDicom.c_str(), modifiedDicom.size());
c1b19f95e166 fix signature of OrthancPluginReceivedInstanceCallback for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4912
diff changeset
50
4914
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4913
diff changeset
51 return OrthancPluginReceivedInstanceCallbackResult_Modify;
4845
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
52 }
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
53
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
54
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 extern "C"
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 {
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 {
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 OrthancPlugins::SetGlobalContext(c);
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
60
4849
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
61 Orthanc::InitializeFramework("", true);
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
62
4845
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 /* Check the version of the Orthanc core */
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
64 // if (OrthancPluginCheckVersion(c) == 0)
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
65 // {
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
66 // OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
67 // ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
68 // ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 // return -1;
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 // }
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
71
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
72 OrthancPlugins::LogWarning("Sanitizer plugin is initializing");
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
73 OrthancPluginSetDescription(c, "Sample plugin to sanitize incoming DICOM instances.");
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
74
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
75 OrthancPluginRegisterReceivedInstanceCallback(c, ReceivedInstanceCallback);
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
76
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 return 0;
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 }
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
79
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
80
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
81 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
82 {
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
83 OrthancPlugins::LogWarning("Sanitizer plugin is finalizing");
4849
4addabcab158 use ParsedDicomFile in Sanitizer sample plugin
Alain Mazy <am@osimis.io>
parents: 4845
diff changeset
84 Orthanc::FinalizeFramework();
4845
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
85 }
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
86
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
87
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
88 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
89 {
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
90 return "sanitizer";
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 }
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
92
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
93
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 {
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
96 return "0.1";
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
97 }
02d77189d8ba added ReceivedInstanceCallback + sample C++ plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 }