comparison RenderingPlugin/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 2124:16c01cc201e7

updated copyright, as Osimis is not active on Orthanc anymore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 May 2024 17:00:29 +0200
parents 11bc8a304038
children 2965172977a4
comparison
equal deleted inserted replaced
2121:4cc9e4a54a89 2124:16c01cc201e7
59 59
60 60
61 namespace OrthancPlugins 61 namespace OrthancPlugins
62 { 62 {
63 static OrthancPluginContext* globalContext_ = NULL; 63 static OrthancPluginContext* globalContext_ = NULL;
64 static std::string pluginName_;
64 65
65 66
66 void SetGlobalContext(OrthancPluginContext* context) 67 void SetGlobalContext(OrthancPluginContext* context)
67 { 68 {
68 if (context == NULL) 69 if (context == NULL)
77 { 78 {
78 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); 79 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls);
79 } 80 }
80 } 81 }
81 82
83
84 void SetGlobalContext(OrthancPluginContext* context,
85 const char* pluginName)
86 {
87 SetGlobalContext(context);
88 pluginName_ = pluginName;
89 }
90
91
82 void ResetGlobalContext() 92 void ResetGlobalContext()
83 { 93 {
84 globalContext_ = NULL; 94 globalContext_ = NULL;
95 pluginName_.clear();
85 } 96 }
86 97
87 bool HasGlobalContext() 98 bool HasGlobalContext()
88 { 99 {
89 return globalContext_ != NULL; 100 return globalContext_ != NULL;
97 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); 108 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls);
98 } 109 }
99 else 110 else
100 { 111 {
101 return globalContext_; 112 return globalContext_;
113 }
114 }
115
116
117 #if HAS_ORTHANC_PLUGIN_LOG_MESSAGE == 1
118 void LogMessage(OrthancPluginLogLevel level,
119 const char* file,
120 uint32_t line,
121 const std::string& message)
122 {
123 if (HasGlobalContext())
124 {
125 #if HAS_ORTHANC_PLUGIN_LOG_MESSAGE == 1
126 const char* pluginName = (pluginName_.empty() ? NULL : pluginName_.c_str());
127 OrthancPluginLogMessage(GetGlobalContext(), message.c_str(), pluginName, file, line, OrthancPluginLogCategory_Generic, level);
128 #else
129 switch (level)
130 {
131 case OrthancPluginLogLevel_Error:
132 OrthancPluginLogError(GetGlobalContext(), message.c_str());
133 break;
134
135 case OrthancPluginLogLevel_Warning:
136 OrthancPluginLogWarning(GetGlobalContext(), message.c_str());
137 break;
138
139 case OrthancPluginLogLevel_Info:
140 OrthancPluginLogInfo(GetGlobalContext(), message.c_str());
141 break;
142
143 default:
144 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
145 }
146 #endif
147 }
148 }
149 #endif
150
151
152 void LogError(const std::string& message)
153 {
154 if (HasGlobalContext())
155 {
156 OrthancPluginLogError(GetGlobalContext(), message.c_str());
157 }
158 }
159
160 void LogWarning(const std::string& message)
161 {
162 if (HasGlobalContext())
163 {
164 OrthancPluginLogWarning(GetGlobalContext(), message.c_str());
165 }
166 }
167
168 void LogInfo(const std::string& message)
169 {
170 if (HasGlobalContext())
171 {
172 OrthancPluginLogInfo(GetGlobalContext(), message.c_str());
102 } 173 }
103 } 174 }
104 175
105 176
106 void MemoryBuffer::Check(OrthancPluginErrorCode code) 177 void MemoryBuffer::Check(OrthancPluginErrorCode code)
231 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 302 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
232 } 303 }
233 304
234 if (!ReadJson(target, buffer_.data, buffer_.size)) 305 if (!ReadJson(target, buffer_.data, buffer_.size))
235 { 306 {
236 LogError("Cannot convert some memory buffer to JSON"); 307 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
237 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 308 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
238 } 309 }
239 } 310 }
240 311
241 312
263 334
264 public: 335 public:
265 explicit PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders) 336 explicit PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders)
266 { 337 {
267 for (std::map<std::string, std::string>::const_iterator 338 for (std::map<std::string, std::string>::const_iterator
268 it = httpHeaders.begin(); it != httpHeaders.end(); ++it) 339 it = httpHeaders.begin(); it != httpHeaders.end(); ++it)
269 { 340 {
270 headersKeys_.push_back(it->first.c_str()); 341 headersKeys_.push_back(it->first.c_str());
271 headersValues_.push_back(it->second.c_str()); 342 headersValues_.push_back(it->second.c_str());
272 } 343 }
273 } 344 }
402 { 473 {
403 return true; 474 return true;
404 } 475 }
405 else 476 else
406 { 477 {
407 LogError("Cannot parse JSON: " + std::string(err)); 478 ORTHANC_PLUGINS_LOG_ERROR("Cannot parse JSON: " + std::string(err));
408 return false; 479 return false;
409 } 480 }
410 #endif 481 #endif
411 } 482 }
412 483
563 634
564 void OrthancString::ToJson(Json::Value& target) const 635 void OrthancString::ToJson(Json::Value& target) const
565 { 636 {
566 if (str_ == NULL) 637 if (str_ == NULL)
567 { 638 {
568 LogError("Cannot convert an empty memory buffer to JSON"); 639 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert an empty memory buffer to JSON");
569 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 640 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
570 } 641 }
571 642
572 if (!ReadJson(target, str_)) 643 if (!ReadJson(target, str_))
573 { 644 {
574 LogError("Cannot convert some memory buffer to JSON"); 645 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
575 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 646 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
576 } 647 }
577 } 648 }
578 649
579 650
580 void OrthancString::ToJsonWithoutComments(Json::Value& target) const 651 void OrthancString::ToJsonWithoutComments(Json::Value& target) const
581 { 652 {
582 if (str_ == NULL) 653 if (str_ == NULL)
583 { 654 {
584 LogError("Cannot convert an empty memory buffer to JSON"); 655 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert an empty memory buffer to JSON");
585 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 656 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
586 } 657 }
587 658
588 if (!ReadJsonWithoutComments(target, str_)) 659 if (!ReadJsonWithoutComments(target, str_))
589 { 660 {
590 LogError("Cannot convert some memory buffer to JSON"); 661 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert some memory buffer to JSON");
591 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 662 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
592 } 663 }
593 } 664 }
594 665
595 666
623 { 694 {
624 Clear(); 695 Clear();
625 696
626 if (body.size() > 0xffffffffu) 697 if (body.size() > 0xffffffffu)
627 { 698 {
628 LogError("Cannot handle body size > 4GB"); 699 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
629 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 700 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
630 } 701 }
631 702
632 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(), 703 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(),
633 body.c_str(), body.size(), 704 body.c_str(), body.size(),
643 { 714 {
644 Clear(); 715 Clear();
645 716
646 if (body.size() > 0xffffffffu) 717 if (body.size() > 0xffffffffu)
647 { 718 {
648 LogError("Cannot handle body size > 4GB"); 719 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
649 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 720 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
650 } 721 }
651 722
652 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(), 723 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(),
653 body.empty() ? NULL : body.c_str(), 724 body.empty() ? NULL : body.c_str(),
686 { 757 {
687 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); 758 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
688 } 759 }
689 } 760 }
690 761
691
692 void LogError(const std::string& message)
693 {
694 if (HasGlobalContext())
695 {
696 OrthancPluginLogError(GetGlobalContext(), message.c_str());
697 }
698 }
699
700
701 void LogWarning(const std::string& message)
702 {
703 if (HasGlobalContext())
704 {
705 OrthancPluginLogWarning(GetGlobalContext(), message.c_str());
706 }
707 }
708
709
710 void LogInfo(const std::string& message)
711 {
712 if (HasGlobalContext())
713 {
714 OrthancPluginLogInfo(GetGlobalContext(), message.c_str());
715 }
716 }
717
718
719 void OrthancConfiguration::LoadConfiguration() 762 void OrthancConfiguration::LoadConfiguration()
720 { 763 {
721 OrthancString str; 764 OrthancString str;
722 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext())); 765 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext()));
723 766
724 if (str.GetContent() == NULL) 767 if (str.GetContent() == NULL)
725 { 768 {
726 LogError("Cannot access the Orthanc configuration"); 769 ORTHANC_PLUGINS_LOG_ERROR("Cannot access the Orthanc configuration");
727 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 770 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
728 } 771 }
729 772
730 str.ToJsonWithoutComments(configuration_); 773 str.ToJsonWithoutComments(configuration_);
731 774
732 if (configuration_.type() != Json::objectValue) 775 if (configuration_.type() != Json::objectValue)
733 { 776 {
734 LogError("Unable to read the Orthanc configuration"); 777 ORTHANC_PLUGINS_LOG_ERROR("Unable to read the Orthanc configuration");
735 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 778 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
736 } 779 }
737 } 780 }
738 781
739 782
797 } 840 }
798 else 841 else
799 { 842 {
800 if (configuration_[key].type() != Json::objectValue) 843 if (configuration_[key].type() != Json::objectValue)
801 { 844 {
802 LogError("The configuration section \"" + target.path_ + 845 ORTHANC_PLUGINS_LOG_ERROR("The configuration section \"" + target.path_ +
803 "\" is not an associative array as expected"); 846 "\" is not an associative array as expected");
804 847
805 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 848 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
806 } 849 }
807 850
808 target.configuration_ = configuration_[key]; 851 target.configuration_ = configuration_[key];
820 return false; 863 return false;
821 } 864 }
822 865
823 if (configuration_[key].type() != Json::stringValue) 866 if (configuration_[key].type() != Json::stringValue)
824 { 867 {
825 LogError("The configuration option \"" + GetPath(key) + 868 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
826 "\" is not a string as expected"); 869 "\" is not a string as expected");
827 870
828 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 871 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
829 } 872 }
830 873
831 target = configuration_[key].asString(); 874 target = configuration_[key].asString();
852 case Json::uintValue: 895 case Json::uintValue:
853 target = configuration_[key].asUInt(); 896 target = configuration_[key].asUInt();
854 return true; 897 return true;
855 898
856 default: 899 default:
857 LogError("The configuration option \"" + GetPath(key) + 900 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
858 "\" is not an integer as expected"); 901 "\" is not an integer as expected");
859 902
860 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 903 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
861 } 904 }
862 } 905 }
863 906
871 return false; 914 return false;
872 } 915 }
873 916
874 if (tmp < 0) 917 if (tmp < 0)
875 { 918 {
876 LogError("The configuration option \"" + GetPath(key) + 919 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
877 "\" is not a positive integer as expected"); 920 "\" is not a positive integer as expected");
878 921
879 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 922 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
880 } 923 }
881 else 924 else
882 { 925 {
896 return false; 939 return false;
897 } 940 }
898 941
899 if (configuration_[key].type() != Json::booleanValue) 942 if (configuration_[key].type() != Json::booleanValue)
900 { 943 {
901 LogError("The configuration option \"" + GetPath(key) + 944 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
902 "\" is not a Boolean as expected"); 945 "\" is not a Boolean as expected");
903 946
904 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 947 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
905 } 948 }
906 949
907 target = configuration_[key].asBool(); 950 target = configuration_[key].asBool();
932 case Json::uintValue: 975 case Json::uintValue:
933 target = static_cast<float>(configuration_[key].asUInt()); 976 target = static_cast<float>(configuration_[key].asUInt());
934 return true; 977 return true;
935 978
936 default: 979 default:
937 LogError("The configuration option \"" + GetPath(key) + 980 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
938 "\" is not an integer as expected"); 981 "\" is not an integer as expected");
939 982
940 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 983 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
941 } 984 }
942 } 985 }
943 986
992 1035
993 default: 1036 default:
994 break; 1037 break;
995 } 1038 }
996 1039
997 LogError("The configuration option \"" + GetPath(key) + 1040 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
998 "\" is not a list of strings as expected"); 1041 "\" is not a list of strings as expected");
999 1042
1000 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 1043 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
1001 } 1044 }
1002 1045
1003 1046
1113 return; 1156 return;
1114 } 1157 }
1115 1158
1116 if (configuration_[key].type() != Json::objectValue) 1159 if (configuration_[key].type() != Json::objectValue)
1117 { 1160 {
1118 LogError("The configuration option \"" + GetPath(key) + 1161 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
1119 "\" is not an object as expected"); 1162 "\" is not an object as expected");
1120 1163
1121 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 1164 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
1122 } 1165 }
1123 1166
1124 Json::Value::Members members = configuration_[key].getMemberNames(); 1167 Json::Value::Members members = configuration_[key].getMemberNames();
1131 { 1174 {
1132 target[members[i]] = value.asString(); 1175 target[members[i]] = value.asString();
1133 } 1176 }
1134 else 1177 else
1135 { 1178 {
1136 LogError("The configuration option \"" + GetPath(key) + 1179 ORTHANC_PLUGINS_LOG_ERROR("The configuration option \"" + GetPath(key) +
1137 "\" is not a dictionary mapping strings to strings"); 1180 "\" is not a dictionary mapping strings to strings");
1138 1181
1139 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 1182 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
1140 } 1183 }
1141 } 1184 }
1142 } 1185 }
1154 1197
1155 void OrthancImage::CheckImageAvailable() const 1198 void OrthancImage::CheckImageAvailable() const
1156 { 1199 {
1157 if (image_ == NULL) 1200 if (image_ == NULL)
1158 { 1201 {
1159 LogError("Trying to access a NULL image"); 1202 ORTHANC_PLUGINS_LOG_ERROR("Trying to access a NULL image");
1160 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); 1203 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
1161 } 1204 }
1162 } 1205 }
1163 1206
1164 1207
1180 { 1223 {
1181 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height); 1224 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height);
1182 1225
1183 if (image_ == NULL) 1226 if (image_ == NULL)
1184 { 1227 {
1185 LogError("Cannot create an image"); 1228 ORTHANC_PLUGINS_LOG_ERROR("Cannot create an image");
1186 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 1229 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
1187 } 1230 }
1188 } 1231 }
1189 1232
1190 1233
1197 image_ = OrthancPluginCreateImageAccessor 1240 image_ = OrthancPluginCreateImageAccessor
1198 (GetGlobalContext(), format, width, height, pitch, buffer); 1241 (GetGlobalContext(), format, width, height, pitch, buffer);
1199 1242
1200 if (image_ == NULL) 1243 if (image_ == NULL)
1201 { 1244 {
1202 LogError("Cannot create an image accessor"); 1245 ORTHANC_PLUGINS_LOG_ERROR("Cannot create an image accessor");
1203 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 1246 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
1204 } 1247 }
1205 } 1248 }
1206 1249
1207 void OrthancImage::UncompressPngImage(const void* data, 1250 void OrthancImage::UncompressPngImage(const void* data,
1211 1254
1212 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png); 1255 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png);
1213 1256
1214 if (image_ == NULL) 1257 if (image_ == NULL)
1215 { 1258 {
1216 LogError("Cannot uncompress a PNG image"); 1259 ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a PNG image");
1217 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); 1260 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
1218 } 1261 }
1219 } 1262 }
1220 1263
1221 1264
1224 { 1267 {
1225 Clear(); 1268 Clear();
1226 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg); 1269 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg);
1227 if (image_ == NULL) 1270 if (image_ == NULL)
1228 { 1271 {
1229 LogError("Cannot uncompress a JPEG image"); 1272 ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a JPEG image");
1230 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); 1273 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
1231 } 1274 }
1232 } 1275 }
1233 1276
1234 1277
1238 { 1281 {
1239 Clear(); 1282 Clear();
1240 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame); 1283 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame);
1241 if (image_ == NULL) 1284 if (image_ == NULL)
1242 { 1285 {
1243 LogError("Cannot uncompress a DICOM image"); 1286 ORTHANC_PLUGINS_LOG_ERROR("Cannot uncompress a DICOM image");
1244 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); 1287 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
1245 } 1288 }
1246 } 1289 }
1247 1290
1248 1291
1652 1695
1653 void ReportMinimalOrthancVersion(unsigned int major, 1696 void ReportMinimalOrthancVersion(unsigned int major,
1654 unsigned int minor, 1697 unsigned int minor,
1655 unsigned int revision) 1698 unsigned int revision)
1656 { 1699 {
1657 LogError("Your version of the Orthanc core (" + 1700 ORTHANC_PLUGINS_LOG_ERROR("Your version of the Orthanc core (" +
1658 std::string(GetGlobalContext()->orthancVersion) + 1701 std::string(GetGlobalContext()->orthancVersion) +
1659 ") is too old to run this plugin (version " + 1702 ") is too old to run this plugin (version " +
1660 boost::lexical_cast<std::string>(major) + "." + 1703 boost::lexical_cast<std::string>(major) + "." +
1661 boost::lexical_cast<std::string>(minor) + "." + 1704 boost::lexical_cast<std::string>(minor) + "." +
1662 boost::lexical_cast<std::string>(revision) + 1705 boost::lexical_cast<std::string>(revision) +
1663 " is required)"); 1706 " is required)");
1664 } 1707 }
1665 1708
1666 bool CheckMinimalVersion(const char* version, 1709 bool CheckMinimalVersion(const char* version,
1667 unsigned int major, 1710 unsigned int major,
1668 unsigned int minor, 1711 unsigned int minor,
1682 1725
1683 // Parse the version 1726 // Parse the version
1684 int aa, bb, cc = 0; 1727 int aa, bb, cc = 0;
1685 if ((ORTHANC_SCANF(version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 && 1728 if ((ORTHANC_SCANF(version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 &&
1686 ORTHANC_SCANF(version, "%4d.%4d", &aa, &bb) != 2) || 1729 ORTHANC_SCANF(version, "%4d.%4d", &aa, &bb) != 2) ||
1687 aa < 0 || 1730 aa < 0 ||
1688 bb < 0 || 1731 bb < 0 ||
1689 cc < 0) 1732 cc < 0)
1690 { 1733 {
1691 return false; 1734 return false;
1692 } 1735 }
1693 1736
1694 unsigned int a = static_cast<unsigned int>(aa); 1737 unsigned int a = static_cast<unsigned int>(aa);
1738 unsigned int minor, 1781 unsigned int minor,
1739 unsigned int revision) 1782 unsigned int revision)
1740 { 1783 {
1741 if (!HasGlobalContext()) 1784 if (!HasGlobalContext())
1742 { 1785 {
1743 LogError("Bad Orthanc context in the plugin"); 1786 ORTHANC_PLUGINS_LOG_ERROR("Bad Orthanc context in the plugin");
1744 return false; 1787 return false;
1745 } 1788 }
1746 1789
1747 return CheckMinimalVersion(GetGlobalContext()->orthancVersion, 1790 return CheckMinimalVersion(GetGlobalContext()->orthancVersion,
1748 major, minor, revision); 1791 major, minor, revision);
1775 { 1818 {
1776 return index; 1819 return index;
1777 } 1820 }
1778 else 1821 else
1779 { 1822 {
1780 LogError("Inexistent peer: " + name); 1823 ORTHANC_PLUGINS_LOG_ERROR("Inexistent peer: " + name);
1781 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); 1824 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
1782 } 1825 }
1783 } 1826 }
1784 1827
1785 1828
2059 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); 2102 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
2060 } 2103 }
2061 2104
2062 if (body.size() > 0xffffffffu) 2105 if (body.size() > 0xffffffffu)
2063 { 2106 {
2064 LogError("Cannot handle body size > 4GB"); 2107 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
2065 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 2108 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2066 } 2109 }
2067 2110
2068 OrthancPlugins::MemoryBuffer answer; 2111 OrthancPlugins::MemoryBuffer answer;
2069 uint16_t status; 2112 uint16_t status;
2096 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); 2139 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange);
2097 } 2140 }
2098 2141
2099 if (body.size() > 0xffffffffu) 2142 if (body.size() > 0xffffffffu)
2100 { 2143 {
2101 LogError("Cannot handle body size > 4GB"); 2144 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
2102 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 2145 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2103 } 2146 }
2104 2147
2105 OrthancPlugins::MemoryBuffer answer; 2148 OrthancPlugins::MemoryBuffer answer;
2106 uint16_t status; 2149 uint16_t status;
2462 2505
2463 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority); 2506 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority);
2464 2507
2465 if (id == NULL) 2508 if (id == NULL)
2466 { 2509 {
2467 LogError("Plugin cannot submit job"); 2510 ORTHANC_PLUGINS_LOG_ERROR("Plugin cannot submit job");
2468 OrthancPluginFreeJob(GetGlobalContext(), orthanc); 2511 OrthancPluginFreeJob(GetGlobalContext(), orthanc);
2469 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); 2512 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin);
2470 } 2513 }
2471 else 2514 else
2472 { 2515 {
2531 { 2574 {
2532 #if HAS_ORTHANC_EXCEPTION == 1 2575 #if HAS_ORTHANC_EXCEPTION == 1
2533 throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()), 2576 throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()),
2534 status["ErrorDescription"].asString()); 2577 status["ErrorDescription"].asString());
2535 #else 2578 #else
2536 LogError("Exception while executing the job: " + status["ErrorDescription"].asString()); 2579 ORTHANC_PLUGINS_LOG_ERROR("Exception while executing the job: " + status["ErrorDescription"].asString());
2537 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); 2580 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt());
2538 #endif 2581 #endif
2539 } 2582 }
2540 } 2583 }
2541 } 2584 }
2556 { 2599 {
2557 #if HAS_ORTHANC_EXCEPTION == 1 2600 #if HAS_ORTHANC_EXCEPTION == 1
2558 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, 2601 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
2559 "Expected a JSON object in the body"); 2602 "Expected a JSON object in the body");
2560 #else 2603 #else
2561 LogError("Expected a JSON object in the body"); 2604 ORTHANC_PLUGINS_LOG_ERROR("Expected a JSON object in the body");
2562 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 2605 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2563 #endif 2606 #endif
2564 } 2607 }
2565 2608
2566 bool synchronous = true; 2609 bool synchronous = true;
2572 #if HAS_ORTHANC_EXCEPTION == 1 2615 #if HAS_ORTHANC_EXCEPTION == 1
2573 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, 2616 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
2574 "Option \"" + std::string(KEY_SYNCHRONOUS) + 2617 "Option \"" + std::string(KEY_SYNCHRONOUS) +
2575 "\" must be Boolean"); 2618 "\" must be Boolean");
2576 #else 2619 #else
2577 LogError("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean"); 2620 ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean");
2578 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 2621 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2579 #endif 2622 #endif
2580 } 2623 }
2581 else 2624 else
2582 { 2625 {
2591 #if HAS_ORTHANC_EXCEPTION == 1 2634 #if HAS_ORTHANC_EXCEPTION == 1
2592 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, 2635 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
2593 "Option \"" + std::string(KEY_ASYNCHRONOUS) + 2636 "Option \"" + std::string(KEY_ASYNCHRONOUS) +
2594 "\" must be Boolean"); 2637 "\" must be Boolean");
2595 #else 2638 #else
2596 LogError("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean"); 2639 ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean");
2597 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 2640 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2598 #endif 2641 #endif
2599 } 2642 }
2600 else 2643 else
2601 { 2644 {
2612 #if HAS_ORTHANC_EXCEPTION == 1 2655 #if HAS_ORTHANC_EXCEPTION == 1
2613 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, 2656 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
2614 "Option \"" + std::string(KEY_PRIORITY) + 2657 "Option \"" + std::string(KEY_PRIORITY) +
2615 "\" must be an integer"); 2658 "\" must be an integer");
2616 #else 2659 #else
2617 LogError("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer"); 2660 ORTHANC_PLUGINS_LOG_ERROR("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer");
2618 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 2661 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
2619 #endif 2662 #endif
2620 } 2663 }
2621 else 2664 else
2622 { 2665 {
3133 3176
3134 MemoryBuffer answerBodyBuffer, answerHeadersBuffer; 3177 MemoryBuffer answerBodyBuffer, answerHeadersBuffer;
3135 3178
3136 if (body.size() > 0xffffffffu) 3179 if (body.size() > 0xffffffffu)
3137 { 3180 {
3138 LogError("Cannot handle body size > 4GB"); 3181 ORTHANC_PLUGINS_LOG_ERROR("Cannot handle body size > 4GB");
3139 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 3182 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
3140 } 3183 }
3141 3184
3142 OrthancPluginErrorCode error = OrthancPluginHttpClient( 3185 OrthancPluginErrorCode error = OrthancPluginHttpClient(
3143 GetGlobalContext(), 3186 GetGlobalContext(),
3278 std::string body; 3321 std::string body;
3279 Execute(answerHeaders, body); 3322 Execute(answerHeaders, body);
3280 3323
3281 if (!ReadJson(answerBody, body)) 3324 if (!ReadJson(answerBody, body))
3282 { 3325 {
3283 LogError("Cannot convert HTTP answer body to JSON"); 3326 ORTHANC_PLUGINS_LOG_ERROR("Cannot convert HTTP answer body to JSON");
3284 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 3327 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
3285 } 3328 }
3286 } 3329 }
3287 3330
3288 3331