allow plugins to be compiled into the f00bar main binary

This commit is contained in:
Daniel Eklöf 2019-01-14 20:57:03 +01:00
parent 00679dbeeb
commit 0d591fe5a1
25 changed files with 400 additions and 72 deletions

109
plugin.c
View file

@ -9,6 +9,54 @@
#include "config.h"
#include "tllist.h"
#if !defined(CORE_PLUGINS_AS_SHARED_LIBRARIES)
#define EXTERN_MODULE(plug_name) \
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( \
const struct yml_node *node, struct particle *common);
#define EXTERN_DECORATION(plug_name) \
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);
EXTERN_MODULE(alsa);
EXTERN_MODULE(backlight);
EXTERN_MODULE(battery);
EXTERN_MODULE(clock);
EXTERN_MODULE(i3);
EXTERN_MODULE(label);
EXTERN_MODULE(mpd);
EXTERN_MODULE(network);
EXTERN_MODULE(removables);
EXTERN_MODULE(xkb);
EXTERN_MODULE(xwindow);
EXTERN_PARTICLE(empty);
EXTERN_PARTICLE(list);
EXTERN_PARTICLE(map);
EXTERN_PARTICLE(progress_bar);
EXTERN_PARTICLE(ramp);
EXTERN_PARTICLE(string);
EXTERN_DECORATION(background);
EXTERN_DECORATION(stack);
EXTERN_DECORATION(underline);
#undef EXTERN_DECORATION
#undef EXTERN_PARTICLE
#undef EXTERN_MODULE
#endif
static tll(struct plugin) plugins = tll_init();
static const char *
@ -23,11 +71,70 @@ type2str(enum plugin_type type)
return NULL;
}
static void __attribute__((constructor))
init(void)
{
#if !defined(CORE_PLUGINS_AS_SHARED_LIBRARIES)
#define REGISTER_CORE_PLUGIN(plug_name, func_prefix, plug_type) \
do { \
tll_push_back( \
plugins, \
((struct plugin){ \
.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)
REGISTER_CORE_MODULE(alsa, alsa);
REGISTER_CORE_MODULE(backlight, backlight);
REGISTER_CORE_MODULE(battery, battery);
REGISTER_CORE_MODULE(clock, clock);
REGISTER_CORE_MODULE(i3, i3);
REGISTER_CORE_MODULE(label, label);
REGISTER_CORE_MODULE(mpd, mpd);
REGISTER_CORE_MODULE(network, network);
REGISTER_CORE_MODULE(removables, removables);
REGISTER_CORE_MODULE(xkb, xkb);
REGISTER_CORE_MODULE(xwindow, xwindow);
REGISTER_CORE_PARTICLE(empty, empty);
REGISTER_CORE_PARTICLE(list, list);
REGISTER_CORE_PARTICLE(map, map);
REGISTER_CORE_PARTICLE(progress-bar, progress_bar);
REGISTER_CORE_PARTICLE(ramp, ramp);
REGISTER_CORE_PARTICLE(string, string);
REGISTER_CORE_DECORATION(background, background);
REGISTER_CORE_DECORATION(stack, stack);
REGISTER_CORE_DECORATION(underline, underline);
#undef REGISTER_CORE_DECORATION
#undef REGISTER_CORE_PARTICLE
#undef REGISTER_CORE_PLUGIN
#endif /* !CORE_PLUGINS_AS_SHARED_LIBRARIES */
}
static void
free_plugin(struct plugin plug)
{
dlerror();
dlclose(plug.lib);
if (plug.lib != NULL)
dlclose(plug.lib);
const char *dl_error = dlerror();
if (dl_error != NULL)