comparison Plugins/Samples/Common/OrthancPluginCppWrapper.h @ 2979:5947aeedf41f

added C++ plugin helpers
author am@osimis.io
date Thu, 06 Dec 2018 13:10:00 +0100
parents 9b734c3e1095
children db8f360fcb41
comparison
equal deleted inserted replaced
2975:e62e296a5714 2979:5947aeedf41f
18 * modify file(s) with this exception, you may extend this exception to 18 * modify file(s) with this exception, you may extend this exception to
19 * your version of the file(s), but you are not obligated to do so. If 19 * your version of the file(s), but you are not obligated to do so. If
20 * you do not wish to do so, delete this exception statement from your 20 * you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files 21 * version. If you delete this exception statement from all source files
22 * in the program, then also delete it here. 22 * in the program, then also delete it here.
23 * 23 *
24 * This program is distributed in the hope that it will be useful, but 24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of 25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details. 27 * General Public License for more details.
28 * 28 *
46 46
47 47
48 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) 48 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
49 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \ 49 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \
50 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \ 50 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \
51 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \ 51 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \
52 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \ 52 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \
53 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \ 53 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \
54 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision)))) 54 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision))))
55 #endif 55 #endif
56 56
57 57
58 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0) 58 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0)
59 // The "OrthancPluginFindMatcher()" primitive was introduced in Orthanc 1.2.0 59 // The "OrthancPluginFindMatcher()" primitive was introduced in Orthanc 1.2.0
203 uint32_t maxStringLength); 203 uint32_t maxStringLength);
204 204
205 bool HttpGet(const std::string& url, 205 bool HttpGet(const std::string& url,
206 const std::string& username, 206 const std::string& username,
207 const std::string& password); 207 const std::string& password);
208 208
209 bool HttpPost(const std::string& url, 209 bool HttpPost(const std::string& url,
210 const std::string& body, 210 const std::string& body,
211 const std::string& username, 211 const std::string& username,
212 const std::string& password); 212 const std::string& password);
213 213
214 bool HttpPut(const std::string& url, 214 bool HttpPut(const std::string& url,
215 const std::string& body, 215 const std::string& body,
216 const std::string& username, 216 const std::string& username,
217 const std::string& password); 217 const std::string& password);
218 218
442 inline bool RestApiPost(Json::Value& result, 442 inline bool RestApiPost(Json::Value& result,
443 const std::string& uri, 443 const std::string& uri,
444 const std::string& body, 444 const std::string& body,
445 bool applyPlugins) 445 bool applyPlugins)
446 { 446 {
447 return RestApiPost(result, uri, body.empty() ? NULL : body.c_str(), 447 return RestApiPost(result, uri, body.empty() ? NULL : body.c_str(),
448 body.size(), applyPlugins); 448 body.size(), applyPlugins);
449 } 449 }
450 450
451 inline bool RestApiPost(Json::Value& result, 451 inline bool RestApiPost(Json::Value& result,
452 const std::string& uri, 452 const std::string& uri,
471 inline bool RestApiPut(Json::Value& result, 471 inline bool RestApiPut(Json::Value& result,
472 const std::string& uri, 472 const std::string& uri,
473 const std::string& body, 473 const std::string& body,
474 bool applyPlugins) 474 bool applyPlugins)
475 { 475 {
476 return RestApiPut(result, uri, body.empty() ? NULL : body.c_str(), 476 return RestApiPut(result, uri, body.empty() ? NULL : body.c_str(),
477 body.size(), applyPlugins); 477 body.size(), applyPlugins);
478 } 478 }
479 479
480 bool RestApiDelete(const std::string& uri, 480 bool RestApiDelete(const std::string& uri,
481 bool applyPlugins); 481 bool applyPlugins);
483 bool HttpDelete(const std::string& url, 483 bool HttpDelete(const std::string& url,
484 const std::string& username, 484 const std::string& username,
485 const std::string& password); 485 const std::string& password);
486 486
487 void AnswerJson(const Json::Value& value, 487 void AnswerJson(const Json::Value& value,
488 OrthancPluginRestOutput* output 488 OrthancPluginRestOutput* output);
489 ); 489
490 void AnswerHttpError(uint16_t httpError,
491 OrthancPluginRestOutput* output);
492
493 void AnswerMethodNotAllowed(OrthancPluginRestOutput* output, const char* allowedMethods);
490 494
491 const char* GetMimeType(const std::string& path); 495 const char* GetMimeType(const std::string& path);
492 496
493 497
494 void LogError(const std::string& message); 498 void LogError(const std::string& message);
526 { 530 {
527 // The "false" instructs Orthanc not to log the detailed 531 // The "false" instructs Orthanc not to log the detailed
528 // error message. This is to avoid duplicating the details, 532 // error message. This is to avoid duplicating the details,
529 // because "OrthancException" already does it on construction. 533 // because "OrthancException" already does it on construction.
530 OrthancPluginSetHttpErrorDetails 534 OrthancPluginSetHttpErrorDetails
531 (GetGlobalContext(), output, e.GetDetails(), false); 535 (GetGlobalContext(), output, e.GetDetails(), false);
532 } 536 }
533 #endif 537 #endif
534 538
535 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); 539 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
536 } 540 }
551 bool isThreadSafe) 555 bool isThreadSafe)
552 { 556 {
553 if (isThreadSafe) 557 if (isThreadSafe)
554 { 558 {
555 OrthancPluginRegisterRestCallbackNoLock 559 OrthancPluginRegisterRestCallbackNoLock
556 (GetGlobalContext(), uri.c_str(), Internals::Protect<Callback>); 560 (GetGlobalContext(), uri.c_str(), Internals::Protect<Callback>);
557 } 561 }
558 else 562 else
559 { 563 {
560 OrthancPluginRegisterRestCallback 564 OrthancPluginRegisterRestCallback
561 (GetGlobalContext(), uri.c_str(), Internals::Protect<Callback>); 565 (GetGlobalContext(), uri.c_str(), Internals::Protect<Callback>);
562 } 566 }
563 } 567 }
564 568
565 569
566 #if HAS_ORTHANC_PLUGIN_PEERS == 1 570 #if HAS_ORTHANC_PLUGIN_PEERS == 1
621 const std::string& uri) const; 625 const std::string& uri) const;
622 626
623 bool DoGet(Json::Value& target, 627 bool DoGet(Json::Value& target,
624 size_t index, 628 size_t index,
625 const std::string& uri) const; 629 const std::string& uri) const;
626 630
627 bool DoGet(Json::Value& target, 631 bool DoGet(Json::Value& target,
628 const std::string& name, 632 const std::string& name,
629 const std::string& uri) const; 633 const std::string& uri) const;
630 634
631 bool DoPost(MemoryBuffer& target, 635 bool DoPost(MemoryBuffer& target,
632 size_t index, 636 size_t index,
633 const std::string& uri, 637 const std::string& uri,
634 const std::string& body) const; 638 const std::string& body) const;
635 639
640 644
641 bool DoPost(Json::Value& target, 645 bool DoPost(Json::Value& target,
642 size_t index, 646 size_t index,
643 const std::string& uri, 647 const std::string& uri,
644 const std::string& body) const; 648 const std::string& body) const;
645 649
646 bool DoPost(Json::Value& target, 650 bool DoPost(Json::Value& target,
647 const std::string& name, 651 const std::string& name,
648 const std::string& uri, 652 const std::string& uri,
649 const std::string& body) const; 653 const std::string& body) const;
650 654