Mercurial > hg > orthanc-webviewer
comparison Plugin/Plugin.cpp @ 260:620ed85fb514
replacing OrthancPluginLog...() by LOG(...)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Jun 2020 17:38:40 +0200 |
parents | 85b6a8bf8c7b |
children | af7108b06b4d |
comparison
equal
deleted
inserted
replaced
259:37a7d9ed4696 | 260:620ed85fb514 |
---|---|
166 | 166 |
167 return OrthancPluginErrorCode_Success; | 167 return OrthancPluginErrorCode_Success; |
168 } | 168 } |
169 catch (std::runtime_error& e) | 169 catch (std::runtime_error& e) |
170 { | 170 { |
171 OrthancPluginLogError(context_, e.what()); | 171 LOG(ERROR) << e.what(); |
172 return OrthancPluginErrorCode_Success; // Ignore error | 172 return OrthancPluginErrorCode_Success; // Ignore error |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 | 176 |
202 | 202 |
203 return OrthancPluginErrorCode_Success; | 203 return OrthancPluginErrorCode_Success; |
204 } | 204 } |
205 catch (Orthanc::OrthancException& e) | 205 catch (Orthanc::OrthancException& e) |
206 { | 206 { |
207 OrthancPluginLogError(context_, e.What()); | 207 LOG(ERROR) << e.What(); |
208 return OrthancPluginErrorCode_Plugin; | 208 return OrthancPluginErrorCode_Plugin; |
209 } | 209 } |
210 catch (std::runtime_error& e) | 210 catch (std::runtime_error& e) |
211 { | 211 { |
212 OrthancPluginLogError(context_, e.what()); | 212 LOG(ERROR) << e.what(); |
213 return OrthancPluginErrorCode_Plugin; | 213 return OrthancPluginErrorCode_Plugin; |
214 } | 214 } |
215 catch (boost::bad_lexical_cast&) | 215 catch (boost::bad_lexical_cast&) |
216 { | 216 { |
217 OrthancPluginLogError(context_, "Bad lexical cast"); | 217 LOG(ERROR) << "Bad lexical cast"; |
218 return OrthancPluginErrorCode_Plugin; | 218 return OrthancPluginErrorCode_Plugin; |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 | 222 |
243 const char* resource = s.size() ? s.c_str() : NULL; | 243 const char* resource = s.size() ? s.c_str() : NULL; |
244 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime); | 244 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime); |
245 } | 245 } |
246 catch (Orthanc::OrthancException&) | 246 catch (Orthanc::OrthancException&) |
247 { | 247 { |
248 std::string s = "Inexistent file in served folder: " + path; | 248 LOG(ERROR) << "Inexistent file in served folder: " << path; |
249 OrthancPluginLogError(context_, s.c_str()); | |
250 OrthancPluginSendHttpStatusCode(context_, output, 404); | 249 OrthancPluginSendHttpStatusCode(context_, output, 404); |
251 } | 250 } |
252 | 251 |
253 return OrthancPluginErrorCode_Success; | 252 return OrthancPluginErrorCode_Success; |
254 } | 253 } |
280 | 279 |
281 return OrthancPluginErrorCode_Success; | 280 return OrthancPluginErrorCode_Success; |
282 } | 281 } |
283 catch (std::runtime_error&) | 282 catch (std::runtime_error&) |
284 { | 283 { |
285 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]); | 284 LOG(ERROR) << "Unknown static resource in plugin: " << request->groups[0]; |
286 OrthancPluginLogError(context_, s.c_str()); | |
287 OrthancPluginSendHttpStatusCode(context_, output, 404); | 285 OrthancPluginSendHttpStatusCode(context_, output, 404); |
288 return OrthancPluginErrorCode_Success; | 286 return OrthancPluginErrorCode_Success; |
289 } | 287 } |
290 } | 288 } |
291 | 289 |
321 | 319 |
322 return OrthancPluginErrorCode_Success; | 320 return OrthancPluginErrorCode_Success; |
323 } | 321 } |
324 catch (Orthanc::OrthancException& e) | 322 catch (Orthanc::OrthancException& e) |
325 { | 323 { |
326 OrthancPluginLogError(context_, e.What()); | 324 LOG(ERROR) << e.What(); |
327 return OrthancPluginErrorCode_Plugin; | 325 return OrthancPluginErrorCode_Plugin; |
328 } | 326 } |
329 catch (std::runtime_error& e) | 327 catch (std::runtime_error& e) |
330 { | 328 { |
331 OrthancPluginLogError(context_, e.what()); | 329 LOG(ERROR) << e.what(); |
332 return OrthancPluginErrorCode_Plugin; | 330 return OrthancPluginErrorCode_Plugin; |
333 } | 331 } |
334 catch (boost::bad_lexical_cast&) | 332 catch (boost::bad_lexical_cast&) |
335 { | 333 { |
336 OrthancPluginLogError(context_, "Bad lexical cast"); | 334 LOG(ERROR) << "Bad lexical cast"; |
337 return OrthancPluginErrorCode_Plugin; | 335 return OrthancPluginErrorCode_Plugin; |
338 } | 336 } |
339 } | 337 } |
340 | 338 |
341 | 339 |
382 | 380 |
383 | 381 |
384 static bool DisplayPerformanceWarning() | 382 static bool DisplayPerformanceWarning() |
385 { | 383 { |
386 (void) DisplayPerformanceWarning; // Disable warning about unused function | 384 (void) DisplayPerformanceWarning; // Disable warning about unused function |
387 OrthancPluginLogWarning(context_, "Performance warning in Web viewer: " | 385 LOG(WARNING) << "Performance warning in Web viewer: " |
388 "Non-release build, runtime debug assertions are turned on"); | 386 << "Non-release build, runtime debug assertions are turned on"; |
389 return true; | 387 return true; |
390 } | 388 } |
391 | 389 |
392 | 390 |
393 extern "C" | 391 extern "C" |
398 | 396 |
399 OrthancPlugins::SetGlobalContext(context); | 397 OrthancPlugins::SetGlobalContext(context); |
400 Orthanc::Logging::Initialize(context); | 398 Orthanc::Logging::Initialize(context); |
401 context_ = context; | 399 context_ = context; |
402 assert(DisplayPerformanceWarning()); | 400 assert(DisplayPerformanceWarning()); |
403 OrthancPluginLogWarning(context_, "Initializing the Web viewer"); | 401 LOG(WARNING) << "Initializing the Web viewer"; |
404 | 402 |
405 | 403 |
406 /* Check the version of the Orthanc core */ | 404 /* Check the version of the Orthanc core */ |
407 if (OrthancPluginCheckVersion(context_) == 0) | 405 if (OrthancPluginCheckVersion(context_) == 0) |
408 { | 406 { |
410 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | 408 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", |
411 context_->orthancVersion, | 409 context_->orthancVersion, |
412 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | 410 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
413 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | 411 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
414 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | 412 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
415 OrthancPluginLogError(context_, info); | 413 OrthancPluginLogError(context, info); |
416 return -1; | 414 return -1; |
417 } | 415 } |
418 | 416 |
419 OrthancPluginSetDescription(context_, "Provides a Web viewer of DICOM series within Orthanc."); | 417 OrthancPluginSetDescription(context_, "Provides a Web viewer of DICOM series within Orthanc."); |
420 | 418 |
432 int cacheSize = 100; | 430 int cacheSize = 100; |
433 | 431 |
434 boost::filesystem::path cachePath; | 432 boost::filesystem::path cachePath; |
435 ParseConfiguration(decodingThreads, cachePath, cacheSize); | 433 ParseConfiguration(decodingThreads, cachePath, cacheSize); |
436 | 434 |
437 std::string message = ("Web viewer using " + boost::lexical_cast<std::string>(decodingThreads) + | 435 LOG(WARNING) << "Web viewer using " << decodingThreads |
438 " threads for the decoding of the DICOM images"); | 436 << " threads for the decoding of the DICOM images"; |
439 OrthancPluginLogWarning(context_, message.c_str()); | 437 |
440 | 438 LOG(WARNING) << "Storing the cache of the Web viewer in folder: " << cachePath.string(); |
441 message = "Storing the cache of the Web viewer in folder: " + cachePath.string(); | |
442 OrthancPluginLogWarning(context_, message.c_str()); | |
443 | 439 |
444 | 440 |
445 /* Create the cache */ | 441 /* Create the cache */ |
446 cache_ = new CacheContext(cachePath.string()); | 442 cache_ = new CacheContext(cachePath.string()); |
447 CacheScheduler& scheduler = cache_->GetScheduler(); | 443 CacheScheduler& scheduler = cache_->GetScheduler(); |
451 std::string orthancVersion("unknown"), webViewerVersion("unknown"); | 447 std::string orthancVersion("unknown"), webViewerVersion("unknown"); |
452 bool clear = false; | 448 bool clear = false; |
453 if (!scheduler.LookupProperty(orthancVersion, CacheProperty_OrthancVersion) || | 449 if (!scheduler.LookupProperty(orthancVersion, CacheProperty_OrthancVersion) || |
454 orthancVersion != std::string(context_->orthancVersion)) | 450 orthancVersion != std::string(context_->orthancVersion)) |
455 { | 451 { |
456 std::string s = ("The version of Orthanc has changed from \"" + orthancVersion + "\" to \"" + | 452 LOG(WARNING) << "The version of Orthanc has changed from \"" << orthancVersion |
457 std::string(context_->orthancVersion) + "\": The cache of the Web viewer will be cleared"); | 453 << "\" to \"" << context_->orthancVersion |
458 OrthancPluginLogWarning(context_, s.c_str()); | 454 << "\": The cache of the Web viewer will be cleared"; |
459 clear = true; | 455 clear = true; |
460 } | 456 } |
461 | 457 |
462 if (!scheduler.LookupProperty(webViewerVersion, CacheProperty_WebViewerVersion) || | 458 if (!scheduler.LookupProperty(webViewerVersion, CacheProperty_WebViewerVersion) || |
463 webViewerVersion != std::string(ORTHANC_PLUGIN_VERSION)) | 459 webViewerVersion != std::string(ORTHANC_PLUGIN_VERSION)) |
464 { | 460 { |
465 std::string s = ("The version of the Web viewer plugin has changed from \"" + webViewerVersion + "\" to \"" + | 461 LOG(WARNING) << "The version of the Web viewer plugin has changed from \"" |
466 std::string(ORTHANC_PLUGIN_VERSION) + "\": The cache of the Web viewer will be cleared"); | 462 << webViewerVersion << "\" to \"" << ORTHANC_PLUGIN_VERSION |
467 OrthancPluginLogWarning(context_, s.c_str()); | 463 << "\": The cache of the Web viewer will be cleared"; |
468 clear = true; | 464 clear = true; |
469 } | 465 } |
470 | 466 |
471 | 467 |
472 /* Clear the cache if needed */ | 468 /* Clear the cache if needed */ |
473 if (clear) | 469 if (clear) |
474 { | 470 { |
475 OrthancPluginLogWarning(context_, "Clearing the cache of the Web viewer"); | 471 LOG(WARNING) << "Clearing the cache of the Web viewer"; |
476 scheduler.Clear(); | 472 scheduler.Clear(); |
477 scheduler.SetProperty(CacheProperty_OrthancVersion, context_->orthancVersion); | 473 scheduler.SetProperty(CacheProperty_OrthancVersion, context_->orthancVersion); |
478 scheduler.SetProperty(CacheProperty_WebViewerVersion, ORTHANC_PLUGIN_VERSION); | 474 scheduler.SetProperty(CacheProperty_WebViewerVersion, ORTHANC_PLUGIN_VERSION); |
479 } | 475 } |
480 else | 476 else |
481 { | 477 { |
482 OrthancPluginLogInfo(context_, "No change in the versions, no need to clear the cache of the Web viewer"); | 478 LOG(INFO) << "No change in the versions, no need to clear the cache of the Web viewer"; |
483 } | 479 } |
484 | 480 |
485 | 481 |
486 /* Configure the cache */ | 482 /* Configure the cache */ |
487 scheduler.RegisterPolicy(new ViewerPrefetchPolicy(context_)); | 483 scheduler.RegisterPolicy(new ViewerPrefetchPolicy(context_)); |
492 | 488 |
493 | 489 |
494 /* Set the quotas */ | 490 /* Set the quotas */ |
495 scheduler.SetQuota(CacheBundle_SeriesInformation, 1000, 0); // Keep info about 1000 series | 491 scheduler.SetQuota(CacheBundle_SeriesInformation, 1000, 0); // Keep info about 1000 series |
496 | 492 |
497 message = "Web viewer using a cache of " + boost::lexical_cast<std::string>(cacheSize) + " MB"; | 493 LOG(WARNING) << "Web viewer using a cache of " << cacheSize << " MB"; |
498 OrthancPluginLogWarning(context_, message.c_str()); | |
499 | 494 |
500 scheduler.SetQuota(CacheBundle_DecodedImage, 0, static_cast<uint64_t>(cacheSize) * 1024 * 1024); | 495 scheduler.SetQuota(CacheBundle_DecodedImage, 0, static_cast<uint64_t>(cacheSize) * 1024 * 1024); |
501 } | 496 } |
502 catch (std::runtime_error& e) | 497 catch (std::runtime_error& e) |
503 { | 498 { |
504 OrthancPluginLogError(context_, e.what()); | 499 LOG(ERROR) << e.what(); |
505 return -1; | 500 return -1; |
506 } | 501 } |
507 catch (Orthanc::OrthancException& e) | 502 catch (Orthanc::OrthancException& e) |
508 { | 503 { |
509 if (e.GetErrorCode() == Orthanc::ErrorCode_BadFileFormat) | 504 if (e.GetErrorCode() == Orthanc::ErrorCode_BadFileFormat) |
510 { | 505 { |
511 OrthancPluginLogError(context_, "Unable to read the configuration of the Web viewer plugin"); | 506 LOG(ERROR) << "Unable to read the configuration of the Web viewer plugin"; |
512 } | 507 } |
513 else | 508 else |
514 { | 509 { |
515 OrthancPluginLogError(context_, e.What()); | 510 LOG(ERROR) << e.What(); |
516 } | 511 } |
517 return -1; | 512 return -1; |
518 } | 513 } |
519 | 514 |
520 | 515 |
542 } | 537 } |
543 | 538 |
544 | 539 |
545 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | 540 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |
546 { | 541 { |
547 OrthancPluginLogWarning(context_, "Finalizing the Web viewer"); | 542 LOG(WARNING) << "Finalizing the Web viewer"; |
548 | 543 |
549 if (cache_ != NULL) | 544 if (cache_ != NULL) |
550 { | 545 { |
551 delete cache_; | 546 delete cache_; |
552 cache_ = NULL; | 547 cache_ = NULL; |