comparison OrthancServer/Internals/CommandDispatcher.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 "CommandDispatcher.h" 21 #include "CommandDispatcher.h"
22 22
23 #include "FindScp.h" 23 #include "FindScp.h"
24 #include "StoreScp.h" 24 #include "StoreScp.h"
25 #include "MoveScp.h" 25 #include "MoveScp.h"
26 #include "DcmtkLogging.h"
26 #include "../../Core/Toolbox.h" 27 #include "../../Core/Toolbox.h"
27 28
28 #include <dcmtk/dcmnet/dcasccfg.h> /* for class DcmAssociationConfiguration */ 29 #include <dcmtk/dcmnet/dcasccfg.h> /* for class DcmAssociationConfiguration */
30 #include <boost/lexical_cast.hpp>
29 31
30 static OFBool opt_rejectWithoutImplementationUID = OFFalse; 32 static OFBool opt_rejectWithoutImplementationUID = OFFalse;
31 33
32 34
33 namespace Orthanc 35 namespace Orthanc
34 { 36 {
35 namespace Internals 37 namespace Internals
36 { 38 {
37 extern OFLogger Logger;
38
39
40
41 OFCondition AssociationCleanup(T_ASC_Association *assoc) 39 OFCondition AssociationCleanup(T_ASC_Association *assoc)
42 { 40 {
43 OFString temp_str; 41 OFString temp_str;
44 OFCondition cond = ASC_dropSCPAssociation(assoc); 42 OFCondition cond = ASC_dropSCPAssociation(assoc);
45 if (cond.bad()) 43 if (cond.bad())
46 { 44 {
47 OFLOG_FATAL(Internals::Logger, DimseCondition::dump(temp_str, cond)); 45 LOG4CPP_FATAL(Internals::GetLogger(), std::string(cond.text()));
48 return cond; 46 return cond;
49 } 47 }
50 48
51 cond = ASC_destroyAssociation(&assoc); 49 cond = ASC_destroyAssociation(&assoc);
52 if (cond.bad()) 50 if (cond.bad())
53 { 51 {
54 OFLOG_FATAL(Internals::Logger, DimseCondition::dump(temp_str, cond)); 52 LOG4CPP_FATAL(Internals::GetLogger(), std::string(cond.text()));
55 return cond; 53 return cond;
56 } 54 }
57 55
58 return cond; 56 return cond;
59 } 57 }
107 } 105 }
108 106
109 // if some kind of error occured, take care of it 107 // if some kind of error occured, take care of it
110 if (cond.bad()) 108 if (cond.bad())
111 { 109 {
112 OFLOG_ERROR(Internals::Logger, "Receiving Association failed: " << DimseCondition::dump(temp_str, cond)); 110 LOG4CPP_ERROR(Internals::GetLogger(), "Receiving Association failed: " + std::string(cond.text()));
113 // no matter what kind of error occurred, we need to do a cleanup 111 // no matter what kind of error occurred, we need to do a cleanup
114 AssociationCleanup(assoc); 112 AssociationCleanup(assoc);
115 return NULL; 113 return NULL;
116 } 114 }
117 115
118 OFLOG_INFO(Internals::Logger, "Association Received"); 116 LOG4CPP_INFO(Internals::GetLogger(), "Association Received");
119 117
120 transferSyntaxes[0] = UID_LittleEndianExplicitTransferSyntax; 118 transferSyntaxes[0] = UID_LittleEndianExplicitTransferSyntax;
121 transferSyntaxes[1] = UID_BigEndianExplicitTransferSyntax; 119 transferSyntaxes[1] = UID_BigEndianExplicitTransferSyntax;
122 transferSyntaxes[2] = UID_LittleEndianImplicitTransferSyntax; 120 transferSyntaxes[2] = UID_LittleEndianImplicitTransferSyntax;
123 numTransferSyntaxes = 3; 121 numTransferSyntaxes = 3;
124 122
125 /* accept the Verification SOP Class if presented */ 123 /* accept the Verification SOP Class if presented */
126 cond = ASC_acceptContextsWithPreferredTransferSyntaxes( assoc->params, &knownAbstractSyntaxes[0], knownAbstractSyntaxes.size(), transferSyntaxes, numTransferSyntaxes); 124 cond = ASC_acceptContextsWithPreferredTransferSyntaxes( assoc->params, &knownAbstractSyntaxes[0], knownAbstractSyntaxes.size(), transferSyntaxes, numTransferSyntaxes);
127 if (cond.bad()) 125 if (cond.bad())
128 { 126 {
129 OFLOG_DEBUG(Internals::Logger, DimseCondition::dump(temp_str, cond)); 127 LOG4CPP_DEBUG(Internals::GetLogger(), std::string(cond.text()));
130 AssociationCleanup(assoc); 128 AssociationCleanup(assoc);
131 return NULL; 129 return NULL;
132 } 130 }
133 131
134 /* the array of Storage SOP Class UIDs comes from dcuid.h */ 132 /* the array of Storage SOP Class UIDs comes from dcuid.h */
135 cond = ASC_acceptContextsWithPreferredTransferSyntaxes( assoc->params, dcmAllStorageSOPClassUIDs, numberOfAllDcmStorageSOPClassUIDs, transferSyntaxes, numTransferSyntaxes); 133 cond = ASC_acceptContextsWithPreferredTransferSyntaxes( assoc->params, dcmAllStorageSOPClassUIDs, numberOfAllDcmStorageSOPClassUIDs, transferSyntaxes, numTransferSyntaxes);
136 if (cond.bad()) 134 if (cond.bad())
137 { 135 {
138 OFLOG_DEBUG(Internals::Logger, DimseCondition::dump(temp_str, cond)); 136 LOG4CPP_DEBUG(Internals::GetLogger(), std::string(cond.text()));
139 AssociationCleanup(assoc); 137 AssociationCleanup(assoc);
140 return NULL; 138 return NULL;
141 } 139 }
142 140
143 /* set our app title */ 141 /* set our app title */
153 ASC_RESULT_REJECTEDPERMANENT, 151 ASC_RESULT_REJECTEDPERMANENT,
154 ASC_SOURCE_SERVICEUSER, 152 ASC_SOURCE_SERVICEUSER,
155 ASC_REASON_SU_APPCONTEXTNAMENOTSUPPORTED 153 ASC_REASON_SU_APPCONTEXTNAMENOTSUPPORTED
156 }; 154 };
157 155
158 OFLOG_INFO(Internals::Logger, "Association Rejected: Bad Application Context Name: " << buf); 156 LOG4CPP_INFO(Internals::GetLogger(), "Association Rejected: Bad Application Context Name: " + std::string(buf));
159 cond = ASC_rejectAssociation(assoc, &rej); 157 cond = ASC_rejectAssociation(assoc, &rej);
160 if (cond.bad()) 158 if (cond.bad())
161 { 159 {
162 OFLOG_DEBUG(Internals::Logger, DimseCondition::dump(temp_str, cond)); 160 LOG4CPP_DEBUG(Internals::GetLogger(), std::string(cond.text()));
163 } 161 }
164 AssociationCleanup(assoc); 162 AssociationCleanup(assoc);
165 return NULL; 163 return NULL;
166 } 164 }
167 165
183 ASC_rejectAssociation(assoc, &rej); 181 ASC_rejectAssociation(assoc, &rej);
184 AssociationCleanup(assoc); 182 AssociationCleanup(assoc);
185 return NULL; 183 return NULL;
186 } 184 }
187 185
188 std::string callingIP(OFSTRING_GUARD(callingIP_C)); 186 std::string callingIP(/*OFSTRING_GUARD*/(callingIP_C));
189 std::string callingTitle(OFSTRING_GUARD(callingTitle_C)); 187 std::string callingTitle(/*OFSTRING_GUARD*/(callingTitle_C));
190 std::string calledTitle(OFSTRING_GUARD(calledTitle_C)); 188 std::string calledTitle(/*OFSTRING_GUARD*/(calledTitle_C));
191 Toolbox::ToUpperCase(callingIP); 189 Toolbox::ToUpperCase(callingIP);
192 Toolbox::ToUpperCase(callingTitle); 190 Toolbox::ToUpperCase(callingTitle);
193 Toolbox::ToUpperCase(calledTitle); 191 Toolbox::ToUpperCase(calledTitle);
194 192
195 if (server.HasCalledApplicationEntityTitleCheck() && 193 if (server.HasCalledApplicationEntityTitleCheck() &&
229 ASC_RESULT_REJECTEDPERMANENT, 227 ASC_RESULT_REJECTEDPERMANENT,
230 ASC_SOURCE_SERVICEUSER, 228 ASC_SOURCE_SERVICEUSER,
231 ASC_REASON_SU_NOREASON 229 ASC_REASON_SU_NOREASON
232 }; 230 };
233 231
234 OFLOG_INFO(Internals::Logger, "Association Rejected: No Implementation Class UID provided"); 232 LOG4CPP_INFO(Internals::GetLogger(), "Association Rejected: No Implementation Class UID provided");
235 cond = ASC_rejectAssociation(assoc, &rej); 233 cond = ASC_rejectAssociation(assoc, &rej);
236 if (cond.bad()) 234 if (cond.bad())
237 { 235 {
238 OFLOG_DEBUG(Internals::Logger, DimseCondition::dump(temp_str, cond)); 236 LOG4CPP_DEBUG(Internals::GetLogger(), std::string(cond.text()));
239 } 237 }
240 AssociationCleanup(assoc); 238 AssociationCleanup(assoc);
241 return NULL; 239 return NULL;
242 } 240 }
243 241
244 { 242 {
245 cond = ASC_acknowledgeAssociation(assoc); 243 cond = ASC_acknowledgeAssociation(assoc);
246 if (cond.bad()) 244 if (cond.bad())
247 { 245 {
248 OFLOG_ERROR(Internals::Logger, DimseCondition::dump(temp_str, cond)); 246 LOG4CPP_ERROR(Internals::GetLogger(), std::string(cond.text()));
249 AssociationCleanup(assoc); 247 AssociationCleanup(assoc);
250 return NULL; 248 return NULL;
251 } 249 }
252 OFLOG_INFO(Internals::Logger, "Association Acknowledged (Max Send PDV: " << assoc->sendPDVLength << ")"); 250 LOG4CPP_INFO(Internals::GetLogger(), "Association Acknowledged (Max Send PDV: " + boost::lexical_cast<std::string>(assoc->sendPDVLength) + ")");
253 if (ASC_countAcceptedPresentationContexts(assoc->params) == 0) 251 if (ASC_countAcceptedPresentationContexts(assoc->params) == 0)
254 OFLOG_INFO(Internals::Logger, " (but no valid presentation contexts)"); 252 LOG4CPP_INFO(Internals::GetLogger(), " (but no valid presentation contexts)");
255 } 253 }
256 254
257 return new CommandDispatcher(server, assoc); 255 return new CommandDispatcher(server, assoc);
258 } 256 }
259 257
276 274
277 // if the command which was received has extra status 275 // if the command which was received has extra status
278 // detail information, dump this information 276 // detail information, dump this information
279 if (statusDetail != NULL) 277 if (statusDetail != NULL)
280 { 278 {
281 OFLOG_WARN(Internals::Logger, "Status Detail:" << OFendl << DcmObject::PrintHelper(*statusDetail)); 279 //LOG4CPP_WARN(Internals::GetLogger(), "Status Detail:" << OFendl << DcmObject::PrintHelper(*statusDetail));
282 delete statusDetail; 280 delete statusDetail;
283 } 281 }
284 282
285 if (cond == DIMSE_OUTOFRESOURCES) 283 if (cond == DIMSE_OUTOFRESOURCES)
286 { 284 {
347 break; 345 break;
348 346
349 default: 347 default:
350 // we cannot handle this kind of message 348 // we cannot handle this kind of message
351 cond = DIMSE_BADCOMMANDTYPE; 349 cond = DIMSE_BADCOMMANDTYPE;
352 OFLOG_ERROR(Internals::Logger, "cannot handle command: 0x" 350 LOG4CPP_ERROR(Internals::GetLogger(), "cannot handle command: 0x"
353 << STD_NAMESPACE hex << OFstatic_cast(unsigned, msg.CommandField)); 351 + boost::lexical_cast<std::string>(hex)
352 + boost::lexical_cast<std::string>(msg.CommandField));
354 break; 353 break;
355 } 354 }
356 } 355 }
357 else 356 else
358 { 357 {
363 362
364 if (finished) 363 if (finished)
365 { 364 {
366 if (cond == DUL_PEERREQUESTEDRELEASE) 365 if (cond == DUL_PEERREQUESTEDRELEASE)
367 { 366 {
368 OFLOG_INFO(Internals::Logger, "Association Release"); 367 LOG4CPP_INFO(Internals::GetLogger(), "Association Release");
369 ASC_acknowledgeRelease(assoc_); 368 ASC_acknowledgeRelease(assoc_);
370 } 369 }
371 else if (cond == DUL_PEERABORTEDASSOCIATION) 370 else if (cond == DUL_PEERABORTEDASSOCIATION)
372 { 371 {
373 OFLOG_INFO(Internals::Logger, "Association Aborted"); 372 LOG4CPP_INFO(Internals::GetLogger(), "Association Aborted");
374 } 373 }
375 else 374 else
376 { 375 {
377 OFString temp_str; 376 OFString temp_str;
378 OFLOG_ERROR(Internals::Logger, "DIMSE failure (aborting association): " << DimseCondition::dump(temp_str, cond)); 377 LOG4CPP_ERROR(Internals::GetLogger(), "DIMSE failure (aborting association): " + std::string(cond.text()));
379 /* some kind of error so abort the association */ 378 /* some kind of error so abort the association */
380 ASC_abortAssociation(assoc_); 379 ASC_abortAssociation(assoc_);
381 } 380 }
382 } 381 }
383 382
386 385
387 386
388 OFCondition EchoScp( T_ASC_Association * assoc, T_DIMSE_Message * msg, T_ASC_PresentationContextID presID) 387 OFCondition EchoScp( T_ASC_Association * assoc, T_DIMSE_Message * msg, T_ASC_PresentationContextID presID)
389 { 388 {
390 OFString temp_str; 389 OFString temp_str;
391 OFLOG_INFO(Internals::Logger, "Received Echo Request"); 390 LOG4CPP_INFO(Internals::GetLogger(), "Received Echo Request");
392 OFLOG_DEBUG(Internals::Logger, DIMSE_dumpMessage(temp_str, msg->msg.CEchoRQ, DIMSE_INCOMING, NULL, presID)); 391 //LOG4CPP_DEBUG(Internals::GetLogger(), DIMSE_dumpMessage(temp_str, msg->msg.CEchoRQ, DIMSE_INCOMING, NULL, presID));
393 392
394 /* the echo succeeded !! */ 393 /* the echo succeeded !! */
395 OFCondition cond = DIMSE_sendEchoResponse(assoc, presID, &msg->msg.CEchoRQ, STATUS_Success, NULL); 394 OFCondition cond = DIMSE_sendEchoResponse(assoc, presID, &msg->msg.CEchoRQ, STATUS_Success, NULL);
396 if (cond.bad()) 395 if (cond.bad())
397 { 396 {
398 OFLOG_ERROR(Internals::Logger, "Echo SCP Failed: " << DimseCondition::dump(temp_str, cond)); 397 LOG4CPP_ERROR(Internals::GetLogger(), "Echo SCP Failed: " + std::string(cond.text()));
399 } 398 }
400 return cond; 399 return cond;
401 } 400 }
402 } 401 }
403 } 402 }