diff --git a/config-verify.c b/config-verify.c index d9f3220..3ab76f9 100644 --- a/config-verify.c +++ b/config-verify.c @@ -335,17 +335,17 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - const struct module_info *info = plugin_load_module(mod_name); - if (info == NULL) { + const struct module_iface *iface = plugin_load_module(mod_name); + if (iface == NULL) { LOG_ERR( "%s: invalid module name: %s", conf_err_prefix(chain, node), mod_name); return false; } - assert(info->verify_conf != NULL); + assert(iface->verify_conf != NULL); chain_push(chain, mod_name); - if (!info->verify_conf(chain, values)) + if (!iface->verify_conf(chain, values)) return false; chain_pop(chain); diff --git a/config.c b/config.c index aae4607..505cb45 100644 --- a/config.c +++ b/config.c @@ -340,8 +340,8 @@ conf_to_bar(const struct yml_node *bar) ? conf_to_color(mod_foreground) : inherited.foreground, }; - const struct module_info *info = plugin_load_module(mod_name); - mods[idx] = info->from_conf(m.value, mod_inherit); + const struct module_iface *iface = plugin_load_module(mod_name); + mods[idx] = iface->from_conf(m.value, mod_inherit); } if (i == 0) { diff --git a/module.h b/module.h index 81d70af..1fa8f91 100644 --- a/module.h +++ b/module.h @@ -9,18 +9,6 @@ #include "yml.h" struct bar; -struct module; - -struct module_info { - bool (*verify_conf)(keychain_t *chain, const struct yml_node *node); - struct module *(*from_conf)( - const struct yml_node *node, struct conf_inherit inherited); - -#define MODULE_COMMON_ATTRS \ - {"font", false, &conf_verify_font}, \ - {"foreground", false, &conf_verify_color}, \ - {NULL, false, NULL} -}; struct module { const struct bar *bar; @@ -47,3 +35,9 @@ struct module { struct module *module_common_new(void); void module_default_destroy(struct module *mod); struct exposable *module_begin_expose(struct module *mod); + +/* List of attributes *all* modules implement */ +#define MODULE_COMMON_ATTRS \ + {"font", false, &conf_verify_font}, \ + {"foreground", false, &conf_verify_color}, \ + {NULL, false, NULL} diff --git a/modules/alsa.c b/modules/alsa.c index 8a8266b..3ba2892 100644 --- a/modules/alsa.c +++ b/modules/alsa.c @@ -266,7 +266,7 @@ alsa_new(const char *card, const char *mixer, struct particle *label) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *card = yml_get_value(node, "card"); @@ -279,7 +279,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited) conf_to_particle(content, inherited)); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -292,8 +292,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/backlight.c b/modules/backlight.c index f5c085c..6f9bf46 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -214,7 +214,7 @@ backlight_new(const char *device, struct particle *label) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *name = yml_get_value(node, "name"); @@ -224,7 +224,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited) yml_value_as_string(name), conf_to_particle(c, inherited)); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -236,8 +236,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/battery.c b/modules/battery.c index d51c2e0..303c80b 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -348,7 +348,7 @@ battery_new(const char *battery, struct particle *label, int poll_interval_secs) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); @@ -361,7 +361,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited) poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -374,8 +374,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/clock.c b/modules/clock.c index 18e8edc..f87995b 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -93,7 +93,7 @@ clock_new(struct particle *label, const char *date_format, const char *time_form return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); @@ -106,7 +106,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited) time_format != NULL ? yml_value_as_string(time_format) : "%H:%M"); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -119,8 +119,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/i3.c b/modules/i3.c index 4e0a3fe..b48772a 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -639,7 +639,7 @@ i3_new(struct i3_workspaces workspaces[], size_t workspace_count, return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); @@ -696,7 +696,7 @@ verify_content(keychain_t *chain, const struct yml_node *node) return true; } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -710,8 +710,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/label.c b/modules/label.c index e63516b..fb0857d 100644 --- a/modules/label.c +++ b/modules/label.c @@ -46,14 +46,14 @@ label_new(struct particle *label) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); return label_new(conf_to_particle(c, inherited)); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -64,8 +64,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/mpd.c b/modules/mpd.c index 681d455..fae5c35 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -475,7 +475,7 @@ mpd_new(const char *host, uint16_t port, struct particle *label) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *host = yml_get_value(node, "host"); @@ -488,7 +488,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited) conf_to_particle(c, inherited)); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -501,8 +501,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/network.c b/modules/network.c index 5a87790..42a087f 100644 --- a/modules/network.c +++ b/modules/network.c @@ -530,7 +530,7 @@ network_new(const char *iface, struct particle *label) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *name = yml_get_value(node, "name"); @@ -540,7 +540,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited) yml_value_as_string(name), conf_to_particle(content, inherited)); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -552,8 +552,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/removables.c b/modules/removables.c index d9bd0e8..b56467e 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -557,7 +557,7 @@ removables_new(struct particle *label, int left_spacing, int right_spacing) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *content = yml_get_value(node, "content"); @@ -573,7 +573,7 @@ from_conf(const struct yml_node *node, struct conf_inherit inherited) return removables_new(conf_to_particle(content, inherited), left, right); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -587,8 +587,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/xkb.c b/modules/xkb.c index 7941b41..9cb422c 100644 --- a/modules/xkb.c +++ b/modules/xkb.c @@ -467,14 +467,14 @@ xkb_new(struct particle *label) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); return xkb_new(conf_to_particle(c, inherited)); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -485,8 +485,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/modules/xwindow.c b/modules/xwindow.c index 62839aa..8fcef32 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -311,14 +311,14 @@ xwindow_new(struct particle *label) return mod; } -static struct module * +struct module * from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); return xwindow_new(conf_to_particle(c, inherited)); } -static bool +bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { @@ -329,8 +329,3 @@ verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } - -const struct module_info plugin_info = { - .verify_conf = &verify_conf, - .from_conf = &from_conf, -}; diff --git a/plugin.c b/plugin.c index ca16f91..0786a56 100644 --- a/plugin.c +++ b/plugin.c @@ -47,7 +47,8 @@ plugin_load(const char *name, enum plugin_type type) tll_foreach(plugins, plug) { if (plug->item.type == type && strcmp(plug->item.name, name) == 0) { LOG_DBG("%s: %s already loaded: %p", type2str(type), name, plug->item.lib); - assert(plug->item.sym != NULL); + assert(plug->item.dummy.sym1 != NULL); + assert(plug->item.dummy.sym2 != NULL); return &plug->item; } } @@ -66,23 +67,18 @@ plugin_load(const char *name, enum plugin_type type) return NULL; } - tll_push_back(plugins, ((struct plugin){strdup(name), type, lib, {NULL}})); + tll_push_back(plugins, ((struct plugin){strdup(name), type, lib, {{NULL}}})); struct plugin *plug = &tll_back(plugins); dlerror(); /* Clear previous error */ const char *dl_error = NULL; - if (type == PLUGIN_MODULE) { - plug->sym = dlsym(lib, "plugin_info"); - dl_error = dlerror(); - } else { - plug->particle.verify_conf = dlsym(lib, "verify_conf"); - dl_error = dlerror(); + plug->dummy.sym1 = dlsym(lib, "verify_conf"); + dl_error = dlerror(); - if (dl_error == NULL) { - plug->particle.from_conf = dlsym(lib, "from_conf"); - dl_error = dlerror(); - } + if (dl_error == NULL) { + plug->dummy.sym2 = dlsym(lib, "from_conf"); + dl_error = dlerror(); } if (dl_error != NULL) { @@ -93,11 +89,11 @@ plugin_load(const char *name, enum plugin_type type) return plug; } -const struct module_info * +const struct module_iface * plugin_load_module(const char *name) { const struct plugin *plug = plugin_load(name, PLUGIN_MODULE); - return plug != NULL ? plug->sym : NULL; + return plug != NULL ? &plug->module : NULL; } const struct particle_iface * diff --git a/plugin.h b/plugin.h index c91c46d..aa910c7 100644 --- a/plugin.h +++ b/plugin.h @@ -4,13 +4,19 @@ #include "module.h" #include "particle.h" +struct module_iface { + bool (*verify_conf)(keychain_t *chain, const struct yml_node *node); + struct module *(*from_conf)( + const struct yml_node *node, struct conf_inherit inherited); +}; + struct particle_iface { bool (*verify_conf)(keychain_t *chain, const struct yml_node *node); struct particle *(*from_conf)( const struct yml_node *node, struct particle *common); }; -const struct module_info *plugin_load_module(const char *name); +const struct module_iface *plugin_load_module(const char *name); const struct particle_iface *plugin_load_particle(const char *name); enum plugin_type { PLUGIN_MODULE, PLUGIN_PARTICLE }; @@ -21,7 +27,12 @@ struct plugin { void *lib; union { - void *sym; + struct { + void *sym1; + void *sym2; + } dummy; + + struct module_iface module; struct particle_iface particle; }; };