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 "FindScp.h"
|
|
22
|
|
23 #include "../FromDcmtkBridge.h"
|
|
24 #include "../ToDcmtkBridge.h"
|
62
|
25 #include "../../Core/OrthancException.h"
|
0
|
26
|
|
27 #include <dcmtk/dcmdata/dcfilefo.h>
|
|
28 #include <dcmtk/dcmdata/dcmetinf.h>
|
|
29 #include <dcmtk/dcmdata/dcostrmb.h>
|
|
30 #include <dcmtk/dcmdata/dcdeftag.h>
|
|
31 #include <dcmtk/dcmnet/diutil.h>
|
|
32
|
|
33
|
62
|
34 namespace Orthanc
|
0
|
35 {
|
|
36 namespace Internals
|
|
37 {
|
|
38 extern OFLogger Logger;
|
|
39 }
|
|
40
|
|
41
|
|
42 namespace
|
|
43 {
|
|
44 struct FindScpData
|
|
45 {
|
|
46 IFindRequestHandler* handler_;
|
|
47 DicomMap input_;
|
|
48 DicomFindAnswers answers_;
|
|
49 DcmDataset* lastRequest_;
|
|
50 };
|
|
51
|
|
52
|
|
53 void FindScpCallback(
|
|
54 /* in */
|
|
55 void *callbackData,
|
|
56 OFBool cancelled,
|
|
57 T_DIMSE_C_FindRQ *request,
|
|
58 DcmDataset *requestIdentifiers,
|
|
59 int responseCount,
|
|
60 /* out */
|
|
61 T_DIMSE_C_FindRSP *response,
|
|
62 DcmDataset **responseIdentifiers,
|
|
63 DcmDataset **statusDetail)
|
|
64 {
|
|
65 bzero(response, sizeof(T_DIMSE_C_FindRSP));
|
|
66 *statusDetail = NULL;
|
|
67
|
|
68 FindScpData& data = *(FindScpData*) callbackData;
|
|
69 if (data.lastRequest_ == NULL)
|
|
70 {
|
|
71 FromDcmtkBridge::Convert(data.input_, *requestIdentifiers);
|
|
72
|
|
73 try
|
|
74 {
|
|
75 data.handler_->Handle(data.input_, data.answers_);
|
|
76 }
|
62
|
77 catch (OrthancException& e)
|
0
|
78 {
|
|
79 // Internal error!
|
|
80 OFLOG_ERROR(Internals::Logger, "IFindRequestHandler Failed: " << e.What());
|
|
81 response->DimseStatus = STATUS_FIND_Failed_UnableToProcess;
|
|
82 *responseIdentifiers = NULL;
|
|
83 return;
|
|
84 }
|
|
85
|
|
86 data.lastRequest_ = requestIdentifiers;
|
|
87 }
|
|
88 else if (data.lastRequest_ != requestIdentifiers)
|
|
89 {
|
|
90 // Internal error!
|
|
91 response->DimseStatus = STATUS_FIND_Failed_UnableToProcess;
|
|
92 *responseIdentifiers = NULL;
|
|
93 return;
|
|
94 }
|
|
95
|
|
96 if (responseCount <= static_cast<int>(data.answers_.GetSize()))
|
|
97 {
|
|
98 response->DimseStatus = STATUS_Pending;
|
|
99 *responseIdentifiers = ToDcmtkBridge::Convert(data.answers_.GetAnswer(responseCount - 1));
|
|
100 }
|
|
101 else
|
|
102 {
|
|
103 response->DimseStatus = STATUS_Success;
|
|
104 *responseIdentifiers = NULL;
|
|
105 }
|
|
106 }
|
|
107 }
|
|
108
|
|
109
|
|
110 OFCondition Internals::findScp(T_ASC_Association * assoc,
|
|
111 T_DIMSE_Message * msg,
|
|
112 T_ASC_PresentationContextID presID,
|
|
113 IFindRequestHandler& handler)
|
|
114 {
|
|
115 FindScpData data;
|
|
116 data.lastRequest_ = NULL;
|
|
117 data.handler_ = &handler;
|
|
118
|
|
119 OFCondition cond = DIMSE_findProvider(assoc, presID, &msg->msg.CFindRQ,
|
|
120 FindScpCallback, &data,
|
|
121 /*opt_blockMode*/ DIMSE_BLOCKING,
|
|
122 /*opt_dimse_timeout*/ 0);
|
|
123
|
|
124 // if some error occured, dump corresponding information and remove the outfile if necessary
|
|
125 if (cond.bad())
|
|
126 {
|
|
127 OFString temp_str;
|
|
128 OFLOG_ERROR(Internals::Logger, "Find SCP Failed: " << DimseCondition::dump(temp_str, cond));
|
|
129 }
|
|
130
|
|
131 return cond;
|
|
132 }
|
|
133 }
|