Mercurial > hg > orthanc
annotate OrthancServer/Internals/MoveScp.cpp @ 613:60d90e48e809 find-move-scp
query/retrieve
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Oct 2013 17:27:26 +0200 |
parents | 4d5f0857ec9c |
children | 08eca5d86aad |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
399 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #include "MoveScp.h" | |
34 | |
35 #include <memory> | |
36 | |
37 #include "../FromDcmtkBridge.h" | |
38 #include "../ToDcmtkBridge.h" | |
62 | 39 #include "../../Core/OrthancException.h" |
0 | 40 |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
41 #include <glog/logging.h> |
0 | 42 |
43 | |
62 | 44 namespace Orthanc |
0 | 45 { |
46 namespace | |
47 { | |
48 struct MoveScpData | |
49 { | |
50 std::string target_; | |
51 IMoveRequestHandler* handler_; | |
52 DicomMap input_; | |
53 DcmDataset* lastRequest_; | |
54 unsigned int subOperationCount_; | |
55 unsigned int failureCount_; | |
56 unsigned int warningCount_; | |
57 std::auto_ptr<IMoveRequestIterator> iterator_; | |
58 }; | |
59 | |
60 | |
61 void MoveScpCallback( | |
62 /* in */ | |
63 void *callbackData, | |
64 OFBool cancelled, | |
65 T_DIMSE_C_MoveRQ *request, | |
66 DcmDataset *requestIdentifiers, | |
67 int responseCount, | |
68 /* out */ | |
69 T_DIMSE_C_MoveRSP *response, | |
70 DcmDataset **responseIdentifiers, | |
71 DcmDataset **statusDetail) | |
72 { | |
73 bzero(response, sizeof(T_DIMSE_C_MoveRSP)); | |
74 *statusDetail = NULL; | |
75 *responseIdentifiers = NULL; | |
76 | |
77 MoveScpData& data = *(MoveScpData*) callbackData; | |
78 if (data.lastRequest_ == NULL) | |
79 { | |
80 FromDcmtkBridge::Convert(data.input_, *requestIdentifiers); | |
81 | |
82 try | |
83 { | |
84 data.iterator_.reset(data.handler_->Handle(data.target_, data.input_)); | |
613 | 85 if (data.iterator_.get() == NULL) |
86 { | |
87 // Internal error! | |
88 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; | |
89 return; | |
90 } | |
91 | |
0 | 92 data.subOperationCount_ = data.iterator_->GetSubOperationCount(); |
93 data.failureCount_ = 0; | |
94 data.warningCount_ = 0; | |
95 } | |
62 | 96 catch (OrthancException& e) |
0 | 97 { |
98 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
99 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 100 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
101 return; | |
102 } | |
103 | |
104 data.lastRequest_ = requestIdentifiers; | |
105 } | |
106 else if (data.lastRequest_ != requestIdentifiers) | |
107 { | |
108 // Internal error! | |
109 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; | |
110 return; | |
111 } | |
112 | |
113 if (data.subOperationCount_ == 0) | |
114 { | |
115 response->DimseStatus = STATUS_Success; | |
116 } | |
117 else | |
118 { | |
119 IMoveRequestIterator::Status status; | |
120 | |
121 try | |
122 { | |
123 status = data.iterator_->DoNext(); | |
124 } | |
62 | 125 catch (OrthancException& e) |
0 | 126 { |
127 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
128 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 129 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
130 return; | |
131 } | |
132 | |
133 if (status == IMoveRequestIterator::Status_Failure) | |
134 { | |
135 data.failureCount_++; | |
136 } | |
137 else if (status == IMoveRequestIterator::Status_Warning) | |
138 { | |
139 data.warningCount_++; | |
140 } | |
141 | |
142 if (responseCount < static_cast<int>(data.subOperationCount_)) | |
143 { | |
144 response->DimseStatus = STATUS_Pending; | |
145 } | |
146 else | |
147 { | |
148 response->DimseStatus = STATUS_Success; | |
149 } | |
150 } | |
151 | |
152 response->NumberOfRemainingSubOperations = data.subOperationCount_ - responseCount; | |
153 response->NumberOfCompletedSubOperations = responseCount; | |
154 response->NumberOfFailedSubOperations = data.failureCount_; | |
155 response->NumberOfWarningSubOperations = data.warningCount_; | |
156 } | |
157 } | |
158 | |
159 | |
160 OFCondition Internals::moveScp(T_ASC_Association * assoc, | |
161 T_DIMSE_Message * msg, | |
162 T_ASC_PresentationContextID presID, | |
163 IMoveRequestHandler& handler) | |
164 { | |
165 MoveScpData data; | |
166 data.target_ = std::string(msg->msg.CMoveRQ.MoveDestination); | |
167 data.lastRequest_ = NULL; | |
168 data.handler_ = &handler; | |
169 | |
170 OFCondition cond = DIMSE_moveProvider(assoc, presID, &msg->msg.CMoveRQ, | |
171 MoveScpCallback, &data, | |
172 /*opt_blockMode*/ DIMSE_BLOCKING, | |
173 /*opt_dimse_timeout*/ 0); | |
174 | |
175 // if some error occured, dump corresponding information and remove the outfile if necessary | |
176 if (cond.bad()) | |
177 { | |
178 OFString temp_str; | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
179 LOG(ERROR) << "Move SCP Failed: " << cond.text(); |
0 | 180 } |
181 | |
182 return cond; | |
183 } | |
184 } |