Mercurial > hg > orthanc
annotate OrthancServer/Internals/MoveScp.cpp @ 804:a017d1a89b4f
fix for windows
author | jodogne |
---|---|
date | Wed, 07 May 2014 10:01:33 +0200 |
parents | 0a2f8c707c78 |
children | a811bdf8b8eb |
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 | |
766
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
33 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
34 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
35 /*========================================================================= |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
36 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
37 This file is based on portions of the following project: |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
38 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
39 Program: DCMTK 3.6.0 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
40 Module: http://dicom.offis.de/dcmtk.php.en |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
41 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
42 Copyright (C) 1994-2011, OFFIS e.V. |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
43 All rights reserved. |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
44 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
45 This software and supporting documentation were developed by |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
46 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
47 OFFIS e.V. |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
48 R&D Division Health |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
49 Escherweg 2 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
50 26121 Oldenburg, Germany |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
51 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
52 Redistribution and use in source and binary forms, with or without |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
53 modification, are permitted provided that the following conditions |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
54 are met: |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
55 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
56 - Redistributions of source code must retain the above copyright |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
57 notice, this list of conditions and the following disclaimer. |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
58 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
59 - Redistributions in binary form must reproduce the above copyright |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
60 notice, this list of conditions and the following disclaimer in the |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
61 documentation and/or other materials provided with the distribution. |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
62 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
63 - Neither the name of OFFIS nor the names of its contributors may be |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
64 used to endorse or promote products derived from this software |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
65 without specific prior written permission. |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
66 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
67 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
68 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
69 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
70 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
71 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
72 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
73 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
74 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
75 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
76 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
77 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
78 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
79 =========================================================================*/ |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
80 |
0a2f8c707c78
Fix missing licensing terms about reuse of some DCMTK code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
722
diff
changeset
|
81 |
0 | 82 #include "MoveScp.h" |
83 | |
84 #include <memory> | |
85 | |
86 #include "../FromDcmtkBridge.h" | |
87 #include "../ToDcmtkBridge.h" | |
62 | 88 #include "../../Core/OrthancException.h" |
0 | 89 |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
90 #include <glog/logging.h> |
0 | 91 |
92 | |
62 | 93 namespace Orthanc |
0 | 94 { |
95 namespace | |
96 { | |
97 struct MoveScpData | |
98 { | |
99 std::string target_; | |
100 IMoveRequestHandler* handler_; | |
101 DicomMap input_; | |
102 DcmDataset* lastRequest_; | |
103 unsigned int subOperationCount_; | |
104 unsigned int failureCount_; | |
105 unsigned int warningCount_; | |
106 std::auto_ptr<IMoveRequestIterator> iterator_; | |
107 }; | |
108 | |
109 | |
110 void MoveScpCallback( | |
111 /* in */ | |
112 void *callbackData, | |
113 OFBool cancelled, | |
114 T_DIMSE_C_MoveRQ *request, | |
115 DcmDataset *requestIdentifiers, | |
116 int responseCount, | |
117 /* out */ | |
118 T_DIMSE_C_MoveRSP *response, | |
119 DcmDataset **responseIdentifiers, | |
120 DcmDataset **statusDetail) | |
121 { | |
122 bzero(response, sizeof(T_DIMSE_C_MoveRSP)); | |
123 *statusDetail = NULL; | |
124 *responseIdentifiers = NULL; | |
125 | |
656 | 126 MoveScpData& data = *reinterpret_cast<MoveScpData*>(callbackData); |
0 | 127 if (data.lastRequest_ == NULL) |
128 { | |
129 FromDcmtkBridge::Convert(data.input_, *requestIdentifiers); | |
130 | |
131 try | |
132 { | |
133 data.iterator_.reset(data.handler_->Handle(data.target_, data.input_)); | |
722 | 134 |
613 | 135 if (data.iterator_.get() == NULL) |
136 { | |
137 // Internal error! | |
138 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; | |
139 return; | |
140 } | |
141 | |
0 | 142 data.subOperationCount_ = data.iterator_->GetSubOperationCount(); |
143 data.failureCount_ = 0; | |
144 data.warningCount_ = 0; | |
145 } | |
62 | 146 catch (OrthancException& e) |
0 | 147 { |
148 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
149 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 150 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
151 return; | |
152 } | |
153 | |
154 data.lastRequest_ = requestIdentifiers; | |
155 } | |
156 else if (data.lastRequest_ != requestIdentifiers) | |
157 { | |
158 // Internal error! | |
159 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; | |
160 return; | |
161 } | |
162 | |
163 if (data.subOperationCount_ == 0) | |
164 { | |
165 response->DimseStatus = STATUS_Success; | |
166 } | |
167 else | |
168 { | |
169 IMoveRequestIterator::Status status; | |
170 | |
171 try | |
172 { | |
173 status = data.iterator_->DoNext(); | |
174 } | |
62 | 175 catch (OrthancException& e) |
0 | 176 { |
177 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
178 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 179 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
180 return; | |
181 } | |
182 | |
183 if (status == IMoveRequestIterator::Status_Failure) | |
184 { | |
185 data.failureCount_++; | |
186 } | |
187 else if (status == IMoveRequestIterator::Status_Warning) | |
188 { | |
189 data.warningCount_++; | |
190 } | |
191 | |
192 if (responseCount < static_cast<int>(data.subOperationCount_)) | |
193 { | |
194 response->DimseStatus = STATUS_Pending; | |
195 } | |
196 else | |
197 { | |
198 response->DimseStatus = STATUS_Success; | |
199 } | |
200 } | |
201 | |
202 response->NumberOfRemainingSubOperations = data.subOperationCount_ - responseCount; | |
203 response->NumberOfCompletedSubOperations = responseCount; | |
204 response->NumberOfFailedSubOperations = data.failureCount_; | |
205 response->NumberOfWarningSubOperations = data.warningCount_; | |
206 } | |
207 } | |
208 | |
209 | |
210 OFCondition Internals::moveScp(T_ASC_Association * assoc, | |
211 T_DIMSE_Message * msg, | |
212 T_ASC_PresentationContextID presID, | |
213 IMoveRequestHandler& handler) | |
214 { | |
215 MoveScpData data; | |
216 data.target_ = std::string(msg->msg.CMoveRQ.MoveDestination); | |
217 data.lastRequest_ = NULL; | |
218 data.handler_ = &handler; | |
219 | |
220 OFCondition cond = DIMSE_moveProvider(assoc, presID, &msg->msg.CMoveRQ, | |
221 MoveScpCallback, &data, | |
222 /*opt_blockMode*/ DIMSE_BLOCKING, | |
223 /*opt_dimse_timeout*/ 0); | |
224 | |
225 // if some error occured, dump corresponding information and remove the outfile if necessary | |
226 if (cond.bad()) | |
227 { | |
228 OFString temp_str; | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
229 LOG(ERROR) << "Move SCP Failed: " << cond.text(); |
0 | 230 } |
231 | |
232 return cond; | |
233 } | |
234 } |