comparison OrthancServer/Internals/StoreScp.cpp @ 101:428784e59dcd

trying to use log4cplus
author jodogne
date Wed, 03 Oct 2012 11:44:46 +0200
parents a70bb32802ae
children 7593b57dc1bf
comparison
equal deleted inserted replaced
100:27dc762e3dc8 101:428784e59dcd
21 #include "StoreScp.h" 21 #include "StoreScp.h"
22 22
23 #include "../FromDcmtkBridge.h" 23 #include "../FromDcmtkBridge.h"
24 #include "../ToDcmtkBridge.h" 24 #include "../ToDcmtkBridge.h"
25 #include "../../Core/OrthancException.h" 25 #include "../../Core/OrthancException.h"
26 #include "DcmtkLogging.h"
26 27
27 #include <dcmtk/dcmdata/dcfilefo.h> 28 #include <dcmtk/dcmdata/dcfilefo.h>
28 #include <dcmtk/dcmdata/dcmetinf.h> 29 #include <dcmtk/dcmdata/dcmetinf.h>
29 #include <dcmtk/dcmdata/dcostrmb.h> 30 #include <dcmtk/dcmdata/dcostrmb.h>
30 #include <dcmtk/dcmdata/dcdeftag.h> 31 #include <dcmtk/dcmdata/dcdeftag.h>
31 #include <dcmtk/dcmnet/diutil.h> 32 #include <dcmtk/dcmnet/diutil.h>
32 33
33 34
34 namespace Orthanc 35 namespace Orthanc
35 { 36 {
36 namespace Internals
37 {
38 extern OFLogger Logger;
39 }
40
41
42 namespace 37 namespace
43 { 38 {
44 struct StoreCallbackData 39 struct StoreCallbackData
45 { 40 {
46 IStoreRequestHandler* handler; 41 IStoreRequestHandler* handler;
66 61
67 buffer.resize(s); 62 buffer.resize(s);
68 DcmOutputBufferStream ob(&buffer[0], s); 63 DcmOutputBufferStream ob(&buffer[0], s);
69 64
70 dataSet->transferInit(); 65 dataSet->transferInit();
66
67 #if 0
71 OFCondition c = dataSet->write(ob, xfer, encodingType, NULL, 68 OFCondition c = dataSet->write(ob, xfer, encodingType, NULL,
72 /*opt_groupLength*/ EGL_recalcGL, 69 /*opt_groupLength*/ EGL_recalcGL,
73 /*opt_paddingType*/ EPD_withoutPadding); 70 /*opt_paddingType*/ EPD_withoutPadding);
71 #endif
72 OFCondition c = dataSet->write(ob, xfer, encodingType);
73
74 dataSet->transferEnd(); 74 dataSet->transferEnd();
75 if (c.good()) 75 if (c.good())
76 { 76 {
77 return 0; 77 return 0;
78 } 78 }
153 FromDcmtkBridge::Convert(summary, **imageDataSet); 153 FromDcmtkBridge::Convert(summary, **imageDataSet);
154 FromDcmtkBridge::ToJson(dicomJson, **imageDataSet); 154 FromDcmtkBridge::ToJson(dicomJson, **imageDataSet);
155 155
156 if (SaveToMemoryBuffer(*imageDataSet, buffer) < 0) 156 if (SaveToMemoryBuffer(*imageDataSet, buffer) < 0)
157 { 157 {
158 OFLOG_ERROR(Internals::Logger, "cannot write DICOM file to memory"); 158 LOG4CPP_ERROR(Internals::GetLogger(), "cannot write DICOM file to memory");
159 rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources; 159 rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources;
160 } 160 }
161 } 161 }
162 catch (...) 162 catch (...)
163 { 163 {
169 if ((rsp->DimseStatus == STATUS_Success)) 169 if ((rsp->DimseStatus == STATUS_Success))
170 { 170 {
171 // which SOP class and SOP instance ? 171 // which SOP class and SOP instance ?
172 if (!DU_findSOPClassAndInstanceInDataSet(*imageDataSet, sopClass, sopInstance, /*opt_correctUIDPadding*/ OFFalse)) 172 if (!DU_findSOPClassAndInstanceInDataSet(*imageDataSet, sopClass, sopInstance, /*opt_correctUIDPadding*/ OFFalse))
173 { 173 {
174 //OFLOG_ERROR(Internals::Logger, "bad DICOM file: " << fileName); 174 //LOG4CPP_ERROR(Internals::GetLogger(), "bad DICOM file: " << fileName);
175 rsp->DimseStatus = STATUS_STORE_Error_CannotUnderstand; 175 rsp->DimseStatus = STATUS_STORE_Error_CannotUnderstand;
176 } 176 }
177 else if (strcmp(sopClass, req->AffectedSOPClassUID) != 0) 177 else if (strcmp(sopClass, req->AffectedSOPClassUID) != 0)
178 { 178 {
179 rsp->DimseStatus = STATUS_STORE_Error_DataSetDoesNotMatchSOPClass; 179 rsp->DimseStatus = STATUS_STORE_Error_DataSetDoesNotMatchSOPClass;
189 cbdata->handler->Handle(buffer, summary, dicomJson, cbdata->distantAET); 189 cbdata->handler->Handle(buffer, summary, dicomJson, cbdata->distantAET);
190 } 190 }
191 catch (OrthancException& e) 191 catch (OrthancException& e)
192 { 192 {
193 rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources; 193 rsp->DimseStatus = STATUS_STORE_Refused_OutOfResources;
194 OFLOG_ERROR(Internals::Logger, "Exception while storing DICOM: " << e.What()); 194 LOG4CPP_ERROR(Internals::GetLogger(), "Exception while storing DICOM: " + std::string(e.What()));
195 } 195 }
196 } 196 }
197 } 197 }
198 } 198 }
199 } 199 }
222 req = &msg->msg.CStoreRQ; 222 req = &msg->msg.CStoreRQ;
223 223
224 // intialize some variables 224 // intialize some variables
225 StoreCallbackData callbackData; 225 StoreCallbackData callbackData;
226 callbackData.handler = &handler; 226 callbackData.handler = &handler;
227 callbackData.modality = dcmSOPClassUIDToModality(req->AffectedSOPClassUID, "UNKNOWN"); 227 callbackData.modality = dcmSOPClassUIDToModality(req->AffectedSOPClassUID/*, "UNKNOWN"*/);
228 if (callbackData.modality == NULL)
229 callbackData.modality = "UNKNOWN";
230
228 callbackData.affectedSOPInstanceUID = req->AffectedSOPInstanceUID; 231 callbackData.affectedSOPInstanceUID = req->AffectedSOPInstanceUID;
229 callbackData.messageID = req->MessageID; 232 callbackData.messageID = req->MessageID;
230 if (assoc && assoc->params) 233 if (assoc && assoc->params)
231 { 234 {
232 callbackData.distantAET = assoc->params->DULparams.callingAPTitle; 235 callbackData.distantAET = assoc->params->DULparams.callingAPTitle;
255 258
256 // if some error occured, dump corresponding information and remove the outfile if necessary 259 // if some error occured, dump corresponding information and remove the outfile if necessary
257 if (cond.bad()) 260 if (cond.bad())
258 { 261 {
259 OFString temp_str; 262 OFString temp_str;
260 OFLOG_ERROR(Logger, "Store SCP Failed: " << DimseCondition::dump(temp_str, cond)); 263 LOG4CPP_ERROR(GetLogger(), "Store SCP Failed: " + std::string(cond.text()));
261 } 264 }
262 265
263 // return return value 266 // return return value
264 return cond; 267 return cond;
265 } 268 }