#include <dlfcn.h>
-/* except for plugin_log_cb, all callback types return an int */
-typedef int (*placeholder_cb_t)(void);
+typedef int (*plugin_read_simple_cb)(void);
+/* all possible callback types */
+typedef union {
+ plugin_init_cb init;
+ plugin_read_cb complex;
+ plugin_read_simple_cb simple;
+ plugin_flush_cb flush;
+ plugin_log_cb log;
+ plugin_missing_cb missing;
+ plugin_notification_cb notification;
+ plugin_shutdown_cb shutdown;
+} plugin_cb_t;
/*
* Private structures
*/
struct callback_func_s {
- placeholder_cb_t cf_callback;
+ plugin_cb_t cf_callback;
user_data_t cf_udata;
plugin_ctx_t cf_ctx;
};
} /* }}} int register_callback */
static int create_register_callback(llist_t **list, /* {{{ */
- const char *name, placeholder_cb_t callback,
+ const char *name, plugin_cb_t callback,
user_data_t const *ud) {
- if (name == NULL || callback == NULL)
+ if (name == NULL || callback.init == NULL)
return EINVAL;
callback_func_t *cf = calloc(1, sizeof(*cf));
old_ctx = plugin_set_ctx(rf->rf_ctx);
if (rf_type == RF_SIMPLE) {
- int (*callback)(void) = rf->rf_callback;
-
+ plugin_read_simple_cb callback = rf->rf_callback.simple;
status = (*callback)();
} else {
assert(rf_type == RF_COMPLEX);
-
- plugin_read_cb callback = (plugin_read_cb)rf->rf_callback;
+ plugin_read_cb callback = rf->rf_callback.complex;
status = (*callback)(&rf->rf_udata);
}
} /* int plugin_register_complex_config */
EXPORT int plugin_register_init(const char *name, plugin_init_cb callback) {
- return create_register_callback(&list_init, name, callback, NULL);
+ plugin_cb_t cb = {.init = callback};
+ return create_register_callback(&list_init, name, cb, NULL);
} /* plugin_register_init */
static int plugin_compare_read_func(const void *arg0, const void *arg1) {
return 0;
} /* int plugin_insert_read */
-EXPORT int plugin_register_read(const char *name, int (*callback)(void)) {
+EXPORT int plugin_register_read(const char *name,
+ plugin_read_simple_cb callback) {
read_func_t *rf;
int status;
return ENOMEM;
}
- rf->rf_callback = callback;
+ rf->rf_callback.simple = callback;
rf->rf_udata.data = NULL;
rf->rf_udata.free_func = NULL;
rf->rf_ctx = plugin_get_ctx();
return ENOMEM;
}
- rf->rf_callback = (placeholder_cb_t)callback;
+ rf->rf_callback.complex = callback;
if (group != NULL)
sstrncpy(rf->rf_group, group, sizeof(rf->rf_group));
else
EXPORT int plugin_register_flush(const char *name, plugin_flush_cb callback,
user_data_t const *ud) {
- plugin_ctx_t ctx = plugin_get_ctx();
-
- int status = create_register_callback(&list_flush, name,
- (placeholder_cb_t)callback, ud);
+ plugin_cb_t flush_cb = {.flush = callback};
+ int status = create_register_callback(&list_flush, name, flush_cb, ud);
if (status != 0) {
return status;
}
+ plugin_ctx_t ctx = plugin_get_ctx();
if (ctx.flush_interval == 0) {
return 0;
}
EXPORT int plugin_register_missing(const char *name, plugin_missing_cb callback,
user_data_t const *ud) {
- return create_register_callback(&list_missing, name,
- (placeholder_cb_t)callback, ud);
+ plugin_cb_t cb = {.missing = callback};
+ return create_register_callback(&list_missing, name, cb, ud);
} /* int plugin_register_missing */
EXPORT int plugin_register_cache_event(const char *name,
EXPORT int plugin_register_shutdown(const char *name,
plugin_shutdown_cb callback) {
- return create_register_callback(&list_shutdown, name, callback, NULL);
+ plugin_cb_t cb = {.shutdown = callback};
+ return create_register_callback(&list_shutdown, name, cb, NULL);
} /* int plugin_register_shutdown */
EXPORT int plugin_register_log(const char *name, plugin_log_cb callback,
user_data_t const *ud) {
- return create_register_callback(&list_log, name, (placeholder_cb_t)callback,
- ud);
+ plugin_cb_t cb = {.log = callback};
+ return create_register_callback(&list_log, name, cb, ud);
} /* int plugin_register_log */
EXPORT int plugin_register_notification(const char *name,
plugin_notification_cb callback,
user_data_t const *ud) {
- return create_register_callback(&list_notification, name,
- (placeholder_cb_t)callback, ud);
+ plugin_cb_t cb = {.notification = callback};
+ return create_register_callback(&list_notification, name, cb, ud);
} /* int plugin_register_log */
EXPORT int plugin_unregister_config(const char *name) {
while (le != NULL) {
callback_func_t *cf = le->value;
plugin_ctx_t old_ctx = plugin_set_ctx(cf->cf_ctx);
- plugin_init_cb callback = cf->cf_callback;
+ plugin_init_cb callback = cf->cf_callback.init;
status = (*callback)();
plugin_set_ctx(old_ctx);
old_ctx = plugin_set_ctx(rf->rf_ctx);
if (rf->rf_type == RF_SIMPLE) {
- int (*callback)(void) = rf->rf_callback;
+ plugin_read_simple_cb callback = rf->rf_callback.simple;
status = (*callback)();
} else {
- plugin_read_cb callback = (plugin_read_cb)rf->rf_callback;
+ plugin_read_cb callback = rf->rf_callback.complex;
status = (*callback)(&rf->rf_udata);
}
callback_func_t *cf = le->value;
plugin_ctx_t old_ctx = plugin_set_ctx(cf->cf_ctx);
- plugin_flush_cb callback = (plugin_flush_cb)cf->cf_callback;
+ plugin_flush_cb callback = cf->cf_callback.flush;
(*callback)(timeout, identifier, &cf->cf_udata);
while (le != NULL) {
callback_func_t *cf = le->value;
plugin_ctx_t old_ctx = plugin_set_ctx(cf->cf_ctx);
- plugin_shutdown_cb callback = cf->cf_callback;
+ plugin_shutdown_cb callback = cf->cf_callback.shutdown;
/* Advance the pointer before calling the callback allows
* shutdown functions to unregister themselves. If done the
while (le != NULL) {
callback_func_t *cf = le->value;
plugin_ctx_t old_ctx = plugin_set_ctx(cf->cf_ctx);
- plugin_missing_cb callback = (plugin_missing_cb)cf->cf_callback;
+ plugin_missing_cb callback = cf->cf_callback.missing;
int status = (*callback)(fam, &cf->cf_udata);
plugin_set_ctx(old_ctx);
* (interval) information of the calling plugin */
callback_func_t *cf = le->value;
- plugin_notification_cb callback = (plugin_notification_cb)cf->cf_callback;
+ plugin_notification_cb callback = cf->cf_callback.notification;
int status = (*callback)(notif, &cf->cf_udata);
if (status != 0) {
le = llist_head(list_log);
while (le != NULL) {
callback_func_t *cf = le->value;
- plugin_log_cb callback = (plugin_log_cb)cf->cf_callback;
+ plugin_log_cb callback = cf->cf_callback.log;
/* do not switch plugin context; rather keep the context
* (interval) information of the calling plugin */