Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/Operations/StorePeerOperation.cpp @ 5853:4d932683049d get-scu tip
very first implementation of C-Get SCU
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 29 Oct 2024 17:25:49 +0100 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
2605 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
2605 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
2641 | 24 #include "../../PrecompiledHeadersServer.h" |
2605 | 25 #include "StorePeerOperation.h" |
26 | |
27 #include "DicomInstanceOperationValue.h" | |
28 | |
4045 | 29 #include "../../../../OrthancFramework/Sources/Logging.h" |
30 #include "../../../../OrthancFramework/Sources/OrthancException.h" | |
31 #include "../../../../OrthancFramework/Sources/HttpClient.h" | |
32 #include "../../../../OrthancFramework/Sources/SerializationToolbox.h" | |
2605 | 33 |
34 namespace Orthanc | |
35 { | |
36 void StorePeerOperation::Apply(JobOperationValues& outputs, | |
4310
2ae905070221
renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
37 const IJobOperationValue& input) |
2605 | 38 { |
39 // Configure the HTTP client | |
40 HttpClient client(peer_, "instances"); | |
41 client.SetMethod(HttpMethod_Post); | |
42 | |
4310
2ae905070221
renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
43 if (input.GetType() != IJobOperationValue::Type_DicomInstance) |
2605 | 44 { |
45 throw OrthancException(ErrorCode_BadParameterType); | |
46 } | |
47 | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
48 const DicomInstanceOperationValue& instance = |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
49 dynamic_cast<const DicomInstanceOperationValue&>(input); |
2605 | 50 |
51 LOG(INFO) << "Lua: Sending instance " << instance.GetId() << " to Orthanc peer \"" | |
52 << peer_.GetUrl() << "\""; | |
53 | |
54 try | |
55 { | |
4650
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
56 // Lifetime of "body" must exceed the call to "client.Apply()" because of "SetExternalBody()" |
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
57 std::string body; |
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
58 instance.ReadDicom(body); |
2605 | 59 |
4650
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
60 client.SetExternalBody(body); // Avoids a memcpy() |
9804d6490872
Reduced memory consumption of HTTP/REST plugins calls on POST/PUT if chunked transfer is disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
61 |
2605 | 62 std::string answer; |
63 if (!client.Apply(answer)) | |
64 { | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
65 LOG(ERROR) << "Lua: Unable to send instance " << instance.GetId() |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
66 << " to Orthanc peer \"" << peer_.GetUrl(); |
2605 | 67 } |
68 } | |
69 catch (OrthancException& e) | |
70 { | |
2608
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
71 LOG(ERROR) << "Lua: Unable to send instance " << instance.GetId() |
25225f0b4f33
simplification wrt. dicom connection manager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
72 << " to Orthanc peer \"" << peer_.GetUrl() << "\": " << e.What(); |
2605 | 73 } |
2609
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
74 |
f7a84b551ee4
switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2608
diff
changeset
|
75 outputs.Append(input.Clone()); |
2605 | 76 } |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
77 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
78 |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
79 void StorePeerOperation::Serialize(Json::Value& result) const |
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
80 { |
2654 | 81 result = Json::objectValue; |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
82 result["Type"] = "StorePeer"; |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
83 peer_.Serialize(result["Peer"], |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
84 true /* force advanced format */, |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2657
diff
changeset
|
85 true /* include passwords */); |
2655 | 86 } |
87 | |
88 | |
89 StorePeerOperation::StorePeerOperation(const Json::Value& serialized) | |
90 { | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
91 if (SerializationToolbox::ReadString(serialized, "Type") != "StorePeer" || |
2655 | 92 !serialized.isMember("Peer")) |
93 { | |
94 throw OrthancException(ErrorCode_BadFileFormat); | |
95 } | |
96 | |
97 peer_ = WebServiceParameters(serialized["Peer"]); | |
2616
2f3007bf0708
event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2609
diff
changeset
|
98 } |
2605 | 99 } |