Skip to content

Commit d5b2769

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 d5b2769

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

include/umf/base.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typedef enum umf_ctl_query_type {
6767
/// @param arg [out] pointer to the variable where the value will be stored
6868
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
6969
///
70-
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg);
70+
umf_result_t umfCtlGet(const char *name, ...);
7171

7272
///
7373
/// @brief Set value of a specified attribute at the given name.
@@ -76,7 +76,7 @@ umf_result_t umfCtlGet(const char *name, void *ctx, void *arg);
7676
/// @param arg [in] pointer to the value that will be set
7777
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
7878
///
79-
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg);
79+
umf_result_t umfCtlSet(const char *name, ...);
8080

8181
///
8282
/// @brief Execute callback related with the specified attribute.
@@ -85,7 +85,7 @@ umf_result_t umfCtlSet(const char *name, void *ctx, void *arg);
8585
/// @param arg [in/out] pointer to the value, can be used as an input or output
8686
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
8787
///
88-
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg);
88+
umf_result_t umfCtlExec(const char *name, ...);
8989

9090
#ifdef __cplusplus
9191
}

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)