Skip to content

Commit

Permalink
[CTL] Make CTL API as a variadic functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KFilipek committed Feb 25, 2025
1 parent 7f102c4 commit 512ee27
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
12 changes: 3 additions & 9 deletions include/umf/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
49 changes: 37 additions & 12 deletions src/ctl/ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <ctype.h>
#include <limits.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 512ee27

Please sign in to comment.