comparison OrthancServer/Plugins/Engine/OrthancPlugins.cpp @ 5207:e7529e6241d2 db-protobuf

first successful protobuf communication
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 Mar 2023 21:31:56 +0200
parents 0ea402b4d901
children 9504de20d43d f2e1ad71e49c
comparison
equal deleted inserted replaced
5206:fb3add662286 5207:e7529e6241d2
61 #include "../../Sources/Search/HierarchicalMatcher.h" 61 #include "../../Sources/Search/HierarchicalMatcher.h"
62 #include "../../Sources/ServerContext.h" 62 #include "../../Sources/ServerContext.h"
63 #include "../../Sources/ServerToolbox.h" 63 #include "../../Sources/ServerToolbox.h"
64 #include "OrthancPluginDatabase.h" 64 #include "OrthancPluginDatabase.h"
65 #include "OrthancPluginDatabaseV3.h" 65 #include "OrthancPluginDatabaseV3.h"
66 #include "OrthancPluginDatabaseV4.h"
66 #include "PluginsEnumerations.h" 67 #include "PluginsEnumerations.h"
67 #include "PluginsJob.h" 68 #include "PluginsJob.h"
68 69
69 #include <boost/regex.hpp> 70 #include <boost/regex.hpp>
70 #include <dcmtk/dcmdata/dcdict.h> 71 #include <dcmtk/dcmdata/dcdict.h>
1542 boost::shared_mutex incomingHttpRequestFilterMutex_; // New in Orthanc 1.8.2 1543 boost::shared_mutex incomingHttpRequestFilterMutex_; // New in Orthanc 1.8.2
1543 1544
1544 Properties properties_; 1545 Properties properties_;
1545 int argc_; 1546 int argc_;
1546 char** argv_; 1547 char** argv_;
1547 std::unique_ptr<OrthancPluginDatabase> database_; 1548 std::unique_ptr<OrthancPluginDatabase> database_;
1548 std::unique_ptr<OrthancPluginDatabaseV3> databaseV3_; // New in Orthanc 1.9.2 1549 std::unique_ptr<OrthancPluginDatabaseV3> databaseV3_; // New in Orthanc 1.9.2
1550 std::unique_ptr<OrthancPluginDatabaseV4> databaseV4_; // New in Orthanc 1.12.0
1549 PluginsErrorDictionary dictionary_; 1551 PluginsErrorDictionary dictionary_;
1550 std::string databaseServerIdentifier_; // New in Orthanc 1.9.2 1552 std::string databaseServerIdentifier_; // New in Orthanc 1.9.2
1551 unsigned int maxDatabaseRetries_; // New in Orthanc 1.9.2 1553 unsigned int maxDatabaseRetries_; // New in Orthanc 1.9.2
1552 1554
1553 explicit PImpl(const std::string& databaseServerIdentifier) : 1555 explicit PImpl(const std::string& databaseServerIdentifier) :
5485 } 5487 }
5486 } 5488 }
5487 5489
5488 case _OrthancPluginService_RegisterDatabaseBackend: 5490 case _OrthancPluginService_RegisterDatabaseBackend:
5489 { 5491 {
5490 LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API"; 5492 LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API (version 1)";
5491 LOG(WARNING) << "The database backend has *no* support for revisions of metadata and attachments"; 5493 LOG(WARNING) << "The database backend has *no* support for revisions of metadata and attachments";
5492 5494
5493 const _OrthancPluginRegisterDatabaseBackend& p = 5495 const _OrthancPluginRegisterDatabaseBackend& p =
5494 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackend*>(parameters); 5496 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackend*>(parameters);
5495 5497
5496 if (pimpl_->database_.get() == NULL && 5498 if (pimpl_->database_.get() == NULL &&
5497 pimpl_->databaseV3_.get() == NULL) 5499 pimpl_->databaseV3_.get() == NULL &&
5500 pimpl_->databaseV4_.get() == NULL)
5498 { 5501 {
5499 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), 5502 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(),
5500 *p.backend, NULL, 0, p.payload)); 5503 *p.backend, NULL, 0, p.payload));
5501 } 5504 }
5502 else 5505 else
5509 return true; 5512 return true;
5510 } 5513 }
5511 5514
5512 case _OrthancPluginService_RegisterDatabaseBackendV2: 5515 case _OrthancPluginService_RegisterDatabaseBackendV2:
5513 { 5516 {
5514 LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API"; 5517 LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API (version 2)";
5515 LOG(WARNING) << "The database backend has *no* support for revisions of metadata and attachments"; 5518 LOG(WARNING) << "The database backend has *no* support for revisions of metadata and attachments";
5516 5519
5517 const _OrthancPluginRegisterDatabaseBackendV2& p = 5520 const _OrthancPluginRegisterDatabaseBackendV2& p =
5518 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV2*>(parameters); 5521 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV2*>(parameters);
5519 5522
5520 if (pimpl_->database_.get() == NULL && 5523 if (pimpl_->database_.get() == NULL &&
5521 pimpl_->databaseV3_.get() == NULL) 5524 pimpl_->databaseV3_.get() == NULL &&
5525 pimpl_->databaseV4_.get() == NULL)
5522 { 5526 {
5523 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), 5527 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(),
5524 *p.backend, p.extensions, 5528 *p.backend, p.extensions,
5525 p.extensionsSize, p.payload)); 5529 p.extensionsSize, p.payload));
5526 } 5530 }
5534 return true; 5538 return true;
5535 } 5539 }
5536 5540
5537 case _OrthancPluginService_RegisterDatabaseBackendV3: 5541 case _OrthancPluginService_RegisterDatabaseBackendV3:
5538 { 5542 {
5539 CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end"; 5543 LOG(WARNING) << "Performance warning: Plugin has registered a custom database back-end with an old API (version 3)";
5540 5544
5541 const _OrthancPluginRegisterDatabaseBackendV3& p = 5545 const _OrthancPluginRegisterDatabaseBackendV3& p =
5542 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV3*>(parameters); 5546 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV3*>(parameters);
5543 5547
5544 if (pimpl_->database_.get() == NULL && 5548 if (pimpl_->database_.get() == NULL &&
5545 pimpl_->databaseV3_.get() == NULL) 5549 pimpl_->databaseV3_.get() == NULL &&
5550 pimpl_->databaseV4_.get() == NULL)
5546 { 5551 {
5547 pimpl_->databaseV3_.reset(new OrthancPluginDatabaseV3(plugin, GetErrorDictionary(), p.backend, 5552 pimpl_->databaseV3_.reset(new OrthancPluginDatabaseV3(plugin, GetErrorDictionary(), p.backend,
5548 p.backendSize, p.database, pimpl_->databaseServerIdentifier_)); 5553 p.backendSize, p.database, pimpl_->databaseServerIdentifier_));
5554 pimpl_->maxDatabaseRetries_ = p.maxDatabaseRetries;
5555 }
5556 else
5557 {
5558 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered);
5559 }
5560
5561 return true;
5562 }
5563
5564 case _OrthancPluginService_RegisterDatabaseBackendV4:
5565 {
5566 CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end";
5567
5568 const _OrthancPluginRegisterDatabaseBackendV4& p =
5569 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV4*>(parameters);
5570
5571 if (pimpl_->database_.get() == NULL &&
5572 pimpl_->databaseV3_.get() == NULL &&
5573 pimpl_->databaseV4_.get() == NULL)
5574 {
5575 pimpl_->databaseV4_.reset(new OrthancPluginDatabaseV4(plugin, GetErrorDictionary(), p, pimpl_->databaseServerIdentifier_));
5549 pimpl_->maxDatabaseRetries_ = p.maxDatabaseRetries; 5576 pimpl_->maxDatabaseRetries_ = p.maxDatabaseRetries;
5550 } 5577 }
5551 else 5578 else
5552 { 5579 {
5553 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered); 5580 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered);
5693 5720
5694 bool OrthancPlugins::HasDatabaseBackend() const 5721 bool OrthancPlugins::HasDatabaseBackend() const
5695 { 5722 {
5696 boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_); 5723 boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_);
5697 return (pimpl_->database_.get() != NULL || 5724 return (pimpl_->database_.get() != NULL ||
5698 pimpl_->databaseV3_.get() != NULL); 5725 pimpl_->databaseV3_.get() != NULL ||
5726 pimpl_->databaseV4_.get() != NULL);
5699 } 5727 }
5700 5728
5701 5729
5702 IStorageArea* OrthancPlugins::CreateStorageArea() 5730 IStorageArea* OrthancPlugins::CreateStorageArea()
5703 { 5731 {
5733 } 5761 }
5734 else if (pimpl_->databaseV3_.get() != NULL) 5762 else if (pimpl_->databaseV3_.get() != NULL)
5735 { 5763 {
5736 return *pimpl_->databaseV3_; 5764 return *pimpl_->databaseV3_;
5737 } 5765 }
5766 else if (pimpl_->databaseV4_.get() != NULL)
5767 {
5768 return *pimpl_->databaseV4_;
5769 }
5738 else 5770 else
5739 { 5771 {
5740 throw OrthancException(ErrorCode_BadSequenceOfCalls); 5772 throw OrthancException(ErrorCode_BadSequenceOfCalls);
5741 } 5773 }
5742 } 5774 }
5749 return pimpl_->database_->GetSharedLibrary(); 5781 return pimpl_->database_->GetSharedLibrary();
5750 } 5782 }
5751 else if (pimpl_->databaseV3_.get() != NULL) 5783 else if (pimpl_->databaseV3_.get() != NULL)
5752 { 5784 {
5753 return pimpl_->databaseV3_->GetSharedLibrary(); 5785 return pimpl_->databaseV3_->GetSharedLibrary();
5786 }
5787 else if (pimpl_->databaseV4_.get() != NULL)
5788 {
5789 return pimpl_->databaseV4_->GetSharedLibrary();
5754 } 5790 }
5755 else 5791 else
5756 { 5792 {
5757 throw OrthancException(ErrorCode_BadSequenceOfCalls); 5793 throw OrthancException(ErrorCode_BadSequenceOfCalls);
5758 } 5794 }