From 452c4b6015d63b41cf38549dd8e539bb6e2d3147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 26 Jan 2019 18:32:04 +0100 Subject: [PATCH] plugins: export a const function pointer interface struct --- decorations/background.c | 21 +++++++-------- decorations/stack.c | 22 ++++++++-------- decorations/underline.c | 21 +++++++-------- modules/alsa.c | 23 +++++++++-------- modules/backlight.c | 21 +++++++-------- modules/battery.c | 21 +++++++-------- modules/clock.c | 21 +++++++-------- modules/i3.c | 21 +++++++-------- modules/label.c | 21 +++++++-------- modules/mpd.c | 21 +++++++-------- modules/network.c | 21 +++++++-------- modules/removables.c | 21 +++++++-------- modules/xkb.c | 21 +++++++-------- modules/xwindow.c | 21 +++++++-------- particles/empty.c | 21 +++++++-------- particles/list.c | 21 +++++++-------- particles/map.c | 21 +++++++-------- particles/progress-bar.c | 21 +++++++-------- particles/ramp.c | 21 +++++++-------- particles/string.c | 21 +++++++-------- plugin.c | 55 +++++++++++++++++++--------------------- plugin.h | 7 +++++ 22 files changed, 255 insertions(+), 230 deletions(-) diff --git a/decorations/background.c b/decorations/background.c index bfc62a0..992bdf2 100644 --- a/decorations/background.c +++ b/decorations/background.c @@ -3,6 +3,7 @@ #include "../config.h" #include "../config-verify.h" #include "../decoration.h" +#include "../plugin.h" struct private { struct rgba color; @@ -40,15 +41,15 @@ background_new(struct rgba color) return deco; } -struct deco * -background_from_conf(const struct yml_node *node) +static struct deco * +from_conf(const struct yml_node *node) { const struct yml_node *color = yml_get_value(node, "color"); return background_new(conf_to_color(color)); } -bool -background_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"color", true, &conf_verify_color}, @@ -58,11 +59,11 @@ background_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct deco_iface deco_background_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("background_verify_conf"))); -struct deco *from_conf(const struct yml_node *node) - __attribute__((weak, alias("background_from_conf"))); - +extern const struct deco_iface iface __attribute__((weak, alias("deco_background_iface"))); #endif diff --git a/decorations/stack.c b/decorations/stack.c index aab7ca8..a5662b0 100644 --- a/decorations/stack.c +++ b/decorations/stack.c @@ -5,6 +5,7 @@ #include "../config.h" #include "../config-verify.h" #include "../decoration.h" +#include "../plugin.h" struct private { struct deco **decos; @@ -47,8 +48,9 @@ stack_new(struct deco *decos[], size_t count) return deco; } -struct deco * -stack_from_conf(const struct yml_node *node) + +static struct deco * +from_conf(const struct yml_node *node) { size_t count = yml_list_length(node); @@ -65,8 +67,8 @@ stack_from_conf(const struct yml_node *node) return stack_new(decos, count); } -bool -stack_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { if (!yml_is_list(node)) { LOG_ERR("%s: must be a list of decorations", conf_err_prefix(chain, node)); @@ -84,11 +86,11 @@ stack_verify_conf(keychain_t *chain, const struct yml_node *node) return true; } +const struct deco_iface deco_stack_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("stack_verify_conf"))); -struct deco *from_conf(const struct yml_node *node) - __attribute__((weak, alias("stack_from_conf"))); - +extern const struct deco_iface iface __attribute__((weak, alias("deco_stack_iface"))); #endif diff --git a/decorations/underline.c b/decorations/underline.c index 453970a..9c71efe 100644 --- a/decorations/underline.c +++ b/decorations/underline.c @@ -3,6 +3,7 @@ #include "../config.h" #include "../config-verify.h" #include "../decoration.h" +#include "../plugin.h" struct private { int size; @@ -42,16 +43,16 @@ underline_new(int size, struct rgba color) return deco; } -struct deco * -underline_from_conf(const struct yml_node *node) +static struct deco * +from_conf(const struct yml_node *node) { const struct yml_node *size = yml_get_value(node, "size"); const struct yml_node *color = yml_get_value(node, "color"); return underline_new(yml_value_as_int(size), conf_to_color(color)); } -bool -underline_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"size", true, &conf_verify_int}, @@ -62,11 +63,11 @@ underline_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct deco_iface deco_underline_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("underline_verify_conf"))); -struct deco *from_conf(const struct yml_node *node) - __attribute__((weak, alias("underline_from_conf"))); - +extern const struct deco_iface iface __attribute__((weak, alias("deco_underline_iface"))); #endif diff --git a/modules/alsa.c b/modules/alsa.c index 81ff058..01fdc8b 100644 --- a/modules/alsa.c +++ b/modules/alsa.c @@ -7,8 +7,9 @@ #define LOG_ENABLE_DBG 0 #include "../log.h" #include "../bar.h" -#include "../config.h" #include "../config-verify.h" +#include "../config.h" +#include "../plugin.h" #include "../tllist.h" struct private { @@ -284,8 +285,8 @@ alsa_new(const char *card, const char *mixer, struct particle *label) return mod; } -struct module * -alsa_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static struct module * +from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *card = yml_get_value(node, "card"); const struct yml_node *mixer = yml_get_value(node, "mixer"); @@ -297,8 +298,8 @@ alsa_from_conf(const struct yml_node *node, struct conf_inherit inherited) conf_to_particle(content, inherited)); } -bool -alsa_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"card", true, &conf_verify_string}, @@ -311,11 +312,11 @@ alsa_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_alsa_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("alsa_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("alsa_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_alsa_iface"))); #endif diff --git a/modules/backlight.c b/modules/backlight.c index 60e4881..69c67ae 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -15,6 +15,7 @@ #include "../bar.h" #include "../config.h" #include "../config-verify.h" +#include "../plugin.h" struct private { struct particle *label; @@ -219,8 +220,8 @@ backlight_new(const char *device, struct particle *label) return mod; } -struct module * -backlight_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static struct module * +from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *name = yml_get_value(node, "name"); const struct yml_node *c = yml_get_value(node, "content"); @@ -229,8 +230,8 @@ backlight_from_conf(const struct yml_node *node, struct conf_inherit inherited) yml_value_as_string(name), conf_to_particle(c, inherited)); } -bool -backlight_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"name", true, &conf_verify_string}, @@ -242,11 +243,11 @@ backlight_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_backlight_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("backlight_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("backlight_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_backlight_iface"))); #endif diff --git a/modules/battery.c b/modules/battery.c index 0802520..777260d 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -16,6 +16,7 @@ #include "../bar.h" #include "../config.h" #include "../config-verify.h" +#include "../plugin.h" enum state { STATE_FULL, STATE_CHARGING, STATE_DISCHARGING }; @@ -349,8 +350,8 @@ battery_new(const char *battery, struct particle *label, int poll_interval_secs) return mod; } -struct module * -battery_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static struct module * +from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); const struct yml_node *name = yml_get_value(node, "name"); @@ -362,8 +363,8 @@ battery_from_conf(const struct yml_node *node, struct conf_inherit inherited) poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); } -bool -battery_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"name", true, &conf_verify_string}, @@ -376,11 +377,11 @@ battery_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_battery_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("battery_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("battery_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_battery_iface"))); #endif diff --git a/modules/clock.c b/modules/clock.c index 2a9fbb4..a374239 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -8,6 +8,7 @@ #include "../bar.h" #include "../config.h" #include "../config-verify.h" +#include "../plugin.h" struct private { struct particle *label; @@ -94,8 +95,8 @@ clock_new(struct particle *label, const char *date_format, const char *time_form return mod; } -struct module * -clock_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static struct module * +from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); const struct yml_node *date_format = yml_get_value(node, "date-format"); @@ -107,8 +108,8 @@ clock_from_conf(const struct yml_node *node, struct conf_inherit inherited) time_format != NULL ? yml_value_as_string(time_format) : "%H:%M"); } -bool -clock_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"date-format", false, &conf_verify_string}, @@ -121,11 +122,11 @@ clock_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_clock_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("clock_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("clock_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_clock_iface"))); #endif diff --git a/modules/i3.c b/modules/i3.c index d90fe44..fbd32c7 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -25,6 +25,7 @@ #include "../config.h" #include "../config-verify.h" #include "../particles/dynlist.h" +#include "../plugin.h" #include "../xcb.h" struct ws_content { @@ -676,8 +677,8 @@ i3_new(struct i3_workspaces workspaces[], size_t workspace_count, return mod; } -struct module * -i3_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static struct module * +from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *c = yml_get_value(node, "content"); const struct yml_node *spacing = yml_get_value(node, "spacing"); @@ -733,8 +734,8 @@ verify_content(keychain_t *chain, const struct yml_node *node) return true; } -bool -i3_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"spacing", false, &conf_verify_int}, @@ -748,11 +749,11 @@ i3_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_i3_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("i3_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("i3_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_i3_iface"))) ; #endif diff --git a/modules/label.c b/modules/label.c index 758e384..8427050 100644 --- a/modules/label.c +++ b/modules/label.c @@ -6,6 +6,7 @@ #include "../config.h" #include "../config-verify.h" #include "../module.h" +#include "../plugin.h" struct private { struct particle *label; @@ -47,15 +48,15 @@ label_new(struct particle *label) return mod; } -struct module * -label_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static 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)); } -bool -label_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"content", true, &conf_verify_particle}, @@ -66,11 +67,11 @@ label_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_label_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("label_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("label_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_label_iface"))); #endif diff --git a/modules/mpd.c b/modules/mpd.c index f6743af..8c3a7ae 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -25,6 +25,7 @@ #include "../bar.h" #include "../config.h" #include "../config-verify.h" +#include "../plugin.h" enum state { STATE_OFFLINE = 1000, @@ -583,8 +584,8 @@ mpd_new(const char *host, uint16_t port, struct particle *label) return mod; } -struct module * -mpd_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static struct module * +from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *host = yml_get_value(node, "host"); const struct yml_node *port = yml_get_value(node, "port"); @@ -596,8 +597,8 @@ mpd_from_conf(const struct yml_node *node, struct conf_inherit inherited) conf_to_particle(c, inherited)); } -bool -mpd_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"host", true, &conf_verify_string}, @@ -610,11 +611,11 @@ mpd_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_mpd_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("mpd_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("mpd_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_mpd_iface"))); #endif diff --git a/modules/network.c b/modules/network.c index a1f61a6..6da16af 100644 --- a/modules/network.c +++ b/modules/network.c @@ -20,6 +20,7 @@ #include "../config.h" #include "../config-verify.h" #include "../module.h" +#include "../plugin.h" #include "../tllist.h" struct af_addr { @@ -530,8 +531,8 @@ network_new(const char *iface, struct particle *label) return mod; } -struct module * -network_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static struct module * +from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *name = yml_get_value(node, "name"); const struct yml_node *content = yml_get_value(node, "content"); @@ -540,8 +541,8 @@ network_from_conf(const struct yml_node *node, struct conf_inherit inherited) yml_value_as_string(name), conf_to_particle(content, inherited)); } -bool -network_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"name", true, &conf_verify_string}, @@ -553,11 +554,11 @@ network_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_network_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("network_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("network_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_network_iface"))); #endif diff --git a/modules/removables.c b/modules/removables.c index 92d186b..5bbaf2c 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -19,6 +19,7 @@ #include "../config.h" #include "../config-verify.h" #include "../particles/dynlist.h" +#include "../plugin.h" #include "../tllist.h" typedef tll(char *) mount_point_list_t; @@ -558,8 +559,8 @@ removables_new(struct particle *label, int left_spacing, int right_spacing) return mod; } -struct module * -removables_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static struct module * +from_conf(const struct yml_node *node, struct conf_inherit inherited) { const struct yml_node *content = yml_get_value(node, "content"); const struct yml_node *spacing = yml_get_value(node, "spacing"); @@ -574,8 +575,8 @@ removables_from_conf(const struct yml_node *node, struct conf_inherit inherited) return removables_new(conf_to_particle(content, inherited), left, right); } -bool -removables_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"spacing", false, &conf_verify_int}, @@ -589,11 +590,11 @@ removables_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_removables_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("removables_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("removables_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_removables_iface"))); #endif diff --git a/modules/xkb.c b/modules/xkb.c index ca1b72a..299f203 100644 --- a/modules/xkb.c +++ b/modules/xkb.c @@ -14,6 +14,7 @@ #include "../bar.h" #include "../config.h" #include "../config-verify.h" +#include "../plugin.h" #include "../xcb.h" struct layout { @@ -658,15 +659,15 @@ xkb_new(struct particle *label) return mod; } -struct module * -xkb_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static 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)); } -bool -xkb_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"content", true, &conf_verify_particle}, @@ -677,11 +678,11 @@ xkb_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_xkb_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("xkb_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("xkb_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_xkb_iface"))); #endif diff --git a/modules/xwindow.c b/modules/xwindow.c index 4a968d5..bb07ea4 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -18,6 +18,7 @@ #include "../bar.h" #include "../config.h" #include "../config-verify.h" +#include "../plugin.h" #include "../xcb.h" struct private { @@ -334,15 +335,15 @@ xwindow_new(struct particle *label) return mod; } -struct module * -xwindow_from_conf(const struct yml_node *node, struct conf_inherit inherited) +static 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)); } -bool -xwindow_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"content", true, &conf_verify_particle}, @@ -353,11 +354,11 @@ xwindow_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct module_iface module_xwindow_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("xwindow_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct conf_inherit inherited) - __attribute__((weak, alias("xwindow_from_conf"))); - +extern const struct module_iface iface __attribute__((weak, alias("module_xwindow_iface"))); #endif diff --git a/particles/empty.c b/particles/empty.c index 55c34c6..8b0cb39 100644 --- a/particles/empty.c +++ b/particles/empty.c @@ -3,6 +3,7 @@ #include "../config.h" #include "../config-verify.h" #include "../particle.h" +#include "../plugin.h" static int begin_expose(struct exposable *exposable) @@ -39,14 +40,14 @@ empty_new(struct particle *common) return common; } -struct particle * -empty_from_conf(const struct yml_node *node, struct particle *common) +static struct particle * +from_conf(const struct yml_node *node, struct particle *common) { return empty_new(common); } -bool -empty_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { PARTICLE_COMMON_ATTRS, @@ -55,11 +56,11 @@ empty_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct particle_iface particle_empty_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("empty_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct particle *common) - __attribute__((weak, alias("empty_from_conf"))); - +extern const struct particle_iface iface __attribute__((weak, alias("particle_empty_iface"))); #endif diff --git a/particles/list.c b/particles/list.c index 04324d9..68b7186 100644 --- a/particles/list.c +++ b/particles/list.c @@ -6,6 +6,7 @@ #include "../config.h" #include "../config-verify.h" #include "../particle.h" +#include "../plugin.h" struct private { struct particle **particles; @@ -163,8 +164,8 @@ particle_list_new(struct particle *common, return common; } -struct particle * -list_from_conf(const struct yml_node *node, struct particle *common) +static struct particle * +from_conf(const struct yml_node *node, struct particle *common) { const struct yml_node *items = yml_get_value(node, "items"); const struct yml_node *spacing = yml_get_value(node, "spacing"); @@ -191,8 +192,8 @@ list_from_conf(const struct yml_node *node, struct particle *common) return particle_list_new(common, parts, count, left_spacing, right_spacing); } -bool -list_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"items", true, &conf_verify_particle_list_items}, @@ -205,11 +206,11 @@ list_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct particle_iface particle_list_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("list_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct particle *common) - __attribute__((weak, alias("list_from_conf"))); - +extern const struct particle_iface iface __attribute__((weak, alias("particle_list_iface"))); #endif diff --git a/particles/map.c b/particles/map.c index 27325eb..5acc7f9 100644 --- a/particles/map.c +++ b/particles/map.c @@ -7,6 +7,7 @@ #include "../config.h" #include "../config-verify.h" #include "../particle.h" +#include "../plugin.h" struct particle_map { const char *tag_value; @@ -196,8 +197,8 @@ verify_map_values(keychain_t *chain, const struct yml_node *node) return true; } -struct particle * -map_from_conf(const struct yml_node *node, struct particle *common) +static struct particle * +from_conf(const struct yml_node *node, struct particle *common) { const struct yml_node *tag = yml_get_value(node, "tag"); const struct yml_node *values = yml_get_value(node, "values"); @@ -227,8 +228,8 @@ map_from_conf(const struct yml_node *node, struct particle *common) default_particle); } -bool -map_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"tag", true, &conf_verify_string}, @@ -240,11 +241,11 @@ map_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct particle_iface particle_map_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("map_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct particle *common) - __attribute__((weak, alias("map_from_conf"))); - +extern const struct particle_iface iface __attribute__((weak, alias("particle_map_iface"))); #endif diff --git a/particles/progress-bar.c b/particles/progress-bar.c index f6f6d23..a10f9e2 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -8,6 +8,7 @@ #include "../config.h" #include "../config-verify.h" #include "../particle.h" +#include "../plugin.h" struct private { char *tag; @@ -228,8 +229,8 @@ progress_bar_new(struct particle *common, const char *tag, int width, return common; } -struct particle * -progress_bar_from_conf(const struct yml_node *node, struct particle *common) +static struct particle * +from_conf(const struct yml_node *node, struct particle *common) { const struct yml_node *tag = yml_get_value(node, "tag"); const struct yml_node *length = yml_get_value(node, "length"); @@ -255,8 +256,8 @@ progress_bar_from_conf(const struct yml_node *node, struct particle *common) conf_to_particle(indicator, inherited)); } -bool -progress_bar_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"tag", true, &conf_verify_string}, @@ -273,11 +274,11 @@ progress_bar_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct particle_iface particle_progress_bar_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("progress_bar_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct particle *common) - __attribute__((weak, alias("progress_bar_from_conf"))); - +extern const struct particle_iface iface __attribute__((weak, alias("particle_progress_bar_iface"))); #endif diff --git a/particles/ramp.c b/particles/ramp.c index 868d854..a9cf627 100644 --- a/particles/ramp.c +++ b/particles/ramp.c @@ -7,6 +7,7 @@ #include "../config.h" #include "../config-verify.h" #include "../particle.h" +#include "../plugin.h" struct private { char *tag; @@ -153,8 +154,8 @@ ramp_new(struct particle *common, const char *tag, return common; } -struct particle * -ramp_from_conf(const struct yml_node *node, struct particle *common) +static struct particle * +from_conf(const struct yml_node *node, struct particle *common) { const struct yml_node *tag = yml_get_value(node, "tag"); const struct yml_node *items = yml_get_value(node, "items"); @@ -174,8 +175,8 @@ ramp_from_conf(const struct yml_node *node, struct particle *common) return ramp_new(common, yml_value_as_string(tag), parts, count); } -bool -ramp_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"tag", true, &conf_verify_string}, @@ -186,11 +187,11 @@ ramp_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct particle_iface particle_ramp_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("ramp_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct particle *common) - __attribute__((weak, alias("ramp_from_conf"))); - +extern const struct particle_iface iface __attribute__((weak, alias("particle_ramp_iface"))); #endif diff --git a/particles/string.c b/particles/string.c index 2d8aede..5c06378 100644 --- a/particles/string.c +++ b/particles/string.c @@ -8,6 +8,7 @@ #include "../config.h" #include "../config-verify.h" #include "../particle.h" +#include "../plugin.h" struct private { char *text; @@ -173,8 +174,8 @@ string_new(struct particle *common, const char *text, size_t max_len) return common; } -struct particle * -string_from_conf(const struct yml_node *node, struct particle *common) +static struct particle * +from_conf(const struct yml_node *node, struct particle *common) { const struct yml_node *text = yml_get_value(node, "text"); const struct yml_node *max = yml_get_value(node, "max"); @@ -185,8 +186,8 @@ string_from_conf(const struct yml_node *node, struct particle *common) max != NULL ? yml_value_as_int(max) : 0); } -bool -string_verify_conf(keychain_t *chain, const struct yml_node *node) +static bool +verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"text", true, &conf_verify_string}, @@ -197,11 +198,11 @@ string_verify_conf(keychain_t *chain, const struct yml_node *node) return conf_verify_dict(chain, node, attrs); } +const struct particle_iface particle_string_iface = { + .verify_conf = &verify_conf, + .from_conf = &from_conf, +}; + #if defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) - -bool verify_conf(keychain_t *chain, const struct yml_node *node) - __attribute__((weak, alias("string_verify_conf"))); -struct deco *from_conf(const struct yml_node *node, struct particle *common) - __attribute__((weak, alias("string_from_conf"))); - +extern const struct particle_iface iface __attribute__((weak, alias("particle_string_iface"))); #endif diff --git a/plugin.c b/plugin.c index c680408..5731f40 100644 --- a/plugin.c +++ b/plugin.c @@ -12,18 +12,21 @@ #if !defined(CORE_PLUGINS_AS_SHARED_LIBRARIES) #define EXTERN_MODULE(plug_name) \ + extern const struct module_iface module_##plug_name##_iface; \ extern bool plug_name##_verify_conf( \ keychain_t *chain, const struct yml_node *node); \ extern struct module *plug_name##_from_conf( \ const struct yml_node *node, struct conf_inherit inherited); -#define EXTERN_PARTICLE(plug_name) \ - extern bool plug_name##_verify_conf( \ - keychain_t *chain, const struct yml_node *node); \ - extern struct particle *plug_name##_from_conf( \ +#define EXTERN_PARTICLE(plug_name) \ + extern const struct particle_iface particle_##plug_name##_iface; \ + extern bool plug_name##_verify_conf( \ + keychain_t *chain, const struct yml_node *node); \ + extern struct particle *plug_name##_from_conf( \ const struct yml_node *node, struct particle *common); #define EXTERN_DECORATION(plug_name) \ + extern const struct deco_iface deco_##plug_name##_iface; \ extern bool plug_name##_verify_conf( \ keychain_t *chain, const struct yml_node *node); \ extern struct deco *plug_name##_from_conf(const struct yml_node *node); @@ -84,19 +87,21 @@ init(void) .name = strdup(#plug_name), \ .type = (plug_type), \ .lib = NULL, \ - .dummy = { \ - .sym1 = &func_prefix##_verify_conf, \ - .sym2 = &func_prefix##_from_conf, \ - } \ })); \ } while (0) -#define REGISTER_CORE_MODULE(plug_name, func_prefix) \ - REGISTER_CORE_PLUGIN(plug_name, func_prefix, PLUGIN_MODULE) -#define REGISTER_CORE_PARTICLE(plug_name, func_prefix) \ - REGISTER_CORE_PLUGIN(plug_name, func_prefix, PLUGIN_PARTICLE) -#define REGISTER_CORE_DECORATION(plug_name, func_prefix) \ - REGISTER_CORE_PLUGIN(plug_name, func_prefix, PLUGIN_DECORATION) +#define REGISTER_CORE_MODULE(plug_name, func_prefix) do { \ + REGISTER_CORE_PLUGIN(plug_name, func_prefix, PLUGIN_MODULE); \ + tll_back(plugins).module = &module_##func_prefix##_iface; \ + } while (0) +#define REGISTER_CORE_PARTICLE(plug_name, func_prefix) do { \ + REGISTER_CORE_PLUGIN(plug_name, func_prefix, PLUGIN_PARTICLE); \ + tll_back(plugins).particle = &particle_##func_prefix##_iface; \ + } while (0) +#define REGISTER_CORE_DECORATION(plug_name, func_prefix) do { \ + REGISTER_CORE_PLUGIN(plug_name, func_prefix, PLUGIN_DECORATION); \ + tll_back(plugins).decoration = &deco_##func_prefix##_iface; \ + } while (0) REGISTER_CORE_MODULE(alsa, alsa); REGISTER_CORE_MODULE(backlight, backlight); @@ -155,8 +160,7 @@ 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.dummy.sym1 != NULL); - assert(plug->item.dummy.sym2 != NULL); + assert(plug->item.dummy != NULL); return &plug->item; } } @@ -174,20 +178,13 @@ 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; - - plug->dummy.sym1 = dlsym(lib, "verify_conf"); - dl_error = dlerror(); - - if (dl_error == NULL) { - plug->dummy.sym2 = dlsym(lib, "from_conf"); - dl_error = dlerror(); - } + plug->dummy = dlsym(lib, "iface"); + const char *dl_error = dlerror(); if (dl_error != NULL) { LOG_ERR("%s: %s: dlsym: %s", type2str(type), name, dl_error); return NULL; @@ -200,19 +197,19 @@ const struct module_iface * plugin_load_module(const char *name) { const struct plugin *plug = plugin_load(name, PLUGIN_MODULE); - return plug != NULL ? &plug->module : NULL; + return plug != NULL ? plug->module : NULL; } const struct particle_iface * plugin_load_particle(const char *name) { const struct plugin *plug = plugin_load(name, PLUGIN_PARTICLE); - return plug != NULL ? &plug->particle : NULL; + return plug != NULL ? plug->particle : NULL; } const struct deco_iface * plugin_load_deco(const char *name) { const struct plugin *plug = plugin_load(name, PLUGIN_DECORATION); - return plug != NULL ? &plug->decoration : NULL; + return plug != NULL ? plug->decoration : NULL; } diff --git a/plugin.h b/plugin.h index f3d7567..1b2da24 100644 --- a/plugin.h +++ b/plugin.h @@ -36,6 +36,12 @@ struct plugin { void *lib; union { + const struct module_iface *module; + const struct particle_iface *particle; + const struct deco_iface *decoration; + const void *dummy; + +#if 0 struct { void *sym1; void *sym2; @@ -44,6 +50,7 @@ struct plugin { struct module_iface module; struct particle_iface particle; struct deco_iface decoration; +#endif }; };