comparison Plugins/Engine/OrthancPlugins.cpp @ 2940:4767d36679ed

refactoring access to Orthanc configuration
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 29 Nov 2018 11:47:00 +0100
parents 9d277f8ad698
children f395460af74d
comparison
equal deleted inserted replaced
2939:577786f59252 2940:4767d36679ed
46 #include "../../Core/OrthancException.h" 46 #include "../../Core/OrthancException.h"
47 #include "../../Core/SerializationToolbox.h" 47 #include "../../Core/SerializationToolbox.h"
48 #include "../../Core/Toolbox.h" 48 #include "../../Core/Toolbox.h"
49 #include "../../Core/DicomParsing/FromDcmtkBridge.h" 49 #include "../../Core/DicomParsing/FromDcmtkBridge.h"
50 #include "../../Core/DicomParsing/ToDcmtkBridge.h" 50 #include "../../Core/DicomParsing/ToDcmtkBridge.h"
51 #include "../../OrthancServer/OrthancInitialization.h" 51 #include "../../OrthancServer/OrthancConfiguration.h"
52 #include "../../OrthancServer/ServerContext.h" 52 #include "../../OrthancServer/ServerContext.h"
53 #include "../../OrthancServer/ServerToolbox.h" 53 #include "../../OrthancServer/ServerToolbox.h"
54 #include "../../OrthancServer/Search/HierarchicalMatcher.h" 54 #include "../../OrthancServer/Search/HierarchicalMatcher.h"
55 #include "../../Core/DicomParsing/Internals/DicomImageDecoder.h" 55 #include "../../Core/DicomParsing/Internals/DicomImageDecoder.h"
56 #include "../../Core/Compression/ZlibCompressor.h" 56 #include "../../Core/Compression/ZlibCompressor.h"
269 } 269 }
270 270
271 public: 271 public:
272 OrthancPeers() 272 OrthancPeers()
273 { 273 {
274 OrthancConfiguration::ReaderLock lock;
275
274 std::set<std::string> peers; 276 std::set<std::string> peers;
275 Configuration::GetListOfOrthancPeers(peers); 277 lock.GetConfiguration().GetListOfOrthancPeers(peers);
276 278
277 names_.reserve(peers.size()); 279 names_.reserve(peers.size());
278 parameters_.reserve(peers.size()); 280 parameters_.reserve(peers.size());
279 281
280 for (std::set<std::string>::const_iterator 282 for (std::set<std::string>::const_iterator
281 it = peers.begin(); it != peers.end(); ++it) 283 it = peers.begin(); it != peers.end(); ++it)
282 { 284 {
283 WebServiceParameters peer; 285 WebServiceParameters peer;
284 if (Configuration::GetOrthancPeer(peer, *it)) 286 if (lock.GetConfiguration().GetOrthancPeer(peer, *it))
285 { 287 {
286 names_.push_back(*it); 288 names_.push_back(*it);
287 parameters_.push_back(peer); 289 parameters_.push_back(peer);
288 } 290 }
289 } 291 }
2103 2105
2104 void OrthancPlugins::GetFontInfo(const void* parameters) 2106 void OrthancPlugins::GetFontInfo(const void* parameters)
2105 { 2107 {
2106 const _OrthancPluginGetFontInfo& p = *reinterpret_cast<const _OrthancPluginGetFontInfo*>(parameters); 2108 const _OrthancPluginGetFontInfo& p = *reinterpret_cast<const _OrthancPluginGetFontInfo*>(parameters);
2107 2109
2108 const Font& font = Configuration::GetFontRegistry().GetFont(p.fontIndex); 2110 {
2109 2111 OrthancConfiguration::ReaderLock lock;
2110 if (p.name != NULL) 2112
2111 { 2113 const Font& font = lock.GetConfiguration().GetFontRegistry().GetFont(p.fontIndex);
2112 *(p.name) = font.GetName().c_str(); 2114
2113 } 2115 if (p.name != NULL)
2114 else if (p.size != NULL) 2116 {
2115 { 2117 *(p.name) = font.GetName().c_str();
2116 *(p.size) = font.GetSize(); 2118 }
2117 } 2119 else if (p.size != NULL)
2118 else 2120 {
2119 { 2121 *(p.size) = font.GetSize();
2120 throw OrthancException(ErrorCode_InternalError); 2122 }
2123 else
2124 {
2125 throw OrthancException(ErrorCode_InternalError);
2126 }
2121 } 2127 }
2122 } 2128 }
2123 2129
2124 2130
2125 void OrthancPlugins::DrawText(const void* parameters) 2131 void OrthancPlugins::DrawText(const void* parameters)
2126 { 2132 {
2127 const _OrthancPluginDrawText& p = *reinterpret_cast<const _OrthancPluginDrawText*>(parameters); 2133 const _OrthancPluginDrawText& p = *reinterpret_cast<const _OrthancPluginDrawText*>(parameters);
2128 2134
2129 ImageAccessor& target = *reinterpret_cast<ImageAccessor*>(p.image); 2135 ImageAccessor& target = *reinterpret_cast<ImageAccessor*>(p.image);
2130 const Font& font = Configuration::GetFontRegistry().GetFont(p.fontIndex); 2136
2131 2137 {
2132 font.Draw(target, p.utf8Text, p.x, p.y, p.r, p.g, p.b); 2138 OrthancConfiguration::ReaderLock lock;
2139 const Font& font = lock.GetConfiguration().GetFontRegistry().GetFont(p.fontIndex);
2140 font.Draw(target, p.utf8Text, p.x, p.y, p.r, p.g, p.b);
2141 }
2133 } 2142 }
2134 2143
2135 2144
2136 void OrthancPlugins::ApplyDicomToJson(_OrthancPluginService service, 2145 void OrthancPlugins::ApplyDicomToJson(_OrthancPluginService service,
2137 const void* parameters) 2146 const void* parameters)
2390 return true; 2399 return true;
2391 } 2400 }
2392 2401
2393 case _OrthancPluginService_GetConfigurationPath: 2402 case _OrthancPluginService_GetConfigurationPath:
2394 { 2403 {
2395 *reinterpret_cast<const _OrthancPluginRetrieveDynamicString*>(parameters)->result = 2404 std::string s;
2396 CopyString(Configuration::GetConfigurationAbsolutePath()); 2405
2406 {
2407 OrthancConfiguration::ReaderLock lock;
2408 s = lock.GetConfiguration().GetConfigurationAbsolutePath();
2409 }
2410
2411 *reinterpret_cast<const _OrthancPluginRetrieveDynamicString*>(parameters)->result = CopyString(s);
2397 return true; 2412 return true;
2398 } 2413 }
2399 2414
2400 case _OrthancPluginService_GetConfiguration: 2415 case _OrthancPluginService_GetConfiguration:
2401 { 2416 {
2402 std::string s; 2417 std::string s;
2403 Configuration::FormatConfiguration(s); 2418
2419 {
2420 OrthancConfiguration::ReaderLock lock;
2421 lock.GetConfiguration().Format(s);
2422 }
2404 2423
2405 *reinterpret_cast<const _OrthancPluginRetrieveDynamicString*>(parameters)->result = CopyString(s); 2424 *reinterpret_cast<const _OrthancPluginRetrieveDynamicString*>(parameters)->result = CopyString(s);
2406 return true; 2425 return true;
2407 } 2426 }
2408 2427
2663 2682
2664 case _OrthancPluginService_GetFontsCount: 2683 case _OrthancPluginService_GetFontsCount:
2665 { 2684 {
2666 const _OrthancPluginReturnSingleValue& p = 2685 const _OrthancPluginReturnSingleValue& p =
2667 *reinterpret_cast<const _OrthancPluginReturnSingleValue*>(parameters); 2686 *reinterpret_cast<const _OrthancPluginReturnSingleValue*>(parameters);
2668 *(p.resultUint32) = Configuration::GetFontRegistry().GetSize(); 2687
2688 {
2689 OrthancConfiguration::ReaderLock lock;
2690 *(p.resultUint32) = lock.GetConfiguration().GetFontRegistry().GetSize();
2691 }
2692
2669 return true; 2693 return true;
2670 } 2694 }
2671 2695
2672 case _OrthancPluginService_GetFontInfo: 2696 case _OrthancPluginService_GetFontInfo:
2673 GetFontInfo(parameters); 2697 GetFontInfo(parameters);