mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +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
|
@ -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 );
|
||||
|
|
25
include/backends/backend_version.hpp
Normal file
25
include/backends/backend_version.hpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idAA27B58429DB41C2AF53204CC5010E94
|
||||
#define idAA27B58429DB41C2AF53204CC5010E94
|
||||
|
||||
namespace dindb {
|
||||
constexpr const int g_current_iface_version = 1;
|
||||
} //namespace dindb
|
||||
|
||||
#endif
|
|
@ -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
|
||||
|
|
|
@ -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…
Reference in a new issue