From 1d9b36a1d9801131be7874fb0c9821332cf2ac57 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 16 Aug 2014 18:14:06 +0200 Subject: [PATCH] plugin: Added sdb_plugin_fetch_timeseries(). This function fetches a time-series from a named backend data-store using a previously registered "time-series fetcher" callback. --- src/core/plugin.c | 28 ++++++++++++++++++++++++++++ src/include/core/plugin.h | 16 ++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/core/plugin.c b/src/core/plugin.c index 85dd76f..d4bf1bd 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -1210,5 +1210,33 @@ sdb_plugin_logf(int prio, const char *fmt, ...) return ret; } /* sdb_plugin_logf */ +sdb_timeseries_t * +sdb_plugin_fetch_timeseries(const char *type, const char *id, + sdb_timeseries_opts_t *opts) +{ + sdb_plugin_cb_t *plugin; + sdb_plugin_fetch_ts_cb callback; + sdb_timeseries_t *ts; + + ctx_t *old_ctx; + + if ((! type) || (! id) || (! opts)) + return NULL; + + plugin = SDB_PLUGIN_CB(sdb_llist_search_by_name(ts_fetcher_list, type)); + if (! plugin) { + sdb_log(SDB_LOG_ERR, "core: Cannot fetch time-series of type %s: " + "no such plugin loaded"); + errno = ENOENT; + return NULL; + } + + old_ctx = ctx_set(plugin->cb_ctx); + callback = (sdb_plugin_fetch_ts_cb)plugin->cb_callback; + ts = callback(id, opts, plugin->cb_user_data); + ctx_set(old_ctx); + return ts; +} /* sdb_plugin_fetch_timeseries */ + /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/core/plugin.h b/src/include/core/plugin.h index 4ccc983..0dce877 100644 --- a/src/include/core/plugin.h +++ b/src/include/core/plugin.h @@ -377,6 +377,22 @@ sdb_plugin_vlogf(int prio, const char *fmt, va_list ap); int sdb_plugin_logf(int prio, const char *fmt, ...); +/* + * sdb_plugin_fetch_timeseries: + * Fetch the time-series identified by 'id' from a backend data-store of the + * specified 'type'. The type has to match an existing time-series fetcher + * callback's name. The identifier is passed through to the callback which + * then needs to make sense of it. The time-series option specify which data + * to fetch. + * + * Returns: + * - a time-series on success + * - NULL else + */ +sdb_timeseries_t * +sdb_plugin_fetch_timeseries(const char *type, const char *id, + sdb_timeseries_opts_t *opts); + #ifdef __cplusplus } /* extern "C" */ #endif -- 2.30.2