Mercurial > hg > orthanc-wsi
comparison Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h @ 254:20a730889ae2
upgrade to 2023
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 07 Jul 2023 17:38:07 +0200 |
parents | 5ed8d1cee52d |
children | 71900ba9c8a9 |
comparison
equal
deleted
inserted
replaced
253:a40295af8771 | 254:20a730889ae2 |
---|---|
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-2021 Osimis S.A., Belgium | 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
6 * Copyright (C) 2021-2021 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. |
113 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 1 | 113 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 1 |
114 #else | 114 #else |
115 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 0 | 115 # define HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP 0 |
116 #endif | 116 #endif |
117 | 117 |
118 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2) | |
119 # define HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API 1 | |
120 #else | |
121 # define HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API 0 | |
122 #endif | |
123 | |
124 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 10, 1) | |
125 # define HAS_ORTHANC_PLUGIN_WEBDAV 1 | |
126 #else | |
127 # define HAS_ORTHANC_PLUGIN_WEBDAV 0 | |
128 #endif | |
129 | |
118 | 130 |
119 | 131 |
120 namespace OrthancPlugins | 132 namespace OrthancPlugins |
121 { | 133 { |
122 typedef void (*RestCallback) (OrthancPluginRestOutput* output, | 134 typedef void (*RestCallback) (OrthancPluginRestOutput* output, |
216 | 228 |
217 bool RestApiPost(const std::string& uri, | 229 bool RestApiPost(const std::string& uri, |
218 const Json::Value& body, | 230 const Json::Value& body, |
219 bool applyPlugins); | 231 bool applyPlugins); |
220 | 232 |
233 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1 | |
234 bool RestApiPost(const std::string& uri, | |
235 const Json::Value& body, | |
236 const std::map<std::string, std::string>& httpHeaders, | |
237 bool applyPlugins); | |
238 | |
239 bool RestApiPost(const std::string& uri, | |
240 const void* body, | |
241 size_t bodySize, | |
242 const std::map<std::string, std::string>& httpHeaders, | |
243 bool applyPlugins); | |
244 #endif | |
245 | |
221 bool RestApiPut(const std::string& uri, | 246 bool RestApiPut(const std::string& uri, |
222 const Json::Value& body, | 247 const Json::Value& body, |
223 bool applyPlugins); | 248 bool applyPlugins); |
224 | 249 |
225 bool RestApiPost(const std::string& uri, | 250 bool RestApiPost(const std::string& uri, |
295 const char* GetContent() const | 320 const char* GetContent() const |
296 { | 321 { |
297 return str_; | 322 return str_; |
298 } | 323 } |
299 | 324 |
325 bool IsNullOrEmpty() const | |
326 { | |
327 return str_ == NULL || str_[0] == 0; | |
328 } | |
329 | |
300 void ToString(std::string& target) const; | 330 void ToString(std::string& target) const; |
301 | 331 |
302 void ToJson(Json::Value& target) const; | 332 void ToJson(Json::Value& target) const; |
303 }; | 333 |
334 void ToJsonWithoutComments(Json::Value& target) const; | |
335 }; | |
304 | 336 |
305 | 337 |
306 class OrthancConfiguration : public boost::noncopyable | 338 class OrthancConfiguration : public boost::noncopyable |
307 { | 339 { |
308 private: | 340 private: |
312 std::string GetPath(const std::string& key) const; | 344 std::string GetPath(const std::string& key) const; |
313 | 345 |
314 void LoadConfiguration(); | 346 void LoadConfiguration(); |
315 | 347 |
316 public: | 348 public: |
317 OrthancConfiguration(); | 349 OrthancConfiguration(); // loads the full Orthanc configuration |
318 | 350 |
319 explicit OrthancConfiguration(bool load); | 351 explicit OrthancConfiguration(bool load); |
352 | |
353 explicit OrthancConfiguration(const Json::Value& configuration, const std::string& path); // e.g. to load a section from a default json content | |
320 | 354 |
321 const Json::Value& GetJson() const | 355 const Json::Value& GetJson() const |
322 { | 356 { |
323 return configuration_; | 357 return configuration_; |
324 } | 358 } |
499 | 533 |
500 bool RestApiGet(Json::Value& result, | 534 bool RestApiGet(Json::Value& result, |
501 const std::string& uri, | 535 const std::string& uri, |
502 bool applyPlugins); | 536 bool applyPlugins); |
503 | 537 |
538 bool RestApiGet(Json::Value& result, | |
539 const std::string& uri, | |
540 const std::map<std::string, std::string>& httpHeaders, | |
541 bool applyPlugins); | |
542 | |
504 bool RestApiGetString(std::string& result, | 543 bool RestApiGetString(std::string& result, |
505 const std::string& uri, | 544 const std::string& uri, |
506 bool applyPlugins); | 545 bool applyPlugins); |
507 | 546 |
508 bool RestApiGetString(std::string& result, | 547 bool RestApiGetString(std::string& result, |
519 bool RestApiPost(Json::Value& result, | 558 bool RestApiPost(Json::Value& result, |
520 const std::string& uri, | 559 const std::string& uri, |
521 const void* body, | 560 const void* body, |
522 size_t bodySize, | 561 size_t bodySize, |
523 bool applyPlugins); | 562 bool applyPlugins); |
563 | |
564 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1 | |
565 bool RestApiPost(Json::Value& result, | |
566 const std::string& uri, | |
567 const Json::Value& body, | |
568 const std::map<std::string, std::string>& httpHeaders, | |
569 bool applyPlugins); | |
570 #endif | |
524 | 571 |
525 bool RestApiPost(Json::Value& result, | 572 bool RestApiPost(Json::Value& result, |
526 const std::string& uri, | 573 const std::string& uri, |
527 const Json::Value& body, | 574 const Json::Value& body, |
528 bool applyPlugins); | 575 bool applyPlugins); |
600 | 647 |
601 bool CheckMinimalOrthancVersion(unsigned int major, | 648 bool CheckMinimalOrthancVersion(unsigned int major, |
602 unsigned int minor, | 649 unsigned int minor, |
603 unsigned int revision); | 650 unsigned int revision); |
604 | 651 |
652 bool CheckMinimalVersion(const char* version, | |
653 unsigned int major, | |
654 unsigned int minor, | |
655 unsigned int revision); | |
605 | 656 |
606 namespace Internals | 657 namespace Internals |
607 { | 658 { |
608 template <RestCallback Callback> | 659 template <RestCallback Callback> |
609 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output, | 660 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output, |
709 const std::string& peer, | 760 const std::string& peer, |
710 const std::string& key) const; | 761 const std::string& key) const; |
711 | 762 |
712 bool DoGet(MemoryBuffer& target, | 763 bool DoGet(MemoryBuffer& target, |
713 size_t index, | 764 size_t index, |
714 const std::string& uri) const; | 765 const std::string& uri, |
766 const std::map<std::string, std::string>& headers) const; | |
715 | 767 |
716 bool DoGet(MemoryBuffer& target, | 768 bool DoGet(MemoryBuffer& target, |
717 const std::string& name, | 769 const std::string& name, |
718 const std::string& uri) const; | 770 const std::string& uri, |
771 const std::map<std::string, std::string>& headers) const; | |
719 | 772 |
720 bool DoGet(Json::Value& target, | 773 bool DoGet(Json::Value& target, |
721 size_t index, | 774 size_t index, |
722 const std::string& uri) const; | 775 const std::string& uri, |
776 const std::map<std::string, std::string>& headers) const; | |
723 | 777 |
724 bool DoGet(Json::Value& target, | 778 bool DoGet(Json::Value& target, |
725 const std::string& name, | 779 const std::string& name, |
726 const std::string& uri) const; | 780 const std::string& uri, |
781 const std::map<std::string, std::string>& headers) const; | |
727 | 782 |
728 bool DoPost(MemoryBuffer& target, | 783 bool DoPost(MemoryBuffer& target, |
729 size_t index, | 784 size_t index, |
730 const std::string& uri, | 785 const std::string& uri, |
731 const std::string& body) const; | 786 const std::string& body, |
787 const std::map<std::string, std::string>& headers) const; | |
732 | 788 |
733 bool DoPost(MemoryBuffer& target, | 789 bool DoPost(MemoryBuffer& target, |
734 const std::string& name, | 790 const std::string& name, |
735 const std::string& uri, | 791 const std::string& uri, |
736 const std::string& body) const; | 792 const std::string& body, |
793 const std::map<std::string, std::string>& headers) const; | |
737 | 794 |
738 bool DoPost(Json::Value& target, | 795 bool DoPost(Json::Value& target, |
739 size_t index, | 796 size_t index, |
740 const std::string& uri, | 797 const std::string& uri, |
741 const std::string& body) const; | 798 const std::string& body, |
799 const std::map<std::string, std::string>& headers) const; | |
742 | 800 |
743 bool DoPost(Json::Value& target, | 801 bool DoPost(Json::Value& target, |
744 const std::string& name, | 802 const std::string& name, |
745 const std::string& uri, | 803 const std::string& uri, |
746 const std::string& body) const; | 804 const std::string& body, |
805 const std::map<std::string, std::string>& headers) const; | |
747 | 806 |
748 bool DoPut(size_t index, | 807 bool DoPut(size_t index, |
749 const std::string& uri, | 808 const std::string& uri, |
750 const std::string& body) const; | 809 const std::string& body, |
810 const std::map<std::string, std::string>& headers) const; | |
751 | 811 |
752 bool DoPut(const std::string& name, | 812 bool DoPut(const std::string& name, |
753 const std::string& uri, | 813 const std::string& uri, |
754 const std::string& body) const; | 814 const std::string& body, |
815 const std::map<std::string, std::string>& headers) const; | |
755 | 816 |
756 bool DoDelete(size_t index, | 817 bool DoDelete(size_t index, |
757 const std::string& uri) const; | 818 const std::string& uri, |
819 const std::map<std::string, std::string>& headers) const; | |
758 | 820 |
759 bool DoDelete(const std::string& name, | 821 bool DoDelete(const std::string& name, |
760 const std::string& uri) const; | 822 const std::string& uri, |
823 const std::map<std::string, std::string>& headers) const; | |
761 }; | 824 }; |
762 #endif | 825 #endif |
763 | 826 |
764 | 827 |
765 | 828 |
775 | 838 |
776 static void CallbackFinalize(void* job); | 839 static void CallbackFinalize(void* job); |
777 | 840 |
778 static float CallbackGetProgress(void* job); | 841 static float CallbackGetProgress(void* job); |
779 | 842 |
843 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
844 static OrthancPluginErrorCode CallbackGetContent(OrthancPluginMemoryBuffer* target, | |
845 void* job); | |
846 #else | |
780 static const char* CallbackGetContent(void* job); | 847 static const char* CallbackGetContent(void* job); |
781 | 848 #endif |
849 | |
850 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
851 static int32_t CallbackGetSerialized(OrthancPluginMemoryBuffer* target, | |
852 void* job); | |
853 #else | |
782 static const char* CallbackGetSerialized(void* job); | 854 static const char* CallbackGetSerialized(void* job); |
855 #endif | |
783 | 856 |
784 static OrthancPluginJobStepStatus CallbackStep(void* job); | 857 static OrthancPluginJobStepStatus CallbackStep(void* job); |
785 | 858 |
786 static OrthancPluginErrorCode CallbackStop(void* job, | 859 static OrthancPluginErrorCode CallbackStop(void* job, |
787 OrthancPluginJobStopReason reason); | 860 OrthancPluginJobStopReason reason); |
1189 size_t size); | 1262 size_t size); |
1190 #endif | 1263 #endif |
1191 | 1264 |
1192 ~DicomInstance(); | 1265 ~DicomInstance(); |
1193 | 1266 |
1267 const OrthancPluginDicomInstance* GetObject() const | |
1268 { | |
1269 return instance_; | |
1270 } | |
1271 | |
1194 std::string GetRemoteAet() const; | 1272 std::string GetRemoteAet() const; |
1195 | 1273 |
1196 const void* GetBuffer() const | 1274 const void* GetBuffer() const |
1197 { | 1275 { |
1198 return OrthancPluginGetInstanceData(GetGlobalContext(), instance_); | 1276 return OrthancPluginGetInstanceData(GetGlobalContext(), instance_); |
1243 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | 1321 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
1244 static DicomInstance* Transcode(const void* buffer, | 1322 static DicomInstance* Transcode(const void* buffer, |
1245 size_t size, | 1323 size_t size, |
1246 const std::string& transferSyntax); | 1324 const std::string& transferSyntax); |
1247 #endif | 1325 #endif |
1326 | |
1327 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 1) | |
1328 static DicomInstance* Load(const std::string& instanceId, | |
1329 OrthancPluginLoadDicomInstanceMode mode); | |
1330 #endif | |
1248 }; | 1331 }; |
1332 | |
1333 // helper method to convert Http headers from the plugin SDK to a std::map | |
1334 void GetHttpHeaders(std::map<std::string, std::string>& result, const OrthancPluginHttpRequest* request); | |
1335 | |
1336 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
1337 class IWebDavCollection : public boost::noncopyable | |
1338 { | |
1339 public: | |
1340 class FileInfo | |
1341 { | |
1342 private: | |
1343 std::string name_; | |
1344 uint64_t contentSize_; | |
1345 std::string mime_; | |
1346 std::string dateTime_; | |
1347 | |
1348 public: | |
1349 FileInfo(const std::string& name, | |
1350 uint64_t contentSize, | |
1351 const std::string& dateTime) : | |
1352 name_(name), | |
1353 contentSize_(contentSize), | |
1354 dateTime_(dateTime) | |
1355 { | |
1356 } | |
1357 | |
1358 const std::string& GetName() const | |
1359 { | |
1360 return name_; | |
1361 } | |
1362 | |
1363 uint64_t GetContentSize() const | |
1364 { | |
1365 return contentSize_; | |
1366 } | |
1367 | |
1368 void SetMimeType(const std::string& mime) | |
1369 { | |
1370 mime_ = mime; | |
1371 } | |
1372 | |
1373 const std::string& GetMimeType() const | |
1374 { | |
1375 return mime_; | |
1376 } | |
1377 | |
1378 const std::string& GetDateTime() const | |
1379 { | |
1380 return dateTime_; | |
1381 } | |
1382 }; | |
1383 | |
1384 class FolderInfo | |
1385 { | |
1386 private: | |
1387 std::string name_; | |
1388 std::string dateTime_; | |
1389 | |
1390 public: | |
1391 FolderInfo(const std::string& name, | |
1392 const std::string& dateTime) : | |
1393 name_(name), | |
1394 dateTime_(dateTime) | |
1395 { | |
1396 } | |
1397 | |
1398 const std::string& GetName() const | |
1399 { | |
1400 return name_; | |
1401 } | |
1402 | |
1403 const std::string& GetDateTime() const | |
1404 { | |
1405 return dateTime_; | |
1406 } | |
1407 }; | |
1408 | |
1409 virtual ~IWebDavCollection() | |
1410 { | |
1411 } | |
1412 | |
1413 virtual bool IsExistingFolder(const std::vector<std::string>& path) = 0; | |
1414 | |
1415 virtual bool ListFolder(std::list<FileInfo>& files, | |
1416 std::list<FolderInfo>& subfolders, | |
1417 const std::vector<std::string>& path) = 0; | |
1418 | |
1419 virtual bool GetFile(std::string& content /* out */, | |
1420 std::string& mime /* out */, | |
1421 std::string& dateTime /* out */, | |
1422 const std::vector<std::string>& path) = 0; | |
1423 | |
1424 virtual bool StoreFile(const std::vector<std::string>& path, | |
1425 const void* data, | |
1426 size_t size) = 0; | |
1427 | |
1428 virtual bool CreateFolder(const std::vector<std::string>& path) = 0; | |
1429 | |
1430 virtual bool DeleteItem(const std::vector<std::string>& path) = 0; | |
1431 | |
1432 static void Register(const std::string& uri, | |
1433 IWebDavCollection& collection); | |
1434 }; | |
1435 #endif | |
1249 } | 1436 } |