From: Sebastian Harl Date: Sun, 14 Oct 2012 14:31:01 +0000 (+0200) Subject: plugin: Added plugin_get_interval(). X-Git-Tag: collectd-5.2.0~20^2~15 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d5ba2cb628f0c5c3e5c3eef1c62aacc23f3d8aef;p=collectd.git plugin: Added plugin_get_interval(). This function returns the current value of the plugin's interval. If no interval has been set in the plugin context, it will fall back to the global interval or ten seconds as a last resort. --- diff --git a/src/plugin.c b/src/plugin.c index 175a89a1..002955d5 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -2054,6 +2054,31 @@ plugin_ctx_t plugin_set_ctx (plugin_ctx_t ctx) return (old); } /* void plugin_set_ctx */ +cdtime_t plugin_get_interval (void) +{ + cdtime_t interval; + + const char *interval_str; + double interval_dbl; + + interval = plugin_get_ctx().interval; + if (interval > 0) + return interval; + + /* this should happen during initialization only */ + interval_str = global_option_get ("Interval"); + if (interval_str != NULL) + { + interval_dbl = atof (interval_str); + if (interval_dbl > 0.0) + interval = DOUBLE_TO_CDTIME_T (interval_dbl); + } + + if (interval > 0) + return interval; + return TIME_T_TO_CDTIME_T (10); +} /* cdtime_t plugin_get_interval */ + typedef struct { plugin_ctx_t ctx; void *(*start_routine) (void *); diff --git a/src/plugin.h b/src/plugin.h index 5036a63b..e147a938 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -379,6 +379,17 @@ 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. */