Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Engine/OrthancPlugins.cpp @ 4595:cc64385593ef db-changes
added OrthancPluginRegisterDatabaseBackendV3() to plugin sdk
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 16 Mar 2021 17:58:16 +0100 |
parents | ff8170d17d90 |
children | c125bfd31023 |
comparison
equal
deleted
inserted
replaced
4594:d494b4f1103e | 4595:cc64385593ef |
---|---|
69 #include "../../Sources/OrthancConfiguration.h" | 69 #include "../../Sources/OrthancConfiguration.h" |
70 #include "../../Sources/OrthancFindRequestHandler.h" | 70 #include "../../Sources/OrthancFindRequestHandler.h" |
71 #include "../../Sources/Search/HierarchicalMatcher.h" | 71 #include "../../Sources/Search/HierarchicalMatcher.h" |
72 #include "../../Sources/ServerContext.h" | 72 #include "../../Sources/ServerContext.h" |
73 #include "../../Sources/ServerToolbox.h" | 73 #include "../../Sources/ServerToolbox.h" |
74 #include "OrthancPluginDatabase.h" | |
75 #include "OrthancPluginDatabaseV3.h" | |
74 #include "PluginsEnumerations.h" | 76 #include "PluginsEnumerations.h" |
75 #include "PluginsJob.h" | 77 #include "PluginsJob.h" |
76 | 78 |
77 #include <boost/regex.hpp> | 79 #include <boost/regex.hpp> |
78 #include <dcmtk/dcmdata/dcdict.h> | 80 #include <dcmtk/dcmdata/dcdict.h> |
1189 | 1191 |
1190 Properties properties_; | 1192 Properties properties_; |
1191 int argc_; | 1193 int argc_; |
1192 char** argv_; | 1194 char** argv_; |
1193 std::unique_ptr<OrthancPluginDatabase> database_; | 1195 std::unique_ptr<OrthancPluginDatabase> database_; |
1196 std::unique_ptr<OrthancPluginDatabaseV3> databaseV3_; // New in Orthanc 1.10.0 | |
1194 PluginsErrorDictionary dictionary_; | 1197 PluginsErrorDictionary dictionary_; |
1195 | 1198 |
1196 PImpl() : | 1199 PImpl() : |
1197 context_(NULL), | 1200 context_(NULL), |
1198 findCallback_(NULL), | 1201 findCallback_(NULL), |
4884 } | 4887 } |
4885 } | 4888 } |
4886 | 4889 |
4887 case _OrthancPluginService_RegisterDatabaseBackend: | 4890 case _OrthancPluginService_RegisterDatabaseBackend: |
4888 { | 4891 { |
4892 // TODO - WARN ABOUT PERFORMANCE | |
4893 | |
4889 CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end"; | 4894 CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end"; |
4890 | 4895 |
4891 const _OrthancPluginRegisterDatabaseBackend& p = | 4896 const _OrthancPluginRegisterDatabaseBackend& p = |
4892 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackend*>(parameters); | 4897 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackend*>(parameters); |
4893 | 4898 |
4894 if (pimpl_->database_.get() == NULL) | 4899 if (pimpl_->database_.get() == NULL && |
4900 pimpl_->databaseV3_.get() == NULL) | |
4895 { | 4901 { |
4896 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), | 4902 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), |
4897 *p.backend, NULL, 0, p.payload)); | 4903 *p.backend, NULL, 0, p.payload)); |
4898 } | 4904 } |
4899 else | 4905 else |
4906 return true; | 4912 return true; |
4907 } | 4913 } |
4908 | 4914 |
4909 case _OrthancPluginService_RegisterDatabaseBackendV2: | 4915 case _OrthancPluginService_RegisterDatabaseBackendV2: |
4910 { | 4916 { |
4917 // TODO - WARN ABOUT PERFORMANCE | |
4918 | |
4911 CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end"; | 4919 CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end"; |
4912 | 4920 |
4913 const _OrthancPluginRegisterDatabaseBackendV2& p = | 4921 const _OrthancPluginRegisterDatabaseBackendV2& p = |
4914 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV2*>(parameters); | 4922 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV2*>(parameters); |
4915 | 4923 |
4916 if (pimpl_->database_.get() == NULL) | 4924 if (pimpl_->database_.get() == NULL && |
4925 pimpl_->databaseV3_.get() == NULL) | |
4917 { | 4926 { |
4918 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), | 4927 pimpl_->database_.reset(new OrthancPluginDatabase(plugin, GetErrorDictionary(), |
4919 *p.backend, p.extensions, | 4928 *p.backend, p.extensions, |
4920 p.extensionsSize, p.payload)); | 4929 p.extensionsSize, p.payload)); |
4921 } | 4930 } |
4923 { | 4932 { |
4924 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered); | 4933 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered); |
4925 } | 4934 } |
4926 | 4935 |
4927 *(p.result) = reinterpret_cast<OrthancPluginDatabaseContext*>(pimpl_->database_.get()); | 4936 *(p.result) = reinterpret_cast<OrthancPluginDatabaseContext*>(pimpl_->database_.get()); |
4937 | |
4938 return true; | |
4939 } | |
4940 | |
4941 case _OrthancPluginService_RegisterDatabaseBackendV3: | |
4942 { | |
4943 CLOG(INFO, PLUGINS) << "Plugin has registered a custom database back-end"; | |
4944 | |
4945 const _OrthancPluginRegisterDatabaseBackendV3& p = | |
4946 *reinterpret_cast<const _OrthancPluginRegisterDatabaseBackendV3*>(parameters); | |
4947 | |
4948 if (pimpl_->database_.get() == NULL && | |
4949 pimpl_->databaseV3_.get() == NULL) | |
4950 { | |
4951 pimpl_->databaseV3_.reset(new OrthancPluginDatabaseV3(plugin, GetErrorDictionary(), | |
4952 p.backend, p.backendSize, p.database)); | |
4953 } | |
4954 else | |
4955 { | |
4956 throw OrthancException(ErrorCode_DatabaseBackendAlreadyRegistered); | |
4957 } | |
4928 | 4958 |
4929 return true; | 4959 return true; |
4930 } | 4960 } |
4931 | 4961 |
4932 case _OrthancPluginService_DatabaseAnswer: | 4962 case _OrthancPluginService_DatabaseAnswer: |
5046 } | 5076 } |
5047 | 5077 |
5048 bool OrthancPlugins::HasDatabaseBackend() const | 5078 bool OrthancPlugins::HasDatabaseBackend() const |
5049 { | 5079 { |
5050 boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_); | 5080 boost::recursive_mutex::scoped_lock lock(pimpl_->invokeServiceMutex_); |
5051 return pimpl_->database_.get() != NULL; | 5081 return (pimpl_->database_.get() != NULL || |
5082 pimpl_->databaseV3_.get() != NULL); | |
5052 } | 5083 } |
5053 | 5084 |
5054 | 5085 |
5055 IStorageArea* OrthancPlugins::CreateStorageArea() | 5086 IStorageArea* OrthancPlugins::CreateStorageArea() |
5056 { | 5087 { |
5078 } | 5109 } |
5079 | 5110 |
5080 | 5111 |
5081 IDatabaseWrapper& OrthancPlugins::GetDatabaseBackend() | 5112 IDatabaseWrapper& OrthancPlugins::GetDatabaseBackend() |
5082 { | 5113 { |
5083 if (!HasDatabaseBackend()) | 5114 if (pimpl_->database_.get() != NULL) |
5115 { | |
5116 return *pimpl_->database_; | |
5117 } | |
5118 else if (pimpl_->databaseV3_.get() != NULL) | |
5119 { | |
5120 return *pimpl_->databaseV3_; | |
5121 } | |
5122 else | |
5084 { | 5123 { |
5085 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 5124 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
5086 } | 5125 } |
5126 } | |
5127 | |
5128 | |
5129 const SharedLibrary& OrthancPlugins::GetDatabaseBackendLibrary() const | |
5130 { | |
5131 if (pimpl_->database_.get() != NULL) | |
5132 { | |
5133 return pimpl_->database_->GetSharedLibrary(); | |
5134 } | |
5135 else if (pimpl_->databaseV3_.get() != NULL) | |
5136 { | |
5137 return pimpl_->databaseV3_->GetSharedLibrary(); | |
5138 } | |
5087 else | 5139 else |
5088 { | 5140 { |
5089 return *pimpl_->database_; | |
5090 } | |
5091 } | |
5092 | |
5093 | |
5094 const SharedLibrary& OrthancPlugins::GetDatabaseBackendLibrary() const | |
5095 { | |
5096 if (!HasDatabaseBackend()) | |
5097 { | |
5098 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 5141 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
5099 } | |
5100 else | |
5101 { | |
5102 return pimpl_->database_->GetSharedLibrary(); | |
5103 } | 5142 } |
5104 } | 5143 } |
5105 | 5144 |
5106 | 5145 |
5107 const char* OrthancPlugins::GetProperty(const char* plugin, | 5146 const char* OrthancPlugins::GetProperty(const char* plugin, |