From a16e2f5a538f978a882d012aee24616e5336008e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:52:16 +0100 Subject: [PATCH] module/mpd: export module info through the new module_info struct type --- config-verify.c | 11 +++-------- config.c | 23 +++++------------------ modules/mpd/mpd.c | 30 ++++++++++++++++++++++++++++-- modules/mpd/mpd.h | 7 +------ 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/config-verify.c b/config-verify.c index 6504b19..2bbef2d 100644 --- a/config-verify.c +++ b/config-verify.c @@ -14,6 +14,8 @@ #include "modules/clock/clock.h" #include "modules/i3/i3.h" #include "modules/label/label.h" +#include "modules/label/label.h" +#include "modules/mpd/mpd.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -435,13 +437,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info mpd[] = { - {"host", true, &conf_verify_string}, - {"port", false, &conf_verify_int}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info network[] = { {"name", true, &conf_verify_string}, {"content", true, &conf_verify_particle}, @@ -477,6 +472,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"clock", &module_clock}, {"i3", &module_i3}, {"label", &module_label}, + {"mpd", &module_mpd}, }; static const struct { @@ -484,7 +480,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"mpd", mpd, sizeof(mpd) / sizeof(mpd[0])}, {"network", network, sizeof(network) / sizeof(network[0])}, {"removables", removables, sizeof(removables) / sizeof(removables[0])}, {"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])}, diff --git a/config.c b/config.c index b7907cb..888ea5d 100644 --- a/config.c +++ b/config.c @@ -377,20 +377,6 @@ module_xkb_from_config(const struct yml_node *node, return module_xkb(conf_to_particle(c, parent_font)); } -static struct module * -module_mpd_from_config(const struct yml_node *node, - const struct font *parent_font) -{ - const struct yml_node *host = yml_get_value(node, "host"); - const struct yml_node *port = yml_get_value(node, "port"); - const struct yml_node *c = yml_get_value(node, "content"); - - return module_mpd( - yml_value_as_string(host), - port != NULL ? yml_value_as_int(port) : 0, - conf_to_particle(c, parent_font)); -} - static struct module * module_network_from_config(const struct yml_node *node, const struct font *parent_font) @@ -522,13 +508,14 @@ conf_to_bar(const struct yml_node *bar) mods[idx] = module_i3.from_conf(m.value, font); else if (strcmp(mod_name, "label") == 0) mods[idx] = module_label.from_conf(m.value, font); - + else if (strcmp(mod_name, "mpd") == 0) + mods[idx] = module_mpd.from_conf(m.value, font); + + else if (strcmp(mod_name, "xwindow") == 0) mods[idx] = module_xwindow_from_config(m.value, font); - else if (strcmp(mod_name, "xkb") == 0) + else if (strcmp(mod_name, "xkb") == 0) mods[idx] = module_xkb_from_config(m.value, font); - else if (strcmp(mod_name, "mpd") == 0) - mods[idx] = module_mpd_from_config(m.value, font); else if (strcmp(mod_name, "network") == 0) mods[idx] = module_network_from_config(m.value, font); else if (strcmp(mod_name, "removables") == 0) diff --git a/modules/mpd/mpd.c b/modules/mpd/mpd.c index 13b3889..f52b7c7 100644 --- a/modules/mpd/mpd.c +++ b/modules/mpd/mpd.c @@ -18,6 +18,7 @@ #define LOG_ENABLE_DBG 0 #include "../../log.h" #include "../../bar.h" +#include "../../config.h" enum state { STATE_OFFLINE = 1000, @@ -451,8 +452,8 @@ refresh_in(struct module *mod, long milli_seconds) return r == 0; } -struct module * -module_mpd(const char *host, uint16_t port, struct particle *label) +static struct module * +mpd_new(const char *host, uint16_t port, struct particle *label) { struct private *priv = malloc(sizeof(*priv)); priv->host = strdup(host); @@ -478,3 +479,28 @@ module_mpd(const char *host, uint16_t port, struct particle *label) mod->refresh_in = &refresh_in; return mod; } + +static struct module * +from_conf(const struct yml_node *node, const struct font *parent_font) +{ + const struct yml_node *host = yml_get_value(node, "host"); + const struct yml_node *port = yml_get_value(node, "port"); + const struct yml_node *c = yml_get_value(node, "content"); + + return mpd_new( + yml_value_as_string(host), + port != NULL ? yml_value_as_int(port) : 0, + conf_to_particle(c, parent_font)); +} + +const struct module_info module_mpd = { + .from_conf = &from_conf, + .attr_count = 4, + .attrs = { + {"host", true, &conf_verify_string}, + {"port", false, &conf_verify_int}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/mpd/mpd.h b/modules/mpd/mpd.h index e1c5183..57959e1 100644 --- a/modules/mpd/mpd.h +++ b/modules/mpd/mpd.h @@ -1,9 +1,4 @@ #pragma once - -#include - #include "../../module.h" -#include "../../particle.h" -struct module *module_mpd( - const char *host, uint16_t port, struct particle *label); +extern const struct module_info module_mpd;