From 697e613b2e28d5a225d346a46935615640f792c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:56:54 +0100 Subject: [PATCH] module/network: export module info through the new module_info struct type --- config-verify.c | 9 ++------- config.c | 15 ++------------- modules/network/network.c | 28 +++++++++++++++++++++++++--- modules/network/network.h | 4 +--- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/config-verify.c b/config-verify.c index 2bbef2d..169914a 100644 --- a/config-verify.c +++ b/config-verify.c @@ -16,6 +16,7 @@ #include "modules/label/label.h" #include "modules/label/label.h" #include "modules/mpd/mpd.h" +#include "modules/network/network.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -437,12 +438,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info network[] = { - {"name", true, &conf_verify_string}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info removables[] = { {"spacing", false, &conf_verify_int}, {"left-spacing", false, &conf_verify_int}, @@ -473,6 +468,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"i3", &module_i3}, {"label", &module_label}, {"mpd", &module_mpd}, + {"network", &module_network}, }; static const struct { @@ -480,7 +476,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"network", network, sizeof(network) / sizeof(network[0])}, {"removables", removables, sizeof(removables) / sizeof(removables[0])}, {"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])}, {"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])}, diff --git a/config.c b/config.c index 888ea5d..fb25202 100644 --- a/config.c +++ b/config.c @@ -377,17 +377,6 @@ module_xkb_from_config(const struct yml_node *node, return module_xkb(conf_to_particle(c, parent_font)); } -static struct module * -module_network_from_config(const struct yml_node *node, - const struct font *parent_font) -{ - const struct yml_node *name = yml_get_value(node, "name"); - const struct yml_node *content = yml_get_value(node, "content"); - - return module_network( - yml_value_as_string(name), conf_to_particle(content, parent_font)); -} - static struct module * module_removables_from_config(const struct yml_node *node, const struct font *parent_font) @@ -510,14 +499,14 @@ conf_to_bar(const struct yml_node *bar) 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, "network") == 0) + mods[idx] = module_network.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) mods[idx] = module_xkb_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) mods[idx] = module_removables_from_config(m.value, font); else diff --git a/modules/network/network.c b/modules/network/network.c index e7da46d..273b688 100644 --- a/modules/network/network.c +++ b/modules/network/network.c @@ -17,8 +17,9 @@ #define LOG_MODULE "network" #define LOG_ENABLE_DBG 0 #include "../../log.h" -#include "../../module.h" #include "../../bar.h" +#include "../../config.h" +#include "../../module.h" #include "../../tllist.h" struct af_addr { @@ -511,8 +512,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_network(const char *iface, struct particle *label) +static struct module * +network_new(const char *iface, struct particle *label) { struct private *priv = malloc(sizeof(*priv)); priv->iface = strdup(iface); @@ -533,3 +534,24 @@ module_network(const char *iface, struct particle *label) mod->content = &content; return mod; } + +static struct module * +from_conf(const struct yml_node *node, const struct font *parent_font) +{ + const struct yml_node *name = yml_get_value(node, "name"); + const struct yml_node *content = yml_get_value(node, "content"); + + return network_new( + yml_value_as_string(name), conf_to_particle(content, parent_font)); +} + +const struct module_info module_network = { + .from_conf = &from_conf, + .attr_count = 3, + .attrs = { + {"name", true, &conf_verify_string}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/network/network.h b/modules/network/network.h index 6c3fee7..2c7aa57 100644 --- a/modules/network/network.h +++ b/modules/network/network.h @@ -1,6 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_network(const char *iface, struct particle *label); +extern const struct module_info module_network;