Mercurial > hg > orthanc-stone
comparison RenderingPlugin/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 2077:07964689cb0b
upgrade to year 2023
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 Jul 2023 21:20:22 +0200 |
parents | c0aa4b03f219 |
children | 3ef91da06636 |
comparison
equal
deleted
inserted
replaced
2076:990f396484b1 | 2077:07964689cb0b |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
4 * Department, University Hospital of Liege, Belgium | 4 * Department, University Hospital of Liege, Belgium |
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium | 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | 6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
7 * | 7 * |
8 * This program is free software: you can redistribute it and/or | 8 * This program is free software: you can redistribute it and/or |
9 * modify it under the terms of the GNU General Public License as | 9 * modify it under the terms of the GNU General Public License as |
10 * published by the Free Software Foundation, either version 3 of the | 10 * published by the Free Software Foundation, either version 3 of the |
11 * License, or (at your option) any later version. | 11 * License, or (at your option) any later version. |
251 } | 251 } |
252 | 252 |
253 // helper class to convert std::map of headers to the plugin SDK C structure | 253 // helper class to convert std::map of headers to the plugin SDK C structure |
254 class PluginHttpHeaders | 254 class PluginHttpHeaders |
255 { | 255 { |
256 private: | |
256 std::vector<const char*> headersKeys_; | 257 std::vector<const char*> headersKeys_; |
257 std::vector<const char*> headersValues_; | 258 std::vector<const char*> headersValues_; |
259 | |
258 public: | 260 public: |
259 | 261 explicit PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders) |
260 PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders) | |
261 { | 262 { |
262 for (std::map<std::string, std::string>::const_iterator | 263 for (std::map<std::string, std::string>::const_iterator |
263 it = httpHeaders.begin(); it != httpHeaders.end(); it++) | 264 it = httpHeaders.begin(); it != httpHeaders.end(); ++it) |
264 { | 265 { |
265 headersKeys_.push_back(it->first.c_str()); | 266 headersKeys_.push_back(it->first.c_str()); |
266 headersValues_.push_back(it->second.c_str()); | 267 headersValues_.push_back(it->second.c_str()); |
267 } | 268 } |
268 } | 269 } |
748 { | 749 { |
749 configuration_ = Json::objectValue; | 750 configuration_ = Json::objectValue; |
750 } | 751 } |
751 } | 752 } |
752 | 753 |
754 OrthancConfiguration::OrthancConfiguration(const Json::Value& configuration, const std::string& path) : | |
755 configuration_(configuration), | |
756 path_(path) | |
757 { | |
758 } | |
759 | |
753 | 760 |
754 std::string OrthancConfiguration::GetPath(const std::string& key) const | 761 std::string OrthancConfiguration::GetPath(const std::string& key) const |
755 { | 762 { |
756 if (path_.empty()) | 763 if (path_.empty()) |
757 { | 764 { |
1103 } | 1110 } |
1104 | 1111 |
1105 if (configuration_[key].type() != Json::objectValue) | 1112 if (configuration_[key].type() != Json::objectValue) |
1106 { | 1113 { |
1107 LogError("The configuration option \"" + GetPath(key) + | 1114 LogError("The configuration option \"" + GetPath(key) + |
1108 "\" is not a string as expected"); | 1115 "\" is not an object as expected"); |
1109 | 1116 |
1110 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | 1117 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
1111 } | 1118 } |
1112 | 1119 |
1113 Json::Value::Members members = configuration_[key].getMemberNames(); | 1120 Json::Value::Members members = configuration_[key].getMemberNames(); |
1448 answer.ToString(result); | 1455 answer.ToString(result); |
1449 return true; | 1456 return true; |
1450 } | 1457 } |
1451 } | 1458 } |
1452 | 1459 |
1460 | |
1461 bool RestApiGet(Json::Value& result, | |
1462 const std::string& uri, | |
1463 const std::map<std::string, std::string>& httpHeaders, | |
1464 bool applyPlugins) | |
1465 { | |
1466 MemoryBuffer answer; | |
1467 | |
1468 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins)) | |
1469 { | |
1470 return false; | |
1471 } | |
1472 else | |
1473 { | |
1474 if (!answer.IsEmpty()) | |
1475 { | |
1476 answer.ToJson(result); | |
1477 } | |
1478 return true; | |
1479 } | |
1480 } | |
1453 | 1481 |
1454 | 1482 |
1455 bool RestApiGet(Json::Value& result, | 1483 bool RestApiGet(Json::Value& result, |
1456 const std::string& uri, | 1484 const std::string& uri, |
1457 bool applyPlugins) | 1485 bool applyPlugins) |
2170 return 0; | 2198 return 0; |
2171 } | 2199 } |
2172 } | 2200 } |
2173 | 2201 |
2174 | 2202 |
2203 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
2204 static OrthancPluginErrorCode CopyStringToMemoryBuffer(OrthancPluginMemoryBuffer* target, | |
2205 const std::string& source) | |
2206 { | |
2207 if (OrthancPluginCreateMemoryBuffer(globalContext_, target, source.size()) != OrthancPluginErrorCode_Success) | |
2208 { | |
2209 return OrthancPluginErrorCode_NotEnoughMemory; | |
2210 } | |
2211 else | |
2212 { | |
2213 if (!source.empty()) | |
2214 { | |
2215 memcpy(target->data, source.c_str(), source.size()); | |
2216 } | |
2217 | |
2218 return OrthancPluginErrorCode_Success; | |
2219 } | |
2220 } | |
2221 #endif | |
2222 | |
2223 | |
2224 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
2225 OrthancPluginErrorCode OrthancJob::CallbackGetContent(OrthancPluginMemoryBuffer* target, | |
2226 void* job) | |
2227 { | |
2228 assert(job != NULL); | |
2229 OrthancJob& that = *reinterpret_cast<OrthancJob*>(job); | |
2230 return CopyStringToMemoryBuffer(target, that.content_); | |
2231 } | |
2232 #else | |
2175 const char* OrthancJob::CallbackGetContent(void* job) | 2233 const char* OrthancJob::CallbackGetContent(void* job) |
2176 { | 2234 { |
2177 assert(job != NULL); | 2235 assert(job != NULL); |
2178 | 2236 |
2179 try | 2237 try |
2183 catch (...) | 2241 catch (...) |
2184 { | 2242 { |
2185 return 0; | 2243 return 0; |
2186 } | 2244 } |
2187 } | 2245 } |
2188 | 2246 #endif |
2189 | 2247 |
2248 | |
2249 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
2250 int32_t OrthancJob::CallbackGetSerialized(OrthancPluginMemoryBuffer* target, | |
2251 void* job) | |
2252 { | |
2253 assert(job != NULL); | |
2254 OrthancJob& that = *reinterpret_cast<OrthancJob*>(job); | |
2255 | |
2256 if (that.hasSerialized_) | |
2257 { | |
2258 if (CopyStringToMemoryBuffer(target, that.serialized_) == OrthancPluginErrorCode_Success) | |
2259 { | |
2260 return 1; | |
2261 } | |
2262 else | |
2263 { | |
2264 return -1; | |
2265 } | |
2266 } | |
2267 else | |
2268 { | |
2269 return 0; | |
2270 } | |
2271 } | |
2272 #else | |
2190 const char* OrthancJob::CallbackGetSerialized(void* job) | 2273 const char* OrthancJob::CallbackGetSerialized(void* job) |
2191 { | 2274 { |
2192 assert(job != NULL); | 2275 assert(job != NULL); |
2193 | 2276 |
2194 try | 2277 try |
2207 catch (...) | 2290 catch (...) |
2208 { | 2291 { |
2209 return 0; | 2292 return 0; |
2210 } | 2293 } |
2211 } | 2294 } |
2295 #endif | |
2212 | 2296 |
2213 | 2297 |
2214 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) | 2298 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) |
2215 { | 2299 { |
2216 assert(job != NULL); | 2300 assert(job != NULL); |
2338 if (job == NULL) | 2422 if (job == NULL) |
2339 { | 2423 { |
2340 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | 2424 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); |
2341 } | 2425 } |
2342 | 2426 |
2343 OrthancPluginJob* orthanc = OrthancPluginCreateJob( | 2427 OrthancPluginJob* orthanc = |
2344 GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), | 2428 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) |
2345 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, | 2429 OrthancPluginCreateJob2 |
2346 CallbackStep, CallbackStop, CallbackReset); | 2430 #else |
2431 OrthancPluginCreateJob | |
2432 #endif | |
2433 (GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), | |
2434 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, | |
2435 CallbackStep, CallbackStop, CallbackReset); | |
2347 | 2436 |
2348 if (orthanc == NULL) | 2437 if (orthanc == NULL) |
2349 { | 2438 { |
2350 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | 2439 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
2351 } | 2440 } |
3646 size_t size, | 3735 size_t size, |
3647 const std::string& transferSyntax) | 3736 const std::string& transferSyntax) |
3648 { | 3737 { |
3649 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance( | 3738 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance( |
3650 GetGlobalContext(), buffer, size, transferSyntax.c_str()); | 3739 GetGlobalContext(), buffer, size, transferSyntax.c_str()); |
3740 | |
3741 if (instance == NULL) | |
3742 { | |
3743 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
3744 } | |
3745 else | |
3746 { | |
3747 boost::movelib::unique_ptr<DicomInstance> result(new DicomInstance(instance)); | |
3748 result->toFree_ = true; | |
3749 return result.release(); | |
3750 } | |
3751 } | |
3752 #endif | |
3753 | |
3754 | |
3755 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 1) | |
3756 DicomInstance* DicomInstance::Load(const std::string& instanceId, | |
3757 OrthancPluginLoadDicomInstanceMode mode) | |
3758 { | |
3759 OrthancPluginDicomInstance* instance = OrthancPluginLoadDicomInstance( | |
3760 GetGlobalContext(), instanceId.c_str(), mode); | |
3651 | 3761 |
3652 if (instance == NULL) | 3762 if (instance == NULL) |
3653 { | 3763 { |
3654 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | 3764 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
3655 } | 3765 } |