X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fplugin.h;h=8f0c6d86105fbfe56547d6b5d78ac9fd7a7f4b26;hb=0d537d56273b8be19dd87b3ec933de575fa2e558;hp=bc873b08c939bc892982b944c62f9085f80f199a;hpb=1f5513547a11512077e64769d3e08a2df35105a3;p=collectd.git diff --git a/src/plugin.h b/src/plugin.h index bc873b08..8f0c6d86 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -2,7 +2,7 @@ #define PLUGIN_H /** * collectd - src/plugin.h - * Copyright (C) 2005-2010 Florian octo Forster + * Copyright (C) 2005-2011 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 @@ -65,6 +65,8 @@ #define NOTIF_WARNING 2 #define NOTIF_OKAY 4 +#define plugin_interval (plugin_get_ctx().interval) + /* * Public data types */ @@ -97,7 +99,8 @@ struct value_list_s }; typedef struct value_list_s value_list_t; -#define VALUE_LIST_INIT { NULL, 0, 0, interval_g, "localhost", "", "", "", "", NULL } +#define VALUE_LIST_INIT { NULL, 0, 0, plugin_get_interval (), \ + "localhost", "", "", "", "", NULL } #define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "", "", NULL } struct data_source_s @@ -161,6 +164,12 @@ struct user_data_s }; typedef struct user_data_s user_data_t; +struct plugin_ctx_s +{ + cdtime_t interval; +}; +typedef struct plugin_ctx_s plugin_ctx_t; + /* * Callback types */ @@ -173,7 +182,7 @@ typedef int (*plugin_flush_cb) (cdtime_t timeout, const char *identifier, /* "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 int (*plugin_missing_cb) (const value_list_t *, user_data_t *); typedef void (*plugin_log_cb) (int severity, const char *message, user_data_t *); typedef int (*plugin_shutdown_cb) (void); @@ -214,7 +223,8 @@ void plugin_set_dir (const char *dir); * and a value below zero if an error occurs. * * NOTES - * No attempt is made to re-load an already loaded module. + * Re-loading an already loaded module is detected and zero is returned in + * this case. */ int plugin_load (const char *name, uint32_t flags); @@ -269,6 +279,8 @@ int plugin_register_init (const char *name, plugin_init_cb callback); int plugin_register_read (const char *name, int (*callback) (void)); +/* "user_data" will be freed automatically, unless + * "plugin_register_complex_read" returns an error (non-zero). */ int plugin_register_complex_read (const char *group, const char *name, plugin_read_cb callback, const struct timespec *interval, @@ -279,7 +291,7 @@ 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, +int plugin_register_shutdown (const char *name, plugin_shutdown_cb callback); int plugin_register_data_set (const data_set_t *ds); int plugin_register_log (const char *name, @@ -315,7 +327,7 @@ int plugin_unregister_notification (const char *name); * `vl' Value list of the values that have been read by a `read' * function. */ -int plugin_dispatch_values (value_list_t *vl); +int plugin_dispatch_values (value_list_t const *vl); int plugin_dispatch_missing (const value_list_t *vl); int plugin_dispatch_notification (const notification_t *notif); @@ -323,6 +335,10 @@ int plugin_dispatch_notification (const notification_t *notif); void plugin_log (int level, const char *format, ...) __attribute__ ((format(printf,2,3))); +/* These functions return the parsed severity or less than zero on failure. */ +int parse_log_severity (const char *severity); +int parse_notif_severity (const char *severity); + #define ERROR(...) plugin_log (LOG_ERR, __VA_ARGS__) #define WARNING(...) plugin_log (LOG_WARNING, __VA_ARGS__) #define NOTICE(...) plugin_log (LOG_NOTICE, __VA_ARGS__) @@ -356,4 +372,31 @@ int plugin_notification_meta_copy (notification_t *dst, int plugin_notification_meta_free (notification_meta_t *n); +/* + * Plugin context management. + */ + +void plugin_init_ctx (void); + +plugin_ctx_t plugin_get_ctx (void); +plugin_ctx_t plugin_set_ctx (plugin_ctx_t ctx); + +/* + * NAME + * plugin_get_interval + * + * DESCRIPTION + * This function returns the current value of the plugin's interval. The + * return value will be strictly greater than zero in all cases. If + * everything else fails, it will fall back to 10 seconds. + */ +cdtime_t plugin_get_interval (void); + +/* + * Context-aware thread management. + */ + +int plugin_thread_create (pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine) (void *), void *arg); + #endif /* PLUGIN_H */