From d5ba2cb628f0c5c3e5c3eef1c62aacc23f3d8aef Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 14 Oct 2012 16:31:01 +0200 Subject: [PATCH] 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. --- src/plugin.c | 25 +++++++++++++++++++++++++ src/plugin.h | 11 +++++++++++ 2 files changed, 36 insertions(+) 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 @@ -378,6 +378,17 @@ 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. */ -- 2.30.2