mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-08-23 16:10:51 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
2d2c7d0b9e
8 changed files with 66 additions and 17 deletions
|
@ -1,5 +1,14 @@
|
|||
project(${bare_name}-backend CXX)
|
||||
|
||||
set(BACKEND_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
function(ln_backend backend_name)
|
||||
add_custom_command(TARGET "${backend_name}" POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:${backend_name}> ${BACKEND_BINARY_DIR}/$<TARGET_FILE_NAME:${backend_name}>
|
||||
DEPENDS ${BACKEND_BINARY_DIR}/$<TARGET_FILE_NAME:${backend_name}>
|
||||
COMMENT "Creating symlink to ${backend_name}"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC
|
||||
backend_loader.cpp
|
||||
)
|
||||
|
@ -26,6 +35,5 @@ target_link_libraries(${PROJECT_NAME}
|
|||
|
||||
add_subdirectory(postgresql)
|
||||
add_subdirectory(redis)
|
||||
|
||||
add_dependencies(${PROJECT_NAME} ${bare_name}-backend-postgresql)
|
||||
add_dependencies(${PROJECT_NAME} ${bare_name}-backend-redis)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <dlfcn.h>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
|
||||
namespace dindb {
|
||||
namespace {
|
||||
|
@ -34,9 +35,22 @@ namespace dindb {
|
|||
assert(parSOHandle);
|
||||
assert(parConfig);
|
||||
|
||||
auto create = reinterpret_cast<CreateBackendFun>(dlsym(parSOHandle, "dindexer_create_backend"));
|
||||
auto destroy = reinterpret_cast<DeleteBackendFun>(dlsym(parSOHandle, "dindexer_destroy_backend"));
|
||||
const char* const fun_name_create = "dindexer_create_backend";
|
||||
const char* const fun_name_destroy = "dindexer_destroy_backend";
|
||||
|
||||
auto create = reinterpret_cast<CreateBackendFun>(dlsym(parSOHandle, fun_name_create));
|
||||
auto destroy = reinterpret_cast<DeleteBackendFun>(dlsym(parSOHandle, fun_name_destroy));
|
||||
|
||||
if (not create) {
|
||||
std::ostringstream oss;
|
||||
oss << "Unable to find function " << fun_name_create;
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
if (not destroy) {
|
||||
std::ostringstream oss;
|
||||
oss << "Unable to find function " << fun_name_destroy;
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
return BackendPtr(create(parConfig), destroy);
|
||||
}
|
||||
|
||||
|
@ -65,7 +79,10 @@ namespace dindb {
|
|||
using SoHandle = std::unique_ptr<void, int(*)(void*)>;
|
||||
|
||||
auto handle = SoHandle(dlopen(parSOPath.c_str(), RTLD_LAZY), &dlclose);
|
||||
return backend_name(handle.get());
|
||||
if (handle)
|
||||
return backend_name(handle.get());
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
BackendPlugin::BackendPlugin() :
|
||||
|
|
|
@ -23,3 +23,4 @@ install(TARGETS ${PROJECT_NAME}
|
|||
RUNTIME DESTINATION bin
|
||||
ARCHIVE DESTINATION lib/static
|
||||
)
|
||||
ln_backend(${PROJECT_NAME})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue