comparison OrthancServer/Plugins/Samples/MultitenantDicom/Plugin.cpp @ 5544:dce22a789a2b

Multitenant DICOM plugin: added support for locales
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 22 Mar 2024 18:56:46 +0100
parents 6ce05f8b5b13
children 0b18690c1935
comparison
equal deleted inserted replaced
5543:cd698247b029 5544:dce22a789a2b
25 #include "MultitenantDicomServer.h" 25 #include "MultitenantDicomServer.h"
26 26
27 #include "../../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h" 27 #include "../../../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
28 #include "../../../../OrthancFramework/Sources/Logging.h" 28 #include "../../../../OrthancFramework/Sources/Logging.h"
29 #include "../../../../OrthancFramework/Sources/OrthancException.h" 29 #include "../../../../OrthancFramework/Sources/OrthancException.h"
30 #include "../../../../OrthancFramework/Sources/OrthancFramework.h"
30 31
31 #include "../Common/OrthancPluginCppWrapper.h" 32 #include "../Common/OrthancPluginCppWrapper.h"
32 33
33 34
34 typedef std::list<MultitenantDicomServer*> DicomServers; 35 typedef std::list<MultitenantDicomServer*> DicomServers;
85 default: 86 default:
86 break; 87 break;
87 } 88 }
88 89
89 return OrthancPluginErrorCode_Success; 90 return OrthancPluginErrorCode_Success;
91 }
92
93
94 static void MyInitialization(const OrthancPlugins::OrthancConfiguration& config)
95 {
96 static const char* const LOCALE = "Locale";
97 static const char* const DEFAULT_ENCODING = "DefaultEncoding";
98
99 /**
100 * This function is a simplified version of function
101 * "Orthanc::OrthancInitialize()" that is executed when starting the
102 * Orthanc server.
103 **/
104
105 Orthanc::InitializeFramework(config.GetStringValue(LOCALE, ""), false /* loadPrivateDictionary */);
106
107 std::string encoding;
108 if (config.LookupStringValue(encoding, DEFAULT_ENCODING))
109 {
110 Orthanc::SetDefaultDicomEncoding(Orthanc::StringToEncoding(encoding.c_str()));
111 }
112 else
113 {
114 Orthanc::SetDefaultDicomEncoding(Orthanc::ORTHANC_DEFAULT_DICOM_ENCODING);
115 }
90 } 116 }
91 117
92 118
93 extern "C" 119 extern "C"
94 { 120 {
119 { 145 {
120 OrthancPlugins::ReportMinimalOrthancVersion(1, 12, 0); 146 OrthancPlugins::ReportMinimalOrthancVersion(1, 12, 0);
121 return -1; 147 return -1;
122 } 148 }
123 149
124 // For static builds, this is not required - but does not harm - because the dictionary seems to be shared between the Orthanc Core and the plugin.
125 // For dynamic builds, this is however required. See https://discourse.orthanc-server.org/t/dimse-failure-using-multitenant-plugin/3665
126 Orthanc::FromDcmtkBridge::InitializeDictionary(false /* loadPrivateDictionary */);
127
128 /* Disable "gethostbyaddr" (which results in memory leaks) and use raw IP addresses */
129 dcmDisableGethostbyaddr.set(OFTrue);
130
131 OrthancPluginSetDescription2(context, ORTHANC_PLUGIN_NAME, "Multitenant plugin for Orthanc."); 150 OrthancPluginSetDescription2(context, ORTHANC_PLUGIN_NAME, "Multitenant plugin for Orthanc.");
132 151
133 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback); 152 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
134 153
135 try 154 try
136 { 155 {
137 OrthancPlugins::OrthancConfiguration globalConfig; 156 OrthancPlugins::OrthancConfiguration globalConfig;
157 MyInitialization(globalConfig);
138 158
139 OrthancPlugins::OrthancConfiguration pluginConfig; 159 OrthancPlugins::OrthancConfiguration pluginConfig;
140 globalConfig.GetSection(pluginConfig, KEY_MULTITENANT_DICOM); 160 globalConfig.GetSection(pluginConfig, KEY_MULTITENANT_DICOM);
141 161
142 if (pluginConfig.GetJson().isMember(KEY_SERVERS)) 162 if (pluginConfig.GetJson().isMember(KEY_SERVERS))
181 { 201 {
182 LOG(ERROR) << "Exception while destroying the multitenant DICOM server: " << e.What(); 202 LOG(ERROR) << "Exception while destroying the multitenant DICOM server: " << e.What();
183 } 203 }
184 } 204 }
185 } 205 }
206
207 Orthanc::FinalizeFramework();
186 } 208 }
187 209
188 210
189 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() 211 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
190 { 212 {