Mercurial > hg > orthanc
annotate OrthancServer/Internals/MoveScp.cpp @ 102:7593b57dc1bf
switch to google log
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Oct 2012 16:28:13 +0200 |
parents | 428784e59dcd |
children | e759f777cb72 |
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. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 **/ | |
19 | |
20 | |
21 #include "MoveScp.h" | |
22 | |
23 #include <memory> | |
24 | |
25 #include "../FromDcmtkBridge.h" | |
26 #include "../ToDcmtkBridge.h" | |
62 | 27 #include "../../Core/OrthancException.h" |
0 | 28 |
29 #include <dcmtk/dcmdata/dcfilefo.h> | |
30 #include <dcmtk/dcmdata/dcmetinf.h> | |
31 #include <dcmtk/dcmdata/dcostrmb.h> | |
32 #include <dcmtk/dcmdata/dcdeftag.h> | |
33 #include <dcmtk/dcmnet/diutil.h> | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
34 #include <glog/logging.h> |
0 | 35 |
36 | |
62 | 37 namespace Orthanc |
0 | 38 { |
39 namespace | |
40 { | |
41 struct MoveScpData | |
42 { | |
43 std::string target_; | |
44 IMoveRequestHandler* handler_; | |
45 DicomMap input_; | |
46 DcmDataset* lastRequest_; | |
47 unsigned int subOperationCount_; | |
48 unsigned int failureCount_; | |
49 unsigned int warningCount_; | |
50 std::auto_ptr<IMoveRequestIterator> iterator_; | |
51 }; | |
52 | |
53 | |
54 void MoveScpCallback( | |
55 /* in */ | |
56 void *callbackData, | |
57 OFBool cancelled, | |
58 T_DIMSE_C_MoveRQ *request, | |
59 DcmDataset *requestIdentifiers, | |
60 int responseCount, | |
61 /* out */ | |
62 T_DIMSE_C_MoveRSP *response, | |
63 DcmDataset **responseIdentifiers, | |
64 DcmDataset **statusDetail) | |
65 { | |
66 bzero(response, sizeof(T_DIMSE_C_MoveRSP)); | |
67 *statusDetail = NULL; | |
68 *responseIdentifiers = NULL; | |
69 | |
70 MoveScpData& data = *(MoveScpData*) callbackData; | |
71 if (data.lastRequest_ == NULL) | |
72 { | |
73 FromDcmtkBridge::Convert(data.input_, *requestIdentifiers); | |
74 | |
75 try | |
76 { | |
77 data.iterator_.reset(data.handler_->Handle(data.target_, data.input_)); | |
78 data.subOperationCount_ = data.iterator_->GetSubOperationCount(); | |
79 data.failureCount_ = 0; | |
80 data.warningCount_ = 0; | |
81 } | |
62 | 82 catch (OrthancException& e) |
0 | 83 { |
84 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
85 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 86 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
87 return; | |
88 } | |
89 | |
90 data.lastRequest_ = requestIdentifiers; | |
91 } | |
92 else if (data.lastRequest_ != requestIdentifiers) | |
93 { | |
94 // Internal error! | |
95 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; | |
96 return; | |
97 } | |
98 | |
99 if (data.subOperationCount_ == 0) | |
100 { | |
101 response->DimseStatus = STATUS_Success; | |
102 } | |
103 else | |
104 { | |
105 IMoveRequestIterator::Status status; | |
106 | |
107 try | |
108 { | |
109 status = data.iterator_->DoNext(); | |
110 } | |
62 | 111 catch (OrthancException& e) |
0 | 112 { |
113 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
114 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 115 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
116 return; | |
117 } | |
118 | |
119 if (status == IMoveRequestIterator::Status_Failure) | |
120 { | |
121 data.failureCount_++; | |
122 } | |
123 else if (status == IMoveRequestIterator::Status_Warning) | |
124 { | |
125 data.warningCount_++; | |
126 } | |
127 | |
128 if (responseCount < static_cast<int>(data.subOperationCount_)) | |
129 { | |
130 response->DimseStatus = STATUS_Pending; | |
131 } | |
132 else | |
133 { | |
134 response->DimseStatus = STATUS_Success; | |
135 } | |
136 } | |
137 | |
138 response->NumberOfRemainingSubOperations = data.subOperationCount_ - responseCount; | |
139 response->NumberOfCompletedSubOperations = responseCount; | |
140 response->NumberOfFailedSubOperations = data.failureCount_; | |
141 response->NumberOfWarningSubOperations = data.warningCount_; | |
142 } | |
143 } | |
144 | |
145 | |
146 OFCondition Internals::moveScp(T_ASC_Association * assoc, | |
147 T_DIMSE_Message * msg, | |
148 T_ASC_PresentationContextID presID, | |
149 IMoveRequestHandler& handler) | |
150 { | |
151 MoveScpData data; | |
152 data.target_ = std::string(msg->msg.CMoveRQ.MoveDestination); | |
153 data.lastRequest_ = NULL; | |
154 data.handler_ = &handler; | |
155 | |
156 OFCondition cond = DIMSE_moveProvider(assoc, presID, &msg->msg.CMoveRQ, | |
157 MoveScpCallback, &data, | |
158 /*opt_blockMode*/ DIMSE_BLOCKING, | |
159 /*opt_dimse_timeout*/ 0); | |
160 | |
161 // if some error occured, dump corresponding information and remove the outfile if necessary | |
162 if (cond.bad()) | |
163 { | |
164 OFString temp_str; | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
165 LOG(ERROR) << "Move SCP Failed: " << cond.text(); |
0 | 166 } |
167 | |
168 return cond; | |
169 } | |
170 } |