Mercurial > hg > orthanc
annotate OrthancServer/Internals/FindScp.cpp @ 726:edffcf3ce7ab
sonar
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 19 Feb 2014 12:39:17 +0100 |
parents | 3596177682a9 |
children | 0a2f8c707c78 |
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 | |
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_; | |
665 | 52 const std::string* callingAETitle_; |
0 | 53 }; |
54 | |
55 | |
56 void FindScpCallback( | |
57 /* in */ | |
58 void *callbackData, | |
59 OFBool cancelled, | |
60 T_DIMSE_C_FindRQ *request, | |
61 DcmDataset *requestIdentifiers, | |
62 int responseCount, | |
63 /* out */ | |
64 T_DIMSE_C_FindRSP *response, | |
65 DcmDataset **responseIdentifiers, | |
66 DcmDataset **statusDetail) | |
67 { | |
68 bzero(response, sizeof(T_DIMSE_C_FindRSP)); | |
69 *statusDetail = NULL; | |
70 | |
656 | 71 FindScpData& data = *reinterpret_cast<FindScpData*>(callbackData); |
0 | 72 if (data.lastRequest_ == NULL) |
73 { | |
74 FromDcmtkBridge::Convert(data.input_, *requestIdentifiers); | |
75 | |
76 try | |
77 { | |
665 | 78 data.handler_->Handle(data.answers_, data.input_, *data.callingAETitle_); |
0 | 79 } |
62 | 80 catch (OrthancException& e) |
0 | 81 { |
82 // Internal error! | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
83 LOG(ERROR) << "IFindRequestHandler Failed: " << e.What(); |
0 | 84 response->DimseStatus = STATUS_FIND_Failed_UnableToProcess; |
85 *responseIdentifiers = NULL; | |
86 return; | |
87 } | |
88 | |
89 data.lastRequest_ = requestIdentifiers; | |
90 } | |
91 else if (data.lastRequest_ != requestIdentifiers) | |
92 { | |
93 // Internal error! | |
94 response->DimseStatus = STATUS_FIND_Failed_UnableToProcess; | |
95 *responseIdentifiers = NULL; | |
96 return; | |
97 } | |
722 | 98 |
0 | 99 if (responseCount <= static_cast<int>(data.answers_.GetSize())) |
100 { | |
101 response->DimseStatus = STATUS_Pending; | |
102 *responseIdentifiers = ToDcmtkBridge::Convert(data.answers_.GetAnswer(responseCount - 1)); | |
103 } | |
104 else | |
105 { | |
106 response->DimseStatus = STATUS_Success; | |
107 *responseIdentifiers = NULL; | |
108 } | |
109 } | |
110 } | |
111 | |
112 | |
113 OFCondition Internals::findScp(T_ASC_Association * assoc, | |
114 T_DIMSE_Message * msg, | |
115 T_ASC_PresentationContextID presID, | |
665 | 116 IFindRequestHandler& handler, |
117 const std::string& callingAETitle) | |
0 | 118 { |
119 FindScpData data; | |
120 data.lastRequest_ = NULL; | |
121 data.handler_ = &handler; | |
665 | 122 data.callingAETitle_ = &callingAETitle; |
0 | 123 |
124 OFCondition cond = DIMSE_findProvider(assoc, presID, &msg->msg.CFindRQ, | |
125 FindScpCallback, &data, | |
126 /*opt_blockMode*/ DIMSE_BLOCKING, | |
127 /*opt_dimse_timeout*/ 0); | |
128 | |
129 // if some error occured, dump corresponding information and remove the outfile if necessary | |
130 if (cond.bad()) | |
131 { | |
132 OFString temp_str; | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
133 LOG(ERROR) << "Find SCP Failed: " << cond.text(); |
0 | 134 } |
135 | |
136 return cond; | |
137 } | |
138 } |