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