summaryrefslogtreecommitdiff
path: root/src/til_settings.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-05-09 11:43:22 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-11 15:18:34 -0700
commit31a0147a720f2f0ef30df41512f41f43734662dd (patch)
treec381b2905eaf5cde93b83b2ee93adc148400b488 /src/til_settings.h
parent1a8abe80dabd6b723897fc507808db30b126b3a4 (diff)
til_settings: introduce til_setting_spec_t concept vs. desc
For recursive settings the individual setting being described needs to get added to a potentially different settings instance than the one being operated on at the top of the current setup_func phase. The settings instance being passed around for a setup_func to operate on is constified, mainly to try ensure modules don't start directly mucking with the settings. They're supposed to just describe what they want next and iterate back and forth, with the front-end creating the settings from the returned descs however is appropriate, eventually building up the settings to completion. But since it's the setup_func that decides which settings instance is appropriate for containing the setting.. at some point it must associate a settings instance with the desc it's producing, one that is going to be necessarily written to. So here I'm just turning the existing til_setting_desc_t to a "spec", unchanged. And introducing a new til_setting_desc_t embedding the spec, accompanied by a non-const til_settings_t* "container". Now what setup_funcs use to express settings are a spec, otherwise identically to before. Instead of cloning a desc to allocate it for returning to the front-end, the desc is created from a spec with the target settings instance passed in. This turns the desc step where we take a constified settings instance and cast it into a non-const a more formal act of going from spec->desc, binding the spec to a specific settings instance. It will also serve to isolate that hacky cast to a til_settings function, and all the accessors of til_setting_desc_t needing to operate on the containing settings instance can just do so. As of this commit, the container pointer is just sitting in the desc_t but isn't being made use of or even assigned yet. This is just to minimize the amount of churn happening in this otherwise mostly mechanical and sprawling commit. There's also been some small changes surrounding the desc generators and plumbing of the settings instance where there previously wasn't any. It's unclear to me if desc generators will stay desc generators or turn into spec generators. For now those are mostly just used by the drm_fb stuff anyways, modules haven't made use of them, so they can stay a little crufty harmlessly for now.
Diffstat (limited to 'src/til_settings.h')
-rw-r--r--src/til_settings.h20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/til_settings.h b/src/til_settings.h
index c9da235..4cfddf3 100644
--- a/src/til_settings.h
+++ b/src/til_settings.h
@@ -7,8 +7,8 @@ typedef struct til_setting_t til_setting_t;
typedef struct til_settings_t til_settings_t;
typedef struct til_setup_t til_setup_t;
-/* Individual setting description */
-typedef struct til_setting_desc_t {
+/* Individual setting specification */
+typedef struct til_setting_spec_t {
const char *name; /* long-form/human name for setting */
const char *key; /* short-form/key for setting, used as left side of =value in settings string */
const char *regex; /* value must conform to this regex */
@@ -16,14 +16,20 @@ typedef struct til_setting_desc_t {
const char **values; /* if a set of values is provided, listed here */
const char **annotations; /* if a set of values is provided, annotations for those values may be listed here */
char * (*random)(unsigned seed);/* if set, returns a valid random value for this setting */
- unsigned as_nested_settings:1; /* if set, this setting expects a settings string for its value and wants a nested til_setting_t.settings instance created for it */
+ unsigned as_nested_settings:1; /* if set, this setting expects a settings string for its value and wants a til_setting_t.value_as_nested_settings instance created for it */
+} til_setting_spec_t;
+
+/* a setting_desc is a setting_spec that's been described to a specific containing settings instance via desc_new(), though desc_new() takes a const settings it's cast away when placed into the allocated desc. */
+typedef struct til_setting_desc_t {
+ til_settings_t *container;
+ til_setting_spec_t spec;
} til_setting_desc_t;
/* For conveniently representing setting description generators */
typedef struct til_setting_desc_generator_t {
const char *key; /* key this generator applies to */
const char **value_ptr; /* where to put the value */
- int (*func)(til_setup_t *setup_context, const til_setting_desc_t **res_desc);
+ int (*func)(const til_settings_t *settings, til_setup_t *setup_context, const til_setting_desc_t **res_desc);
} til_setting_desc_generator_t;
/* Encapsulates a single til_settings_t.settings[] entry */
@@ -41,13 +47,13 @@ const char * til_settings_get_value_by_key(const til_settings_t *settings, const
const char * til_settings_get_value_by_idx(const til_settings_t *settings, unsigned idx, til_setting_t **res_setting);
til_setting_t * til_settings_add_value(til_settings_t *settings, const char *key, const char *value, const til_setting_desc_t *desc);
void til_settings_reset_descs(til_settings_t *settings);
-int til_settings_get_and_describe_value(const til_settings_t *settings, const til_setting_desc_t *desc, const char **res_value, til_setting_t **res_setting, const til_setting_desc_t **res_desc);
+int til_settings_get_and_describe_value(const til_settings_t *settings, const til_setting_spec_t *spec, const char **res_value, til_setting_t **res_setting, const til_setting_desc_t **res_desc);
char * til_settings_as_arg(const til_settings_t *settings);
int til_settings_apply_desc_generators(const til_settings_t *settings, const til_setting_desc_generator_t generators[], unsigned n_generators, til_setup_t *setup, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup);
-int til_setting_desc_clone(const til_setting_desc_t *desc, const til_setting_desc_t **res_desc);
+int til_setting_desc_new(const til_settings_t *settings, const til_setting_spec_t *spec, const til_setting_desc_t **res_desc);
til_setting_desc_t * til_setting_desc_free(const til_setting_desc_t *desc);
-int til_setting_desc_check(const til_setting_desc_t *desc, const char *value);
+int til_setting_spec_check(const til_setting_spec_t *spec, const char *value);
#ifndef TIL_SETTINGS_STR
#define _TIL_SETTINGS_STR(s) #s
© All Rights Reserved