comparison Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h @ 40:1256194e1c08

sync orthanc + sdk 1.5.0 + added more info in error logs
author Alain Mazy <am@osimis.io>
date Tue, 12 Jul 2022 12:43:43 +0200
parents 81262707d68e
children f4e828607f02
comparison
equal deleted inserted replaced
39:f627882388dc 40:1256194e1c08
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-2022 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 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,
215 228
216 bool RestApiPost(const std::string& uri, 229 bool RestApiPost(const std::string& uri,
217 const Json::Value& body, 230 const Json::Value& body,
218 bool applyPlugins); 231 bool applyPlugins);
219 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
220 bool RestApiPut(const std::string& uri, 246 bool RestApiPut(const std::string& uri,
221 const Json::Value& body, 247 const Json::Value& body,
222 bool applyPlugins); 248 bool applyPlugins);
223 249
224 bool RestApiPost(const std::string& uri, 250 bool RestApiPost(const std::string& uri,
294 const char* GetContent() const 320 const char* GetContent() const
295 { 321 {
296 return str_; 322 return str_;
297 } 323 }
298 324
325 bool IsNullOrEmpty() const
326 {
327 return str_ == NULL || str_[0] == 0;
328 }
329
299 void ToString(std::string& target) const; 330 void ToString(std::string& target) const;
300 331
301 void ToJson(Json::Value& target) const; 332 void ToJson(Json::Value& target) const;
302 }; 333
334 void ToJsonWithoutComments(Json::Value& target) const;
335 };
303 336
304 337
305 class OrthancConfiguration : public boost::noncopyable 338 class OrthancConfiguration : public boost::noncopyable
306 { 339 {
307 private: 340 private:
518 bool RestApiPost(Json::Value& result, 551 bool RestApiPost(Json::Value& result,
519 const std::string& uri, 552 const std::string& uri,
520 const void* body, 553 const void* body,
521 size_t bodySize, 554 size_t bodySize,
522 bool applyPlugins); 555 bool applyPlugins);
556
557 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1
558 bool RestApiPost(Json::Value& result,
559 const std::string& uri,
560 const Json::Value& body,
561 const std::map<std::string, std::string>& httpHeaders,
562 bool applyPlugins);
563 #endif
523 564
524 bool RestApiPost(Json::Value& result, 565 bool RestApiPost(Json::Value& result,
525 const std::string& uri, 566 const std::string& uri,
526 const Json::Value& body, 567 const Json::Value& body,
527 bool applyPlugins); 568 bool applyPlugins);
599 640
600 bool CheckMinimalOrthancVersion(unsigned int major, 641 bool CheckMinimalOrthancVersion(unsigned int major,
601 unsigned int minor, 642 unsigned int minor,
602 unsigned int revision); 643 unsigned int revision);
603 644
645 bool CheckMinimalVersion(const char* version,
646 unsigned int major,
647 unsigned int minor,
648 unsigned int revision);
604 649
605 namespace Internals 650 namespace Internals
606 { 651 {
607 template <RestCallback Callback> 652 template <RestCallback Callback>
608 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output, 653 static OrthancPluginErrorCode Protect(OrthancPluginRestOutput* output,
1243 static DicomInstance* Transcode(const void* buffer, 1288 static DicomInstance* Transcode(const void* buffer,
1244 size_t size, 1289 size_t size,
1245 const std::string& transferSyntax); 1290 const std::string& transferSyntax);
1246 #endif 1291 #endif
1247 }; 1292 };
1293
1294 // helper method to convert Http headers from the plugin SDK to a std::map
1295 void GetHttpHeaders(std::map<std::string, std::string>& result, const OrthancPluginHttpRequest* request);
1296
1297 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
1298 class IWebDavCollection : public boost::noncopyable
1299 {
1300 public:
1301 class FileInfo
1302 {
1303 private:
1304 std::string name_;
1305 uint64_t contentSize_;
1306 std::string mime_;
1307 std::string dateTime_;
1308
1309 public:
1310 FileInfo(const std::string& name,
1311 uint64_t contentSize,
1312 const std::string& dateTime) :
1313 name_(name),
1314 contentSize_(contentSize),
1315 dateTime_(dateTime)
1316 {
1317 }
1318
1319 const std::string& GetName() const
1320 {
1321 return name_;
1322 }
1323
1324 uint64_t GetContentSize() const
1325 {
1326 return contentSize_;
1327 }
1328
1329 void SetMimeType(const std::string& mime)
1330 {
1331 mime_ = mime;
1332 }
1333
1334 const std::string& GetMimeType() const
1335 {
1336 return mime_;
1337 }
1338
1339 const std::string& GetDateTime() const
1340 {
1341 return dateTime_;
1342 }
1343 };
1344
1345 class FolderInfo
1346 {
1347 private:
1348 std::string name_;
1349 std::string dateTime_;
1350
1351 public:
1352 FolderInfo(const std::string& name,
1353 const std::string& dateTime) :
1354 name_(name),
1355 dateTime_(dateTime)
1356 {
1357 }
1358
1359 const std::string& GetName() const
1360 {
1361 return name_;
1362 }
1363
1364 const std::string& GetDateTime() const
1365 {
1366 return dateTime_;
1367 }
1368 };
1369
1370 virtual ~IWebDavCollection()
1371 {
1372 }
1373
1374 virtual bool IsExistingFolder(const std::vector<std::string>& path) = 0;
1375
1376 virtual bool ListFolder(std::list<FileInfo>& files,
1377 std::list<FolderInfo>& subfolders,
1378 const std::vector<std::string>& path) = 0;
1379
1380 virtual bool GetFile(std::string& content /* out */,
1381 std::string& mime /* out */,
1382 std::string& dateTime /* out */,
1383 const std::vector<std::string>& path) = 0;
1384
1385 virtual bool StoreFile(const std::vector<std::string>& path,
1386 const void* data,
1387 size_t size) = 0;
1388
1389 virtual bool CreateFolder(const std::vector<std::string>& path) = 0;
1390
1391 virtual bool DeleteItem(const std::vector<std::string>& path) = 0;
1392
1393 static void Register(const std::string& uri,
1394 IWebDavCollection& collection);
1395 };
1396 #endif
1248 } 1397 }