mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-16 15:17:18 +02:00
C API: Use nix_get_string_callback
typedef
This commit is contained in:
parent
76444a3958
commit
774e7213e8
6 changed files with 19 additions and 62 deletions
|
@ -56,11 +56,7 @@ void nix_store_free(Store * store)
|
||||||
delete store;
|
delete store;
|
||||||
}
|
}
|
||||||
|
|
||||||
nix_err nix_store_get_uri(
|
nix_err nix_store_get_uri(nix_c_context * context, Store * store, nix_get_string_callback callback, void * user_data)
|
||||||
nix_c_context * context,
|
|
||||||
Store * store,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data)
|
|
||||||
{
|
{
|
||||||
if (context)
|
if (context)
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
|
@ -71,11 +67,8 @@ nix_err nix_store_get_uri(
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
|
||||||
nix_err nix_store_get_version(
|
nix_err
|
||||||
nix_c_context * context,
|
nix_store_get_version(nix_c_context * context, Store * store, nix_get_string_callback callback, void * user_data)
|
||||||
Store * store,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data)
|
|
||||||
{
|
{
|
||||||
if (context)
|
if (context)
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
|
@ -136,13 +129,10 @@ nix_err nix_store_realise(
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
|
||||||
void nix_store_path_name(
|
void nix_store_path_name(const StorePath * store_path, nix_get_string_callback callback, void * user_data)
|
||||||
const StorePath * store_path,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data)
|
|
||||||
{
|
{
|
||||||
std::string_view name = store_path->path.name();
|
std::string_view name = store_path->path.name();
|
||||||
((nix_get_string_callback) callback)(name.data(), name.size(), user_data);
|
callback(name.data(), name.size(), user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nix_store_path_free(StorePath * sp)
|
void nix_store_path_free(StorePath * sp)
|
||||||
|
|
|
@ -76,11 +76,7 @@ void nix_store_free(Store * store);
|
||||||
* @see nix_get_string_callback
|
* @see nix_get_string_callback
|
||||||
* @return error code, NIX_OK on success.
|
* @return error code, NIX_OK on success.
|
||||||
*/
|
*/
|
||||||
nix_err nix_store_get_uri(
|
nix_err nix_store_get_uri(nix_c_context * context, Store * store, nix_get_string_callback callback, void * user_data);
|
||||||
nix_c_context * context,
|
|
||||||
Store * store,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
// returns: owned StorePath*
|
// returns: owned StorePath*
|
||||||
/**
|
/**
|
||||||
|
@ -101,10 +97,7 @@ StorePath * nix_store_parse_path(nix_c_context * context, Store * store, const c
|
||||||
* @param[in] callback called with the name
|
* @param[in] callback called with the name
|
||||||
* @param[in] user_data arbitrary data, passed to the callback when it's called.
|
* @param[in] user_data arbitrary data, passed to the callback when it's called.
|
||||||
*/
|
*/
|
||||||
void nix_store_path_name(
|
void nix_store_path_name(const StorePath * store_path, nix_get_string_callback callback, void * user_data);
|
||||||
const StorePath * store_path,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copy a StorePath
|
* @brief Copy a StorePath
|
||||||
|
@ -163,11 +156,8 @@ nix_err nix_store_realise(
|
||||||
* @see nix_get_string_callback
|
* @see nix_get_string_callback
|
||||||
* @return error code, NIX_OK on success.
|
* @return error code, NIX_OK on success.
|
||||||
*/
|
*/
|
||||||
nix_err nix_store_get_version(
|
nix_err
|
||||||
nix_c_context * context,
|
nix_store_get_version(nix_c_context * context, Store * store, nix_get_string_callback callback, void * user_data);
|
||||||
Store * store,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
// cffi end
|
// cffi end
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -64,11 +64,7 @@ const char * nix_version_get()
|
||||||
|
|
||||||
// Implementations
|
// Implementations
|
||||||
|
|
||||||
nix_err nix_setting_get(
|
nix_err nix_setting_get(nix_c_context * context, const char * key, nix_get_string_callback callback, void * user_data)
|
||||||
nix_c_context * context,
|
|
||||||
const char * key,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data)
|
|
||||||
{
|
{
|
||||||
if (context)
|
if (context)
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
|
@ -120,10 +116,7 @@ const char * nix_err_msg(nix_c_context * context, const nix_c_context * read_con
|
||||||
}
|
}
|
||||||
|
|
||||||
nix_err nix_err_name(
|
nix_err nix_err_name(
|
||||||
nix_c_context * context,
|
nix_c_context * context, const nix_c_context * read_context, nix_get_string_callback callback, void * user_data)
|
||||||
const nix_c_context * read_context,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data)
|
|
||||||
{
|
{
|
||||||
if (context)
|
if (context)
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
|
@ -134,10 +127,7 @@ nix_err nix_err_name(
|
||||||
}
|
}
|
||||||
|
|
||||||
nix_err nix_err_info_msg(
|
nix_err nix_err_info_msg(
|
||||||
nix_c_context * context,
|
nix_c_context * context, const nix_c_context * read_context, nix_get_string_callback callback, void * user_data)
|
||||||
const nix_c_context * read_context,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data)
|
|
||||||
{
|
{
|
||||||
if (context)
|
if (context)
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
|
@ -153,9 +143,8 @@ nix_err nix_err_code(const nix_c_context * read_context)
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
nix_err call_nix_get_string_callback(
|
nix_err call_nix_get_string_callback(const std::string str, nix_get_string_callback callback, void * user_data)
|
||||||
const std::string str, void (*callback)(const char * start, unsigned int n, void * user_data), void * user_data)
|
|
||||||
{
|
{
|
||||||
((nix_get_string_callback) callback)(str.c_str(), str.size(), user_data);
|
callback(str.c_str(), str.size(), user_data);
|
||||||
return NIX_OK;
|
return NIX_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,11 +175,7 @@ nix_err nix_libutil_init(nix_c_context * context);
|
||||||
* @return NIX_ERR_KEY if the setting is unknown, or NIX_OK if the setting was retrieved
|
* @return NIX_ERR_KEY if the setting is unknown, or NIX_OK if the setting was retrieved
|
||||||
* successfully.
|
* successfully.
|
||||||
*/
|
*/
|
||||||
nix_err nix_setting_get(
|
nix_err nix_setting_get(nix_c_context * context, const char * key, nix_get_string_callback callback, void * user_data);
|
||||||
nix_c_context * context,
|
|
||||||
const char * key,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets a setting in the nix global configuration.
|
* @brief Sets a setting in the nix global configuration.
|
||||||
|
@ -246,10 +242,7 @@ const char * nix_err_msg(nix_c_context * context, const nix_c_context * ctx, uns
|
||||||
* @return NIX_OK if there were no errors, an error code otherwise.
|
* @return NIX_OK if there were no errors, an error code otherwise.
|
||||||
*/
|
*/
|
||||||
nix_err nix_err_info_msg(
|
nix_err nix_err_info_msg(
|
||||||
nix_c_context * context,
|
nix_c_context * context, const nix_c_context * read_context, nix_get_string_callback callback, void * user_data);
|
||||||
const nix_c_context * read_context,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieves the error name from a context.
|
* @brief Retrieves the error name from a context.
|
||||||
|
@ -268,10 +261,7 @@ nix_err nix_err_info_msg(
|
||||||
* @return NIX_OK if there were no errors, an error code otherwise.
|
* @return NIX_OK if there were no errors, an error code otherwise.
|
||||||
*/
|
*/
|
||||||
nix_err nix_err_name(
|
nix_err nix_err_name(
|
||||||
nix_c_context * context,
|
nix_c_context * context, const nix_c_context * read_context, nix_get_string_callback callback, void * user_data);
|
||||||
const nix_c_context * read_context,
|
|
||||||
void (*callback)(const char * start, unsigned int n, void * user_data),
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieves the most recent error code from a nix_c_context
|
* @brief Retrieves the most recent error code from a nix_c_context
|
||||||
|
|
|
@ -29,8 +29,7 @@ nix_err nix_context_error(nix_c_context * context);
|
||||||
* @return NIX_OK if there were no errors.
|
* @return NIX_OK if there were no errors.
|
||||||
* @see nix_get_string_callback
|
* @see nix_get_string_callback
|
||||||
*/
|
*/
|
||||||
nix_err call_nix_get_string_callback(
|
nix_err call_nix_get_string_callback(const std::string str, nix_get_string_callback callback, void * user_data);
|
||||||
const std::string str, void (*callback)(const char * start, unsigned int n, void * user_data), void * user_data);
|
|
||||||
|
|
||||||
#define NIXC_CATCH_ERRS \
|
#define NIXC_CATCH_ERRS \
|
||||||
catch (...) \
|
catch (...) \
|
||||||
|
|
|
@ -11,7 +11,6 @@ inline void * observe_string_cb_data(std::string & out)
|
||||||
};
|
};
|
||||||
|
|
||||||
#define OBSERVE_STRING(str) \
|
#define OBSERVE_STRING(str) \
|
||||||
(void (*)(const char *, unsigned int, void *)) nix::testing::observe_string_cb, \
|
(nix_get_string_callback) nix::testing::observe_string_cb, nix::testing::observe_string_cb_data(str)
|
||||||
nix::testing::observe_string_cb_data(str)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue