From bbd39b8185960be597b52c9d7f00f38629db8f5d Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 28 Aug 2021 06:08:00 -0400 Subject: [PATCH] [common] option: implement the ability to set option values This can then be used to update the options from EGL filters, and then dumping them to files. --- common/include/common/option.h | 6 +++++ common/src/option.c | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/common/include/common/option.h b/common/include/common/option.h index 324f72de..4f386fca 100644 --- a/common/include/common/option.h +++ b/common/include/common/option.h @@ -83,6 +83,12 @@ const char * option_get_string(const char * module, const char * name); bool option_get_bool (const char * module, const char * name); float option_get_float (const char * module, const char * name); +// update the value of an option +void option_set_int (const char * module, const char * name, int value); +void option_set_string(const char * module, const char * name, const char * value); +void option_set_bool (const char * module, const char * name, bool value); +void option_set_float (const char * module, const char * name, float value); + // called by the main application to parse the command line arguments bool option_parse(int argc, char * argv[]); diff --git a/common/src/option.c b/common/src/option.c index 8c0ec93e..eb10a102 100644 --- a/common/src/option.c +++ b/common/src/option.c @@ -824,3 +824,52 @@ float option_get_float(const char * module, const char * name) DEBUG_ASSERT(o->type == OPTION_TYPE_FLOAT); return o->value.x_float; } + +void option_set_int(const char * module, const char * name, int value) +{ + struct Option * o = option_get(module, name); + if (!o) + { + DEBUG_ERROR("BUG: Failed to set the value for option %s:%s", module, name); + return; + } + DEBUG_ASSERT(o->type == OPTION_TYPE_INT); + o->value.x_int = value; +} + +void option_set_string(const char * module, const char * name, const char * value) +{ + struct Option * o = option_get(module, name); + if (!o) + { + DEBUG_ERROR("BUG: Failed to set the value for option %s:%s", module, name); + return; + } + DEBUG_ASSERT(o->type == OPTION_TYPE_STRING); + free(o->value.x_string); + o->value.x_string = strdup(value); +} + +void option_set_bool(const char * module, const char * name, bool value) +{ + struct Option * o = option_get(module, name); + if (!o) + { + DEBUG_ERROR("BUG: Failed to set the value for option %s:%s", module, name); + return; + } + DEBUG_ASSERT(o->type == OPTION_TYPE_BOOL); + o->value.x_bool = value; +} + +void option_set_float(const char * module, const char * name, float value) +{ + struct Option * o = option_get(module, name); + if (!o) + { + DEBUG_ERROR("BUG: Failed to set the value for option %s:%s", module, name); + return; + } + DEBUG_ASSERT(o->type == OPTION_TYPE_FLOAT); + o->value.x_float = value; +}