module/network: export module info through the new module_info struct type

This commit is contained in:
Daniel Eklöf 2019-01-12 12:56:54 +01:00
parent a16e2f5a53
commit 697e613b2e
4 changed files with 30 additions and 26 deletions

View file

@ -16,6 +16,7 @@
#include "modules/label/label.h" #include "modules/label/label.h"
#include "modules/label/label.h" #include "modules/label/label.h"
#include "modules/mpd/mpd.h" #include "modules/mpd/mpd.h"
#include "modules/network/network.h"
const char * const char *
conf_err_prefix(const keychain_t *chain, const struct yml_node *node) 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; 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[] = { static const struct attr_info removables[] = {
{"spacing", false, &conf_verify_int}, {"spacing", false, &conf_verify_int},
{"left-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}, {"i3", &module_i3},
{"label", &module_label}, {"label", &module_label},
{"mpd", &module_mpd}, {"mpd", &module_mpd},
{"network", &module_network},
}; };
static const struct { static const struct {
@ -480,7 +476,6 @@ verify_module(keychain_t *chain, const struct yml_node *node)
const struct attr_info *attrs; const struct attr_info *attrs;
size_t count; size_t count;
} modules[] = { } modules[] = {
{"network", network, sizeof(network) / sizeof(network[0])},
{"removables", removables, sizeof(removables) / sizeof(removables[0])}, {"removables", removables, sizeof(removables) / sizeof(removables[0])},
{"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])}, {"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])},
{"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])}, {"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])},

View file

@ -377,17 +377,6 @@ module_xkb_from_config(const struct yml_node *node,
return module_xkb(conf_to_particle(c, parent_font)); 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 * static struct module *
module_removables_from_config(const struct yml_node *node, module_removables_from_config(const struct yml_node *node,
const struct font *parent_font) 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); mods[idx] = module_label.from_conf(m.value, font);
else if (strcmp(mod_name, "mpd") == 0) else if (strcmp(mod_name, "mpd") == 0)
mods[idx] = module_mpd.from_conf(m.value, font); 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) else if (strcmp(mod_name, "xwindow") == 0)
mods[idx] = module_xwindow_from_config(m.value, font); 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); 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) else if (strcmp(mod_name, "removables") == 0)
mods[idx] = module_removables_from_config(m.value, font); mods[idx] = module_removables_from_config(m.value, font);
else else

View file

@ -17,8 +17,9 @@
#define LOG_MODULE "network" #define LOG_MODULE "network"
#define LOG_ENABLE_DBG 0 #define LOG_ENABLE_DBG 0
#include "../../log.h" #include "../../log.h"
#include "../../module.h"
#include "../../bar.h" #include "../../bar.h"
#include "../../config.h"
#include "../../module.h"
#include "../../tllist.h" #include "../../tllist.h"
struct af_addr { struct af_addr {
@ -511,8 +512,8 @@ run(struct module_run_context *ctx)
return 0; return 0;
} }
struct module * static struct module *
module_network(const char *iface, struct particle *label) network_new(const char *iface, struct particle *label)
{ {
struct private *priv = malloc(sizeof(*priv)); struct private *priv = malloc(sizeof(*priv));
priv->iface = strdup(iface); priv->iface = strdup(iface);
@ -533,3 +534,24 @@ module_network(const char *iface, struct particle *label)
mod->content = &content; mod->content = &content;
return mod; 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},
},
};

View file

@ -1,6 +1,4 @@
#pragma once #pragma once
#include "../../module.h" #include "../../module.h"
#include "../../particle.h"
struct module *module_network(const char *iface, struct particle *label); extern const struct module_info module_network;