Mercurial > hg > orthanc
annotate OrthancServer/Internals/MoveScp.cpp @ 754:b440dab8640d Orthanc-0.7.4
Orthanc-0.7.4
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Apr 2014 11:41:23 +0200 |
parents | 3596177682a9 |
children | 0a2f8c707c78 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 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 | |
656 | 77 MoveScpData& data = *reinterpret_cast<MoveScpData*>(callbackData); |
0 | 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_)); | |
722 | 85 |
613 | 86 if (data.iterator_.get() == NULL) |
87 { | |
88 // Internal error! | |
89 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; | |
90 return; | |
91 } | |
92 | |
0 | 93 data.subOperationCount_ = data.iterator_->GetSubOperationCount(); |
94 data.failureCount_ = 0; | |
95 data.warningCount_ = 0; | |
96 } | |
62 | 97 catch (OrthancException& e) |
0 | 98 { |
99 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
100 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 101 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
102 return; | |
103 } | |
104 | |
105 data.lastRequest_ = requestIdentifiers; | |
106 } | |
107 else if (data.lastRequest_ != requestIdentifiers) | |
108 { | |
109 // Internal error! | |
110 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; | |
111 return; | |
112 } | |
113 | |
114 if (data.subOperationCount_ == 0) | |
115 { | |
116 response->DimseStatus = STATUS_Success; | |
117 } | |
118 else | |
119 { | |
120 IMoveRequestIterator::Status status; | |
121 | |
122 try | |
123 { | |
124 status = data.iterator_->DoNext(); | |
125 } | |
62 | 126 catch (OrthancException& e) |
0 | 127 { |
128 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
129 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 130 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
131 return; | |
132 } | |
133 | |
134 if (status == IMoveRequestIterator::Status_Failure) | |
135 { | |
136 data.failureCount_++; | |
137 } | |
138 else if (status == IMoveRequestIterator::Status_Warning) | |
139 { | |
140 data.warningCount_++; | |
141 } | |
142 | |
143 if (responseCount < static_cast<int>(data.subOperationCount_)) | |
144 { | |
145 response->DimseStatus = STATUS_Pending; | |
146 } | |
147 else | |
148 { | |
149 response->DimseStatus = STATUS_Success; | |
150 } | |
151 } | |
152 | |
153 response->NumberOfRemainingSubOperations = data.subOperationCount_ - responseCount; | |
154 response->NumberOfCompletedSubOperations = responseCount; | |
155 response->NumberOfFailedSubOperations = data.failureCount_; | |
156 response->NumberOfWarningSubOperations = data.warningCount_; | |
157 } | |
158 } | |
159 | |
160 | |
161 OFCondition Internals::moveScp(T_ASC_Association * assoc, | |
162 T_DIMSE_Message * msg, | |
163 T_ASC_PresentationContextID presID, | |
164 IMoveRequestHandler& handler) | |
165 { | |
166 MoveScpData data; | |
167 data.target_ = std::string(msg->msg.CMoveRQ.MoveDestination); | |
168 data.lastRequest_ = NULL; | |
169 data.handler_ = &handler; | |
170 | |
171 OFCondition cond = DIMSE_moveProvider(assoc, presID, &msg->msg.CMoveRQ, | |
172 MoveScpCallback, &data, | |
173 /*opt_blockMode*/ DIMSE_BLOCKING, | |
174 /*opt_dimse_timeout*/ 0); | |
175 | |
176 // if some error occured, dump corresponding information and remove the outfile if necessary | |
177 if (cond.bad()) | |
178 { | |
179 OFString temp_str; | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
180 LOG(ERROR) << "Move SCP Failed: " << cond.text(); |
0 | 181 } |
182 | |
183 return cond; | |
184 } | |
185 } |