comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 2058:43cd2ab060c7

cont OrthancPluginCppWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 Jun 2016 08:20:23 +0200
parents 154f3e73ad3a
children 8e67325eaa3f
comparison
equal deleted inserted replaced
2057:54417b0831c4 2058:43cd2ab060c7
31 31
32 32
33 #include "OrthancPluginCppWrapper.h" 33 #include "OrthancPluginCppWrapper.h"
34 34
35 #include <json/reader.h> 35 #include <json/reader.h>
36 #include <json/writer.h>
36 37
37 38
38 namespace OrthancPlugins 39 namespace OrthancPlugins
39 { 40 {
40 const char* PluginException::GetErrorDescription(OrthancPluginContext* context) const 41 const char* PluginException::GetErrorDescription(OrthancPluginContext* context) const
209 } 210 }
210 else 211 else
211 { 212 {
212 throw PluginException(error); 213 throw PluginException(error);
213 } 214 }
215 }
216
217
218 bool MemoryBuffer::RestApiPost(const std::string& uri,
219 const Json::Value& body,
220 bool applyPlugins)
221 {
222 Json::FastWriter writer;
223 return RestApiPost(uri, writer.write(body), applyPlugins);
224 }
225
226
227 bool MemoryBuffer::RestApiPut(const std::string& uri,
228 const Json::Value& body,
229 bool applyPlugins)
230 {
231 Json::FastWriter writer;
232 return RestApiPut(uri, writer.write(body), applyPlugins);
214 } 233 }
215 234
216 235
217 OrthancString::OrthancString(OrthancPluginContext* context, 236 OrthancString::OrthancString(OrthancPluginContext* context,
218 char* str) : 237 char* str) :
736 OrthancPluginCompressAndAnswerJpegImage(context_, output, GetPixelFormat(), 755 OrthancPluginCompressAndAnswerJpegImage(context_, output, GetPixelFormat(),
737 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); 756 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality);
738 } 757 }
739 758
740 759
741 bool RestApiGetJson(Json::Value& result, 760 bool RestApiGet(Json::Value& result,
742 OrthancPluginContext* context, 761 OrthancPluginContext* context,
743 const std::string& uri, 762 const std::string& uri,
744 bool applyPlugins) 763 bool applyPlugins)
745 { 764 {
746 MemoryBuffer answer(context); 765 MemoryBuffer answer(context);
747 if (!answer.RestApiGet(uri, applyPlugins)) 766 if (!answer.RestApiGet(uri, applyPlugins))
748 { 767 {
749 return false; 768 return false;
754 return true; 773 return true;
755 } 774 }
756 } 775 }
757 776
758 777
759 bool RestApiPostJson(Json::Value& result, 778 bool RestApiPost(Json::Value& result,
760 OrthancPluginContext* context, 779 OrthancPluginContext* context,
761 const std::string& uri, 780 const std::string& uri,
762 const char* body, 781 const char* body,
763 size_t bodySize, 782 size_t bodySize,
764 bool applyPlugins) 783 bool applyPlugins)
765 { 784 {
766 MemoryBuffer answer(context); 785 MemoryBuffer answer(context);
767 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) 786 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins))
768 { 787 {
769 return false; 788 return false;
774 return true; 793 return true;
775 } 794 }
776 } 795 }
777 796
778 797
779 bool RestApiPutJson(Json::Value& result, 798 bool RestApiPost(Json::Value& result,
780 OrthancPluginContext* context, 799 OrthancPluginContext* context,
781 const std::string& uri, 800 const std::string& uri,
782 const char* body, 801 const Json::Value& body,
783 size_t bodySize, 802 bool applyPlugins)
784 bool applyPlugins) 803 {
804 Json::FastWriter writer;
805 return RestApiPost(result, context, uri, writer.write(body), applyPlugins);
806 }
807
808
809 bool RestApiPut(Json::Value& result,
810 OrthancPluginContext* context,
811 const std::string& uri,
812 const char* body,
813 size_t bodySize,
814 bool applyPlugins)
785 { 815 {
786 MemoryBuffer answer(context); 816 MemoryBuffer answer(context);
787 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins)) 817 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins))
788 { 818 {
789 return false; 819 return false;
791 else 821 else
792 { 822 {
793 answer.ToJson(result); 823 answer.ToJson(result);
794 return true; 824 return true;
795 } 825 }
826 }
827
828
829 bool RestApiPut(Json::Value& result,
830 OrthancPluginContext* context,
831 const std::string& uri,
832 const Json::Value& body,
833 bool applyPlugins)
834 {
835 Json::FastWriter writer;
836 return RestApiPut(result, context, uri, writer.write(body), applyPlugins);
796 } 837 }
797 838
798 839
799 bool RestApiDelete(OrthancPluginContext* context, 840 bool RestApiDelete(OrthancPluginContext* context,
800 const std::string& uri, 841 const std::string& uri,