From e536391df6f2eae5fb15a903564fc73e02de94a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:53:55 +0100 Subject: [PATCH] module/alsa: export module info through the new module_info struct type --- config-verify.c | 34 ++++++++++++++++++++++++++-------- config.c | 2 +- modules/alsa/alsa.c | 21 ++++++++++++++++----- modules/alsa/alsa.h | 7 +------ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/config-verify.c b/config-verify.c index 490bab1..9d9af2f 100644 --- a/config-verify.c +++ b/config-verify.c @@ -8,6 +8,8 @@ #include "log.h" #include "tllist.h" +#include "modules/alsa/alsa.h" + static const char * err_prefix(const keychain_t *chain, const struct yml_node *node) { @@ -458,13 +460,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info alsa[] = { - {"card", true, &conf_verify_string}, - {"mixer", true, &conf_verify_string}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info backlight[] = { {"name", true, &conf_verify_string}, {"content", true, &conf_verify_particle}, @@ -529,12 +524,19 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"anchors", false, NULL}, }; + /* TODO: this will dlopened later */ + static const struct { + const char *name; + const struct module_info *info; + } modules_v2[] = { + {"alsa", &module_alsa}, + }; + static const struct { const char *name; const struct attr_info *attrs; size_t count; } modules[] = { - {"alsa", alsa, sizeof(alsa) / sizeof(alsa[0])}, {"backlight", backlight, sizeof(backlight) / sizeof(backlight[0])}, {"battery", battery, sizeof(battery) / sizeof(battery[0])}, {"clock", clock, sizeof(clock) / sizeof(clock[0])}, @@ -547,6 +549,22 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])}, }; + for (size_t i = 0; i < sizeof(modules_v2) / sizeof(modules_v2[0]); i++) { + if (strcmp(modules_v2[i].name, mod_name) != 0) + continue; + + if (!conf_verify_dict(chain_push(chain, mod_name), + values, + modules_v2[i].info->attrs, + modules_v2[i].info->attr_count)) + { + return false; + } + + chain_pop(chain); + return true; + } + for (size_t i = 0; i < sizeof(modules) / sizeof(modules[0]); i++) { if (strcmp(modules[i].name, mod_name) != 0) continue; diff --git a/config.c b/config.c index b2afafa..f712b18 100644 --- a/config.c +++ b/config.c @@ -603,7 +603,7 @@ conf_to_bar(const struct yml_node *bar) else if (strcmp(mod_name, "removables") == 0) mods[idx] = module_removables_from_config(m.value, font); else if (strcmp(mod_name, "alsa") == 0) - mods[idx] = module_alsa_from_config(m.value, font); + mods[idx] = module_alsa.from_conf(m.value, font); else assert(false); } diff --git a/modules/alsa/alsa.c b/modules/alsa/alsa.c index 2e55ea9..5a34346 100644 --- a/modules/alsa/alsa.c +++ b/modules/alsa/alsa.c @@ -251,7 +251,7 @@ run(struct module_run_context *ctx) } static struct module * -module_alsa(const char *card, const char *mixer, struct particle *label) +alsa_new(const char *card, const char *mixer, struct particle *label) { struct private *priv = malloc(sizeof(*priv)); priv->label = label; @@ -269,16 +269,27 @@ module_alsa(const char *card, const char *mixer, struct particle *label) return mod; } -struct module * -module_alsa_from_config(const struct yml_node *node, - const struct font *parent_font) +static struct module * +from_conf(const struct yml_node *node, const struct font *parent_font) { const struct yml_node *card = yml_get_value(node, "card"); const struct yml_node *mixer = yml_get_value(node, "mixer"); const struct yml_node *content = yml_get_value(node, "content"); - return module_alsa( + return alsa_new( yml_value_as_string(card), yml_value_as_string(mixer), conf_to_particle(content, parent_font)); } + +const struct module_info module_alsa = { + .from_conf = &from_conf, + .attr_count = 4, + .attrs = { + {"card", true, &conf_verify_string}, + {"mixer", true, &conf_verify_string}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL} + }, +}; diff --git a/modules/alsa/alsa.h b/modules/alsa/alsa.h index 6570895..a19c122 100644 --- a/modules/alsa/alsa.h +++ b/modules/alsa/alsa.h @@ -1,9 +1,4 @@ #pragma once - -#include "../../font.h" #include "../../module.h" -#include "../../particle.h" -#include "../../yml.h" -struct module *module_alsa_from_config( - const struct yml_node *node, const struct font *parent_font); +extern const struct module_info module_alsa;