From ceaf6773305dd4fc511e8b111fa2c4b1fc97b218 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 10 Aug 2009 18:21:16 -0700 Subject: [PATCH] Add support for variable task argument setup --- include/task.h | 6 ++++-- src/task.c | 52 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/include/task.h b/include/task.h index ec68935..76639d4 100644 --- a/include/task.h +++ b/include/task.h @@ -45,10 +45,12 @@ typedef void (* connman_task_notify_t) (struct connman_task *task, struct connman_task *connman_task_create(const char *program); void connman_task_destroy(struct connman_task *task); +const char *connman_task_get_path(struct connman_task *task); + int connman_task_add_argument(struct connman_task *task, - const char *argument, const char *value); + const char *name, const char *format, ...); int connman_task_add_variable(struct connman_task *task, - const char *key, const char *value); + const char *key, const char *format, ...); int connman_task_set_notify(struct connman_task *task, const char *member, connman_task_notify_t function, void *user_data); diff --git a/src/task.c b/src/task.c index 550027b..f5495d7 100644 --- a/src/task.c +++ b/src/task.c @@ -24,6 +24,7 @@ #endif #include +#include #include #include @@ -133,31 +134,48 @@ void connman_task_destroy(struct connman_task *task) } /** + * connman_task_get_path: + * @task: task structure + * + * Get object path + */ +const char *connman_task_get_path(struct connman_task *task) +{ + return task->path; +} + +/** * connman_task_add_argument: * @task: task structure - * @argument: argument name - * @value: optional argument value + * @name: argument name + * @format: format string + * @Varargs: list of arguments * * Add a new command line argument */ int connman_task_add_argument(struct connman_task *task, - const char *argument, const char *value) + const char *name, const char *format, ...) { + va_list ap; char *str; - DBG("task %p arg %s val %s", task, argument, value); + DBG("task %p arg %s", task, name); - if (argument == NULL) + if (name == NULL) return -EINVAL; - str = g_strdup(argument); + str = g_strdup(name); g_ptr_array_add(task->argv, str); - if (value != NULL) { - str = g_strdup(value); + va_start(ap, format); + + if (format != NULL) { + str = g_strdup_vprintf(format, ap); g_ptr_array_add(task->argv, str); } + va_end(ap); + return 0; } @@ -165,22 +183,30 @@ int connman_task_add_argument(struct connman_task *task, * connman_task_add_variable: * @task: task structure * @key: variable name - * @value: optional variable value + * @format: format string + * @Varargs: list of arguments * * Add a new environment variable */ int connman_task_add_variable(struct connman_task *task, - const char *key, const char *value) + const char *key, const char *format, ...) { - char *str; + va_list ap; + char *str, *val; - DBG("task %p key %s val %s", task, key, value); + DBG("task %p key %s", task, key); if (key == NULL) return -EINVAL; - str = g_strdup_printf("%s=%s", key, value ? value : ""); + va_start(ap, format); + + val = g_strdup_vprintf(format, ap); + str = g_strdup_printf("%s=%s", key, format ? format : ""); g_ptr_array_add(task->envp, str); + g_free(val); + + va_end(ap); return 0; } -- 2.7.4