Mercurial > hg > orthanc
annotate OrthancServer/Internals/FindScp.cpp @ 310:6ab6cdeedf4e
global sequences
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Dec 2012 11:18:27 +0100 |
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 "FindScp.h" | |
34 | |
35 #include "../FromDcmtkBridge.h" | |
36 #include "../ToDcmtkBridge.h" | |
62 | 37 #include "../../Core/OrthancException.h" |
0 | 38 |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
39 #include <glog/logging.h> |
0 | 40 |
41 | |
62 | 42 namespace Orthanc |
0 | 43 { |
44 namespace | |
45 { | |
46 struct FindScpData | |
47 { | |
48 IFindRequestHandler* handler_; | |
49 DicomMap input_; | |
50 DicomFindAnswers answers_; | |
51 DcmDataset* lastRequest_; | |
52 }; | |
53 | |
54 | |
55 void FindScpCallback( | |
56 /* in */ | |
57 void *callbackData, | |
58 OFBool cancelled, | |
59 T_DIMSE_C_FindRQ *request, | |
60 DcmDataset *requestIdentifiers, | |
61 int responseCount, | |
62 /* out */ | |
63 T_DIMSE_C_FindRSP *response, | |
64 DcmDataset **responseIdentifiers, | |
65 DcmDataset **statusDetail) | |
66 { | |
67 bzero(response, sizeof(T_DIMSE_C_FindRSP)); | |
68 *statusDetail = NULL; | |
69 | |
70 FindScpData& data = *(FindScpData*) callbackData; | |
71 if (data.lastRequest_ == NULL) | |
72 { | |
73 FromDcmtkBridge::Convert(data.input_, *requestIdentifiers); | |
74 | |
75 try | |
76 { | |
77 data.handler_->Handle(data.input_, data.answers_); | |
78 } | |
62 | 79 catch (OrthancException& e) |
0 | 80 { |
81 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
82 LOG(ERROR) << "IFindRequestHandler Failed: " << e.What(); |
0 | 83 response->DimseStatus = STATUS_FIND_Failed_UnableToProcess; |
84 *responseIdentifiers = NULL; | |
85 return; | |
86 } | |
87 | |
88 data.lastRequest_ = requestIdentifiers; | |
89 } | |
90 else if (data.lastRequest_ != requestIdentifiers) | |
91 { | |
92 // Internal error! | |
93 response->DimseStatus = STATUS_FIND_Failed_UnableToProcess; | |
94 *responseIdentifiers = NULL; | |
95 return; | |
96 } | |
97 | |
98 if (responseCount <= static_cast<int>(data.answers_.GetSize())) | |
99 { | |
100 response->DimseStatus = STATUS_Pending; | |
101 *responseIdentifiers = ToDcmtkBridge::Convert(data.answers_.GetAnswer(responseCount - 1)); | |
102 } | |
103 else | |
104 { | |
105 response->DimseStatus = STATUS_Success; | |
106 *responseIdentifiers = NULL; | |
107 } | |
108 } | |
109 } | |
110 | |
111 | |
112 OFCondition Internals::findScp(T_ASC_Association * assoc, | |
113 T_DIMSE_Message * msg, | |
114 T_ASC_PresentationContextID presID, | |
115 IFindRequestHandler& handler) | |
116 { | |
117 FindScpData data; | |
118 data.lastRequest_ = NULL; | |
119 data.handler_ = &handler; | |
120 | |
121 OFCondition cond = DIMSE_findProvider(assoc, presID, &msg->msg.CFindRQ, | |
122 FindScpCallback, &data, | |
123 /*opt_blockMode*/ DIMSE_BLOCKING, | |
124 /*opt_dimse_timeout*/ 0); | |
125 | |
126 // if some error occured, dump corresponding information and remove the outfile if necessary | |
127 if (cond.bad()) | |
128 { | |
129 OFString temp_str; | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
130 LOG(ERROR) << "Find SCP Failed: " << cond.text(); |
0 | 131 } |
132 | |
133 return cond; | |
134 } | |
135 } |