Mercurial > hg > orthanc-webviewer
comparison Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h @ 309:a8a2471ece25
sync orthanc folder
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 13 Nov 2023 21:19:57 +0100 |
parents | fb7d62e3235e |
children | 0a1ad7492050 |
comparison
equal
deleted
inserted
replaced
307:6bfb8a4d9abe | 309:a8a2471ece25 |
---|---|
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. |
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, |
123 const char* url, | 135 const char* url, |
124 const OrthancPluginHttpRequest* request); | 136 const OrthancPluginHttpRequest* request); |
125 | 137 |
126 void SetGlobalContext(OrthancPluginContext* context); | 138 void SetGlobalContext(OrthancPluginContext* context); |
127 | 139 |
140 void ResetGlobalContext(); | |
141 | |
128 bool HasGlobalContext(); | 142 bool HasGlobalContext(); |
129 | 143 |
130 OrthancPluginContext* GetGlobalContext(); | 144 OrthancPluginContext* GetGlobalContext(); |
131 | 145 |
132 | 146 |
216 | 230 |
217 bool RestApiPost(const std::string& uri, | 231 bool RestApiPost(const std::string& uri, |
218 const Json::Value& body, | 232 const Json::Value& body, |
219 bool applyPlugins); | 233 bool applyPlugins); |
220 | 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 | |
221 bool RestApiPut(const std::string& uri, | 248 bool RestApiPut(const std::string& uri, |
222 const Json::Value& body, | 249 const Json::Value& body, |
223 bool applyPlugins); | 250 bool applyPlugins); |
224 | 251 |
225 bool RestApiPost(const std::string& uri, | 252 bool RestApiPost(const std::string& uri, |
295 const char* GetContent() const | 322 const char* GetContent() const |
296 { | 323 { |
297 return str_; | 324 return str_; |
298 } | 325 } |
299 | 326 |
327 bool IsNullOrEmpty() const | |
328 { | |
329 return str_ == NULL || str_[0] == 0; | |
330 } | |
331 | |
300 void ToString(std::string& target) const; | 332 void ToString(std::string& target) const; |
301 | 333 |
302 void ToJson(Json::Value& target) const; | 334 void ToJson(Json::Value& target) const; |
303 }; | 335 |
336 void ToJsonWithoutComments(Json::Value& target) const; | |
337 }; | |
304 | 338 |
305 | 339 |
306 class OrthancConfiguration : public boost::noncopyable | 340 class OrthancConfiguration : public boost::noncopyable |
307 { | 341 { |
308 private: | 342 private: |
312 std::string GetPath(const std::string& key) const; | 346 std::string GetPath(const std::string& key) const; |
313 | 347 |
314 void LoadConfiguration(); | 348 void LoadConfiguration(); |
315 | 349 |
316 public: | 350 public: |
317 OrthancConfiguration(); | 351 OrthancConfiguration(); // loads the full Orthanc configuration |
318 | 352 |
319 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 | |
320 | 356 |
321 const Json::Value& GetJson() const | 357 const Json::Value& GetJson() const |
322 { | 358 { |
323 return configuration_; | 359 return configuration_; |
324 } | 360 } |
499 | 535 |
500 bool RestApiGet(Json::Value& result, | 536 bool RestApiGet(Json::Value& result, |
501 const std::string& uri, | 537 const std::string& uri, |
502 bool applyPlugins); | 538 bool applyPlugins); |
503 | 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 | |
504 bool RestApiGetString(std::string& result, | 545 bool RestApiGetString(std::string& result, |
505 const std::string& uri, | 546 const std::string& uri, |
506 bool applyPlugins); | 547 bool applyPlugins); |
507 | 548 |
508 bool RestApiGetString(std::string& result, | 549 bool RestApiGetString(std::string& result, |
519 bool RestApiPost(Json::Value& result, | 560 bool RestApiPost(Json::Value& result, |
520 const std::string& uri, | 561 const std::string& uri, |
521 const void* body, | 562 const void* body, |
522 size_t bodySize, | 563 size_t bodySize, |
523 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 | |
524 | 573 |
525 bool RestApiPost(Json::Value& result, | 574 bool RestApiPost(Json::Value& result, |
526 const std::string& uri, | 575 const std::string& uri, |
527 const Json::Value& body, | 576 const Json::Value& body, |
528 bool applyPlugins); | 577 bool applyPlugins); |
600 | 649 |
601 bool CheckMinimalOrthancVersion(unsigned int major, | 650 bool CheckMinimalOrthancVersion(unsigned int major, |
602 unsigned int minor, | 651 unsigned int minor, |
603 unsigned int revision); | 652 unsigned int revision); |
604 | 653 |
654 bool CheckMinimalVersion(const char* version, | |
655 unsigned int major, | |
656 unsigned int minor, | |
657 unsigned int revision); | |
605 | 658 |
606 namespace Internals | 659 namespace Internals |
607 { | 660 { |
608 template <RestCallback Callback> | 661 template <RestCallback Callback> |
609 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output, | 662 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output, |
709 const std::string& peer, | 762 const std::string& peer, |
710 const std::string& key) const; | 763 const std::string& key) const; |
711 | 764 |
712 bool DoGet(MemoryBuffer& target, | 765 bool DoGet(MemoryBuffer& target, |
713 size_t index, | 766 size_t index, |
714 const std::string& uri) const; | 767 const std::string& uri, |
768 const std::map<std::string, std::string>& headers) const; | |
715 | 769 |
716 bool DoGet(MemoryBuffer& target, | 770 bool DoGet(MemoryBuffer& target, |
717 const std::string& name, | 771 const std::string& name, |
718 const std::string& uri) const; | 772 const std::string& uri, |
773 const std::map<std::string, std::string>& headers) const; | |
719 | 774 |
720 bool DoGet(Json::Value& target, | 775 bool DoGet(Json::Value& target, |
721 size_t index, | 776 size_t index, |
722 const std::string& uri) const; | 777 const std::string& uri, |
778 const std::map<std::string, std::string>& headers) const; | |
723 | 779 |
724 bool DoGet(Json::Value& target, | 780 bool DoGet(Json::Value& target, |
725 const std::string& name, | 781 const std::string& name, |
726 const std::string& uri) const; | 782 const std::string& uri, |
783 const std::map<std::string, std::string>& headers) const; | |
727 | 784 |
728 bool DoPost(MemoryBuffer& target, | 785 bool DoPost(MemoryBuffer& target, |
729 size_t index, | 786 size_t index, |
730 const std::string& uri, | 787 const std::string& uri, |
731 const std::string& body) const; | 788 const std::string& body, |
789 const std::map<std::string, std::string>& headers) const; | |
732 | 790 |
733 bool DoPost(MemoryBuffer& target, | 791 bool DoPost(MemoryBuffer& target, |
734 const std::string& name, | 792 const std::string& name, |
735 const std::string& uri, | 793 const std::string& uri, |
736 const std::string& body) const; | 794 const std::string& body, |
795 const std::map<std::string, std::string>& headers) const; | |
737 | 796 |
738 bool DoPost(Json::Value& target, | 797 bool DoPost(Json::Value& target, |
739 size_t index, | 798 size_t index, |
740 const std::string& uri, | 799 const std::string& uri, |
741 const std::string& body) const; | 800 const std::string& body, |
801 const std::map<std::string, std::string>& headers) const; | |
742 | 802 |
743 bool DoPost(Json::Value& target, | 803 bool DoPost(Json::Value& target, |
744 const std::string& name, | 804 const std::string& name, |
745 const std::string& uri, | 805 const std::string& uri, |
746 const std::string& body) const; | 806 const std::string& body, |
807 const std::map<std::string, std::string>& headers) const; | |
747 | 808 |
748 bool DoPut(size_t index, | 809 bool DoPut(size_t index, |
749 const std::string& uri, | 810 const std::string& uri, |
750 const std::string& body) const; | 811 const std::string& body, |
812 const std::map<std::string, std::string>& headers) const; | |
751 | 813 |
752 bool DoPut(const std::string& name, | 814 bool DoPut(const std::string& name, |
753 const std::string& uri, | 815 const std::string& uri, |
754 const std::string& body) const; | 816 const std::string& body, |
817 const std::map<std::string, std::string>& headers) const; | |
755 | 818 |
756 bool DoDelete(size_t index, | 819 bool DoDelete(size_t index, |
757 const std::string& uri) const; | 820 const std::string& uri, |
821 const std::map<std::string, std::string>& headers) const; | |
758 | 822 |
759 bool DoDelete(const std::string& name, | 823 bool DoDelete(const std::string& name, |
760 const std::string& uri) const; | 824 const std::string& uri, |
825 const std::map<std::string, std::string>& headers) const; | |
761 }; | 826 }; |
762 #endif | 827 #endif |
763 | 828 |
764 | 829 |
765 | 830 |
775 | 840 |
776 static void CallbackFinalize(void* job); | 841 static void CallbackFinalize(void* job); |
777 | 842 |
778 static float CallbackGetProgress(void* job); | 843 static float CallbackGetProgress(void* job); |
779 | 844 |
845 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 11, 3) | |
846 static OrthancPluginErrorCode CallbackGetContent(OrthancPluginMemoryBuffer* target, | |
847 void* job); | |
848 #else | |
780 static const char* CallbackGetContent(void* job); | 849 static const char* CallbackGetContent(void* job); |
781 | 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 | |
782 static const char* CallbackGetSerialized(void* job); | 856 static const char* CallbackGetSerialized(void* job); |
857 #endif | |
783 | 858 |
784 static OrthancPluginJobStepStatus CallbackStep(void* job); | 859 static OrthancPluginJobStepStatus CallbackStep(void* job); |
785 | 860 |
786 static OrthancPluginErrorCode CallbackStop(void* job, | 861 static OrthancPluginErrorCode CallbackStop(void* job, |
787 OrthancPluginJobStopReason reason); | 862 OrthancPluginJobStopReason reason); |
1189 size_t size); | 1264 size_t size); |
1190 #endif | 1265 #endif |
1191 | 1266 |
1192 ~DicomInstance(); | 1267 ~DicomInstance(); |
1193 | 1268 |
1269 const OrthancPluginDicomInstance* GetObject() const | |
1270 { | |
1271 return instance_; | |
1272 } | |
1273 | |
1194 std::string GetRemoteAet() const; | 1274 std::string GetRemoteAet() const; |
1195 | 1275 |
1196 const void* GetBuffer() const | 1276 const void* GetBuffer() const |
1197 { | 1277 { |
1198 return OrthancPluginGetInstanceData(GetGlobalContext(), instance_); | 1278 return OrthancPluginGetInstanceData(GetGlobalContext(), instance_); |
1243 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | 1323 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) |
1244 static DicomInstance* Transcode(const void* buffer, | 1324 static DicomInstance* Transcode(const void* buffer, |
1245 size_t size, | 1325 size_t size, |
1246 const std::string& transferSyntax); | 1326 const std::string& transferSyntax); |
1247 #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 | |
1248 }; | 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 | |
1249 } | 1438 } |