Mercurial > hg > orthanc
annotate OrthancServer/Internals/MoveScp.cpp @ 135:a2dbb5024fdf
install in cmake
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Oct 2012 12:07:27 +0200 |
parents | e759f777cb72 |
children | fe180eae201d |
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 |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
29 #include <glog/logging.h> |
0 | 30 |
31 | |
62 | 32 namespace Orthanc |
0 | 33 { |
34 namespace | |
35 { | |
36 struct MoveScpData | |
37 { | |
38 std::string target_; | |
39 IMoveRequestHandler* handler_; | |
40 DicomMap input_; | |
41 DcmDataset* lastRequest_; | |
42 unsigned int subOperationCount_; | |
43 unsigned int failureCount_; | |
44 unsigned int warningCount_; | |
45 std::auto_ptr<IMoveRequestIterator> iterator_; | |
46 }; | |
47 | |
48 | |
49 void MoveScpCallback( | |
50 /* in */ | |
51 void *callbackData, | |
52 OFBool cancelled, | |
53 T_DIMSE_C_MoveRQ *request, | |
54 DcmDataset *requestIdentifiers, | |
55 int responseCount, | |
56 /* out */ | |
57 T_DIMSE_C_MoveRSP *response, | |
58 DcmDataset **responseIdentifiers, | |
59 DcmDataset **statusDetail) | |
60 { | |
61 bzero(response, sizeof(T_DIMSE_C_MoveRSP)); | |
62 *statusDetail = NULL; | |
63 *responseIdentifiers = NULL; | |
64 | |
65 MoveScpData& data = *(MoveScpData*) callbackData; | |
66 if (data.lastRequest_ == NULL) | |
67 { | |
68 FromDcmtkBridge::Convert(data.input_, *requestIdentifiers); | |
69 | |
70 try | |
71 { | |
72 data.iterator_.reset(data.handler_->Handle(data.target_, data.input_)); | |
73 data.subOperationCount_ = data.iterator_->GetSubOperationCount(); | |
74 data.failureCount_ = 0; | |
75 data.warningCount_ = 0; | |
76 } | |
62 | 77 catch (OrthancException& e) |
0 | 78 { |
79 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
80 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 81 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
82 return; | |
83 } | |
84 | |
85 data.lastRequest_ = requestIdentifiers; | |
86 } | |
87 else if (data.lastRequest_ != requestIdentifiers) | |
88 { | |
89 // Internal error! | |
90 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; | |
91 return; | |
92 } | |
93 | |
94 if (data.subOperationCount_ == 0) | |
95 { | |
96 response->DimseStatus = STATUS_Success; | |
97 } | |
98 else | |
99 { | |
100 IMoveRequestIterator::Status status; | |
101 | |
102 try | |
103 { | |
104 status = data.iterator_->DoNext(); | |
105 } | |
62 | 106 catch (OrthancException& e) |
0 | 107 { |
108 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
109 LOG(ERROR) << "IMoveRequestHandler Failed: " << e.What(); |
0 | 110 response->DimseStatus = STATUS_MOVE_Failed_UnableToProcess; |
111 return; | |
112 } | |
113 | |
114 if (status == IMoveRequestIterator::Status_Failure) | |
115 { | |
116 data.failureCount_++; | |
117 } | |
118 else if (status == IMoveRequestIterator::Status_Warning) | |
119 { | |
120 data.warningCount_++; | |
121 } | |
122 | |
123 if (responseCount < static_cast<int>(data.subOperationCount_)) | |
124 { | |
125 response->DimseStatus = STATUS_Pending; | |
126 } | |
127 else | |
128 { | |
129 response->DimseStatus = STATUS_Success; | |
130 } | |
131 } | |
132 | |
133 response->NumberOfRemainingSubOperations = data.subOperationCount_ - responseCount; | |
134 response->NumberOfCompletedSubOperations = responseCount; | |
135 response->NumberOfFailedSubOperations = data.failureCount_; | |
136 response->NumberOfWarningSubOperations = data.warningCount_; | |
137 } | |
138 } | |
139 | |
140 | |
141 OFCondition Internals::moveScp(T_ASC_Association * assoc, | |
142 T_DIMSE_Message * msg, | |
143 T_ASC_PresentationContextID presID, | |
144 IMoveRequestHandler& handler) | |
145 { | |
146 MoveScpData data; | |
147 data.target_ = std::string(msg->msg.CMoveRQ.MoveDestination); | |
148 data.lastRequest_ = NULL; | |
149 data.handler_ = &handler; | |
150 | |
151 OFCondition cond = DIMSE_moveProvider(assoc, presID, &msg->msg.CMoveRQ, | |
152 MoveScpCallback, &data, | |
153 /*opt_blockMode*/ DIMSE_BLOCKING, | |
154 /*opt_dimse_timeout*/ 0); | |
155 | |
156 // if some error occured, dump corresponding information and remove the outfile if necessary | |
157 if (cond.bad()) | |
158 { | |
159 OFString temp_str; | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
160 LOG(ERROR) << "Move SCP Failed: " << cond.text(); |
0 | 161 } |
162 | |
163 return cond; | |
164 } | |
165 } |