summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-08-10 15:48:31 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-10 00:01:46 -0700
commit886fb547a3bda848a8b8e1db2b74ae4293c9ccb2 (patch)
tree1bb35990854667da2e99056f25a416c0e7f33169
parent11d07e544c85836bf18cf3b79f9fc3d1f88d070d (diff)
til_settings: label til_settings_t instances
This adds a mandatory label string to til_setttings_new() and updates call sites accordingly. For now the root-level settings created by main.c are simply named "module" and "video" respectively. Any nested settings creations on behalf of modules will be labeled using the module's name the settings are being created for use with. This might evolve with time, for now it's just a minimum churn kind of decision. I can see it changing such that the top-level settings also become labeled by the module/video driver name rather than the obtuse "module" "video" strings. How these will be leveraged is unclear presently. At the least it'll be nice to have a label for debugging til_settings_t heirarchies once recursive settings support lands. In a sense this is a preparatory commit for that work. But I could see the labels ending up in serialization contents as markup/syntactic sugar just to self-document things as well. There might also be a need to address til_settings_t instances in the settings heirarchy, which may be something like a "label/label/label/label" path style thing - though there'd be a need to deal with name collisions in that approach. I'm just thinking a bit about how knobs will become addressed when those become a real thing. The settings label heirarchy might be the convenient place to name everything in a tree, which knobs could then inherit their parent paths from under which their respective knob labels will reside. For the whole name collision issue there could just be some builtin settings keys for overriding the automatic module name labeling, something like: --module=compose,layers=checkers\,label=first\,fill_module=shapes:checkers\,label=second\,fill_module=shapes would result in: /module/first/shapes /module/second/shapes or in a world where the root settings weren't just named "module" and "video": /compose/first/shapes /compose/second/shapes then if there were knobs under checkers and shapes, say checkers had a "foo" knob and checkers had a "bar" knob, they'd be under .knobs in each directory: /compose/first/.knobs/foo /compose/first/shapes/.knobs/bar /compose/second/.knobs/foo /compose/second/shapes/.knobs/bar something along those lines, and of course if compose had knobs they'd be under /compose/.knobs This is just a brain dump and will surely all change before implemented.
-rw-r--r--src/main.c4
-rw-r--r--src/til.c2
-rw-r--r--src/til_settings.c11
-rw-r--r--src/til_settings.h2
4 files changed, 13 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 2e0229e..54abe18 100644
--- a/src/main.c
+++ b/src/main.c
@@ -219,11 +219,11 @@ static int setup_from_args(til_args_t *args, setup_t *res_setup, const til_setti
*/
srand(setup.seed);
- setup.module_settings = til_settings_new(args->module);
+ setup.module_settings = til_settings_new("module", args->module);
if (!setup.module_settings)
goto _err;
- setup.video_settings = til_settings_new(args->video);
+ setup.video_settings = til_settings_new("video", args->video);
if (!setup.video_settings)
goto _err;
diff --git a/src/til.c b/src/til.c
index 489fcf1..58e52bb 100644
--- a/src/til.c
+++ b/src/til.c
@@ -327,7 +327,7 @@ int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_se
if (!module->setup)
return 0;
- settings = til_settings_new(NULL);
+ settings = til_settings_new(module->name, NULL);
if (!settings)
return -ENOMEM;
diff --git a/src/til_settings.c b/src/til_settings.c
index 3e26686..9fce32f 100644
--- a/src/til_settings.c
+++ b/src/til_settings.c
@@ -31,6 +31,7 @@ char * strndup(const char *s, size_t n)
/* Split form of key=value[,key=value...] settings string */
typedef struct til_settings_t {
+ const char *label;
unsigned num;
til_setting_t **settings;
} til_settings_t;
@@ -62,7 +63,7 @@ static int add_value(til_settings_t *settings, const char *key, const char *valu
/* split settings_string into a data structure */
-til_settings_t * til_settings_new(const char *settings_string)
+til_settings_t * til_settings_new(const char *label, const char *settings_string)
{
til_settings_fsm_state_t state = TIL_SETTINGS_FSM_STATE_KEY;
const char *p, *token;
@@ -71,9 +72,15 @@ til_settings_t * til_settings_new(const char *settings_string)
char *value_buf;
size_t value_sz;
+ assert(label);
+
settings = calloc(1, sizeof(til_settings_t));
if (!settings)
- return NULL;
+ goto _err;
+
+ settings->label = strdup(label);
+ if (!settings->label)
+ goto _err;
if (!settings_string)
return settings;
diff --git a/src/til_settings.h b/src/til_settings.h
index df8a307..93c0ed8 100644
--- a/src/til_settings.h
+++ b/src/til_settings.h
@@ -33,7 +33,7 @@ struct til_setting_t {
void *user_data;
};
-til_settings_t * til_settings_new(const char *settings);
+til_settings_t * til_settings_new(const char *label, const char *settings);
til_settings_t * til_settings_free(til_settings_t *settings);
const char * til_settings_get_value(const til_settings_t *settings, const char *key, til_setting_t **res_setting);
const char * til_settings_get_key(const til_settings_t *settings, unsigned pos, til_setting_t **res_setting);
© All Rights Reserved