From e2275ce5dbc3d1558185fc6b3f2d6bde7a01d49b Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 2 Jun 2016 10:01:19 +0200 Subject: [PATCH] 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). --- include/backends/backend_loader.hpp | 3 +++ include/backends/backend_version.hpp | 25 +++++++++++++++++++ include/backends/exposed_functions.hpp | 1 + src/backends/backend_loader.cpp | 23 ++++++++++++++++- .../postgresql/backend_postgresql.cpp | 5 ++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 include/backends/backend_version.hpp diff --git a/include/backends/backend_loader.hpp b/include/backends/backend_loader.hpp index 70bb592..7795d0c 100644 --- a/include/backends/backend_loader.hpp +++ b/include/backends/backend_loader.hpp @@ -42,6 +42,8 @@ namespace dindb { Backend& backend ( void ); const Backend& backend ( void ) const; bool is_loaded ( void ) const; + int backend_interface_version ( void ) const; + int max_supported_interface_version ( void ) const; BackendPlugin& operator= ( BackendPlugin&& ) = default; @@ -51,6 +53,7 @@ namespace dindb { SoHandle m_lib; BackendPtr m_backend; boost::string_ref m_name; + int m_iface_ver; }; std::string backend_name ( const std::string& parSOPath ); diff --git a/include/backends/backend_version.hpp b/include/backends/backend_version.hpp new file mode 100644 index 0000000..8b31e82 --- /dev/null +++ b/include/backends/backend_version.hpp @@ -0,0 +1,25 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#ifndef idAA27B58429DB41C2AF53204CC5010E94 +#define idAA27B58429DB41C2AF53204CC5010E94 + +namespace dindb { + constexpr const int g_current_iface_version = 1; +} //namespace dindb + +#endif diff --git a/include/backends/exposed_functions.hpp b/include/backends/exposed_functions.hpp index a1b21e9..ef174d3 100644 --- a/include/backends/exposed_functions.hpp +++ b/include/backends/exposed_functions.hpp @@ -29,5 +29,6 @@ namespace dindb { extern "C" dindb::Backend* dindexer_create_backend ( const YAML::Node* parConfig ); extern "C" void dindexer_destroy_backend ( dindb::Backend* parDele ); extern "C" const char* dindexer_backend_name ( void ); +extern "C" int dindexer_backend_iface_version ( void ); #endif diff --git a/src/backends/backend_loader.cpp b/src/backends/backend_loader.cpp index a6eba27..3aa8547 100644 --- a/src/backends/backend_loader.cpp +++ b/src/backends/backend_loader.cpp @@ -20,6 +20,7 @@ #include "backends/backend_loader.hpp" #include "backends/exposed_functions.hpp" +#include "backends/backend_version.hpp" #include #include #include @@ -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(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(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 diff --git a/src/backends/postgresql/backend_postgresql.cpp b/src/backends/postgresql/backend_postgresql.cpp index 95e6332..68577ec 100644 --- a/src/backends/postgresql/backend_postgresql.cpp +++ b/src/backends/postgresql/backend_postgresql.cpp @@ -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; +}