From 1f5513547a11512077e64769d3e08a2df35105a3 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 23 Nov 2010 12:56:11 +0100 Subject: [PATCH] src/plugin.[ch]: Implement "missing" callbacks. This is a first step towards moving the threshold checking code into a plugin. --- src/plugin.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/plugin.h | 12 ++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index f6bc506c..e32c8f9c 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1,6 +1,6 @@ /** * collectd - src/plugin.c - * Copyright (C) 2005-2009 Florian octo Forster + * Copyright (C) 2005-2010 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -16,7 +16,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster * Sebastian Harl **/ @@ -74,6 +74,7 @@ typedef struct read_func_s read_func_t; static llist_t *list_init; static llist_t *list_write; static llist_t *list_flush; +static llist_t *list_missing; static llist_t *list_shutdown; static llist_t *list_log; static llist_t *list_notification; @@ -836,6 +837,13 @@ int plugin_register_flush (const char *name, (void *) callback, ud)); } /* int plugin_register_flush */ +int plugin_register_missing (const char *name, + plugin_missing_cb callback, user_data_t *ud) +{ + return (create_register_callback (&list_missing, name, + (void *) callback, ud)); +} /* int plugin_register_missing */ + int plugin_register_shutdown (char *name, int (*callback) (void)) { @@ -1022,6 +1030,11 @@ int plugin_unregister_flush (const char *name) return (plugin_unregister (list_flush, name)); } +int plugin_unregister_missing (const char *name) +{ + return (plugin_unregister (list_missing, name)); +} + int plugin_unregister_shutdown (const char *name) { return (plugin_unregister (list_shutdown, name)); @@ -1321,6 +1334,7 @@ void plugin_shutdown_all (void) * the real free function when registering the write callback. This way * the data isn't freed twice. */ destroy_all_callbacks (&list_flush); + destroy_all_callbacks (&list_missing); destroy_all_callbacks (&list_write); destroy_all_callbacks (&list_notification); @@ -1328,6 +1342,44 @@ void plugin_shutdown_all (void) destroy_all_callbacks (&list_log); } /* void plugin_shutdown_all */ +int plugin_dispatch_missing (const value_list_t *vl) /* {{{ */ +{ + llentry_t *le; + + if (list_missing == NULL) + return (0); + + le = llist_head (list_missing); + while (le != NULL) + { + callback_func_t *cf; + plugin_missing_cb callback; + int status; + + cf = le->value; + callback = cf->cf_callback; + + status = (*callback) (vl); + if (status != 0) + { + if (status < 0) + { + ERROR ("plugin_dispatch_missing: Callback function \"%s\" " + "failed with status %i.", + le->key, status); + return (status); + } + else + { + return (0); + } + } + + le = le->next; + } + return (0); +} /* int }}} plugin_dispatch_missing */ + int plugin_dispatch_values (value_list_t *vl) { int status; diff --git a/src/plugin.h b/src/plugin.h index 490aed03..bc873b08 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -2,7 +2,7 @@ #define PLUGIN_H /** * collectd - src/plugin.h - * Copyright (C) 2005-2008 Florian octo Forster + * Copyright (C) 2005-2010 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -18,7 +18,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster * Sebastian Harl **/ @@ -170,6 +170,10 @@ typedef int (*plugin_write_cb) (const data_set_t *, const value_list_t *, user_data_t *); typedef int (*plugin_flush_cb) (cdtime_t timeout, const char *identifier, user_data_t *); +/* "missing" callback. Returns less than zero on failure, zero if other + * callbacks should be called, greater than zero if no more callbacks should be + * called. */ +typedef int (*plugin_missing_cb) (const value_list_t *); typedef void (*plugin_log_cb) (int severity, const char *message, user_data_t *); typedef int (*plugin_shutdown_cb) (void); @@ -273,6 +277,8 @@ int plugin_register_write (const char *name, plugin_write_cb callback, user_data_t *user_data); int plugin_register_flush (const char *name, plugin_flush_cb callback, user_data_t *user_data); +int plugin_register_missing (const char *name, + plugin_missing_cb callback, user_data_t *user_data); int plugin_register_shutdown (char *name, plugin_shutdown_cb callback); int plugin_register_data_set (const data_set_t *ds); @@ -288,6 +294,7 @@ int plugin_unregister_read (const char *name); int plugin_unregister_read_group (const char *group); int plugin_unregister_write (const char *name); int plugin_unregister_flush (const char *name); +int plugin_unregister_missing (const char *name); int plugin_unregister_shutdown (const char *name); int plugin_unregister_data_set (const char *name); int plugin_unregister_log (const char *name); @@ -309,6 +316,7 @@ int plugin_unregister_notification (const char *name); * function. */ int plugin_dispatch_values (value_list_t *vl); +int plugin_dispatch_missing (const value_list_t *vl); int plugin_dispatch_notification (const notification_t *notif); -- 2.11.0