Skip to content

Commit 46b49d9

Browse files
committed
[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.
1 parent 75e79b0 commit 46b49d9

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

include/umf/base.h

+3-9
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,23 @@ typedef enum umf_ctl_query_type {
6363
///
6464
/// @brief Get value of a specified attribute at the given name.
6565
/// @param name name of an attribute to be retrieved
66-
/// @param ctx pointer to the pool or the provider
67-
/// @param arg [out] pointer to the variable where the value will be stored
6866
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
6967
///
70-
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg);
68+
umf_result_t umfCtlGet(const char *name, ...);
7169

7270
///
7371
/// @brief Set value of a specified attribute at the given name.
7472
/// @param name name of an attribute to be set
75-
/// @param ctx pointer to the pool or the provider
76-
/// @param arg [in] pointer to the value that will be set
7773
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
7874
///
79-
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg);
75+
umf_result_t umfCtlSet(const char *name, ...);
8076

8177
///
8278
/// @brief Execute callback related with the specified attribute.
8379
/// @param name name of an attribute to be executed
84-
/// @param ctx pointer to the pool or the provider
85-
/// @param arg [in/out] pointer to the value, can be used as an input or output
8680
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
8781
///
88-
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg);
82+
umf_result_t umfCtlExec(const char *name, ...);
8983

9084
#ifdef __cplusplus
9185
}

src/ctl/ctl.c

+28-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <ctype.h>
2222
#include <limits.h>
23+
#include <stdarg.h>
2324
#include <stdint.h>
2425
#include <stdlib.h>
2526
#include <string.h>
@@ -81,8 +82,16 @@ char *Strdup(const char *s) {
8182
return p;
8283
}
8384

84-
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg) {
85+
umf_result_t umfCtlGet(const char *name, ...) {
8586
assert(name != NULL);
87+
88+
va_list args;
89+
va_start(args, name);
90+
91+
void *ctx = va_arg(args, void *);
92+
void *arg = va_arg(args, void *);
93+
va_end(args);
94+
8695
assert(arg != NULL);
8796
assert(ctx != NULL);
8897
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ,
@@ -91,8 +100,16 @@ umf_result_t umfCtlGet(const char *name, void *ctx, void *arg) {
91100
: UMF_RESULT_SUCCESS;
92101
}
93102

94-
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg) {
103+
umf_result_t umfCtlSet(const char *name, ...) {
95104
assert(name != NULL);
105+
106+
va_list args;
107+
va_start(args, name);
108+
109+
void *ctx = va_arg(args, void *);
110+
void *arg = va_arg(args, void *);
111+
va_end(args);
112+
96113
assert(arg != NULL);
97114
assert(ctx != NULL);
98115
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE,
@@ -101,8 +118,16 @@ umf_result_t umfCtlSet(const char *name, void *ctx, void *arg) {
101118
: UMF_RESULT_SUCCESS;
102119
}
103120

104-
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg) {
121+
umf_result_t umfCtlExec(const char *name, ...) {
105122
assert(name != NULL);
123+
124+
va_list args;
125+
va_start(args, name);
126+
127+
void *ctx = va_arg(args, void *);
128+
void *arg = va_arg(args, void *);
129+
va_end(args);
130+
106131
assert(arg != NULL);
107132
assert(ctx != NULL);
108133
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name,

0 commit comments

Comments
 (0)