mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-08-14 14:49:48 +00:00
Add a backend interface version number for eventual future changes.
Note that the interface is still a work in progress and might change while still keeping the same interface version. This is going to be true until the first stable release of this project (non beta).
This commit is contained in:
parent
0cb91fb9ca
commit
e2275ce5db
5 changed files with 56 additions and 1 deletions
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "backends/backend_loader.hpp"
|
||||
#include "backends/exposed_functions.hpp"
|
||||
#include "backends/backend_version.hpp"
|
||||
#include <dlfcn.h>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
|
@ -50,6 +51,13 @@ namespace dindb {
|
|||
|
||||
void nop_destroy (Backend*) {
|
||||
}
|
||||
|
||||
int backend_iface_version (void* parSOHandle) {
|
||||
typedef decltype(&dindexer_backend_iface_version) GetVersionFun;
|
||||
|
||||
auto get_version = reinterpret_cast<GetVersionFun>(dlsym(parSOHandle, "dindexer_backend_iface_version"));
|
||||
return get_version();
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
std::string backend_name (const std::string& parSOPath) {
|
||||
|
@ -70,8 +78,13 @@ namespace dindb {
|
|||
BackendPlugin::BackendPlugin (const std::string& parSOPath, const YAML::Node* parConfig) :
|
||||
m_lib(dlopen(parSOPath.c_str(), RTLD_LAZY), &dlclose),
|
||||
m_backend(load_backend(m_lib.get(), parConfig)),
|
||||
m_name(backend_name(m_lib.get()))
|
||||
m_name(backend_name(m_lib.get())),
|
||||
m_iface_ver(backend_iface_version(m_lib.get()))
|
||||
{
|
||||
if (g_current_iface_version != m_iface_ver) {
|
||||
m_backend.reset();
|
||||
m_lib.reset();
|
||||
}
|
||||
}
|
||||
|
||||
BackendPlugin::~BackendPlugin() noexcept {
|
||||
|
@ -104,4 +117,12 @@ namespace dindb {
|
|||
bool BackendPlugin::is_loaded() const {
|
||||
return static_cast<bool>(m_backend);
|
||||
}
|
||||
|
||||
int BackendPlugin::backend_interface_version() const {
|
||||
return m_iface_ver;
|
||||
}
|
||||
|
||||
int BackendPlugin::max_supported_interface_version() const {
|
||||
return g_current_iface_version;
|
||||
}
|
||||
} //namespace dindb
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "backend_postgresql.hpp"
|
||||
#include "backends/exposed_functions.hpp"
|
||||
#include "backends/backend_version.hpp"
|
||||
#include "tag.hpp"
|
||||
#include "delete.hpp"
|
||||
#include "scan.hpp"
|
||||
|
@ -179,3 +180,7 @@ extern "C" void dindexer_destroy_backend (dindb::Backend* parDele) {
|
|||
extern "C" const char* dindexer_backend_name() {
|
||||
return "postgresql";
|
||||
}
|
||||
|
||||
extern "C" int dindexer_backend_iface_version() {
|
||||
return dindb::g_current_iface_version;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue