From dc74ee0cb34b86d6fe70850db72fa8179ce54b28 Mon Sep 17 00:00:00 2001 From: Philipp Geier Date: Mon, 18 Mar 2024 09:44:58 +0100 Subject: [PATCH] Proposal to create an FDB instance from config path via C-API (for pyfdb) --- src/fdb5/api/FDB.cc | 2 ++ src/fdb5/api/fdb_c.cc | 6 ++++++ src/fdb5/api/fdb_c.h | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/fdb5/api/FDB.cc b/src/fdb5/api/FDB.cc index f04547e36..0e3ed3d27 100644 --- a/src/fdb5/api/FDB.cc +++ b/src/fdb5/api/FDB.cc @@ -26,10 +26,12 @@ #include "fdb5/api/FDB.h" #include "fdb5/api/FDBFactory.h" #include "fdb5/api/helpers/FDBToolRequest.h" +#include "fdb5/config/Config.h" #include "fdb5/database/Key.h" #include "fdb5/io/HandleGatherer.h" #include "fdb5/message/MessageDecoder.h" + namespace fdb5 { //---------------------------------------------------------------------------------------------------------------------- diff --git a/src/fdb5/api/fdb_c.cc b/src/fdb5/api/fdb_c.cc index 9c2fa3363..afa89fbdd 100644 --- a/src/fdb5/api/fdb_c.cc +++ b/src/fdb5/api/fdb_c.cc @@ -307,6 +307,12 @@ int fdb_new_handle(fdb_handle_t** fdb) { }); } +int fdb_new_handle_from_config_path(fdb_handle_t** fdb, const char* path) { + return wrapApiFunction([fdb, path] { + *fdb = new fdb_handle_t(Config::make(path)); + }); +} + int fdb_archive(fdb_handle_t* fdb, fdb_key_t* key, const char* data, size_t length) { return wrapApiFunction([fdb, key, data, length] { ASSERT(fdb); diff --git a/src/fdb5/api/fdb_c.h b/src/fdb5/api/fdb_c.h index dc725a757..9c1eeaa92 100644 --- a/src/fdb5/api/fdb_c.h +++ b/src/fdb5/api/fdb_c.h @@ -283,7 +283,7 @@ int fdb_delete_datareader(fdb_datareader_t* dr); /** \defgroup FDB API */ -/** @{ */ +/** @{*/ struct fdb_handle_t; /** Opaque type for the FDB object. */ @@ -294,6 +294,13 @@ typedef struct fdb_handle_t fdb_handle_t; * \returns Return code (#FdbErrorValues) */ int fdb_new_handle(fdb_handle_t** fdb); + +/** Creates a FDB instance from a given path to an FDB (alternative to read FDB5_CONFIG_FILE). + * \param fdb FDB instance. Returned instance must be deleted using #fdb_delete_handle. + * \param path Path to an fdb config file + * \returns Return code (#FdbErrorValues) + */ +int fdb_new_handle_from_config_path(fdb_handle_t** fdb, const char* path); /** Archives binary data to a FDB instance. * \warning this is a low-level API. The provided key and the corresponding data are not checked for consistency