From 512ee27973a24069269825ad376901414a838601 Mon Sep 17 00:00:00 2001 From: Krzysztof Filipek Date: Fri, 21 Feb 2025 12:36:28 +0100 Subject: [PATCH] [CTL] Make CTL API as a variadic functions Since this commit all the CTL API functions (umfCtlSet/Get/Exec) will be defined as a variadic functions to provide more elastic approach in future development. --- include/umf/base.h | 12 +++--------- src/ctl/ctl.c | 49 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/include/umf/base.h b/include/umf/base.h index cc6b0ccbd..2cbdcc26b 100644 --- a/include/umf/base.h +++ b/include/umf/base.h @@ -63,29 +63,23 @@ typedef enum umf_ctl_query_type { /// /// @brief Get value of a specified attribute at the given name. /// @param name name of an attribute to be retrieved -/// @param ctx pointer to the pool or the provider -/// @param arg [out] pointer to the variable where the value will be stored /// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure. /// -umf_result_t umfCtlGet(const char *name, void *ctx, void *arg); +umf_result_t umfCtlGet(const char *name, ...); /// /// @brief Set value of a specified attribute at the given name. /// @param name name of an attribute to be set -/// @param ctx pointer to the pool or the provider -/// @param arg [in] pointer to the value that will be set /// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure. /// -umf_result_t umfCtlSet(const char *name, void *ctx, void *arg); +umf_result_t umfCtlSet(const char *name, ...); /// /// @brief Execute callback related with the specified attribute. /// @param name name of an attribute to be executed -/// @param ctx pointer to the pool or the provider -/// @param arg [in/out] pointer to the value, can be used as an input or output /// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure. /// -umf_result_t umfCtlExec(const char *name, void *ctx, void *arg); +umf_result_t umfCtlExec(const char *name, ...); #ifdef __cplusplus } diff --git a/src/ctl/ctl.c b/src/ctl/ctl.c index 99ab2d96e..131e71255 100644 --- a/src/ctl/ctl.c +++ b/src/ctl/ctl.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -81,30 +82,54 @@ char *Strdup(const char *s) { return p; } -umf_result_t umfCtlGet(const char *name, void *ctx, void *arg) { - if (name == NULL || arg == NULL || ctx == NULL) { - return UMF_RESULT_ERROR_INVALID_ARGUMENT; - } +umf_result_t umfCtlGet(const char *name, ...) { + assert(name != NULL); + + va_list args; + va_start(args, name); + + void *ctx = va_arg(args, void *); + void *arg = va_arg(args, void *); + va_end(args); + + assert(arg != NULL); + assert(ctx != NULL); return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ, arg) ? UMF_RESULT_ERROR_UNKNOWN : UMF_RESULT_SUCCESS; } -umf_result_t umfCtlSet(const char *name, void *ctx, void *arg) { - if (name == NULL || arg == NULL || ctx == NULL) { - return UMF_RESULT_ERROR_INVALID_ARGUMENT; - } +umf_result_t umfCtlSet(const char *name, ...) { + assert(name != NULL); + + va_list args; + va_start(args, name); + + void *ctx = va_arg(args, void *); + void *arg = va_arg(args, void *); + va_end(args); + + assert(arg != NULL); + assert(ctx != NULL); return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE, arg) ? UMF_RESULT_ERROR_UNKNOWN : UMF_RESULT_SUCCESS; } -umf_result_t umfCtlExec(const char *name, void *ctx, void *arg) { - if (name == NULL || arg == NULL || ctx == NULL) { - return UMF_RESULT_ERROR_INVALID_ARGUMENT; - } +umf_result_t umfCtlExec(const char *name, ...) { + assert(name != NULL); + + va_list args; + va_start(args, name); + + void *ctx = va_arg(args, void *); + void *arg = va_arg(args, void *); + va_end(args); + + assert(arg != NULL); + assert(ctx != NULL); return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_RUNNABLE, arg) ? UMF_RESULT_ERROR_UNKNOWN