comparison Plugins/Engine/OrthancPluginDatabase.cpp @ 1630:ffd23c0104af

"/system" URI gives information about the plugins used for storage area and DB back-end
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Sep 2015 13:26:45 +0200
parents bad4772b605c
children eb8fbcf008b5
comparison
equal deleted inserted replaced
1629:bad4772b605c 1630:ffd23c0104af
111 void OrthancPluginDatabase::ForwardAnswers(std::list<int64_t>& target) 111 void OrthancPluginDatabase::ForwardAnswers(std::list<int64_t>& target)
112 { 112 {
113 if (type_ != _OrthancPluginDatabaseAnswerType_None && 113 if (type_ != _OrthancPluginDatabaseAnswerType_None &&
114 type_ != _OrthancPluginDatabaseAnswerType_Int64) 114 type_ != _OrthancPluginDatabaseAnswerType_Int64)
115 { 115 {
116 throw OrthancException(ErrorCode_Plugin); 116 throw OrthancException(ErrorCode_DatabasePlugin);
117 } 117 }
118 118
119 target.clear(); 119 target.clear();
120 120
121 if (type_ == _OrthancPluginDatabaseAnswerType_Int64) 121 if (type_ == _OrthancPluginDatabaseAnswerType_Int64)
132 void OrthancPluginDatabase::ForwardAnswers(std::list<std::string>& target) 132 void OrthancPluginDatabase::ForwardAnswers(std::list<std::string>& target)
133 { 133 {
134 if (type_ != _OrthancPluginDatabaseAnswerType_None && 134 if (type_ != _OrthancPluginDatabaseAnswerType_None &&
135 type_ != _OrthancPluginDatabaseAnswerType_String) 135 type_ != _OrthancPluginDatabaseAnswerType_String)
136 { 136 {
137 throw OrthancException(ErrorCode_Plugin); 137 throw OrthancException(ErrorCode_DatabasePlugin);
138 } 138 }
139 139
140 target.clear(); 140 target.clear();
141 141
142 if (type_ == _OrthancPluginDatabaseAnswerType_String) 142 if (type_ == _OrthancPluginDatabaseAnswerType_String)
162 target = answerStrings_.front(); 162 target = answerStrings_.front();
163 return true; 163 return true;
164 } 164 }
165 else 165 else
166 { 166 {
167 throw OrthancException(ErrorCode_Plugin); 167 throw OrthancException(ErrorCode_DatabasePlugin);
168 } 168 }
169 } 169 }
170 170
171 171
172 bool OrthancPluginDatabase::ForwardSingleAnswer(int64_t& target) 172 bool OrthancPluginDatabase::ForwardSingleAnswer(int64_t& target)
181 target = answerInt64_.front(); 181 target = answerInt64_.front();
182 return true; 182 return true;
183 } 183 }
184 else 184 else
185 { 185 {
186 throw OrthancException(ErrorCode_Plugin); 186 throw OrthancException(ErrorCode_DatabasePlugin);
187 } 187 }
188 } 188 }
189 189
190 190
191 OrthancPluginDatabase::OrthancPluginDatabase(const OrthancPluginDatabaseBackend& backend, 191 OrthancPluginDatabase::OrthancPluginDatabase(SharedLibrary& library,
192 const OrthancPluginDatabaseBackend& backend,
192 const OrthancPluginDatabaseExtensions* extensions, 193 const OrthancPluginDatabaseExtensions* extensions,
193 size_t extensionsSize, 194 size_t extensionsSize,
194 void *payload) : 195 void *payload) :
196 library_(library),
195 type_(_OrthancPluginDatabaseAnswerType_None), 197 type_(_OrthancPluginDatabaseAnswerType_None),
196 backend_(backend), 198 backend_(backend),
197 payload_(payload), 199 payload_(payload),
198 listener_(NULL), 200 listener_(NULL),
199 answerDicomMap_(NULL), 201 answerDicomMap_(NULL),
331 it = metadata.begin(); it != metadata.end(); ++it) 333 it = metadata.begin(); it != metadata.end(); ++it)
332 { 334 {
333 std::string value; 335 std::string value;
334 if (!LookupMetadata(value, id, *it)) 336 if (!LookupMetadata(value, id, *it))
335 { 337 {
336 throw OrthancException(ErrorCode_Plugin); 338 throw OrthancException(ErrorCode_DatabasePlugin);
337 } 339 }
338 340
339 target[*it] = value; 341 target[*it] = value;
340 } 342 }
341 } 343 }
542 throw OrthancException(Plugins::Convert(error)); 544 throw OrthancException(Plugins::Convert(error));
543 } 545 }
544 546
545 if (!ForwardSingleAnswer(s)) 547 if (!ForwardSingleAnswer(s))
546 { 548 {
547 throw OrthancException(ErrorCode_Plugin); 549 throw OrthancException(ErrorCode_DatabasePlugin);
548 } 550 }
549 551
550 return s; 552 return s;
551 } 553 }
552 554
654 } 656 }
655 657
656 if (type_ != _OrthancPluginDatabaseAnswerType_None && 658 if (type_ != _OrthancPluginDatabaseAnswerType_None &&
657 type_ != _OrthancPluginDatabaseAnswerType_Int32) 659 type_ != _OrthancPluginDatabaseAnswerType_Int32)
658 { 660 {
659 throw OrthancException(ErrorCode_Plugin); 661 throw OrthancException(ErrorCode_DatabasePlugin);
660 } 662 }
661 663
662 target.clear(); 664 target.clear();
663 665
664 if (type_ == _OrthancPluginDatabaseAnswerType_Int32) 666 if (type_ == _OrthancPluginDatabaseAnswerType_Int32)
685 } 687 }
686 688
687 if (type_ != _OrthancPluginDatabaseAnswerType_None && 689 if (type_ != _OrthancPluginDatabaseAnswerType_None &&
688 type_ != _OrthancPluginDatabaseAnswerType_Int32) 690 type_ != _OrthancPluginDatabaseAnswerType_Int32)
689 { 691 {
690 throw OrthancException(ErrorCode_Plugin); 692 throw OrthancException(ErrorCode_DatabasePlugin);
691 } 693 }
692 694
693 target.clear(); 695 target.clear();
694 696
695 if (type_ == _OrthancPluginDatabaseAnswerType_Int32) 697 if (type_ == _OrthancPluginDatabaseAnswerType_Int32)
768 attachment = answerAttachments_.front(); 770 attachment = answerAttachments_.front();
769 return true; 771 return true;
770 } 772 }
771 else 773 else
772 { 774 {
773 throw OrthancException(ErrorCode_Plugin); 775 throw OrthancException(ErrorCode_DatabasePlugin);
774 } 776 }
775 } 777 }
776 778
777 779
778 bool OrthancPluginDatabase::LookupGlobalProperty(std::string& target, 780 bool OrthancPluginDatabase::LookupGlobalProperty(std::string& target,
887 type = answerResources_.front().second; 889 type = answerResources_.front().second;
888 return true; 890 return true;
889 } 891 }
890 else 892 else
891 { 893 {
892 throw OrthancException(ErrorCode_Plugin); 894 throw OrthancException(ErrorCode_DatabasePlugin);
893 } 895 }
894 } 896 }
895 897
896 898
897 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId) 899 bool OrthancPluginDatabase::SelectPatientToRecycle(int64_t& internalId)
1070 listener.SignalChange(change); 1072 listener.SignalChange(change);
1071 break; 1073 break;
1072 } 1074 }
1073 1075
1074 default: 1076 default:
1075 throw OrthancException(ErrorCode_Plugin); 1077 throw OrthancException(ErrorCode_DatabasePlugin);
1076 } 1078 }
1077 } 1079 }
1078 1080
1079 1081
1080 unsigned int OrthancPluginDatabase::GetDatabaseVersion() 1082 unsigned int OrthancPluginDatabase::GetDatabaseVersion()
1120 1122
1121 void OrthancPluginDatabase::AnswerReceived(const _OrthancPluginDatabaseAnswer& answer) 1123 void OrthancPluginDatabase::AnswerReceived(const _OrthancPluginDatabaseAnswer& answer)
1122 { 1124 {
1123 if (answer.type == _OrthancPluginDatabaseAnswerType_None) 1125 if (answer.type == _OrthancPluginDatabaseAnswerType_None)
1124 { 1126 {
1125 throw OrthancException(ErrorCode_Plugin); 1127 throw OrthancException(ErrorCode_DatabasePlugin);
1126 } 1128 }
1127 1129
1128 if (answer.type == _OrthancPluginDatabaseAnswerType_DeletedAttachment || 1130 if (answer.type == _OrthancPluginDatabaseAnswerType_DeletedAttachment ||
1129 answer.type == _OrthancPluginDatabaseAnswerType_DeletedResource || 1131 answer.type == _OrthancPluginDatabaseAnswerType_DeletedResource ||
1130 answer.type == _OrthancPluginDatabaseAnswerType_RemainingAncestor) 1132 answer.type == _OrthancPluginDatabaseAnswerType_RemainingAncestor)
1175 answerExportedResources_->clear(); 1177 answerExportedResources_->clear();
1176 break; 1178 break;
1177 1179
1178 default: 1180 default:
1179 LOG(ERROR) << "Unhandled type of answer for custom index plugin: " << answer.type; 1181 LOG(ERROR) << "Unhandled type of answer for custom index plugin: " << answer.type;
1180 throw OrthancException(ErrorCode_Plugin); 1182 throw OrthancException(ErrorCode_DatabasePlugin);
1181 } 1183 }
1182 } 1184 }
1183 else if (type_ != answer.type) 1185 else if (type_ != answer.type)
1184 { 1186 {
1185 LOG(ERROR) << "Error in the plugin protocol: Cannot change the answer type"; 1187 LOG(ERROR) << "Error in the plugin protocol: Cannot change the answer type";
1186 throw OrthancException(ErrorCode_Plugin); 1188 throw OrthancException(ErrorCode_DatabasePlugin);
1187 } 1189 }
1188 1190
1189 switch (answer.type) 1191 switch (answer.type)
1190 { 1192 {
1191 case _OrthancPluginDatabaseAnswerType_Int32: 1193 case _OrthancPluginDatabaseAnswerType_Int32:
1226 1228
1227 case _OrthancPluginDatabaseAnswerType_String: 1229 case _OrthancPluginDatabaseAnswerType_String:
1228 { 1230 {
1229 if (answer.valueString == NULL) 1231 if (answer.valueString == NULL)
1230 { 1232 {
1231 throw OrthancException(ErrorCode_Plugin); 1233 throw OrthancException(ErrorCode_DatabasePlugin);
1232 } 1234 }
1233 1235
1234 if (type_ == _OrthancPluginDatabaseAnswerType_None) 1236 if (type_ == _OrthancPluginDatabaseAnswerType_None)
1235 { 1237 {
1236 type_ = _OrthancPluginDatabaseAnswerType_String; 1238 type_ = _OrthancPluginDatabaseAnswerType_String;
1237 answerStrings_.clear(); 1239 answerStrings_.clear();
1238 } 1240 }
1239 else if (type_ != _OrthancPluginDatabaseAnswerType_String) 1241 else if (type_ != _OrthancPluginDatabaseAnswerType_String)
1240 { 1242 {
1241 throw OrthancException(ErrorCode_Plugin); 1243 throw OrthancException(ErrorCode_DatabasePlugin);
1242 } 1244 }
1243 1245
1244 answerStrings_.push_back(std::string(answer.valueString)); 1246 answerStrings_.push_back(std::string(answer.valueString));
1245 break; 1247 break;
1246 } 1248 }
1252 { 1254 {
1253 *answerDone_ = true; 1255 *answerDone_ = true;
1254 } 1256 }
1255 else if (*answerDone_) 1257 else if (*answerDone_)
1256 { 1258 {
1257 throw OrthancException(ErrorCode_Plugin); 1259 throw OrthancException(ErrorCode_DatabasePlugin);
1258 } 1260 }
1259 else 1261 else
1260 { 1262 {
1261 const OrthancPluginChange& change = *reinterpret_cast<const OrthancPluginChange*>(answer.valueGeneric); 1263 const OrthancPluginChange& change = *reinterpret_cast<const OrthancPluginChange*>(answer.valueGeneric);
1262 assert(answerChanges_ != NULL); 1264 assert(answerChanges_ != NULL);
1278 { 1280 {
1279 *answerDone_ = true; 1281 *answerDone_ = true;
1280 } 1282 }
1281 else if (*answerDone_) 1283 else if (*answerDone_)
1282 { 1284 {
1283 throw OrthancException(ErrorCode_Plugin); 1285 throw OrthancException(ErrorCode_DatabasePlugin);
1284 } 1286 }
1285 else 1287 else
1286 { 1288 {
1287 const OrthancPluginExportedResource& exported = 1289 const OrthancPluginExportedResource& exported =
1288 *reinterpret_cast<const OrthancPluginExportedResource*>(answer.valueGeneric); 1290 *reinterpret_cast<const OrthancPluginExportedResource*>(answer.valueGeneric);
1302 break; 1304 break;
1303 } 1305 }
1304 1306
1305 default: 1307 default:
1306 LOG(ERROR) << "Unhandled type of answer for custom index plugin: " << answer.type; 1308 LOG(ERROR) << "Unhandled type of answer for custom index plugin: " << answer.type;
1307 throw OrthancException(ErrorCode_Plugin); 1309 throw OrthancException(ErrorCode_DatabasePlugin);
1308 } 1310 }
1309 } 1311 }
1310 } 1312 }