Mercurial > hg > orthanc-databases
comparison Framework/Plugins/DatabaseBackendAdapterV4.cpp @ 569:f18e46d7dbf8 attach-custom-data
merged find-refactoring -> attach-custom-data
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 24 Sep 2024 15:04:21 +0200 |
parents | cd9521e04249 77c8544bbd7d |
children |
comparison
equal
deleted
inserted
replaced
368:82f73188b58d | 569:f18e46d7dbf8 |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
4 * Department, University Hospital of Liege, Belgium | 4 * Department, University Hospital of Liege, Belgium |
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium | 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium | |
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium | |
6 * | 8 * |
7 * This program is free software: you can redistribute it and/or | 9 * This program is free software: you can redistribute it and/or |
8 * modify it under the terms of the GNU Affero General Public License | 10 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | 11 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | 12 * the License, or (at your option) any later version. |
22 #include "DatabaseBackendAdapterV4.h" | 24 #include "DatabaseBackendAdapterV4.h" |
23 | 25 |
24 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 | 26 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
25 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) | 27 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) |
26 | 28 |
29 #include "IndexConnectionsPool.h" | |
30 #include "MessagesToolbox.h" | |
31 | |
32 #include <OrthancDatabasePlugin.pb.h> // Include protobuf messages | |
33 | |
27 #include <Logging.h> | 34 #include <Logging.h> |
28 #include <MultiThreading/SharedMessageQueue.h> | |
29 #include <OrthancException.h> | 35 #include <OrthancException.h> |
30 | 36 |
31 #include <stdexcept> | 37 #include <stdexcept> |
32 #include <list> | 38 #include <list> |
33 #include <string> | 39 #include <string> |
34 #include <cassert> | 40 #include <cassert> |
35 | 41 |
36 | 42 |
37 #define ORTHANC_PLUGINS_DATABASE_CATCH(context) \ | 43 #define ORTHANC_PLUGINS_DATABASE_CATCH(context) \ |
38 catch (::Orthanc::OrthancException& e) \ | |
39 { \ | |
40 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); \ | |
41 } \ | |
42 catch (::std::runtime_error& e) \ | |
43 { \ | |
44 const std::string message = "Exception in database back-end: " + std::string(e.what()); \ | |
45 OrthancPluginLogError(context, message.c_str()); \ | |
46 return OrthancPluginErrorCode_DatabasePlugin; \ | |
47 } \ | |
48 catch (...) \ | |
49 { \ | |
50 OrthancPluginLogError(context, "Native exception"); \ | |
51 return OrthancPluginErrorCode_DatabasePlugin; \ | |
52 } | |
53 | 44 |
54 | 45 |
55 namespace OrthancDatabases | 46 namespace OrthancDatabases |
56 { | 47 { |
57 static bool isBackendInUse_ = false; // Only for sanity checks | 48 static bool isBackendInUse_ = false; // Only for sanity checks |
58 | 49 |
59 | 50 |
60 template <typename T> | 51 static Orthanc::DatabasePluginMessages::ResourceType Convert(OrthancPluginResourceType resourceType) |
61 static void CopyListToVector(std::vector<T>& target, | |
62 const std::list<T>& source) | |
63 { | 52 { |
64 /** | 53 switch (resourceType) |
65 * This has the the same effect as: | 54 { |
66 * | 55 case OrthancPluginResourceType_Patient: |
67 * target.reserve(source.size()); | 56 return Orthanc::DatabasePluginMessages::RESOURCE_PATIENT; |
68 * std::copy(std::begin(source), std::end(source), std::back_inserter(target)); | 57 |
69 * | 58 case OrthancPluginResourceType_Study: |
70 * However, this implementation is compatible with C++03 (Linux | 59 return Orthanc::DatabasePluginMessages::RESOURCE_STUDY; |
71 * Standard Base), whereas "std::back_inserter" requires C++11. | 60 |
72 **/ | 61 case OrthancPluginResourceType_Series: |
73 | 62 return Orthanc::DatabasePluginMessages::RESOURCE_SERIES; |
74 target.clear(); | 63 |
75 target.reserve(source.size()); | 64 case OrthancPluginResourceType_Instance: |
76 | 65 return Orthanc::DatabasePluginMessages::RESOURCE_INSTANCE; |
77 for (typename std::list<T>::const_iterator it = source.begin(); it != source.end(); ++it) | 66 |
78 { | 67 default: |
79 target.push_back(*it); | 68 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
80 } | 69 } |
81 } | 70 } |
82 | 71 |
83 | 72 |
84 class DatabaseBackendAdapterV4::Adapter : public boost::noncopyable | 73 static OrthancPluginResourceType Convert(Orthanc::DatabasePluginMessages::ResourceType resourceType) |
74 { | |
75 switch (resourceType) | |
76 { | |
77 case Orthanc::DatabasePluginMessages::RESOURCE_PATIENT: | |
78 return OrthancPluginResourceType_Patient; | |
79 | |
80 case Orthanc::DatabasePluginMessages::RESOURCE_STUDY: | |
81 return OrthancPluginResourceType_Study; | |
82 | |
83 case Orthanc::DatabasePluginMessages::RESOURCE_SERIES: | |
84 return OrthancPluginResourceType_Series; | |
85 | |
86 case Orthanc::DatabasePluginMessages::RESOURCE_INSTANCE: | |
87 return OrthancPluginResourceType_Instance; | |
88 | |
89 default: | |
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
91 } | |
92 } | |
93 | |
94 | |
95 class Output : public IDatabaseBackendOutput | |
85 { | 96 { |
86 private: | 97 private: |
87 class ManagerReference : public Orthanc::IDynamicObject | 98 Orthanc::DatabasePluginMessages::DeleteAttachment::Response* deleteAttachment_; |
88 { | 99 Orthanc::DatabasePluginMessages::DeleteResource::Response* deleteResource_; |
89 private: | 100 Orthanc::DatabasePluginMessages::GetChanges::Response* getChanges_; |
90 DatabaseManager* manager_; | 101 Orthanc::DatabasePluginMessages::GetExportedResources::Response* getExportedResources_; |
91 | 102 Orthanc::DatabasePluginMessages::GetLastChange::Response* getLastChange_; |
92 public: | 103 Orthanc::DatabasePluginMessages::GetLastExportedResource::Response* getLastExportedResource_; |
93 ManagerReference(DatabaseManager& manager) : | 104 Orthanc::DatabasePluginMessages::GetMainDicomTags::Response* getMainDicomTags_; |
94 manager_(&manager) | 105 Orthanc::DatabasePluginMessages::LookupAttachment::Response* lookupAttachment_; |
95 { | 106 Orthanc::DatabasePluginMessages::LookupResources::Response* lookupResources_; |
96 } | 107 |
97 | 108 #if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1 |
98 DatabaseManager& GetManager() | 109 Orthanc::DatabasePluginMessages::GetChangesExtended::Response* getChangesExtended_; |
99 { | 110 #endif |
100 assert(manager_ != NULL); | 111 |
101 return *manager_; | 112 void Clear() |
102 } | 113 { |
103 }; | 114 deleteAttachment_ = NULL; |
104 | 115 deleteResource_ = NULL; |
105 std::unique_ptr<IndexBackend> backend_; | 116 getChanges_ = NULL; |
106 OrthancPluginContext* context_; | 117 getExportedResources_ = NULL; |
107 boost::shared_mutex connectionsMutex_; | 118 getLastChange_ = NULL; |
108 size_t countConnections_; | 119 getLastExportedResource_ = NULL; |
109 std::list<DatabaseManager*> connections_; | 120 getMainDicomTags_ = NULL; |
110 Orthanc::SharedMessageQueue availableConnections_; | 121 lookupAttachment_ = NULL; |
111 | 122 lookupResources_ = NULL; |
112 public: | 123 |
113 Adapter(IndexBackend* backend, | 124 #if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1 |
114 size_t countConnections) : | 125 getChangesExtended_ = NULL; |
115 backend_(backend), | 126 #endif |
116 countConnections_(countConnections) | |
117 { | |
118 if (countConnections == 0) | |
119 { | |
120 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, | |
121 "There must be a non-zero number of connections to the database"); | |
122 } | |
123 else if (backend == NULL) | |
124 { | |
125 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
126 } | |
127 else | |
128 { | |
129 context_ = backend_->GetContext(); | |
130 } | |
131 } | |
132 | |
133 ~Adapter() | |
134 { | |
135 for (std::list<DatabaseManager*>::iterator | |
136 it = connections_.begin(); it != connections_.end(); ++it) | |
137 { | |
138 assert(*it != NULL); | |
139 delete *it; | |
140 } | |
141 } | |
142 | |
143 OrthancPluginContext* GetContext() const | |
144 { | |
145 return context_; | |
146 } | |
147 | |
148 void OpenConnections() | |
149 { | |
150 boost::unique_lock<boost::shared_mutex> lock(connectionsMutex_); | |
151 | |
152 if (connections_.size() == 0) | |
153 { | |
154 assert(backend_.get() != NULL); | |
155 | |
156 { | |
157 std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend_->CreateDatabaseFactory())); | |
158 manager->GetDatabase(); // Make sure to open the database connection | |
159 | |
160 backend_->ConfigureDatabase(*manager); | |
161 connections_.push_back(manager.release()); | |
162 } | |
163 | |
164 for (size_t i = 1; i < countConnections_; i++) | |
165 { | |
166 connections_.push_back(new DatabaseManager(backend_->CreateDatabaseFactory())); | |
167 connections_.back()->GetDatabase(); // Make sure to open the database connection | |
168 } | |
169 | |
170 for (std::list<DatabaseManager*>::iterator | |
171 it = connections_.begin(); it != connections_.end(); ++it) | |
172 { | |
173 assert(*it != NULL); | |
174 availableConnections_.Enqueue(new ManagerReference(**it)); | |
175 } | |
176 } | |
177 else | |
178 { | |
179 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
180 } | |
181 } | |
182 | |
183 void CloseConnections() | |
184 { | |
185 boost::unique_lock<boost::shared_mutex> lock(connectionsMutex_); | |
186 | |
187 if (connections_.size() != countConnections_) | |
188 { | |
189 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
190 } | |
191 else if (availableConnections_.GetSize() != countConnections_) | |
192 { | |
193 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database, "Some connections are still in use, bug in the Orthanc core"); | |
194 } | |
195 else | |
196 { | |
197 for (std::list<DatabaseManager*>::iterator | |
198 it = connections_.begin(); it != connections_.end(); ++it) | |
199 { | |
200 assert(*it != NULL); | |
201 (*it)->Close(); | |
202 } | |
203 } | |
204 } | |
205 | |
206 class DatabaseAccessor : public boost::noncopyable | |
207 { | |
208 private: | |
209 boost::shared_lock<boost::shared_mutex> lock_; | |
210 Adapter& adapter_; | |
211 DatabaseManager* manager_; | |
212 | |
213 public: | |
214 DatabaseAccessor(Adapter& adapter) : | |
215 lock_(adapter.connectionsMutex_), | |
216 adapter_(adapter), | |
217 manager_(NULL) | |
218 { | |
219 for (;;) | |
220 { | |
221 std::unique_ptr<Orthanc::IDynamicObject> manager(adapter.availableConnections_.Dequeue(100)); | |
222 if (manager.get() != NULL) | |
223 { | |
224 manager_ = &dynamic_cast<ManagerReference&>(*manager).GetManager(); | |
225 return; | |
226 } | |
227 } | |
228 } | |
229 | |
230 ~DatabaseAccessor() | |
231 { | |
232 assert(manager_ != NULL); | |
233 adapter_.availableConnections_.Enqueue(new ManagerReference(*manager_)); | |
234 } | |
235 | |
236 IndexBackend& GetBackend() const | |
237 { | |
238 return *adapter_.backend_; | |
239 } | |
240 | |
241 DatabaseManager& GetManager() const | |
242 { | |
243 assert(manager_ != NULL); | |
244 return *manager_; | |
245 } | |
246 }; | |
247 }; | |
248 | |
249 | |
250 class DatabaseBackendAdapterV4::Output : public IDatabaseBackendOutput | |
251 { | |
252 private: | |
253 struct Metadata | |
254 { | |
255 int32_t metadata; | |
256 const char* value; | |
257 }; | |
258 | |
259 _OrthancPluginDatabaseAnswerType answerType_; | |
260 std::list<std::string> stringsStore_; | |
261 | |
262 std::vector<OrthancPluginAttachment2> attachments_; | |
263 std::vector<OrthancPluginChange> changes_; | |
264 std::vector<OrthancPluginDicomTag> tags_; | |
265 std::vector<OrthancPluginExportedResource> exported_; | |
266 std::vector<OrthancPluginDatabaseEvent2> events_; | |
267 std::vector<int32_t> integers32_; | |
268 std::vector<int64_t> integers64_; | |
269 std::vector<OrthancPluginMatchingResource> matches_; | |
270 std::vector<Metadata> metadata_; | |
271 std::vector<std::string> stringAnswers_; | |
272 | |
273 const char* StoreString(const std::string& s) | |
274 { | |
275 stringsStore_.push_back(s); | |
276 return stringsStore_.back().c_str(); | |
277 } | |
278 | |
279 void SetupAnswerType(_OrthancPluginDatabaseAnswerType type) | |
280 { | |
281 if (answerType_ == _OrthancPluginDatabaseAnswerType_None) | |
282 { | |
283 answerType_ = type; | |
284 } | |
285 else if (answerType_ != type) | |
286 { | |
287 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
288 } | |
289 } | 127 } |
290 | 128 |
291 public: | 129 public: |
292 Output() : | 130 Output(Orthanc::DatabasePluginMessages::DeleteAttachment::Response& deleteAttachment) |
293 answerType_(_OrthancPluginDatabaseAnswerType_None) | 131 { |
294 { | 132 Clear(); |
295 } | 133 deleteAttachment_ = &deleteAttachment; |
296 | 134 } |
297 void Clear() | |
298 { | |
299 // We don't systematically clear all the vectors, in order to | |
300 // avoid spending unnecessary time | |
301 | |
302 switch (answerType_) | |
303 { | |
304 case _OrthancPluginDatabaseAnswerType_None: | |
305 break; | |
306 | |
307 case _OrthancPluginDatabaseAnswerType_Attachment: | |
308 attachments_.clear(); | |
309 break; | |
310 | |
311 case _OrthancPluginDatabaseAnswerType_Change: | |
312 changes_.clear(); | |
313 break; | |
314 | |
315 case _OrthancPluginDatabaseAnswerType_DicomTag: | |
316 tags_.clear(); | |
317 break; | |
318 | |
319 case _OrthancPluginDatabaseAnswerType_ExportedResource: | |
320 exported_.clear(); | |
321 break; | |
322 | |
323 case _OrthancPluginDatabaseAnswerType_Int32: | |
324 integers32_.clear(); | |
325 break; | |
326 | |
327 case _OrthancPluginDatabaseAnswerType_Int64: | |
328 integers64_.clear(); | |
329 break; | |
330 | |
331 case _OrthancPluginDatabaseAnswerType_MatchingResource: | |
332 matches_.clear(); | |
333 break; | |
334 | |
335 case _OrthancPluginDatabaseAnswerType_Metadata: | |
336 metadata_.clear(); | |
337 break; | |
338 | |
339 case _OrthancPluginDatabaseAnswerType_String: | |
340 stringAnswers_.clear(); | |
341 break; | |
342 | |
343 default: | |
344 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
345 } | |
346 | |
347 answerType_ = _OrthancPluginDatabaseAnswerType_None; | |
348 stringsStore_.clear(); | |
349 events_.clear(); | |
350 | |
351 assert(attachments_.empty()); | |
352 assert(changes_.empty()); | |
353 assert(tags_.empty()); | |
354 assert(exported_.empty()); | |
355 assert(events_.empty()); | |
356 assert(integers32_.empty()); | |
357 assert(integers64_.empty()); | |
358 assert(matches_.empty()); | |
359 assert(metadata_.empty()); | |
360 assert(stringAnswers_.empty()); | |
361 } | |
362 | |
363 | |
364 OrthancPluginErrorCode ReadAnswersCount(uint32_t& target) const | |
365 { | |
366 switch (answerType_) | |
367 { | |
368 case _OrthancPluginDatabaseAnswerType_None: | |
369 target = static_cast<uint32_t>(0); | |
370 break; | |
371 | |
372 case _OrthancPluginDatabaseAnswerType_Attachment: | |
373 target = static_cast<uint32_t>(attachments_.size()); | |
374 break; | |
375 | |
376 case _OrthancPluginDatabaseAnswerType_Change: | |
377 target = static_cast<uint32_t>(changes_.size()); | |
378 break; | |
379 | |
380 case _OrthancPluginDatabaseAnswerType_DicomTag: | |
381 target = static_cast<uint32_t>(tags_.size()); | |
382 break; | |
383 | |
384 case _OrthancPluginDatabaseAnswerType_ExportedResource: | |
385 target = static_cast<uint32_t>(exported_.size()); | |
386 break; | |
387 | |
388 case _OrthancPluginDatabaseAnswerType_Int32: | |
389 target = static_cast<uint32_t>(integers32_.size()); | |
390 break; | |
391 | |
392 case _OrthancPluginDatabaseAnswerType_Int64: | |
393 target = static_cast<uint32_t>(integers64_.size()); | |
394 break; | |
395 | |
396 case _OrthancPluginDatabaseAnswerType_MatchingResource: | |
397 target = static_cast<uint32_t>(matches_.size()); | |
398 break; | |
399 | |
400 case _OrthancPluginDatabaseAnswerType_Metadata: | |
401 target = static_cast<uint32_t>(metadata_.size()); | |
402 break; | |
403 | |
404 case _OrthancPluginDatabaseAnswerType_String: | |
405 target = static_cast<uint32_t>(stringAnswers_.size()); | |
406 break; | |
407 | |
408 default: | |
409 return OrthancPluginErrorCode_InternalError; | |
410 } | |
411 | |
412 return OrthancPluginErrorCode_Success; | |
413 } | |
414 | |
415 | |
416 OrthancPluginErrorCode ReadAnswerAttachment2(OrthancPluginAttachment2& target /* out */, | |
417 uint32_t index) const | |
418 { | |
419 if (index < attachments_.size()) | |
420 { | |
421 target = attachments_[index]; | |
422 return OrthancPluginErrorCode_Success; | |
423 } | |
424 else | |
425 { | |
426 return OrthancPluginErrorCode_ParameterOutOfRange; | |
427 } | |
428 } | |
429 | |
430 | |
431 OrthancPluginErrorCode ReadAnswerChange(OrthancPluginChange& target /* out */, | |
432 uint32_t index) const | |
433 { | |
434 if (index < changes_.size()) | |
435 { | |
436 target = changes_[index]; | |
437 return OrthancPluginErrorCode_Success; | |
438 } | |
439 else | |
440 { | |
441 return OrthancPluginErrorCode_ParameterOutOfRange; | |
442 } | |
443 } | |
444 | |
445 | |
446 OrthancPluginErrorCode ReadAnswerDicomTag(uint16_t& group, | |
447 uint16_t& element, | |
448 const char*& value, | |
449 uint32_t index) const | |
450 { | |
451 if (index < tags_.size()) | |
452 { | |
453 const OrthancPluginDicomTag& tag = tags_[index]; | |
454 group = tag.group; | |
455 element = tag.element; | |
456 value = tag.value; | |
457 return OrthancPluginErrorCode_Success; | |
458 } | |
459 else | |
460 { | |
461 return OrthancPluginErrorCode_ParameterOutOfRange; | |
462 } | |
463 } | |
464 | |
465 | |
466 OrthancPluginErrorCode ReadAnswerExportedResource(OrthancPluginExportedResource& target /* out */, | |
467 uint32_t index) const | |
468 { | |
469 if (index < exported_.size()) | |
470 { | |
471 target = exported_[index]; | |
472 return OrthancPluginErrorCode_Success; | |
473 } | |
474 else | |
475 { | |
476 return OrthancPluginErrorCode_ParameterOutOfRange; | |
477 } | |
478 } | |
479 | |
480 | |
481 OrthancPluginErrorCode ReadAnswerInt32(int32_t& target, | |
482 uint32_t index) const | |
483 { | |
484 if (index < integers32_.size()) | |
485 { | |
486 target = integers32_[index]; | |
487 return OrthancPluginErrorCode_Success; | |
488 } | |
489 else | |
490 { | |
491 return OrthancPluginErrorCode_ParameterOutOfRange; | |
492 } | |
493 } | |
494 | |
495 | |
496 OrthancPluginErrorCode ReadAnswerInt64(int64_t& target, | |
497 uint32_t index) const | |
498 { | |
499 if (index < integers64_.size()) | |
500 { | |
501 target = integers64_[index]; | |
502 return OrthancPluginErrorCode_Success; | |
503 } | |
504 else | |
505 { | |
506 return OrthancPluginErrorCode_ParameterOutOfRange; | |
507 } | |
508 } | |
509 | |
510 | |
511 OrthancPluginErrorCode ReadAnswerMatchingResource(OrthancPluginMatchingResource& target, | |
512 uint32_t index) const | |
513 { | |
514 if (index < matches_.size()) | |
515 { | |
516 target = matches_[index]; | |
517 return OrthancPluginErrorCode_Success; | |
518 } | |
519 else | |
520 { | |
521 return OrthancPluginErrorCode_ParameterOutOfRange; | |
522 } | |
523 } | |
524 | |
525 | |
526 OrthancPluginErrorCode ReadAnswerMetadata(int32_t& metadata, | |
527 const char*& value, | |
528 uint32_t index) const | |
529 { | |
530 if (index < metadata_.size()) | |
531 { | |
532 const Metadata& tmp = metadata_[index]; | |
533 metadata = tmp.metadata; | |
534 value = tmp.value; | |
535 return OrthancPluginErrorCode_Success; | |
536 } | |
537 else | |
538 { | |
539 return OrthancPluginErrorCode_ParameterOutOfRange; | |
540 } | |
541 } | |
542 | |
543 | |
544 OrthancPluginErrorCode ReadAnswerString(const char*& target, | |
545 uint32_t index) const | |
546 { | |
547 if (index < stringAnswers_.size()) | |
548 { | |
549 target = stringAnswers_[index].c_str(); | |
550 return OrthancPluginErrorCode_Success; | |
551 } | |
552 else | |
553 { | |
554 return OrthancPluginErrorCode_ParameterOutOfRange; | |
555 } | |
556 } | |
557 | |
558 | |
559 OrthancPluginErrorCode ReadEventsCount(uint32_t& target /* out */) const | |
560 { | |
561 target = static_cast<uint32_t>(events_.size()); | |
562 return OrthancPluginErrorCode_Success; | |
563 } | |
564 | |
565 | 135 |
566 OrthancPluginErrorCode ReadEvent2(OrthancPluginDatabaseEvent2& event /* out */, | 136 Output(Orthanc::DatabasePluginMessages::DeleteResource::Response& deleteResource) |
567 uint32_t index) const | 137 { |
568 { | 138 Clear(); |
569 if (index < events_.size()) | 139 deleteResource_ = &deleteResource; |
570 { | 140 } |
571 event = events_[index]; | 141 |
572 return OrthancPluginErrorCode_Success; | 142 Output(Orthanc::DatabasePluginMessages::GetChanges::Response& getChanges) |
573 } | 143 { |
574 else | 144 Clear(); |
575 { | 145 getChanges_ = &getChanges; |
576 return OrthancPluginErrorCode_ParameterOutOfRange; | 146 } |
577 } | 147 |
578 } | 148 #if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1 |
579 | 149 Output(Orthanc::DatabasePluginMessages::GetChangesExtended::Response& getChangesExtended) |
580 | 150 { |
151 Clear(); | |
152 getChangesExtended_ = &getChangesExtended; | |
153 } | |
154 #endif | |
155 | |
156 Output(Orthanc::DatabasePluginMessages::GetExportedResources::Response& getExportedResources) | |
157 { | |
158 Clear(); | |
159 getExportedResources_ = &getExportedResources; | |
160 } | |
161 | |
162 Output(Orthanc::DatabasePluginMessages::GetLastChange::Response& getLastChange) | |
163 { | |
164 Clear(); | |
165 getLastChange_ = &getLastChange; | |
166 } | |
167 | |
168 Output(Orthanc::DatabasePluginMessages::GetLastExportedResource::Response& getLastExportedResource) | |
169 { | |
170 Clear(); | |
171 getLastExportedResource_ = &getLastExportedResource; | |
172 } | |
173 | |
174 Output(Orthanc::DatabasePluginMessages::GetMainDicomTags::Response& getMainDicomTags) | |
175 { | |
176 Clear(); | |
177 getMainDicomTags_ = &getMainDicomTags; | |
178 } | |
179 | |
180 Output(Orthanc::DatabasePluginMessages::LookupAttachment::Response& lookupAttachment) | |
181 { | |
182 Clear(); | |
183 lookupAttachment_ = &lookupAttachment; | |
184 } | |
185 | |
186 Output(Orthanc::DatabasePluginMessages::LookupResources::Response& lookupResources) | |
187 { | |
188 Clear(); | |
189 lookupResources_ = &lookupResources; | |
190 } | |
191 | |
581 virtual void SignalDeletedAttachment(const std::string& uuid, | 192 virtual void SignalDeletedAttachment(const std::string& uuid, |
582 int32_t contentType, | 193 int32_t contentType, |
583 uint64_t uncompressedSize, | 194 uint64_t uncompressedSize, |
584 const std::string& uncompressedHash, | 195 const std::string& uncompressedHash, |
585 int32_t compressionType, | 196 int32_t compressionType, |
586 uint64_t compressedSize, | 197 uint64_t compressedSize, |
587 const std::string& compressedHash, | 198 const std::string& compressedHash, |
588 const std::string& customData) ORTHANC_OVERRIDE | 199 const std::string& customData) ORTHANC_OVERRIDE |
589 { | 200 { |
590 OrthancPluginDatabaseEvent2 event; | 201 Orthanc::DatabasePluginMessages::FileInfo* attachment; |
591 event.type = OrthancPluginDatabaseEventType_DeletedAttachment; | 202 |
592 event.content.attachment.uuid = StoreString(uuid); | 203 if (deleteAttachment_ != NULL) |
593 event.content.attachment.contentType = contentType; | 204 { |
594 event.content.attachment.uncompressedSize = uncompressedSize; | 205 if (deleteAttachment_->has_deleted_attachment()) |
595 event.content.attachment.uncompressedHash = StoreString(uncompressedHash); | 206 { |
596 event.content.attachment.compressionType = compressionType; | 207 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
597 event.content.attachment.compressedSize = compressedSize; | 208 } |
598 event.content.attachment.compressedHash = StoreString(compressedHash); | 209 |
599 event.content.attachment.customData = StoreString(customData); | 210 attachment = deleteAttachment_->mutable_deleted_attachment(); |
600 | 211 } |
601 events_.push_back(event); | 212 else if (deleteResource_ != NULL) |
602 } | 213 { |
603 | 214 attachment = deleteResource_->add_deleted_attachments(); |
604 | 215 } |
216 else | |
217 { | |
218 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
219 } | |
220 | |
221 attachment->set_uuid(uuid); | |
222 attachment->set_content_type(contentType); | |
223 attachment->set_uncompressed_size(uncompressedSize); | |
224 attachment->set_uncompressed_hash(uncompressedHash); | |
225 attachment->set_compression_type(compressionType); | |
226 attachment->set_compressed_size(compressedSize); | |
227 attachment->set_compressed_hash(compressedHash); | |
228 } | |
229 | |
605 virtual void SignalDeletedResource(const std::string& publicId, | 230 virtual void SignalDeletedResource(const std::string& publicId, |
606 OrthancPluginResourceType resourceType) ORTHANC_OVERRIDE | 231 OrthancPluginResourceType resourceType) ORTHANC_OVERRIDE |
607 { | 232 { |
608 OrthancPluginDatabaseEvent2 event; | 233 if (deleteResource_ != NULL) |
609 event.type = OrthancPluginDatabaseEventType_DeletedResource; | 234 { |
610 event.content.resource.level = resourceType; | 235 Orthanc::DatabasePluginMessages::DeleteResource_Response_Resource* resource = deleteResource_->add_deleted_resources(); |
611 event.content.resource.publicId = StoreString(publicId); | 236 resource->set_level(Convert(resourceType)); |
612 | 237 resource->set_public_id(publicId); |
613 events_.push_back(event); | 238 } |
614 } | 239 else |
615 | 240 { |
241 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
242 } | |
243 } | |
616 | 244 |
617 virtual void SignalRemainingAncestor(const std::string& ancestorId, | 245 virtual void SignalRemainingAncestor(const std::string& ancestorId, |
618 OrthancPluginResourceType ancestorType) ORTHANC_OVERRIDE | 246 OrthancPluginResourceType ancestorType) ORTHANC_OVERRIDE |
619 { | 247 { |
620 OrthancPluginDatabaseEvent2 event; | 248 if (deleteResource_ != NULL) |
621 event.type = OrthancPluginDatabaseEventType_RemainingAncestor; | 249 { |
622 event.content.resource.level = ancestorType; | 250 if (deleteResource_->is_remaining_ancestor()) |
623 event.content.resource.publicId = StoreString(ancestorId); | 251 { |
624 | 252 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
625 events_.push_back(event); | 253 } |
626 } | 254 else |
627 | 255 { |
256 deleteResource_->set_is_remaining_ancestor(true); | |
257 deleteResource_->mutable_remaining_ancestor()->set_level(Convert(ancestorType)); | |
258 deleteResource_->mutable_remaining_ancestor()->set_public_id(ancestorId); | |
259 } | |
260 } | |
261 else | |
262 { | |
263 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
264 } | |
265 } | |
628 | 266 |
629 virtual void AnswerAttachment(const std::string& uuid, | 267 virtual void AnswerAttachment(const std::string& uuid, |
630 int32_t contentType, | 268 int32_t contentType, |
631 uint64_t uncompressedSize, | 269 uint64_t uncompressedSize, |
632 const std::string& uncompressedHash, | 270 const std::string& uncompressedHash, |
633 int32_t compressionType, | 271 int32_t compressionType, |
634 uint64_t compressedSize, | 272 uint64_t compressedSize, |
635 const std::string& compressedHash, | 273 const std::string& compressedHash, |
636 const std::string& customData) ORTHANC_OVERRIDE | 274 const std::string& customData) ORTHANC_OVERRIDE |
637 { | 275 { |
638 SetupAnswerType(_OrthancPluginDatabaseAnswerType_Attachment); | 276 if (lookupAttachment_ != NULL) |
639 | 277 { |
640 OrthancPluginAttachment2 attachment; | 278 if (lookupAttachment_->found()) |
641 attachment.uuid = StoreString(uuid); | 279 { |
642 attachment.contentType = contentType; | 280 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
643 attachment.uncompressedSize = uncompressedSize; | 281 } |
644 attachment.uncompressedHash = StoreString(uncompressedHash); | 282 |
645 attachment.compressionType = compressionType; | 283 lookupAttachment_->set_found(true); |
646 attachment.compressedSize = compressedSize; | 284 lookupAttachment_->mutable_attachment()->set_uuid(uuid); |
647 attachment.compressedHash = StoreString(compressedHash); | 285 lookupAttachment_->mutable_attachment()->set_content_type(contentType); |
648 attachment.customData = StoreString(customData); | 286 lookupAttachment_->mutable_attachment()->set_uncompressed_size(uncompressedSize); |
649 | 287 lookupAttachment_->mutable_attachment()->set_uncompressed_hash(uncompressedHash); |
650 attachments_.push_back(attachment); | 288 lookupAttachment_->mutable_attachment()->set_compression_type(compressionType); |
651 } | 289 lookupAttachment_->mutable_attachment()->set_compressed_size(compressedSize); |
652 | 290 lookupAttachment_->mutable_attachment()->set_compressed_hash(compressedHash); |
291 } | |
292 else | |
293 { | |
294 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
295 } | |
296 } | |
653 | 297 |
654 virtual void AnswerChange(int64_t seq, | 298 virtual void AnswerChange(int64_t seq, |
655 int32_t changeType, | 299 int32_t changeType, |
656 OrthancPluginResourceType resourceType, | 300 OrthancPluginResourceType resourceType, |
657 const std::string& publicId, | 301 const std::string& publicId, |
658 const std::string& date) ORTHANC_OVERRIDE | 302 const std::string& date) ORTHANC_OVERRIDE |
659 { | 303 { |
660 SetupAnswerType(_OrthancPluginDatabaseAnswerType_Change); | 304 Orthanc::DatabasePluginMessages::ServerIndexChange* change; |
661 | 305 |
662 OrthancPluginChange change; | 306 if (getChanges_ != NULL) |
663 change.seq = seq; | 307 { |
664 change.changeType = changeType; | 308 change = getChanges_->add_changes(); |
665 change.resourceType = resourceType; | 309 } |
666 change.publicId = StoreString(publicId); | 310 #if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1 |
667 change.date = StoreString(date); | 311 else if (getChangesExtended_ != NULL) |
668 | 312 { |
669 changes_.push_back(change); | 313 change = getChangesExtended_->add_changes(); |
670 } | 314 } |
671 | 315 #endif |
316 else if (getLastChange_ != NULL) | |
317 { | |
318 if (getLastChange_->found()) | |
319 { | |
320 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
321 } | |
322 | |
323 getLastChange_->set_found(true); | |
324 change = getLastChange_->mutable_change(); | |
325 } | |
326 else | |
327 { | |
328 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
329 } | |
330 | |
331 change->set_seq(seq); | |
332 change->set_change_type(changeType); | |
333 change->set_resource_type(Convert(resourceType)); | |
334 change->set_public_id(publicId); | |
335 change->set_date(date); | |
336 } | |
672 | 337 |
673 virtual void AnswerDicomTag(uint16_t group, | 338 virtual void AnswerDicomTag(uint16_t group, |
674 uint16_t element, | 339 uint16_t element, |
675 const std::string& value) ORTHANC_OVERRIDE | 340 const std::string& value) ORTHANC_OVERRIDE |
676 { | 341 { |
677 SetupAnswerType(_OrthancPluginDatabaseAnswerType_DicomTag); | 342 if (getMainDicomTags_ != NULL) |
678 | 343 { |
679 OrthancPluginDicomTag tag; | 344 Orthanc::DatabasePluginMessages::GetMainDicomTags_Response_Tag* tag = getMainDicomTags_->add_tags(); |
680 tag.group = group; | 345 tag->set_group(group); |
681 tag.element = element; | 346 tag->set_element(element); |
682 tag.value = StoreString(value); | 347 tag->set_value(value); |
683 | 348 } |
684 tags_.push_back(tag); | 349 else |
685 } | 350 { |
686 | 351 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
352 } | |
353 } | |
687 | 354 |
688 virtual void AnswerExportedResource(int64_t seq, | 355 virtual void AnswerExportedResource(int64_t seq, |
689 OrthancPluginResourceType resourceType, | 356 OrthancPluginResourceType resourceType, |
690 const std::string& publicId, | 357 const std::string& publicId, |
691 const std::string& modality, | 358 const std::string& modality, |
693 const std::string& patientId, | 360 const std::string& patientId, |
694 const std::string& studyInstanceUid, | 361 const std::string& studyInstanceUid, |
695 const std::string& seriesInstanceUid, | 362 const std::string& seriesInstanceUid, |
696 const std::string& sopInstanceUid) ORTHANC_OVERRIDE | 363 const std::string& sopInstanceUid) ORTHANC_OVERRIDE |
697 { | 364 { |
698 SetupAnswerType(_OrthancPluginDatabaseAnswerType_ExportedResource); | 365 Orthanc::DatabasePluginMessages::ExportedResource* resource; |
699 | 366 |
700 OrthancPluginExportedResource exported; | 367 if (getExportedResources_ != NULL) |
701 exported.seq = seq; | 368 { |
702 exported.resourceType = resourceType; | 369 resource = getExportedResources_->add_resources(); |
703 exported.publicId = StoreString(publicId); | 370 } |
704 exported.modality = StoreString(modality); | 371 else if (getLastExportedResource_ != NULL) |
705 exported.date = StoreString(date); | 372 { |
706 exported.patientId = StoreString(patientId); | 373 if (getLastExportedResource_->found()) |
707 exported.studyInstanceUid = StoreString(studyInstanceUid); | 374 { |
708 exported.seriesInstanceUid = StoreString(seriesInstanceUid); | 375 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
709 exported.sopInstanceUid = StoreString(sopInstanceUid); | 376 } |
710 | 377 |
711 exported_.push_back(exported); | 378 getLastExportedResource_->set_found(true); |
712 } | 379 resource = getLastExportedResource_->mutable_resource(); |
713 | 380 } |
381 else | |
382 { | |
383 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
384 } | |
385 | |
386 resource->set_seq(seq); | |
387 resource->set_resource_type(Convert(resourceType)); | |
388 resource->set_public_id(publicId); | |
389 resource->set_modality(modality); | |
390 resource->set_date(date); | |
391 resource->set_patient_id(patientId); | |
392 resource->set_study_instance_uid(studyInstanceUid); | |
393 resource->set_series_instance_uid(seriesInstanceUid); | |
394 resource->set_sop_instance_uid(sopInstanceUid); | |
395 } | |
714 | 396 |
715 virtual void AnswerMatchingResource(const std::string& resourceId) ORTHANC_OVERRIDE | 397 virtual void AnswerMatchingResource(const std::string& resourceId) ORTHANC_OVERRIDE |
716 { | 398 { |
717 SetupAnswerType(_OrthancPluginDatabaseAnswerType_MatchingResource); | 399 if (lookupResources_ != NULL) |
718 | 400 { |
719 OrthancPluginMatchingResource match; | 401 lookupResources_->add_resources_ids(resourceId); |
720 match.resourceId = StoreString(resourceId); | 402 } |
721 match.someInstanceId = NULL; | 403 else |
722 | 404 { |
723 matches_.push_back(match); | 405 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
724 } | 406 } |
725 | 407 } |
726 | 408 |
727 virtual void AnswerMatchingResource(const std::string& resourceId, | 409 virtual void AnswerMatchingResource(const std::string& resourceId, |
728 const std::string& someInstanceId) ORTHANC_OVERRIDE | 410 const std::string& someInstanceId) ORTHANC_OVERRIDE |
729 { | 411 { |
730 SetupAnswerType(_OrthancPluginDatabaseAnswerType_MatchingResource); | 412 if (lookupResources_ != NULL) |
731 | 413 { |
732 OrthancPluginMatchingResource match; | 414 lookupResources_->add_resources_ids(resourceId); |
733 match.resourceId = StoreString(resourceId); | 415 lookupResources_->add_instances_ids(someInstanceId); |
734 match.someInstanceId = StoreString(someInstanceId); | |
735 | |
736 matches_.push_back(match); | |
737 } | |
738 | |
739 | |
740 void AnswerIntegers32(const std::list<int32_t>& values) | |
741 { | |
742 SetupAnswerType(_OrthancPluginDatabaseAnswerType_Int32); | |
743 CopyListToVector(integers32_, values); | |
744 } | |
745 | |
746 | |
747 void AnswerIntegers64(const std::list<int64_t>& values) | |
748 { | |
749 SetupAnswerType(_OrthancPluginDatabaseAnswerType_Int64); | |
750 CopyListToVector(integers64_, values); | |
751 } | |
752 | |
753 | |
754 void AnswerInteger64(int64_t value) | |
755 { | |
756 SetupAnswerType(_OrthancPluginDatabaseAnswerType_Int64); | |
757 | |
758 integers64_.resize(1); | |
759 integers64_[0] = value; | |
760 } | |
761 | |
762 | |
763 void AnswerMetadata(int32_t metadata, | |
764 const std::string& value) | |
765 { | |
766 SetupAnswerType(_OrthancPluginDatabaseAnswerType_Metadata); | |
767 | |
768 Metadata tmp; | |
769 tmp.metadata = metadata; | |
770 tmp.value = StoreString(value); | |
771 | |
772 metadata_.push_back(tmp); | |
773 } | |
774 | |
775 | |
776 void AnswerStrings(const std::list<std::string>& values) | |
777 { | |
778 SetupAnswerType(_OrthancPluginDatabaseAnswerType_String); | |
779 CopyListToVector(stringAnswers_, values); | |
780 } | |
781 | |
782 | |
783 void AnswerString(const std::string& value) | |
784 { | |
785 SetupAnswerType(_OrthancPluginDatabaseAnswerType_String); | |
786 | |
787 if (stringAnswers_.empty()) | |
788 { | |
789 stringAnswers_.push_back(value); | |
790 } | 416 } |
791 else | 417 else |
792 { | 418 { |
793 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 419 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
794 } | 420 } |
795 } | 421 } |
796 }; | 422 }; |
797 | 423 |
798 | 424 |
799 IDatabaseBackendOutput* DatabaseBackendAdapterV4::Factory::CreateOutput() | 425 static void ProcessDatabaseOperation(Orthanc::DatabasePluginMessages::DatabaseResponse& response, |
426 const Orthanc::DatabasePluginMessages::DatabaseRequest& request, | |
427 IndexConnectionsPool& pool) | |
800 { | 428 { |
801 return new DatabaseBackendAdapterV4::Output; | 429 switch (request.operation()) |
430 { | |
431 case Orthanc::DatabasePluginMessages::OPERATION_GET_SYSTEM_INFORMATION: | |
432 { | |
433 IndexConnectionsPool::Accessor accessor(pool); | |
434 response.mutable_get_system_information()->set_database_version(accessor.GetBackend().GetDatabaseVersion(accessor.GetManager())); | |
435 response.mutable_get_system_information()->set_supports_flush_to_disk(false); | |
436 response.mutable_get_system_information()->set_supports_revisions(accessor.GetBackend().HasRevisionsSupport()); | |
437 response.mutable_get_system_information()->set_supports_labels(accessor.GetBackend().HasLabelsSupport()); | |
438 | |
439 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 3) | |
440 response.mutable_get_system_information()->set_supports_increment_global_property(accessor.GetBackend().HasAtomicIncrementGlobalProperty()); | |
441 response.mutable_get_system_information()->set_has_update_and_get_statistics(accessor.GetBackend().HasUpdateAndGetStatistics()); | |
442 response.mutable_get_system_information()->set_has_measure_latency(accessor.GetBackend().HasMeasureLatency()); | |
443 #endif | |
444 | |
445 #if ORTHANC_PLUGINS_HAS_INTEGRATED_FIND == 1 | |
446 response.mutable_get_system_information()->set_supports_find(accessor.GetBackend().HasFindSupport()); | |
447 response.mutable_get_system_information()->set_has_extended_changes(accessor.GetBackend().HasExtendedChanges()); | |
448 #endif | |
449 | |
450 break; | |
451 } | |
452 | |
453 case Orthanc::DatabasePluginMessages::OPERATION_OPEN: | |
454 { | |
455 std::list<IdentifierTag> identifierTags; | |
456 | |
457 if (request.open().identifier_tags().empty()) | |
458 { | |
459 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | |
460 "No identifier tag was provided by the Orthanc core"); | |
461 } | |
462 | |
463 for (int i = 0; i < request.open().identifier_tags().size(); i++) | |
464 { | |
465 const Orthanc::DatabasePluginMessages::Open_Request_IdentifierTag& tag = request.open().identifier_tags(i); | |
466 identifierTags.push_back(IdentifierTag(MessagesToolbox::Convert(tag.level()), | |
467 Orthanc::DicomTag(tag.group(), tag.element()), | |
468 tag.name())); | |
469 } | |
470 | |
471 pool.OpenConnections(true, identifierTags); | |
472 | |
473 break; | |
474 } | |
475 | |
476 case Orthanc::DatabasePluginMessages::OPERATION_CLOSE: | |
477 { | |
478 pool.CloseConnections(); | |
479 break; | |
480 } | |
481 | |
482 case Orthanc::DatabasePluginMessages::OPERATION_FLUSH_TO_DISK: | |
483 { | |
484 // Raise an exception since "set_supports_flush_to_disk(false)" | |
485 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
486 } | |
487 | |
488 case Orthanc::DatabasePluginMessages::OPERATION_START_TRANSACTION: | |
489 { | |
490 std::unique_ptr<IndexConnectionsPool::Accessor> transaction(new IndexConnectionsPool::Accessor(pool)); | |
491 | |
492 switch (request.start_transaction().type()) | |
493 { | |
494 case Orthanc::DatabasePluginMessages::TRANSACTION_READ_ONLY: | |
495 transaction->GetManager().StartTransaction(TransactionType_ReadOnly); | |
496 break; | |
497 | |
498 case Orthanc::DatabasePluginMessages::TRANSACTION_READ_WRITE: | |
499 transaction->GetManager().StartTransaction(TransactionType_ReadWrite); | |
500 break; | |
501 | |
502 default: | |
503 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
504 } | |
505 | |
506 response.mutable_start_transaction()->set_transaction(reinterpret_cast<intptr_t>(transaction.release())); | |
507 break; | |
508 } | |
509 | |
510 case Orthanc::DatabasePluginMessages::OPERATION_UPGRADE: | |
511 { | |
512 IndexConnectionsPool::Accessor accessor(pool); | |
513 OrthancPluginStorageArea* storageArea = reinterpret_cast<OrthancPluginStorageArea*>(request.upgrade().storage_area()); | |
514 accessor.GetBackend().UpgradeDatabase(accessor.GetManager(), request.upgrade().target_version(), storageArea); | |
515 break; | |
516 } | |
517 | |
518 case Orthanc::DatabasePluginMessages::OPERATION_FINALIZE_TRANSACTION: | |
519 { | |
520 IndexConnectionsPool::Accessor* transaction = reinterpret_cast<IndexConnectionsPool::Accessor*>(request.finalize_transaction().transaction()); | |
521 | |
522 if (transaction == NULL) | |
523 { | |
524 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
525 } | |
526 else | |
527 { | |
528 delete transaction; | |
529 } | |
530 | |
531 break; | |
532 } | |
533 | |
534 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 3) | |
535 case Orthanc::DatabasePluginMessages::OPERATION_MEASURE_LATENCY: | |
536 { | |
537 IndexConnectionsPool::Accessor accessor(pool); | |
538 response.mutable_measure_latency()->set_latency_us(accessor.GetBackend().MeasureLatency(accessor.GetManager())); | |
539 break; | |
540 } | |
541 #endif | |
542 | |
543 default: | |
544 LOG(ERROR) << "Not implemented database operation from protobuf: " << request.operation(); | |
545 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
546 } | |
802 } | 547 } |
803 | 548 |
804 | 549 |
805 class DatabaseBackendAdapterV4::Transaction : public boost::noncopyable | 550 static void ApplyLookupResources(Orthanc::DatabasePluginMessages::LookupResources_Response& response, |
551 const Orthanc::DatabasePluginMessages::LookupResources_Request& request, | |
552 IndexBackend& backend, | |
553 DatabaseManager& manager) | |
806 { | 554 { |
807 private: | 555 size_t countValues = 0; |
808 Adapter& adapter_; | 556 |
809 std::unique_ptr<Adapter::DatabaseAccessor> accessor_; | 557 for (int i = 0; i < request.lookup().size(); i++) |
810 std::unique_ptr<Output> output_; | 558 { |
811 | 559 const Orthanc::DatabasePluginMessages::DatabaseConstraint& constraint = request.lookup(i); |
812 public: | 560 countValues += constraint.values().size(); |
813 Transaction(Adapter& adapter) : | 561 } |
814 adapter_(adapter), | 562 |
815 accessor_(new Adapter::DatabaseAccessor(adapter)), | 563 std::vector<const char*> values; |
816 output_(new Output) | 564 values.reserve(countValues); |
817 { | 565 |
818 } | 566 DatabaseConstraints lookup; |
819 | 567 |
820 ~Transaction() | 568 for (int i = 0; i < request.lookup().size(); i++) |
821 { | 569 { |
822 } | 570 const Orthanc::DatabasePluginMessages::DatabaseConstraint& constraint = request.lookup(i); |
823 | 571 |
824 IndexBackend& GetBackend() const | 572 if (constraint.tag_group() > 0xffffu || |
825 { | 573 constraint.tag_element() > 0xffffu) |
826 return accessor_->GetBackend(); | 574 { |
827 } | 575 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
828 | 576 } |
829 Output& GetOutput() const | 577 |
830 { | 578 OrthancPluginDatabaseConstraint c; |
831 return *output_; | 579 c.level = Convert(constraint.level()); |
832 } | 580 c.tagGroup = constraint.tag_group(); |
833 | 581 c.tagElement = constraint.tag_element(); |
834 DatabaseManager& GetManager() const | 582 c.isIdentifierTag = (constraint.is_identifier_tag() ? 1 : 0); |
835 { | 583 c.isCaseSensitive = (constraint.is_case_sensitive() ? 1 : 0); |
836 return accessor_->GetManager(); | 584 c.isMandatory = (constraint.is_mandatory() ? 1 : 0); |
837 } | 585 |
838 }; | 586 switch (constraint.type()) |
839 | 587 { |
840 | 588 case Orthanc::DatabasePluginMessages::CONSTRAINT_EQUAL: |
841 static OrthancPluginErrorCode ReadAnswersCount(OrthancPluginDatabaseTransaction* transaction, | 589 c.type = OrthancPluginConstraintType_Equal; |
842 uint32_t* target /* out */) | |
843 { | |
844 assert(target != NULL); | |
845 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
846 return that.GetOutput().ReadAnswersCount(*target); | |
847 } | |
848 | |
849 | |
850 static OrthancPluginErrorCode ReadAnswerAttachment2(OrthancPluginDatabaseTransaction* transaction, | |
851 OrthancPluginAttachment2* target /* out */, | |
852 uint32_t index) | |
853 { | |
854 assert(target != NULL); | |
855 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
856 return that.GetOutput().ReadAnswerAttachment2(*target, index); | |
857 } | |
858 | |
859 | |
860 static OrthancPluginErrorCode ReadAnswerChange(OrthancPluginDatabaseTransaction* transaction, | |
861 OrthancPluginChange* target /* out */, | |
862 uint32_t index) | |
863 { | |
864 assert(target != NULL); | |
865 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
866 return that.GetOutput().ReadAnswerChange(*target, index); | |
867 } | |
868 | |
869 | |
870 static OrthancPluginErrorCode ReadAnswerDicomTag(OrthancPluginDatabaseTransaction* transaction, | |
871 uint16_t* group, | |
872 uint16_t* element, | |
873 const char** value, | |
874 uint32_t index) | |
875 { | |
876 assert(group != NULL); | |
877 assert(element != NULL); | |
878 assert(value != NULL); | |
879 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
880 return that.GetOutput().ReadAnswerDicomTag(*group, *element, *value, index); | |
881 } | |
882 | |
883 | |
884 static OrthancPluginErrorCode ReadAnswerExportedResource(OrthancPluginDatabaseTransaction* transaction, | |
885 OrthancPluginExportedResource* target /* out */, | |
886 uint32_t index) | |
887 { | |
888 assert(target != NULL); | |
889 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
890 return that.GetOutput().ReadAnswerExportedResource(*target, index); | |
891 } | |
892 | |
893 | |
894 static OrthancPluginErrorCode ReadAnswerInt32(OrthancPluginDatabaseTransaction* transaction, | |
895 int32_t* target, | |
896 uint32_t index) | |
897 { | |
898 assert(target != NULL); | |
899 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
900 return that.GetOutput().ReadAnswerInt32(*target, index); | |
901 } | |
902 | |
903 | |
904 static OrthancPluginErrorCode ReadAnswerInt64(OrthancPluginDatabaseTransaction* transaction, | |
905 int64_t* target, | |
906 uint32_t index) | |
907 { | |
908 assert(target != NULL); | |
909 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
910 return that.GetOutput().ReadAnswerInt64(*target, index); | |
911 } | |
912 | |
913 | |
914 static OrthancPluginErrorCode ReadAnswerMatchingResource(OrthancPluginDatabaseTransaction* transaction, | |
915 OrthancPluginMatchingResource* target, | |
916 uint32_t index) | |
917 { | |
918 assert(target != NULL); | |
919 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
920 return that.GetOutput().ReadAnswerMatchingResource(*target, index); | |
921 } | |
922 | |
923 | |
924 static OrthancPluginErrorCode ReadAnswerMetadata(OrthancPluginDatabaseTransaction* transaction, | |
925 int32_t* metadata, | |
926 const char** value, | |
927 uint32_t index) | |
928 { | |
929 assert(metadata != NULL); | |
930 assert(value != NULL); | |
931 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
932 return that.GetOutput().ReadAnswerMetadata(*metadata, *value, index); | |
933 } | |
934 | |
935 | |
936 static OrthancPluginErrorCode ReadAnswerString(OrthancPluginDatabaseTransaction* transaction, | |
937 const char** target, | |
938 uint32_t index) | |
939 { | |
940 assert(target != NULL); | |
941 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
942 return that.GetOutput().ReadAnswerString(*target, index); | |
943 } | |
944 | |
945 | |
946 static OrthancPluginErrorCode ReadEventsCount(OrthancPluginDatabaseTransaction* transaction, | |
947 uint32_t* target /* out */) | |
948 { | |
949 assert(target != NULL); | |
950 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
951 return that.GetOutput().ReadEventsCount(*target); | |
952 } | |
953 | |
954 | |
955 static OrthancPluginErrorCode ReadEvent2(OrthancPluginDatabaseTransaction* transaction, | |
956 OrthancPluginDatabaseEvent2* event /* out */, | |
957 uint32_t index) | |
958 { | |
959 assert(event != NULL); | |
960 const DatabaseBackendAdapterV4::Transaction& that = *reinterpret_cast<const DatabaseBackendAdapterV4::Transaction*>(transaction); | |
961 return that.GetOutput().ReadEvent2(*event, index); | |
962 } | |
963 | |
964 | |
965 static OrthancPluginErrorCode Open(void* database) | |
966 { | |
967 DatabaseBackendAdapterV4::Adapter* adapter = reinterpret_cast<DatabaseBackendAdapterV4::Adapter*>(database); | |
968 | |
969 try | |
970 { | |
971 adapter->OpenConnections(); | |
972 return OrthancPluginErrorCode_Success; | |
973 } | |
974 ORTHANC_PLUGINS_DATABASE_CATCH(adapter->GetContext()); | |
975 } | |
976 | |
977 | |
978 static OrthancPluginErrorCode Close(void* database) | |
979 { | |
980 DatabaseBackendAdapterV4::Adapter* adapter = reinterpret_cast<DatabaseBackendAdapterV4::Adapter*>(database); | |
981 | |
982 try | |
983 { | |
984 adapter->CloseConnections(); | |
985 return OrthancPluginErrorCode_Success; | |
986 } | |
987 ORTHANC_PLUGINS_DATABASE_CATCH(adapter->GetContext()); | |
988 } | |
989 | |
990 | |
991 static OrthancPluginErrorCode DestructDatabase(void* database) | |
992 { | |
993 DatabaseBackendAdapterV4::Adapter* adapter = reinterpret_cast<DatabaseBackendAdapterV4::Adapter*>(database); | |
994 | |
995 if (adapter == NULL) | |
996 { | |
997 return OrthancPluginErrorCode_InternalError; | |
998 } | |
999 else | |
1000 { | |
1001 if (isBackendInUse_) | |
1002 { | |
1003 isBackendInUse_ = false; | |
1004 } | |
1005 else | |
1006 { | |
1007 OrthancPluginLogError(adapter->GetContext(), "More than one index backend was registered, internal error"); | |
1008 } | |
1009 | |
1010 delete adapter; | |
1011 | |
1012 return OrthancPluginErrorCode_Success; | |
1013 } | |
1014 } | |
1015 | |
1016 | |
1017 static OrthancPluginErrorCode GetDatabaseVersion(void* database, | |
1018 uint32_t* version) | |
1019 { | |
1020 DatabaseBackendAdapterV4::Adapter* adapter = reinterpret_cast<DatabaseBackendAdapterV4::Adapter*>(database); | |
1021 | |
1022 try | |
1023 { | |
1024 DatabaseBackendAdapterV4::Adapter::DatabaseAccessor accessor(*adapter); | |
1025 *version = accessor.GetBackend().GetDatabaseVersion(accessor.GetManager()); | |
1026 return OrthancPluginErrorCode_Success; | |
1027 } | |
1028 ORTHANC_PLUGINS_DATABASE_CATCH(adapter->GetContext()); | |
1029 } | |
1030 | |
1031 | |
1032 static OrthancPluginErrorCode UpgradeDatabase(void* database, | |
1033 OrthancPluginStorageArea* storageArea, | |
1034 uint32_t targetVersion) | |
1035 { | |
1036 DatabaseBackendAdapterV4::Adapter* adapter = reinterpret_cast<DatabaseBackendAdapterV4::Adapter*>(database); | |
1037 | |
1038 try | |
1039 { | |
1040 DatabaseBackendAdapterV4::Adapter::DatabaseAccessor accessor(*adapter); | |
1041 accessor.GetBackend().UpgradeDatabase(accessor.GetManager(), targetVersion, storageArea); | |
1042 return OrthancPluginErrorCode_Success; | |
1043 } | |
1044 ORTHANC_PLUGINS_DATABASE_CATCH(adapter->GetContext()); | |
1045 } | |
1046 | |
1047 | |
1048 static OrthancPluginErrorCode HasRevisionsSupport(void* database, | |
1049 uint8_t* target) | |
1050 { | |
1051 DatabaseBackendAdapterV4::Adapter* adapter = reinterpret_cast<DatabaseBackendAdapterV4::Adapter*>(database); | |
1052 | |
1053 try | |
1054 { | |
1055 DatabaseBackendAdapterV4::Adapter::DatabaseAccessor accessor(*adapter); | |
1056 *target = (accessor.GetBackend().HasRevisionsSupport() ? 1 : 0); | |
1057 return OrthancPluginErrorCode_Success; | |
1058 } | |
1059 ORTHANC_PLUGINS_DATABASE_CATCH(adapter->GetContext()); | |
1060 } | |
1061 | |
1062 | |
1063 static OrthancPluginErrorCode HasAttachmentCustomDataSupport(void* database, | |
1064 uint8_t* target) | |
1065 { | |
1066 DatabaseBackendAdapterV4::Adapter* adapter = reinterpret_cast<DatabaseBackendAdapterV4::Adapter*>(database); | |
1067 | |
1068 try | |
1069 { | |
1070 DatabaseBackendAdapterV4::Adapter::DatabaseAccessor accessor(*adapter); | |
1071 *target = (accessor.GetBackend().HasAttachmentCustomDataSupport() ? 1 : 0); | |
1072 return OrthancPluginErrorCode_Success; | |
1073 } | |
1074 ORTHANC_PLUGINS_DATABASE_CATCH(adapter->GetContext()); | |
1075 } | |
1076 | |
1077 static OrthancPluginErrorCode StartTransaction(void* database, | |
1078 OrthancPluginDatabaseTransaction** target /* out */, | |
1079 OrthancPluginDatabaseTransactionType type) | |
1080 { | |
1081 DatabaseBackendAdapterV4::Adapter* adapter = reinterpret_cast<DatabaseBackendAdapterV4::Adapter*>(database); | |
1082 | |
1083 try | |
1084 { | |
1085 std::unique_ptr<DatabaseBackendAdapterV4::Transaction> transaction(new DatabaseBackendAdapterV4::Transaction(*adapter)); | |
1086 | |
1087 switch (type) | |
1088 { | |
1089 case OrthancPluginDatabaseTransactionType_ReadOnly: | |
1090 transaction->GetManager().StartTransaction(TransactionType_ReadOnly); | |
1091 break; | 590 break; |
1092 | 591 |
1093 case OrthancPluginDatabaseTransactionType_ReadWrite: | 592 case Orthanc::DatabasePluginMessages::CONSTRAINT_SMALLER_OR_EQUAL: |
1094 transaction->GetManager().StartTransaction(TransactionType_ReadWrite); | 593 c.type = OrthancPluginConstraintType_SmallerOrEqual; |
1095 break; | 594 break; |
1096 | 595 |
596 case Orthanc::DatabasePluginMessages::CONSTRAINT_GREATER_OR_EQUAL: | |
597 c.type = OrthancPluginConstraintType_GreaterOrEqual; | |
598 break; | |
599 | |
600 case Orthanc::DatabasePluginMessages::CONSTRAINT_WILDCARD: | |
601 c.type = OrthancPluginConstraintType_Wildcard; | |
602 break; | |
603 | |
604 case Orthanc::DatabasePluginMessages::CONSTRAINT_LIST: | |
605 c.type = OrthancPluginConstraintType_List; | |
606 break; | |
607 | |
1097 default: | 608 default: |
1098 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | 609 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
1099 } | 610 } |
1100 | 611 |
1101 *target = reinterpret_cast<OrthancPluginDatabaseTransaction*>(transaction.release()); | 612 c.valuesCount = constraint.values().size(); |
1102 | 613 |
614 if (c.valuesCount == 0) | |
615 { | |
616 c.values = NULL; | |
617 } | |
618 else | |
619 { | |
620 c.values = &values[values.size()]; | |
621 | |
622 for (int j = 0; j < constraint.values().size(); j++) | |
623 { | |
624 assert(values.size() < countValues); | |
625 values.push_back(constraint.values(j).c_str()); | |
626 } | |
627 } | |
628 | |
629 lookup.AddConstraint(new DatabaseConstraint(c)); | |
630 } | |
631 | |
632 assert(values.size() == countValues); | |
633 | |
634 std::set<std::string> labels; | |
635 | |
636 for (int i = 0; i < request.labels().size(); i++) | |
637 { | |
638 labels.insert(request.labels(i)); | |
639 } | |
640 | |
641 LabelsConstraint labelsConstraint; | |
642 switch (request.labels_constraint()) | |
643 { | |
644 case Orthanc::DatabasePluginMessages::LABELS_CONSTRAINT_ALL: | |
645 labelsConstraint = LabelsConstraint_All; | |
646 break; | |
647 | |
648 case Orthanc::DatabasePluginMessages::LABELS_CONSTRAINT_ANY: | |
649 labelsConstraint = LabelsConstraint_Any; | |
650 break; | |
651 | |
652 case Orthanc::DatabasePluginMessages::LABELS_CONSTRAINT_NONE: | |
653 labelsConstraint = LabelsConstraint_None; | |
654 break; | |
655 | |
656 default: | |
657 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
658 } | |
659 | |
660 Output output(response); | |
661 backend.LookupResources(output, manager, lookup, Convert(request.query_level()), | |
662 labels, labelsConstraint, request.limit(), request.retrieve_instances_ids()); | |
663 } | |
664 | |
665 | |
666 static void ProcessTransactionOperation(Orthanc::DatabasePluginMessages::TransactionResponse& response, | |
667 const Orthanc::DatabasePluginMessages::TransactionRequest& request, | |
668 IndexBackend& backend, | |
669 DatabaseManager& manager) | |
670 { | |
671 switch (request.operation()) | |
672 { | |
673 case Orthanc::DatabasePluginMessages::OPERATION_ROLLBACK: | |
674 { | |
675 manager.RollbackTransaction(); | |
676 break; | |
677 } | |
678 | |
679 case Orthanc::DatabasePluginMessages::OPERATION_COMMIT: | |
680 { | |
681 manager.CommitTransaction(); | |
682 break; | |
683 } | |
684 | |
685 case Orthanc::DatabasePluginMessages::OPERATION_ADD_ATTACHMENT: | |
686 { | |
687 OrthancPluginAttachment attachment; | |
688 attachment.uuid = request.add_attachment().attachment().uuid().c_str(); | |
689 attachment.contentType = request.add_attachment().attachment().content_type(); | |
690 attachment.uncompressedSize = request.add_attachment().attachment().uncompressed_size(); | |
691 attachment.uncompressedHash = request.add_attachment().attachment().uncompressed_hash().c_str(); | |
692 attachment.compressionType = request.add_attachment().attachment().compression_type(); | |
693 attachment.compressedSize = request.add_attachment().attachment().compressed_size(); | |
694 attachment.compressedHash = request.add_attachment().attachment().compressed_hash().c_str(); | |
695 | |
696 backend.AddAttachment(manager, request.add_attachment().id(), attachment, request.add_attachment().revision()); | |
697 break; | |
698 } | |
699 | |
700 case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_CHANGES: | |
701 { | |
702 backend.ClearChanges(manager); | |
703 break; | |
704 } | |
705 | |
706 case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_EXPORTED_RESOURCES: | |
707 { | |
708 backend.ClearExportedResources(manager); | |
709 break; | |
710 } | |
711 | |
712 case Orthanc::DatabasePluginMessages::OPERATION_DELETE_ATTACHMENT: | |
713 { | |
714 Output output(*response.mutable_delete_attachment()); | |
715 backend.DeleteAttachment(output, manager, request.delete_attachment().id(), request.delete_attachment().type()); | |
716 break; | |
717 } | |
718 | |
719 case Orthanc::DatabasePluginMessages::OPERATION_DELETE_METADATA: | |
720 { | |
721 backend.DeleteMetadata(manager, request.delete_metadata().id(), request.delete_metadata().type()); | |
722 break; | |
723 } | |
724 | |
725 case Orthanc::DatabasePluginMessages::OPERATION_DELETE_RESOURCE: | |
726 { | |
727 response.mutable_delete_resource()->set_is_remaining_ancestor(false); | |
728 | |
729 Output output(*response.mutable_delete_resource()); | |
730 backend.DeleteResource(output, manager, request.delete_resource().id()); | |
731 break; | |
732 } | |
733 | |
734 case Orthanc::DatabasePluginMessages::OPERATION_GET_ALL_METADATA: | |
735 { | |
736 typedef std::map<int32_t, std::string> Values; | |
737 | |
738 Values values; | |
739 backend.GetAllMetadata(values, manager, request.get_all_metadata().id()); | |
740 | |
741 response.mutable_get_all_metadata()->mutable_metadata()->Reserve(values.size()); | |
742 for (Values::const_iterator it = values.begin(); it != values.end(); ++it) | |
743 { | |
744 Orthanc::DatabasePluginMessages::GetAllMetadata_Response_Metadata* metadata = | |
745 response.mutable_get_all_metadata()->add_metadata(); | |
746 metadata->set_type(it->first); | |
747 metadata->set_value(it->second); | |
748 } | |
749 | |
750 break; | |
751 } | |
752 | |
753 case Orthanc::DatabasePluginMessages::OPERATION_GET_ALL_PUBLIC_IDS: | |
754 { | |
755 std::list<std::string> values; | |
756 backend.GetAllPublicIds(values, manager, Convert(request.get_all_public_ids().resource_type())); | |
757 | |
758 response.mutable_get_all_public_ids()->mutable_ids()->Reserve(values.size()); | |
759 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) | |
760 { | |
761 response.mutable_get_all_public_ids()->add_ids(*it); | |
762 } | |
763 | |
764 break; | |
765 } | |
766 | |
767 case Orthanc::DatabasePluginMessages::OPERATION_GET_ALL_PUBLIC_IDS_WITH_LIMITS: | |
768 { | |
769 std::list<std::string> values; | |
770 backend.GetAllPublicIds(values, manager, Convert(request.get_all_public_ids_with_limits().resource_type()), | |
771 request.get_all_public_ids_with_limits().since(), | |
772 request.get_all_public_ids_with_limits().limit()); | |
773 | |
774 response.mutable_get_all_public_ids_with_limits()->mutable_ids()->Reserve(values.size()); | |
775 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) | |
776 { | |
777 response.mutable_get_all_public_ids_with_limits()->add_ids(*it); | |
778 } | |
779 | |
780 break; | |
781 } | |
782 | |
783 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHANGES: | |
784 { | |
785 Output output(*response.mutable_get_changes()); | |
786 | |
787 bool done; | |
788 backend.GetChanges(output, done, manager, request.get_changes().since(), request.get_changes().limit()); | |
789 | |
790 response.mutable_get_changes()->set_done(done); | |
791 break; | |
792 } | |
793 #if ORTHANC_PLUGINS_HAS_CHANGES_EXTENDED == 1 | |
794 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHANGES_EXTENDED: | |
795 { | |
796 Output output(*response.mutable_get_changes_extended()); | |
797 | |
798 bool done; | |
799 std::set<uint32_t> changeTypes; | |
800 for (int i = 0; i < request.get_changes_extended().change_type_size(); ++i) | |
801 { | |
802 changeTypes.insert(request.get_changes_extended().change_type(i)); | |
803 } | |
804 | |
805 backend.GetChangesExtended(output, done, manager, request.get_changes_extended().since(), request.get_changes_extended().to(), changeTypes, request.get_changes_extended().limit()); | |
806 | |
807 response.mutable_get_changes_extended()->set_done(done); | |
808 break; | |
809 } | |
810 #endif | |
811 | |
812 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHILDREN_INTERNAL_ID: | |
813 { | |
814 std::list<int64_t> values; | |
815 backend.GetChildrenInternalId(values, manager, request.get_children_internal_id().id()); | |
816 | |
817 response.mutable_get_children_internal_id()->mutable_ids()->Reserve(values.size()); | |
818 for (std::list<int64_t>::const_iterator it = values.begin(); it != values.end(); ++it) | |
819 { | |
820 response.mutable_get_children_internal_id()->add_ids(*it); | |
821 } | |
822 | |
823 break; | |
824 } | |
825 | |
826 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHILDREN_PUBLIC_ID: | |
827 { | |
828 std::list<std::string> values; | |
829 backend.GetChildrenPublicId(values, manager, request.get_children_public_id().id()); | |
830 | |
831 response.mutable_get_children_public_id()->mutable_ids()->Reserve(values.size()); | |
832 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) | |
833 { | |
834 response.mutable_get_children_public_id()->add_ids(*it); | |
835 } | |
836 | |
837 break; | |
838 } | |
839 | |
840 case Orthanc::DatabasePluginMessages::OPERATION_GET_EXPORTED_RESOURCES: | |
841 { | |
842 Output output(*response.mutable_get_exported_resources()); | |
843 | |
844 bool done; | |
845 backend.GetExportedResources(output, done, manager, request.get_exported_resources().since(), | |
846 request.get_exported_resources().limit()); | |
847 | |
848 response.mutable_get_exported_resources()->set_done(done); | |
849 break; | |
850 } | |
851 | |
852 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_CHANGE: | |
853 { | |
854 response.mutable_get_last_change()->set_found(false); | |
855 | |
856 Output output(*response.mutable_get_last_change()); | |
857 backend.GetLastChange(output, manager); | |
858 break; | |
859 } | |
860 | |
861 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_EXPORTED_RESOURCE: | |
862 { | |
863 response.mutable_get_last_exported_resource()->set_found(false); | |
864 | |
865 Output output(*response.mutable_get_last_exported_resource()); | |
866 backend.GetLastExportedResource(output, manager); | |
867 break; | |
868 } | |
869 | |
870 case Orthanc::DatabasePluginMessages::OPERATION_GET_MAIN_DICOM_TAGS: | |
871 { | |
872 Output output(*response.mutable_get_main_dicom_tags()); | |
873 backend.GetMainDicomTags(output, manager, request.get_main_dicom_tags().id()); | |
874 break; | |
875 } | |
876 | |
877 case Orthanc::DatabasePluginMessages::OPERATION_GET_PUBLIC_ID: | |
878 { | |
879 const std::string id = backend.GetPublicId(manager, request.get_public_id().id()); | |
880 response.mutable_get_public_id()->set_id(id); | |
881 break; | |
882 } | |
883 | |
884 case Orthanc::DatabasePluginMessages::OPERATION_GET_RESOURCES_COUNT: | |
885 { | |
886 OrthancPluginResourceType type = Convert(request.get_resources_count().type()); | |
887 uint64_t count = backend.GetResourcesCount(manager, type); | |
888 response.mutable_get_resources_count()->set_count(count); | |
889 break; | |
890 } | |
891 | |
892 case Orthanc::DatabasePluginMessages::OPERATION_GET_RESOURCE_TYPE: | |
893 { | |
894 OrthancPluginResourceType type = backend.GetResourceType(manager, request.get_resource_type().id()); | |
895 response.mutable_get_resource_type()->set_type(Convert(type)); | |
896 break; | |
897 } | |
898 | |
899 case Orthanc::DatabasePluginMessages::OPERATION_GET_TOTAL_COMPRESSED_SIZE: | |
900 { | |
901 response.mutable_get_total_compressed_size()->set_size(backend.GetTotalCompressedSize(manager)); | |
902 break; | |
903 } | |
904 | |
905 case Orthanc::DatabasePluginMessages::OPERATION_GET_TOTAL_UNCOMPRESSED_SIZE: | |
906 { | |
907 response.mutable_get_total_uncompressed_size()->set_size(backend.GetTotalUncompressedSize(manager)); | |
908 break; | |
909 } | |
910 | |
911 case Orthanc::DatabasePluginMessages::OPERATION_IS_PROTECTED_PATIENT: | |
912 { | |
913 bool isProtected = backend.IsProtectedPatient(manager, request.is_protected_patient().patient_id()); | |
914 response.mutable_is_protected_patient()->set_protected_patient(isProtected); | |
915 break; | |
916 } | |
917 | |
918 case Orthanc::DatabasePluginMessages::OPERATION_LIST_AVAILABLE_ATTACHMENTS: | |
919 { | |
920 std::list<int32_t> values; | |
921 backend.ListAvailableAttachments(values, manager, request.list_available_attachments().id()); | |
922 | |
923 response.mutable_list_available_attachments()->mutable_attachments()->Reserve(values.size()); | |
924 for (std::list<int32_t>::const_iterator it = values.begin(); it != values.end(); ++it) | |
925 { | |
926 response.mutable_list_available_attachments()->add_attachments(*it); | |
927 } | |
928 | |
929 break; | |
930 } | |
931 | |
932 case Orthanc::DatabasePluginMessages::OPERATION_LOG_CHANGE: | |
933 { | |
934 backend.LogChange(manager, request.log_change().change_type(), | |
935 request.log_change().resource_id(), | |
936 Convert(request.log_change().resource_type()), | |
937 request.log_change().date().c_str()); | |
938 break; | |
939 } | |
940 | |
941 case Orthanc::DatabasePluginMessages::OPERATION_LOG_EXPORTED_RESOURCE: | |
942 { | |
943 backend.LogExportedResource(manager, | |
944 Convert(request.log_exported_resource().resource_type()), | |
945 request.log_exported_resource().public_id().c_str(), | |
946 request.log_exported_resource().modality().c_str(), | |
947 request.log_exported_resource().date().c_str(), | |
948 request.log_exported_resource().patient_id().c_str(), | |
949 request.log_exported_resource().study_instance_uid().c_str(), | |
950 request.log_exported_resource().series_instance_uid().c_str(), | |
951 request.log_exported_resource().sop_instance_uid().c_str()); | |
952 break; | |
953 } | |
954 | |
955 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_ATTACHMENT: | |
956 { | |
957 Output output(*response.mutable_lookup_attachment()); | |
958 | |
959 int64_t revision = -1; | |
960 backend.LookupAttachment(output, revision, manager, request.lookup_attachment().id(), request.lookup_attachment().content_type()); | |
961 | |
962 if (response.lookup_attachment().found()) | |
963 { | |
964 response.mutable_lookup_attachment()->set_revision(revision); | |
965 } | |
966 | |
967 break; | |
968 } | |
969 | |
970 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_GLOBAL_PROPERTY: | |
971 { | |
972 std::string value; | |
973 if (backend.LookupGlobalProperty(value, manager, request.lookup_global_property().server_id().c_str(), | |
974 request.lookup_global_property().property())) | |
975 { | |
976 response.mutable_lookup_global_property()->set_found(true); | |
977 response.mutable_lookup_global_property()->set_value(value); | |
978 } | |
979 else | |
980 { | |
981 response.mutable_lookup_global_property()->set_found(false); | |
982 } | |
983 | |
984 break; | |
985 } | |
986 | |
987 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 3) | |
988 case Orthanc::DatabasePluginMessages::OPERATION_UPDATE_AND_GET_STATISTICS: | |
989 { | |
990 int64_t patientsCount, studiesCount, seriesCount, instancesCount, compressedSize, uncompressedSize; | |
991 backend.UpdateAndGetStatistics(manager, patientsCount, studiesCount, seriesCount, instancesCount, compressedSize, uncompressedSize); | |
992 | |
993 response.mutable_update_and_get_statistics()->set_patients_count(patientsCount); | |
994 response.mutable_update_and_get_statistics()->set_studies_count(studiesCount); | |
995 response.mutable_update_and_get_statistics()->set_series_count(seriesCount); | |
996 response.mutable_update_and_get_statistics()->set_instances_count(instancesCount); | |
997 response.mutable_update_and_get_statistics()->set_total_compressed_size(compressedSize); | |
998 response.mutable_update_and_get_statistics()->set_total_uncompressed_size(uncompressedSize); | |
999 break; | |
1000 } | |
1001 #endif | |
1002 | |
1003 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 3) | |
1004 case Orthanc::DatabasePluginMessages::OPERATION_INCREMENT_GLOBAL_PROPERTY: | |
1005 { | |
1006 int64_t value = backend.IncrementGlobalProperty(manager, request.increment_global_property().server_id().c_str(), | |
1007 request.increment_global_property().property(), | |
1008 request.increment_global_property().increment()); | |
1009 response.mutable_increment_global_property()->set_new_value(value); | |
1010 break; | |
1011 } | |
1012 #endif | |
1013 | |
1014 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_METADATA: | |
1015 { | |
1016 std::string value; | |
1017 int64_t revision = -1; | |
1018 if (backend.LookupMetadata(value, revision, manager, request.lookup_metadata().id(), request.lookup_metadata().metadata_type())) | |
1019 { | |
1020 response.mutable_lookup_metadata()->set_found(true); | |
1021 response.mutable_lookup_metadata()->set_value(value); | |
1022 response.mutable_lookup_metadata()->set_revision(revision); | |
1023 } | |
1024 else | |
1025 { | |
1026 response.mutable_lookup_metadata()->set_found(false); | |
1027 } | |
1028 | |
1029 break; | |
1030 } | |
1031 | |
1032 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_PARENT: | |
1033 { | |
1034 int64_t parent = -1; | |
1035 if (backend.LookupParent(parent, manager, request.lookup_parent().id())) | |
1036 { | |
1037 response.mutable_lookup_parent()->set_found(true); | |
1038 response.mutable_lookup_parent()->set_parent(parent); | |
1039 } | |
1040 else | |
1041 { | |
1042 response.mutable_lookup_parent()->set_found(false); | |
1043 } | |
1044 | |
1045 break; | |
1046 } | |
1047 | |
1048 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_RESOURCE: | |
1049 { | |
1050 int64_t internalId = -1; | |
1051 OrthancPluginResourceType type; | |
1052 if (backend.LookupResource(internalId, type, manager, request.lookup_resource().public_id().c_str())) | |
1053 { | |
1054 response.mutable_lookup_resource()->set_found(true); | |
1055 response.mutable_lookup_resource()->set_internal_id(internalId); | |
1056 response.mutable_lookup_resource()->set_type(Convert(type)); | |
1057 } | |
1058 else | |
1059 { | |
1060 response.mutable_lookup_resource()->set_found(false); | |
1061 } | |
1062 | |
1063 break; | |
1064 } | |
1065 | |
1066 case Orthanc::DatabasePluginMessages::OPERATION_SELECT_PATIENT_TO_RECYCLE: | |
1067 { | |
1068 int64_t patientId = -1; | |
1069 if (backend.SelectPatientToRecycle(patientId, manager)) | |
1070 { | |
1071 response.mutable_select_patient_to_recycle()->set_found(true); | |
1072 response.mutable_select_patient_to_recycle()->set_patient_id(patientId); | |
1073 } | |
1074 else | |
1075 { | |
1076 response.mutable_select_patient_to_recycle()->set_found(false); | |
1077 } | |
1078 | |
1079 break; | |
1080 } | |
1081 | |
1082 case Orthanc::DatabasePluginMessages::OPERATION_SELECT_PATIENT_TO_RECYCLE_WITH_AVOID: | |
1083 { | |
1084 int64_t patientId = -1; | |
1085 if (backend.SelectPatientToRecycle(patientId, manager, request.select_patient_to_recycle_with_avoid().patient_id_to_avoid())) | |
1086 { | |
1087 response.mutable_select_patient_to_recycle_with_avoid()->set_found(true); | |
1088 response.mutable_select_patient_to_recycle_with_avoid()->set_patient_id(patientId); | |
1089 } | |
1090 else | |
1091 { | |
1092 response.mutable_select_patient_to_recycle_with_avoid()->set_found(false); | |
1093 } | |
1094 | |
1095 break; | |
1096 } | |
1097 | |
1098 case Orthanc::DatabasePluginMessages::OPERATION_SET_GLOBAL_PROPERTY: | |
1099 { | |
1100 backend.SetGlobalProperty(manager, request.set_global_property().server_id().c_str(), | |
1101 request.set_global_property().property(), | |
1102 request.set_global_property().value().c_str()); | |
1103 break; | |
1104 } | |
1105 | |
1106 case Orthanc::DatabasePluginMessages::OPERATION_CLEAR_MAIN_DICOM_TAGS: | |
1107 { | |
1108 backend.ClearMainDicomTags(manager, request.clear_main_dicom_tags().id()); | |
1109 break; | |
1110 } | |
1111 | |
1112 case Orthanc::DatabasePluginMessages::OPERATION_SET_METADATA: | |
1113 { | |
1114 backend.SetMetadata(manager, request.set_metadata().id(), | |
1115 request.set_metadata().metadata_type(), | |
1116 request.set_metadata().value().c_str(), | |
1117 request.set_metadata().revision()); | |
1118 break; | |
1119 } | |
1120 | |
1121 case Orthanc::DatabasePluginMessages::OPERATION_SET_PROTECTED_PATIENT: | |
1122 { | |
1123 backend.SetProtectedPatient(manager, request.set_protected_patient().patient_id(), | |
1124 request.set_protected_patient().protected_patient()); | |
1125 break; | |
1126 } | |
1127 | |
1128 case Orthanc::DatabasePluginMessages::OPERATION_IS_DISK_SIZE_ABOVE: | |
1129 { | |
1130 bool above = (backend.GetTotalCompressedSize(manager) >= request.is_disk_size_above().threshold()); | |
1131 response.mutable_is_disk_size_above()->set_result(above); | |
1132 break; | |
1133 } | |
1134 | |
1135 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_RESOURCES: | |
1136 { | |
1137 ApplyLookupResources(*response.mutable_lookup_resources(), request.lookup_resources(), backend, manager); | |
1138 break; | |
1139 } | |
1140 | |
1141 case Orthanc::DatabasePluginMessages::OPERATION_CREATE_INSTANCE: | |
1142 { | |
1143 const char* hashPatient = request.create_instance().patient().c_str(); | |
1144 const char* hashStudy = request.create_instance().study().c_str(); | |
1145 const char* hashSeries = request.create_instance().series().c_str(); | |
1146 const char* hashInstance = request.create_instance().instance().c_str(); | |
1147 | |
1148 OrthancPluginCreateInstanceResult result; | |
1149 | |
1150 if (backend.HasCreateInstance()) | |
1151 { | |
1152 backend.CreateInstance(result, manager, hashPatient, hashStudy, hashSeries, hashInstance); | |
1153 } | |
1154 else | |
1155 { | |
1156 backend.CreateInstanceGeneric(result, manager, hashPatient, hashStudy, hashSeries, hashInstance); | |
1157 } | |
1158 | |
1159 response.mutable_create_instance()->set_is_new_instance(result.isNewInstance); | |
1160 response.mutable_create_instance()->set_instance_id(result.instanceId); | |
1161 | |
1162 if (result.isNewInstance) | |
1163 { | |
1164 response.mutable_create_instance()->set_is_new_patient(result.isNewPatient); | |
1165 response.mutable_create_instance()->set_is_new_study(result.isNewStudy); | |
1166 response.mutable_create_instance()->set_is_new_series(result.isNewSeries); | |
1167 response.mutable_create_instance()->set_patient_id(result.patientId); | |
1168 response.mutable_create_instance()->set_study_id(result.studyId); | |
1169 response.mutable_create_instance()->set_series_id(result.seriesId); | |
1170 } | |
1171 | |
1172 break; | |
1173 } | |
1174 | |
1175 case Orthanc::DatabasePluginMessages::OPERATION_SET_RESOURCES_CONTENT: | |
1176 { | |
1177 std::vector<OrthancPluginResourcesContentTags> identifierTags; | |
1178 std::vector<OrthancPluginResourcesContentTags> mainDicomTags; | |
1179 | |
1180 identifierTags.reserve(request.set_resources_content().tags().size()); | |
1181 mainDicomTags.reserve(request.set_resources_content().tags().size()); | |
1182 | |
1183 for (int i = 0; i < request.set_resources_content().tags().size(); i++) | |
1184 { | |
1185 if (request.set_resources_content().tags(i).group() > 0xffffu || | |
1186 request.set_resources_content().tags(i).element() > 0xffffu) | |
1187 { | |
1188 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
1189 } | |
1190 | |
1191 OrthancPluginResourcesContentTags tag; | |
1192 tag.resource = request.set_resources_content().tags(i).resource_id(); | |
1193 tag.group = request.set_resources_content().tags(i).group(); | |
1194 tag.element = request.set_resources_content().tags(i).element(); | |
1195 tag.value = request.set_resources_content().tags(i).value().c_str(); | |
1196 | |
1197 if (request.set_resources_content().tags(i).is_identifier()) | |
1198 { | |
1199 identifierTags.push_back(tag); | |
1200 } | |
1201 else | |
1202 { | |
1203 mainDicomTags.push_back(tag); | |
1204 } | |
1205 } | |
1206 | |
1207 std::vector<OrthancPluginResourcesContentMetadata> metadata; | |
1208 metadata.reserve(request.set_resources_content().metadata().size()); | |
1209 | |
1210 for (int i = 0; i < request.set_resources_content().metadata().size(); i++) | |
1211 { | |
1212 OrthancPluginResourcesContentMetadata item; | |
1213 item.resource = request.set_resources_content().metadata(i).resource_id(); | |
1214 item.metadata = request.set_resources_content().metadata(i).metadata(); | |
1215 item.value = request.set_resources_content().metadata(i).value().c_str(); | |
1216 metadata.push_back(item); | |
1217 } | |
1218 | |
1219 backend.SetResourcesContent(manager, | |
1220 identifierTags.size(), (identifierTags.empty() ? NULL : &identifierTags[0]), | |
1221 mainDicomTags.size(), (mainDicomTags.empty() ? NULL : &mainDicomTags[0]), | |
1222 metadata.size(), (metadata.empty() ? NULL : &metadata[0])); | |
1223 break; | |
1224 } | |
1225 | |
1226 case Orthanc::DatabasePluginMessages::OPERATION_GET_CHILDREN_METADATA: | |
1227 { | |
1228 std::list<std::string> values; | |
1229 backend.GetChildrenMetadata(values, manager, request.get_children_metadata().id(), request.get_children_metadata().metadata()); | |
1230 | |
1231 response.mutable_get_children_metadata()->mutable_values()->Reserve(values.size()); | |
1232 for (std::list<std::string>::const_iterator it = values.begin(); it != values.end(); ++it) | |
1233 { | |
1234 response.mutable_get_children_metadata()->add_values(*it); | |
1235 } | |
1236 | |
1237 break; | |
1238 } | |
1239 | |
1240 case Orthanc::DatabasePluginMessages::OPERATION_GET_LAST_CHANGE_INDEX: | |
1241 { | |
1242 response.mutable_get_last_change_index()->set_result(backend.GetLastChangeIndex(manager)); | |
1243 break; | |
1244 } | |
1245 | |
1246 case Orthanc::DatabasePluginMessages::OPERATION_LOOKUP_RESOURCE_AND_PARENT: | |
1247 { | |
1248 int64_t id; | |
1249 OrthancPluginResourceType type; | |
1250 std::string parent; | |
1251 | |
1252 if (backend.LookupResourceAndParent(id, type, parent, manager, request.lookup_resource_and_parent().public_id().c_str())) | |
1253 { | |
1254 response.mutable_lookup_resource_and_parent()->set_found(true); | |
1255 response.mutable_lookup_resource_and_parent()->set_id(id); | |
1256 response.mutable_lookup_resource_and_parent()->set_type(Convert(type)); | |
1257 | |
1258 switch (type) | |
1259 { | |
1260 case OrthancPluginResourceType_Study: | |
1261 case OrthancPluginResourceType_Series: | |
1262 case OrthancPluginResourceType_Instance: | |
1263 if (parent.empty()) | |
1264 { | |
1265 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1266 } | |
1267 else | |
1268 { | |
1269 response.mutable_lookup_resource_and_parent()->set_parent_public_id(parent); | |
1270 } | |
1271 break; | |
1272 | |
1273 case OrthancPluginResourceType_Patient: | |
1274 if (!parent.empty()) | |
1275 { | |
1276 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1277 } | |
1278 break; | |
1279 | |
1280 default: | |
1281 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
1282 } | |
1283 } | |
1284 else | |
1285 { | |
1286 response.mutable_lookup_resource_and_parent()->set_found(false); | |
1287 } | |
1288 | |
1289 break; | |
1290 } | |
1291 | |
1292 case Orthanc::DatabasePluginMessages::OPERATION_ADD_LABEL: | |
1293 { | |
1294 backend.AddLabel(manager, request.add_label().id(), request.add_label().label()); | |
1295 break; | |
1296 } | |
1297 | |
1298 case Orthanc::DatabasePluginMessages::OPERATION_REMOVE_LABEL: | |
1299 { | |
1300 backend.RemoveLabel(manager, request.remove_label().id(), request.remove_label().label()); | |
1301 break; | |
1302 } | |
1303 | |
1304 case Orthanc::DatabasePluginMessages::OPERATION_LIST_LABELS: | |
1305 { | |
1306 std::list<std::string> labels; | |
1307 | |
1308 if (request.list_labels().single_resource()) | |
1309 { | |
1310 backend.ListLabels(labels, manager, request.list_labels().id()); | |
1311 } | |
1312 else | |
1313 { | |
1314 backend.ListAllLabels(labels, manager); | |
1315 } | |
1316 | |
1317 response.mutable_list_available_attachments()->mutable_attachments()->Reserve(labels.size()); | |
1318 for (std::list<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it) | |
1319 { | |
1320 response.mutable_list_labels()->add_labels(*it); | |
1321 } | |
1322 | |
1323 break; | |
1324 } | |
1325 | |
1326 #if ORTHANC_PLUGINS_HAS_INTEGRATED_FIND == 1 | |
1327 case Orthanc::DatabasePluginMessages::OPERATION_FIND: | |
1328 { | |
1329 backend.ExecuteFind(response, manager, request.find()); | |
1330 break; | |
1331 } | |
1332 #endif | |
1333 | |
1334 default: | |
1335 LOG(ERROR) << "Not implemented transaction operation from protobuf: " << request.operation(); | |
1336 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
1337 } | |
1338 } | |
1339 | |
1340 | |
1341 static OrthancPluginErrorCode CallBackend(OrthancPluginMemoryBuffer64* serializedResponse, | |
1342 void* rawPool, | |
1343 const void* requestData, | |
1344 uint64_t requestSize) | |
1345 { | |
1346 Orthanc::DatabasePluginMessages::Request request; | |
1347 if (!request.ParseFromArray(requestData, requestSize)) | |
1348 { | |
1349 LOG(ERROR) << "Cannot parse message from the Orthanc core using protobuf"; | |
1350 return OrthancPluginErrorCode_InternalError; | |
1351 } | |
1352 | |
1353 if (rawPool == NULL) | |
1354 { | |
1355 LOG(ERROR) << "Received a NULL pointer from the database"; | |
1356 return OrthancPluginErrorCode_InternalError; | |
1357 } | |
1358 | |
1359 IndexConnectionsPool& pool = *reinterpret_cast<IndexConnectionsPool*>(rawPool); | |
1360 | |
1361 try | |
1362 { | |
1363 Orthanc::DatabasePluginMessages::Response response; | |
1364 | |
1365 switch (request.type()) | |
1366 { | |
1367 case Orthanc::DatabasePluginMessages::REQUEST_DATABASE: | |
1368 ProcessDatabaseOperation(*response.mutable_database_response(), request.database_request(), pool); | |
1369 break; | |
1370 | |
1371 case Orthanc::DatabasePluginMessages::REQUEST_TRANSACTION: | |
1372 { | |
1373 IndexConnectionsPool::Accessor& transaction = *reinterpret_cast<IndexConnectionsPool::Accessor*>(request.transaction_request().transaction()); | |
1374 ProcessTransactionOperation(*response.mutable_transaction_response(), request.transaction_request(), | |
1375 transaction.GetBackend(), transaction.GetManager()); | |
1376 break; | |
1377 } | |
1378 | |
1379 default: | |
1380 LOG(ERROR) << "Not implemented request type from protobuf: " << request.type(); | |
1381 break; | |
1382 } | |
1383 | |
1384 std::string s; | |
1385 if (!response.SerializeToString(&s)) | |
1386 { | |
1387 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Cannot serialize to protobuf"); | |
1388 } | |
1389 | |
1390 if (OrthancPluginCreateMemoryBuffer64(pool.GetContext(), serializedResponse, s.size()) != OrthancPluginErrorCode_Success) | |
1391 { | |
1392 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotEnoughMemory, "Cannot allocate a memory buffer"); | |
1393 } | |
1394 | |
1395 if (!s.empty()) | |
1396 { | |
1397 assert(serializedResponse->size == s.size()); | |
1398 memcpy(serializedResponse->data, s.c_str(), s.size()); | |
1399 } | |
1400 | |
1103 return OrthancPluginErrorCode_Success; | 1401 return OrthancPluginErrorCode_Success; |
1104 } | 1402 } |
1105 ORTHANC_PLUGINS_DATABASE_CATCH(adapter->GetContext()); | 1403 catch (::Orthanc::OrthancException& e) |
1404 { | |
1405 if (e.GetErrorCode() == ::Orthanc::ErrorCode_DatabaseCannotSerialize) | |
1406 { | |
1407 LOG(WARNING) << "An SQL transaction failed and will likely be retried: " << e.GetDetails(); | |
1408 } | |
1409 else | |
1410 { | |
1411 LOG(ERROR) << "Exception in database back-end: " << e.What(); | |
1412 } | |
1413 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
1414 } | |
1415 catch (::std::runtime_error& e) | |
1416 { | |
1417 LOG(ERROR) << "Exception in database back-end: " << e.what(); | |
1418 return OrthancPluginErrorCode_DatabasePlugin; | |
1419 } | |
1420 catch (...) | |
1421 { | |
1422 LOG(ERROR) << "Native exception"; | |
1423 return OrthancPluginErrorCode_DatabasePlugin; | |
1424 } | |
1106 } | 1425 } |
1107 | 1426 |
1427 static void FinalizeBackend(void* rawPool) | |
1428 { | |
1429 if (rawPool != NULL) | |
1430 { | |
1431 IndexConnectionsPool* pool = reinterpret_cast<IndexConnectionsPool*>(rawPool); | |
1432 | |
1433 if (isBackendInUse_) | |
1434 { | |
1435 isBackendInUse_ = false; | |
1436 } | |
1437 else | |
1438 { | |
1439 LOG(ERROR) << "More than one index backend was registered, internal error"; | |
1440 } | |
1441 | |
1442 delete pool; | |
1443 } | |
1444 else | |
1445 { | |
1446 LOG(ERROR) << "Received a null pointer from the Orthanc core, internal error"; | |
1447 } | |
1448 } | |
1449 | |
1108 | 1450 |
1109 static OrthancPluginErrorCode DestructTransaction(OrthancPluginDatabaseTransaction* transaction) | |
1110 { | |
1111 if (transaction == NULL) | |
1112 { | |
1113 return OrthancPluginErrorCode_NullPointer; | |
1114 } | |
1115 else | |
1116 { | |
1117 delete reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1118 return OrthancPluginErrorCode_Success; | |
1119 } | |
1120 } | |
1121 | |
1122 | |
1123 static OrthancPluginErrorCode Rollback(OrthancPluginDatabaseTransaction* transaction) | |
1124 { | |
1125 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1126 | |
1127 try | |
1128 { | |
1129 t->GetOutput().Clear(); | |
1130 t->GetManager().RollbackTransaction(); | |
1131 return OrthancPluginErrorCode_Success; | |
1132 } | |
1133 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1134 } | |
1135 | |
1136 | |
1137 static OrthancPluginErrorCode Commit(OrthancPluginDatabaseTransaction* transaction, | |
1138 int64_t fileSizeDelta /* TODO - not used? */) | |
1139 { | |
1140 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1141 | |
1142 try | |
1143 { | |
1144 t->GetOutput().Clear(); | |
1145 t->GetManager().CommitTransaction(); | |
1146 return OrthancPluginErrorCode_Success; | |
1147 } | |
1148 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1149 } | |
1150 | |
1151 | |
1152 static OrthancPluginErrorCode AddAttachment2(OrthancPluginDatabaseTransaction* transaction, | |
1153 int64_t id, | |
1154 const OrthancPluginAttachment2* attachment, | |
1155 int64_t revision) | |
1156 { | |
1157 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1158 | |
1159 try | |
1160 { | |
1161 t->GetOutput().Clear(); | |
1162 t->GetBackend().AddAttachment2(t->GetManager(), id, *attachment, revision); | |
1163 return OrthancPluginErrorCode_Success; | |
1164 } | |
1165 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1166 } | |
1167 | |
1168 | |
1169 static OrthancPluginErrorCode ClearChanges(OrthancPluginDatabaseTransaction* transaction) | |
1170 { | |
1171 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1172 | |
1173 try | |
1174 { | |
1175 t->GetOutput().Clear(); | |
1176 t->GetBackend().ClearChanges(t->GetManager()); | |
1177 return OrthancPluginErrorCode_Success; | |
1178 } | |
1179 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1180 } | |
1181 | |
1182 | |
1183 static OrthancPluginErrorCode ClearExportedResources(OrthancPluginDatabaseTransaction* transaction) | |
1184 { | |
1185 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1186 | |
1187 try | |
1188 { | |
1189 t->GetOutput().Clear(); | |
1190 t->GetBackend().ClearExportedResources(t->GetManager()); | |
1191 return OrthancPluginErrorCode_Success; | |
1192 } | |
1193 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1194 } | |
1195 | |
1196 | |
1197 static OrthancPluginErrorCode ClearMainDicomTags(OrthancPluginDatabaseTransaction* transaction, | |
1198 int64_t resourceId) | |
1199 { | |
1200 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1201 | |
1202 try | |
1203 { | |
1204 t->GetOutput().Clear(); | |
1205 t->GetBackend().ClearMainDicomTags(t->GetManager(), resourceId); | |
1206 return OrthancPluginErrorCode_Success; | |
1207 } | |
1208 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1209 } | |
1210 | |
1211 | |
1212 static OrthancPluginErrorCode CreateInstance(OrthancPluginDatabaseTransaction* transaction, | |
1213 OrthancPluginCreateInstanceResult* target /* out */, | |
1214 const char* hashPatient, | |
1215 const char* hashStudy, | |
1216 const char* hashSeries, | |
1217 const char* hashInstance) | |
1218 { | |
1219 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1220 | |
1221 try | |
1222 { | |
1223 t->GetOutput().Clear(); | |
1224 | |
1225 if (t->GetBackend().HasCreateInstance()) | |
1226 { | |
1227 t->GetBackend().CreateInstance(*target, t->GetManager(), hashPatient, hashStudy, hashSeries, hashInstance); | |
1228 } | |
1229 else | |
1230 { | |
1231 t->GetBackend().CreateInstanceGeneric(*target, t->GetManager(), hashPatient, hashStudy, hashSeries, hashInstance); | |
1232 } | |
1233 | |
1234 return OrthancPluginErrorCode_Success; | |
1235 } | |
1236 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1237 } | |
1238 | |
1239 | |
1240 static OrthancPluginErrorCode DeleteAttachment(OrthancPluginDatabaseTransaction* transaction, | |
1241 int64_t id, | |
1242 int32_t contentType) | |
1243 { | |
1244 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1245 | |
1246 try | |
1247 { | |
1248 t->GetOutput().Clear(); | |
1249 t->GetBackend().DeleteAttachment(t->GetOutput(), t->GetManager(), id, contentType); | |
1250 return OrthancPluginErrorCode_Success; | |
1251 } | |
1252 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1253 } | |
1254 | |
1255 | |
1256 static OrthancPluginErrorCode DeleteMetadata(OrthancPluginDatabaseTransaction* transaction, | |
1257 int64_t id, | |
1258 int32_t metadataType) | |
1259 { | |
1260 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1261 | |
1262 try | |
1263 { | |
1264 t->GetOutput().Clear(); | |
1265 t->GetBackend().DeleteMetadata(t->GetManager(), id, metadataType); | |
1266 return OrthancPluginErrorCode_Success; | |
1267 } | |
1268 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1269 } | |
1270 | |
1271 | |
1272 static OrthancPluginErrorCode DeleteResource(OrthancPluginDatabaseTransaction* transaction, | |
1273 int64_t id) | |
1274 { | |
1275 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1276 | |
1277 try | |
1278 { | |
1279 t->GetOutput().Clear(); | |
1280 t->GetBackend().DeleteResource(t->GetOutput(), t->GetManager(), id); | |
1281 return OrthancPluginErrorCode_Success; | |
1282 } | |
1283 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1284 } | |
1285 | |
1286 | |
1287 static OrthancPluginErrorCode GetAllMetadata(OrthancPluginDatabaseTransaction* transaction, | |
1288 int64_t id) | |
1289 { | |
1290 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1291 | |
1292 try | |
1293 { | |
1294 t->GetOutput().Clear(); | |
1295 | |
1296 std::map<int32_t, std::string> values; | |
1297 t->GetBackend().GetAllMetadata(values, t->GetManager(), id); | |
1298 | |
1299 for (std::map<int32_t, std::string>::const_iterator it = values.begin(); it != values.end(); ++it) | |
1300 { | |
1301 t->GetOutput().AnswerMetadata(it->first, it->second); | |
1302 } | |
1303 | |
1304 return OrthancPluginErrorCode_Success; | |
1305 } | |
1306 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1307 } | |
1308 | |
1309 | |
1310 static OrthancPluginErrorCode GetAllPublicIds(OrthancPluginDatabaseTransaction* transaction, | |
1311 OrthancPluginResourceType resourceType) | |
1312 { | |
1313 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1314 | |
1315 try | |
1316 { | |
1317 t->GetOutput().Clear(); | |
1318 | |
1319 std::list<std::string> values; | |
1320 t->GetBackend().GetAllPublicIds(values, t->GetManager(), resourceType); | |
1321 t->GetOutput().AnswerStrings(values); | |
1322 | |
1323 return OrthancPluginErrorCode_Success; | |
1324 } | |
1325 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1326 } | |
1327 | |
1328 | |
1329 static OrthancPluginErrorCode GetAllPublicIdsWithLimit(OrthancPluginDatabaseTransaction* transaction, | |
1330 OrthancPluginResourceType resourceType, | |
1331 uint64_t since, | |
1332 uint64_t limit) | |
1333 { | |
1334 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1335 | |
1336 try | |
1337 { | |
1338 t->GetOutput().Clear(); | |
1339 | |
1340 std::list<std::string> values; | |
1341 t->GetBackend().GetAllPublicIds(values, t->GetManager(), resourceType, since, limit); | |
1342 t->GetOutput().AnswerStrings(values); | |
1343 | |
1344 return OrthancPluginErrorCode_Success; | |
1345 } | |
1346 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1347 } | |
1348 | |
1349 | |
1350 static OrthancPluginErrorCode GetChanges(OrthancPluginDatabaseTransaction* transaction, | |
1351 uint8_t* targetDone /* out */, | |
1352 int64_t since, | |
1353 uint32_t maxResults) | |
1354 { | |
1355 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1356 | |
1357 try | |
1358 { | |
1359 t->GetOutput().Clear(); | |
1360 | |
1361 bool done; | |
1362 t->GetBackend().GetChanges(t->GetOutput(), done, t->GetManager(), since, maxResults); | |
1363 *targetDone = (done ? 1 : 0); | |
1364 | |
1365 return OrthancPluginErrorCode_Success; | |
1366 } | |
1367 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1368 } | |
1369 | |
1370 | |
1371 static OrthancPluginErrorCode GetChildrenInternalId(OrthancPluginDatabaseTransaction* transaction, | |
1372 int64_t id) | |
1373 { | |
1374 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1375 | |
1376 try | |
1377 { | |
1378 t->GetOutput().Clear(); | |
1379 | |
1380 std::list<int64_t> values; | |
1381 t->GetBackend().GetChildrenInternalId(values, t->GetManager(), id); | |
1382 t->GetOutput().AnswerIntegers64(values); | |
1383 | |
1384 return OrthancPluginErrorCode_Success; | |
1385 } | |
1386 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1387 } | |
1388 | |
1389 | |
1390 static OrthancPluginErrorCode GetChildrenMetadata(OrthancPluginDatabaseTransaction* transaction, | |
1391 int64_t resourceId, | |
1392 int32_t metadata) | |
1393 { | |
1394 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1395 | |
1396 try | |
1397 { | |
1398 t->GetOutput().Clear(); | |
1399 | |
1400 std::list<std::string> values; | |
1401 t->GetBackend().GetChildrenMetadata(values, t->GetManager(), resourceId, metadata); | |
1402 t->GetOutput().AnswerStrings(values); | |
1403 | |
1404 return OrthancPluginErrorCode_Success; | |
1405 } | |
1406 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1407 } | |
1408 | |
1409 | |
1410 static OrthancPluginErrorCode GetChildrenPublicId(OrthancPluginDatabaseTransaction* transaction, | |
1411 int64_t id) | |
1412 { | |
1413 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1414 | |
1415 try | |
1416 { | |
1417 t->GetOutput().Clear(); | |
1418 | |
1419 std::list<std::string> values; | |
1420 t->GetBackend().GetChildrenPublicId(values, t->GetManager(), id); | |
1421 t->GetOutput().AnswerStrings(values); | |
1422 | |
1423 return OrthancPluginErrorCode_Success; | |
1424 } | |
1425 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1426 } | |
1427 | |
1428 | |
1429 static OrthancPluginErrorCode GetExportedResources(OrthancPluginDatabaseTransaction* transaction, | |
1430 uint8_t* targetDone /* out */, | |
1431 int64_t since, | |
1432 uint32_t maxResults) | |
1433 { | |
1434 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1435 | |
1436 try | |
1437 { | |
1438 t->GetOutput().Clear(); | |
1439 | |
1440 bool done; | |
1441 t->GetBackend().GetExportedResources(t->GetOutput(), done, t->GetManager(), since, maxResults); | |
1442 *targetDone = (done ? 1 : 0); | |
1443 | |
1444 return OrthancPluginErrorCode_Success; | |
1445 } | |
1446 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1447 } | |
1448 | |
1449 | |
1450 static OrthancPluginErrorCode GetLastChange(OrthancPluginDatabaseTransaction* transaction) | |
1451 { | |
1452 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1453 | |
1454 try | |
1455 { | |
1456 t->GetOutput().Clear(); | |
1457 t->GetBackend().GetLastChange(t->GetOutput(), t->GetManager()); | |
1458 return OrthancPluginErrorCode_Success; | |
1459 } | |
1460 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1461 } | |
1462 | |
1463 | |
1464 static OrthancPluginErrorCode GetLastChangeIndex(OrthancPluginDatabaseTransaction* transaction, | |
1465 int64_t* target) | |
1466 { | |
1467 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1468 | |
1469 try | |
1470 { | |
1471 t->GetOutput().Clear(); | |
1472 *target = t->GetBackend().GetLastChangeIndex(t->GetManager()); | |
1473 return OrthancPluginErrorCode_Success; | |
1474 } | |
1475 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1476 } | |
1477 | |
1478 | |
1479 static OrthancPluginErrorCode GetLastExportedResource(OrthancPluginDatabaseTransaction* transaction) | |
1480 { | |
1481 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1482 | |
1483 try | |
1484 { | |
1485 t->GetOutput().Clear(); | |
1486 t->GetBackend().GetLastExportedResource(t->GetOutput(), t->GetManager()); | |
1487 return OrthancPluginErrorCode_Success; | |
1488 } | |
1489 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1490 } | |
1491 | |
1492 | |
1493 static OrthancPluginErrorCode GetMainDicomTags(OrthancPluginDatabaseTransaction* transaction, | |
1494 int64_t id) | |
1495 { | |
1496 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1497 | |
1498 try | |
1499 { | |
1500 t->GetOutput().Clear(); | |
1501 t->GetBackend().GetMainDicomTags(t->GetOutput(), t->GetManager(), id); | |
1502 return OrthancPluginErrorCode_Success; | |
1503 } | |
1504 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1505 } | |
1506 | |
1507 | |
1508 static OrthancPluginErrorCode GetPublicId(OrthancPluginDatabaseTransaction* transaction, | |
1509 int64_t id) | |
1510 { | |
1511 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1512 | |
1513 try | |
1514 { | |
1515 t->GetOutput().Clear(); | |
1516 t->GetOutput().AnswerString(t->GetBackend().GetPublicId(t->GetManager(), id)); | |
1517 return OrthancPluginErrorCode_Success; | |
1518 } | |
1519 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1520 } | |
1521 | |
1522 | |
1523 static OrthancPluginErrorCode GetResourcesCount(OrthancPluginDatabaseTransaction* transaction, | |
1524 uint64_t* target /* out */, | |
1525 OrthancPluginResourceType resourceType) | |
1526 { | |
1527 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1528 | |
1529 try | |
1530 { | |
1531 t->GetOutput().Clear(); | |
1532 *target = t->GetBackend().GetResourcesCount(t->GetManager(), resourceType); | |
1533 return OrthancPluginErrorCode_Success; | |
1534 } | |
1535 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1536 } | |
1537 | |
1538 | |
1539 static OrthancPluginErrorCode GetResourceType(OrthancPluginDatabaseTransaction* transaction, | |
1540 OrthancPluginResourceType* target /* out */, | |
1541 uint64_t resourceId) | |
1542 { | |
1543 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1544 | |
1545 try | |
1546 { | |
1547 t->GetOutput().Clear(); | |
1548 *target = t->GetBackend().GetResourceType(t->GetManager(), resourceId); | |
1549 return OrthancPluginErrorCode_Success; | |
1550 } | |
1551 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1552 } | |
1553 | |
1554 | |
1555 static OrthancPluginErrorCode GetTotalCompressedSize(OrthancPluginDatabaseTransaction* transaction, | |
1556 uint64_t* target /* out */) | |
1557 { | |
1558 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1559 | |
1560 try | |
1561 { | |
1562 t->GetOutput().Clear(); | |
1563 *target = t->GetBackend().GetTotalCompressedSize(t->GetManager()); | |
1564 return OrthancPluginErrorCode_Success; | |
1565 } | |
1566 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1567 } | |
1568 | |
1569 | |
1570 static OrthancPluginErrorCode GetTotalUncompressedSize(OrthancPluginDatabaseTransaction* transaction, | |
1571 uint64_t* target /* out */) | |
1572 { | |
1573 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1574 | |
1575 try | |
1576 { | |
1577 t->GetOutput().Clear(); | |
1578 *target = t->GetBackend().GetTotalUncompressedSize(t->GetManager()); | |
1579 return OrthancPluginErrorCode_Success; | |
1580 } | |
1581 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1582 } | |
1583 | |
1584 | |
1585 static OrthancPluginErrorCode IsDiskSizeAbove(OrthancPluginDatabaseTransaction* transaction, | |
1586 uint8_t* target, | |
1587 uint64_t threshold) | |
1588 { | |
1589 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1590 | |
1591 try | |
1592 { | |
1593 t->GetOutput().Clear(); | |
1594 bool above = (t->GetBackend().GetTotalCompressedSize(t->GetManager()) >= threshold); | |
1595 *target = (above ? 1 : 0); | |
1596 return OrthancPluginErrorCode_Success; | |
1597 } | |
1598 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1599 } | |
1600 | |
1601 | |
1602 static OrthancPluginErrorCode IsExistingResource(OrthancPluginDatabaseTransaction* transaction, | |
1603 uint8_t* target, | |
1604 int64_t resourceId) | |
1605 { | |
1606 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1607 | |
1608 try | |
1609 { | |
1610 t->GetOutput().Clear(); | |
1611 bool exists = t->GetBackend().IsExistingResource(t->GetManager(), resourceId); | |
1612 *target = (exists ? 1 : 0); | |
1613 return OrthancPluginErrorCode_Success; | |
1614 } | |
1615 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1616 } | |
1617 | |
1618 | |
1619 static OrthancPluginErrorCode IsProtectedPatient(OrthancPluginDatabaseTransaction* transaction, | |
1620 uint8_t* target, | |
1621 int64_t resourceId) | |
1622 { | |
1623 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1624 | |
1625 try | |
1626 { | |
1627 t->GetOutput().Clear(); | |
1628 bool isProtected = t->GetBackend().IsProtectedPatient(t->GetManager(), resourceId); | |
1629 *target = (isProtected ? 1 : 0); | |
1630 return OrthancPluginErrorCode_Success; | |
1631 } | |
1632 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1633 } | |
1634 | |
1635 | |
1636 static OrthancPluginErrorCode ListAvailableAttachments(OrthancPluginDatabaseTransaction* transaction, | |
1637 int64_t resourceId) | |
1638 { | |
1639 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1640 | |
1641 try | |
1642 { | |
1643 t->GetOutput().Clear(); | |
1644 | |
1645 std::list<int32_t> values; | |
1646 t->GetBackend().ListAvailableAttachments(values, t->GetManager(), resourceId); | |
1647 t->GetOutput().AnswerIntegers32(values); | |
1648 return OrthancPluginErrorCode_Success; | |
1649 } | |
1650 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1651 } | |
1652 | |
1653 | |
1654 static OrthancPluginErrorCode LogChange(OrthancPluginDatabaseTransaction* transaction, | |
1655 int32_t changeType, | |
1656 int64_t resourceId, | |
1657 OrthancPluginResourceType resourceType, | |
1658 const char* date) | |
1659 { | |
1660 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1661 | |
1662 try | |
1663 { | |
1664 t->GetOutput().Clear(); | |
1665 t->GetBackend().LogChange(t->GetManager(), changeType, resourceId, resourceType, date); | |
1666 return OrthancPluginErrorCode_Success; | |
1667 } | |
1668 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1669 } | |
1670 | |
1671 | |
1672 static OrthancPluginErrorCode LogExportedResource(OrthancPluginDatabaseTransaction* transaction, | |
1673 OrthancPluginResourceType resourceType, | |
1674 const char* publicId, | |
1675 const char* modality, | |
1676 const char* date, | |
1677 const char* patientId, | |
1678 const char* studyInstanceUid, | |
1679 const char* seriesInstanceUid, | |
1680 const char* sopInstanceUid) | |
1681 { | |
1682 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1683 | |
1684 try | |
1685 { | |
1686 OrthancPluginExportedResource exported; | |
1687 exported.seq = 0; | |
1688 exported.resourceType = resourceType; | |
1689 exported.publicId = publicId; | |
1690 exported.modality = modality; | |
1691 exported.date = date; | |
1692 exported.patientId = patientId; | |
1693 exported.studyInstanceUid = studyInstanceUid; | |
1694 exported.seriesInstanceUid = seriesInstanceUid; | |
1695 exported.sopInstanceUid = sopInstanceUid; | |
1696 | |
1697 t->GetOutput().Clear(); | |
1698 t->GetBackend().LogExportedResource(t->GetManager(), exported); | |
1699 return OrthancPluginErrorCode_Success; | |
1700 } | |
1701 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1702 } | |
1703 | |
1704 | |
1705 static OrthancPluginErrorCode LookupAttachment(OrthancPluginDatabaseTransaction* transaction, | |
1706 int64_t* revision /* out */, | |
1707 int64_t resourceId, | |
1708 int32_t contentType) | |
1709 { | |
1710 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1711 | |
1712 try | |
1713 { | |
1714 t->GetOutput().Clear(); | |
1715 t->GetBackend().LookupAttachment(t->GetOutput(), *revision, t->GetManager(), resourceId, contentType); | |
1716 return OrthancPluginErrorCode_Success; | |
1717 } | |
1718 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1719 } | |
1720 | |
1721 | |
1722 static OrthancPluginErrorCode LookupGlobalProperty(OrthancPluginDatabaseTransaction* transaction, | |
1723 const char* serverIdentifier, | |
1724 int32_t property) | |
1725 { | |
1726 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1727 | |
1728 try | |
1729 { | |
1730 t->GetOutput().Clear(); | |
1731 | |
1732 std::string s; | |
1733 if (t->GetBackend().LookupGlobalProperty(s, t->GetManager(), serverIdentifier, property)) | |
1734 { | |
1735 t->GetOutput().AnswerString(s); | |
1736 } | |
1737 | |
1738 return OrthancPluginErrorCode_Success; | |
1739 } | |
1740 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1741 } | |
1742 | |
1743 | |
1744 static OrthancPluginErrorCode LookupMetadata(OrthancPluginDatabaseTransaction* transaction, | |
1745 int64_t* revision /* out */, | |
1746 int64_t id, | |
1747 int32_t metadata) | |
1748 { | |
1749 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1750 | |
1751 try | |
1752 { | |
1753 t->GetOutput().Clear(); | |
1754 | |
1755 std::string s; | |
1756 if (t->GetBackend().LookupMetadata(s, *revision, t->GetManager(), id, metadata)) | |
1757 { | |
1758 t->GetOutput().AnswerString(s); | |
1759 } | |
1760 | |
1761 return OrthancPluginErrorCode_Success; | |
1762 } | |
1763 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1764 } | |
1765 | |
1766 | |
1767 static OrthancPluginErrorCode LookupParent(OrthancPluginDatabaseTransaction* transaction, | |
1768 uint8_t* existing /* out */, | |
1769 int64_t* parentId /* out */, | |
1770 int64_t id) | |
1771 { | |
1772 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1773 | |
1774 try | |
1775 { | |
1776 t->GetOutput().Clear(); | |
1777 | |
1778 if (t->GetBackend().LookupParent(*parentId, t->GetManager(), id)) | |
1779 { | |
1780 *existing = 1; | |
1781 } | |
1782 else | |
1783 { | |
1784 *existing = 0; | |
1785 } | |
1786 | |
1787 return OrthancPluginErrorCode_Success; | |
1788 } | |
1789 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1790 } | |
1791 | |
1792 | |
1793 static OrthancPluginErrorCode LookupResource(OrthancPluginDatabaseTransaction* transaction, | |
1794 uint8_t* isExisting /* out */, | |
1795 int64_t* id /* out */, | |
1796 OrthancPluginResourceType* type /* out */, | |
1797 const char* publicId) | |
1798 { | |
1799 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1800 | |
1801 try | |
1802 { | |
1803 t->GetOutput().Clear(); | |
1804 | |
1805 if (t->GetBackend().LookupResource(*id, *type, t->GetManager(), publicId)) | |
1806 { | |
1807 *isExisting = 1; | |
1808 } | |
1809 else | |
1810 { | |
1811 *isExisting = 0; | |
1812 } | |
1813 | |
1814 return OrthancPluginErrorCode_Success; | |
1815 } | |
1816 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1817 } | |
1818 | |
1819 | |
1820 static OrthancPluginErrorCode LookupResources(OrthancPluginDatabaseTransaction* transaction, | |
1821 uint32_t constraintsCount, | |
1822 const OrthancPluginDatabaseConstraint* constraints, | |
1823 OrthancPluginResourceType queryLevel, | |
1824 uint32_t limit, | |
1825 uint8_t requestSomeInstanceId) | |
1826 { | |
1827 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1828 | |
1829 try | |
1830 { | |
1831 t->GetOutput().Clear(); | |
1832 | |
1833 std::vector<Orthanc::DatabaseConstraint> lookup; | |
1834 lookup.reserve(constraintsCount); | |
1835 | |
1836 for (uint32_t i = 0; i < constraintsCount; i++) | |
1837 { | |
1838 lookup.push_back(Orthanc::DatabaseConstraint(constraints[i])); | |
1839 } | |
1840 | |
1841 t->GetBackend().LookupResources(t->GetOutput(), t->GetManager(), lookup, queryLevel, limit, (requestSomeInstanceId != 0)); | |
1842 return OrthancPluginErrorCode_Success; | |
1843 } | |
1844 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1845 } | |
1846 | |
1847 | |
1848 static OrthancPluginErrorCode LookupResourceAndParent(OrthancPluginDatabaseTransaction* transaction, | |
1849 uint8_t* isExisting /* out */, | |
1850 int64_t* id /* out */, | |
1851 OrthancPluginResourceType* type /* out */, | |
1852 const char* publicId) | |
1853 { | |
1854 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1855 | |
1856 try | |
1857 { | |
1858 t->GetOutput().Clear(); | |
1859 | |
1860 std::string parent; | |
1861 if (t->GetBackend().LookupResourceAndParent(*id, *type, parent, t->GetManager(), publicId)) | |
1862 { | |
1863 *isExisting = 1; | |
1864 | |
1865 if (!parent.empty()) | |
1866 { | |
1867 t->GetOutput().AnswerString(parent); | |
1868 } | |
1869 } | |
1870 else | |
1871 { | |
1872 *isExisting = 0; | |
1873 } | |
1874 | |
1875 return OrthancPluginErrorCode_Success; | |
1876 } | |
1877 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1878 } | |
1879 | |
1880 | |
1881 static OrthancPluginErrorCode SelectPatientToRecycle(OrthancPluginDatabaseTransaction* transaction, | |
1882 uint8_t* patientAvailable, | |
1883 int64_t* patientId) | |
1884 { | |
1885 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1886 | |
1887 try | |
1888 { | |
1889 t->GetOutput().Clear(); | |
1890 | |
1891 if (t->GetBackend().SelectPatientToRecycle(*patientId, t->GetManager())) | |
1892 { | |
1893 *patientAvailable = 1; | |
1894 } | |
1895 else | |
1896 { | |
1897 *patientAvailable = 0; | |
1898 } | |
1899 | |
1900 return OrthancPluginErrorCode_Success; | |
1901 } | |
1902 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1903 } | |
1904 | |
1905 | |
1906 static OrthancPluginErrorCode SelectPatientToRecycle2(OrthancPluginDatabaseTransaction* transaction, | |
1907 uint8_t* patientAvailable, | |
1908 int64_t* patientId, | |
1909 int64_t patientIdToAvoid) | |
1910 { | |
1911 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1912 | |
1913 try | |
1914 { | |
1915 t->GetOutput().Clear(); | |
1916 | |
1917 if (t->GetBackend().SelectPatientToRecycle(*patientId, t->GetManager(), patientIdToAvoid)) | |
1918 { | |
1919 *patientAvailable = 1; | |
1920 } | |
1921 else | |
1922 { | |
1923 *patientAvailable = 0; | |
1924 } | |
1925 | |
1926 return OrthancPluginErrorCode_Success; | |
1927 } | |
1928 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1929 } | |
1930 | |
1931 | |
1932 static OrthancPluginErrorCode SetGlobalProperty(OrthancPluginDatabaseTransaction* transaction, | |
1933 const char* serverIdentifier, | |
1934 int32_t property, | |
1935 const char* value) | |
1936 { | |
1937 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1938 | |
1939 try | |
1940 { | |
1941 t->GetOutput().Clear(); | |
1942 t->GetBackend().SetGlobalProperty(t->GetManager(), serverIdentifier, property, value); | |
1943 return OrthancPluginErrorCode_Success; | |
1944 } | |
1945 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1946 } | |
1947 | |
1948 | |
1949 static OrthancPluginErrorCode SetMetadata(OrthancPluginDatabaseTransaction* transaction, | |
1950 int64_t id, | |
1951 int32_t metadata, | |
1952 const char* value, | |
1953 int64_t revision) | |
1954 { | |
1955 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1956 | |
1957 try | |
1958 { | |
1959 t->GetOutput().Clear(); | |
1960 t->GetBackend().SetMetadata(t->GetManager(), id, metadata, value, revision); | |
1961 return OrthancPluginErrorCode_Success; | |
1962 } | |
1963 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1964 } | |
1965 | |
1966 | |
1967 static OrthancPluginErrorCode SetProtectedPatient(OrthancPluginDatabaseTransaction* transaction, | |
1968 int64_t id, | |
1969 uint8_t isProtected) | |
1970 { | |
1971 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1972 | |
1973 try | |
1974 { | |
1975 t->GetOutput().Clear(); | |
1976 t->GetBackend().SetProtectedPatient(t->GetManager(), id, (isProtected != 0)); | |
1977 return OrthancPluginErrorCode_Success; | |
1978 } | |
1979 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
1980 } | |
1981 | |
1982 | |
1983 static OrthancPluginErrorCode SetResourcesContent(OrthancPluginDatabaseTransaction* transaction, | |
1984 uint32_t countIdentifierTags, | |
1985 const OrthancPluginResourcesContentTags* identifierTags, | |
1986 uint32_t countMainDicomTags, | |
1987 const OrthancPluginResourcesContentTags* mainDicomTags, | |
1988 uint32_t countMetadata, | |
1989 const OrthancPluginResourcesContentMetadata* metadata) | |
1990 { | |
1991 DatabaseBackendAdapterV4::Transaction* t = reinterpret_cast<DatabaseBackendAdapterV4::Transaction*>(transaction); | |
1992 | |
1993 try | |
1994 { | |
1995 t->GetOutput().Clear(); | |
1996 t->GetBackend().SetResourcesContent(t->GetManager(), countIdentifierTags, identifierTags, | |
1997 countMainDicomTags, mainDicomTags, countMetadata, metadata); | |
1998 return OrthancPluginErrorCode_Success; | |
1999 } | |
2000 ORTHANC_PLUGINS_DATABASE_CATCH(t->GetBackend().GetContext()); | |
2001 } | |
2002 | |
2003 | |
2004 void DatabaseBackendAdapterV4::Register(IndexBackend* backend, | 1451 void DatabaseBackendAdapterV4::Register(IndexBackend* backend, |
2005 size_t countConnections, | 1452 size_t countConnections, |
2006 unsigned int maxDatabaseRetries) | 1453 unsigned int maxDatabaseRetries) |
2007 { | 1454 { |
1455 std::unique_ptr<IndexConnectionsPool> pool(new IndexConnectionsPool(backend, countConnections)); | |
1456 | |
2008 if (isBackendInUse_) | 1457 if (isBackendInUse_) |
2009 { | 1458 { |
2010 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 1459 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
2011 } | 1460 } |
2012 | |
2013 if (backend == NULL) | |
2014 { | |
2015 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
2016 } | |
2017 | |
2018 OrthancPluginDatabaseBackendV4 params; | |
2019 memset(¶ms, 0, sizeof(params)); | |
2020 | |
2021 params.readAnswersCount = ReadAnswersCount; | |
2022 params.readAnswerAttachment2 = ReadAnswerAttachment2; | |
2023 params.readAnswerChange = ReadAnswerChange; | |
2024 params.readAnswerDicomTag = ReadAnswerDicomTag; | |
2025 params.readAnswerExportedResource = ReadAnswerExportedResource; | |
2026 params.readAnswerInt32 = ReadAnswerInt32; | |
2027 params.readAnswerInt64 = ReadAnswerInt64; | |
2028 params.readAnswerMatchingResource = ReadAnswerMatchingResource; | |
2029 params.readAnswerMetadata = ReadAnswerMetadata; | |
2030 params.readAnswerString = ReadAnswerString; | |
2031 | |
2032 params.readEventsCount = ReadEventsCount; | |
2033 params.readEvent2 = ReadEvent2; | |
2034 | |
2035 params.open = Open; | |
2036 params.close = Close; | |
2037 params.destructDatabase = DestructDatabase; | |
2038 params.getDatabaseVersion = GetDatabaseVersion; | |
2039 params.upgradeDatabase = UpgradeDatabase; | |
2040 params.hasRevisionsSupport = HasRevisionsSupport; | |
2041 params.hasAttachmentCustomDataSupport = HasAttachmentCustomDataSupport; | |
2042 params.startTransaction = StartTransaction; | |
2043 params.destructTransaction = DestructTransaction; | |
2044 params.rollback = Rollback; | |
2045 params.commit = Commit; | |
2046 | |
2047 params.addAttachment2 = AddAttachment2; | |
2048 params.clearChanges = ClearChanges; | |
2049 params.clearExportedResources = ClearExportedResources; | |
2050 params.clearMainDicomTags = ClearMainDicomTags; | |
2051 params.createInstance = CreateInstance; | |
2052 params.deleteAttachment = DeleteAttachment; | |
2053 params.deleteMetadata = DeleteMetadata; | |
2054 params.deleteResource = DeleteResource; | |
2055 params.getAllMetadata = GetAllMetadata; | |
2056 params.getAllPublicIds = GetAllPublicIds; | |
2057 params.getAllPublicIdsWithLimit = GetAllPublicIdsWithLimit; | |
2058 params.getChanges = GetChanges; | |
2059 params.getChildrenInternalId = GetChildrenInternalId; | |
2060 params.getChildrenMetadata = GetChildrenMetadata; | |
2061 params.getChildrenPublicId = GetChildrenPublicId; | |
2062 params.getExportedResources = GetExportedResources; | |
2063 params.getLastChange = GetLastChange; | |
2064 params.getLastChangeIndex = GetLastChangeIndex; | |
2065 params.getLastExportedResource = GetLastExportedResource; | |
2066 params.getMainDicomTags = GetMainDicomTags; | |
2067 params.getPublicId = GetPublicId; | |
2068 params.getResourceType = GetResourceType; | |
2069 params.getResourcesCount = GetResourcesCount; | |
2070 params.getTotalCompressedSize = GetTotalCompressedSize; | |
2071 params.getTotalUncompressedSize = GetTotalUncompressedSize; | |
2072 params.isDiskSizeAbove = IsDiskSizeAbove; | |
2073 params.isExistingResource = IsExistingResource; | |
2074 params.isProtectedPatient = IsProtectedPatient; | |
2075 params.listAvailableAttachments = ListAvailableAttachments; | |
2076 params.logChange = LogChange; | |
2077 params.logExportedResource = LogExportedResource; | |
2078 params.lookupAttachment = LookupAttachment; | |
2079 params.lookupGlobalProperty = LookupGlobalProperty; | |
2080 params.lookupMetadata = LookupMetadata; | |
2081 params.lookupParent = LookupParent; | |
2082 params.lookupResource = LookupResource; | |
2083 params.lookupResourceAndParent = LookupResourceAndParent; | |
2084 params.lookupResources = LookupResources; | |
2085 params.selectPatientToRecycle = SelectPatientToRecycle; | |
2086 params.selectPatientToRecycle2 = SelectPatientToRecycle2; | |
2087 params.setGlobalProperty = SetGlobalProperty; | |
2088 params.setMetadata = SetMetadata; | |
2089 params.setProtectedPatient = SetProtectedPatient; | |
2090 params.setResourcesContent = SetResourcesContent; | |
2091 | 1461 |
2092 OrthancPluginContext* context = backend->GetContext(); | 1462 OrthancPluginContext* context = backend->GetContext(); |
2093 | 1463 |
2094 if (OrthancPluginRegisterDatabaseBackendV4( | 1464 if (OrthancPluginRegisterDatabaseBackendV4(context, pool.release(), maxDatabaseRetries, |
2095 context, ¶ms, sizeof(params), maxDatabaseRetries, | 1465 CallBackend, FinalizeBackend) != OrthancPluginErrorCode_Success) |
2096 new Adapter(backend, countConnections)) != OrthancPluginErrorCode_Success) | 1466 { |
2097 { | 1467 delete backend; |
2098 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Unable to register the database backend"); | 1468 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Unable to register the database backend"); |
2099 } | 1469 } |
2100 | |
2101 backend->SetOutputFactory(new Factory); | |
2102 | 1470 |
2103 isBackendInUse_ = true; | 1471 isBackendInUse_ = true; |
2104 } | 1472 } |
2105 | 1473 |
2106 | 1474 |
2107 void DatabaseBackendAdapterV4::Finalize() | 1475 void DatabaseBackendAdapterV4::Finalize() |
2108 { | 1476 { |
2109 if (isBackendInUse_) | 1477 if (isBackendInUse_) |
2110 { | 1478 { |
2111 fprintf(stderr, "The Orthanc core has not destructed the index backend, internal error\n"); | 1479 LOG(ERROR) << "The Orthanc core has not destructed the index backend, internal error"; |
2112 } | 1480 } |
2113 } | 1481 } |
2114 } | 1482 } |
2115 | 1483 |
2116 # endif | 1484 # endif |