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