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