comparison OrthancServer/OrthancInitialization.cpp @ 2381:b8969010b534

uncoupling DCMTK primitives from Orthanc::Configuration
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Aug 2017 19:59:01 +0200
parents 96b3ec054b69
children 7284093111b0
comparison
equal deleted inserted replaced
2380:96b3ec054b69 2381:b8969010b534
41 #include "../Core/FileStorage/FilesystemStorage.h" 41 #include "../Core/FileStorage/FilesystemStorage.h"
42 42
43 #include "ServerEnumerations.h" 43 #include "ServerEnumerations.h"
44 #include "DatabaseWrapper.h" 44 #include "DatabaseWrapper.h"
45 #include "FromDcmtkBridge.h" 45 #include "FromDcmtkBridge.h"
46 #include "ToDcmtkBridge.h"
47 46
48 #include <boost/lexical_cast.hpp> 47 #include <boost/lexical_cast.hpp>
49 #include <boost/filesystem.hpp> 48 #include <boost/filesystem.hpp>
50 #include <curl/curl.h> 49 #include <curl/curl.h>
51 #include <boost/thread/recursive_mutex.hpp> 50 #include <boost/thread/recursive_mutex.hpp>
52 51
53 52 #include <dcmtk/dcmnet/dul.h> // For dcmDisableGethostbyaddr()
54 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
55 # include <dcmtk/dcmjpeg/djdecode.h>
56 #endif
57
58
59 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1
60 # include <dcmtk/dcmjpls/djdecode.h>
61 #endif
62
63
64 #include <dcmtk/dcmnet/dul.h>
65 53
66 54
67 55
68 namespace Orthanc 56 namespace Orthanc
69 { 57 {
480 else 468 else
481 { 469 {
482 Toolbox::InitializeGlobalLocale(NULL); 470 Toolbox::InitializeGlobalLocale(NULL);
483 } 471 }
484 472
473 if (configuration_.isMember("DefaultEncoding"))
474 {
475 std::string encoding = GetGlobalStringParameterInternal("DefaultEncoding", "");
476 SetDefaultDicomEncoding(StringToEncoding(encoding.c_str()));
477 }
478 else
479 {
480 SetDefaultDicomEncoding(ORTHANC_DEFAULT_DICOM_ENCODING);
481 }
482
485 if (configuration_.isMember("Pkcs11")) 483 if (configuration_.isMember("Pkcs11"))
486 { 484 {
487 ConfigurePkcs11(configuration_["Pkcs11"]); 485 ConfigurePkcs11(configuration_["Pkcs11"]);
488 } 486 }
489 487
493 RegisterUserContentType(); 491 RegisterUserContentType();
494 492
495 FromDcmtkBridge::InitializeDictionary(GetGlobalBoolParameterInternal("LoadPrivateDictionary", true)); 493 FromDcmtkBridge::InitializeDictionary(GetGlobalBoolParameterInternal("LoadPrivateDictionary", true));
496 LoadCustomDictionary(configuration_); 494 LoadCustomDictionary(configuration_);
497 495
498 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1 496 FromDcmtkBridge::InitializeCodecs();
499 LOG(WARNING) << "Registering JPEG Lossless codecs";
500 DJLSDecoderRegistration::registerCodecs();
501 #endif
502
503 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
504 LOG(WARNING) << "Registering JPEG codecs";
505 DJDecoderRegistration::registerCodecs();
506 #endif
507 497
508 fontRegistry_.AddFromResource(EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16); 498 fontRegistry_.AddFromResource(EmbeddedResources::FONT_UBUNTU_MONO_BOLD_16);
509 499
510 /* Disable "gethostbyaddr" (which results in memory leaks) and use raw IP addresses */ 500 /* Disable "gethostbyaddr" (which results in memory leaks) and use raw IP addresses */
511 dcmDisableGethostbyaddr.set(OFTrue); 501 dcmDisableGethostbyaddr.set(OFTrue);
515 505
516 void OrthancFinalize() 506 void OrthancFinalize()
517 { 507 {
518 boost::recursive_mutex::scoped_lock lock(globalMutex_); 508 boost::recursive_mutex::scoped_lock lock(globalMutex_);
519 HttpClient::GlobalFinalize(); 509 HttpClient::GlobalFinalize();
520 510 FromDcmtkBridge::FinalizeCodecs();
521 #if ORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS == 1
522 // Unregister JPEG-LS codecs
523 DJLSDecoderRegistration::cleanup();
524 #endif
525
526 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
527 // Unregister JPEG codecs
528 DJDecoderRegistration::cleanup();
529 #endif
530
531 HttpClient::FinalizeOpenSsl(); 511 HttpClient::FinalizeOpenSsl();
532 Toolbox::FinalizeGlobalLocale(); 512 Toolbox::FinalizeGlobalLocale();
533 } 513 }
534 514
535 515
1132 { 1112 {
1133 return fontRegistry_; 1113 return fontRegistry_;
1134 } 1114 }
1135 1115
1136 1116
1137 Encoding Configuration::GetDefaultEncoding()
1138 {
1139 std::string s = GetGlobalStringParameter("DefaultEncoding", "Latin1");
1140
1141 // By default, Latin1 encoding is assumed
1142 return s.empty() ? Encoding_Latin1 : StringToEncoding(s.c_str());
1143 }
1144
1145
1146 void Configuration::SetDefaultEncoding(Encoding encoding) 1117 void Configuration::SetDefaultEncoding(Encoding encoding)
1147 { 1118 {
1148 std::string name = EnumerationToString(encoding); 1119 SetDefaultDicomEncoding(encoding);
1149 1120
1150 { 1121 {
1122 // Propagate the encoding to the configuration file that is
1123 // stored in memory
1151 boost::recursive_mutex::scoped_lock lock(globalMutex_); 1124 boost::recursive_mutex::scoped_lock lock(globalMutex_);
1152 configuration_["DefaultEncoding"] = name; 1125 configuration_["DefaultEncoding"] = EnumerationToString(encoding);
1153 } 1126 }
1154
1155 LOG(INFO) << "Default encoding was changed to: " << name;
1156 } 1127 }
1157 1128
1158 1129
1159 bool Configuration::HasConfigurationChanged() 1130 bool Configuration::HasConfigurationChanged()
1160 { 1131 {
1168 std::string a = writer.write(starting); 1139 std::string a = writer.write(starting);
1169 std::string b = writer.write(current); 1140 std::string b = writer.write(current);
1170 1141
1171 return a != b; 1142 return a != b;
1172 } 1143 }
1173
1174
1175 void Configuration::ExtractDicomSummary(DicomMap& target,
1176 DcmItem& dataset)
1177 {
1178 FromDcmtkBridge::ExtractDicomSummary(target, dataset,
1179 ORTHANC_MAXIMUM_TAG_LENGTH, GetDefaultEncoding());
1180 }
1181
1182
1183 void Configuration::ExtractDicomAsJson(Json::Value& target,
1184 DcmDataset& dataset)
1185 {
1186 FromDcmtkBridge::ExtractDicomAsJson(target, dataset,
1187 DicomToJsonFormat_Full, DicomToJsonFlags_Default,
1188 ORTHANC_MAXIMUM_TAG_LENGTH, GetDefaultEncoding());
1189 }
1190 } 1144 }