comparison Plugins/Engine/OrthancPluginDatabase.cpp @ 1609:c74495267acf

Implementation of the "GetAllPublicIdsWithLimit" extension
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Sep 2015 15:07:47 +0200
parents 33d34bc4ac15
children c40fe92a68e7
comparison
equal deleted inserted replaced
1608:adc6a5704cdb 1609:c74495267acf
185 } 185 }
186 } 186 }
187 187
188 188
189 OrthancPluginDatabase::OrthancPluginDatabase(const OrthancPluginDatabaseBackend& backend, 189 OrthancPluginDatabase::OrthancPluginDatabase(const OrthancPluginDatabaseBackend& backend,
190 const OrthancPluginDatabaseExtensions* extensions,
191 size_t extensionsSize,
190 void *payload) : 192 void *payload) :
191 type_(_OrthancPluginDatabaseAnswerType_None), 193 type_(_OrthancPluginDatabaseAnswerType_None),
192 backend_(backend), 194 backend_(backend),
193 payload_(payload), 195 payload_(payload),
194 listener_(NULL), 196 listener_(NULL),
195 answerDicomMap_(NULL), 197 answerDicomMap_(NULL),
196 answerChanges_(NULL), 198 answerChanges_(NULL),
197 answerExportedResources_(NULL), 199 answerExportedResources_(NULL),
198 answerDone_(NULL) 200 answerDone_(NULL)
199 { 201 {
202 memset(&extensions_, 0, sizeof(extensions_));
203
204 size_t size = sizeof(extensions_);
205 if (extensionsSize < size)
206 {
207 size = extensionsSize; // Not all the extensions are available
208 }
209
210 memcpy(&extensions_, extensions, size);
200 } 211 }
201 212
202 213
203 void OrthancPluginDatabase::AddAttachment(int64_t id, 214 void OrthancPluginDatabase::AddAttachment(int64_t id,
204 const FileInfo& attachment) 215 const FileInfo& attachment)
329 void OrthancPluginDatabase::GetAllPublicIds(std::list<std::string>& target, 340 void OrthancPluginDatabase::GetAllPublicIds(std::list<std::string>& target,
330 ResourceType resourceType, 341 ResourceType resourceType,
331 size_t since, 342 size_t since,
332 size_t limit) 343 size_t limit)
333 { 344 {
334 // TODO add the corresponding primitives to the SDK 345 if (extensions_.getAllPublicIdsWithLimit != NULL)
335 346 {
336 target.clear(); 347 // This extension is available since Orthanc 0.9.4
337 348 ResetAnswers();
338 if (limit == 0) 349
339 { 350 if (extensions_.getAllPublicIdsWithLimit(GetContext(), payload_, Convert(resourceType), since, limit) != 0)
340 return; 351 {
341 } 352 throw OrthancException(ErrorCode_Plugin);
342 353 }
343 std::list<std::string> tmp; 354
344 GetAllPublicIds(tmp, resourceType); 355 ForwardAnswers(target);
356 }
357 else
358 {
359 // The extension is not available in the database plugin, use a
360 // fallback implementation
361 target.clear();
362
363 if (limit == 0)
364 {
365 return;
366 }
367
368 std::list<std::string> tmp;
369 GetAllPublicIds(tmp, resourceType);
345 370
346 if (tmp.size() <= since) 371 if (tmp.size() <= since)
347 { 372 {
348 // Not enough results => empty answer 373 // Not enough results => empty answer
349 return; 374 return;
350 } 375 }
351 376
352 std::list<std::string>::iterator current = tmp.begin(); 377 std::list<std::string>::iterator current = tmp.begin();
353 std::advance(current, since); 378 std::advance(current, since);
354 379
355 while (limit > 0 && current != tmp.end()) 380 while (limit > 0 && current != tmp.end())
356 { 381 {
357 target.push_back(*current); 382 target.push_back(*current);
358 --limit; 383 --limit;
359 ++current; 384 ++current;
385 }
360 } 386 }
361 } 387 }
362 388
363 389
364 390