Code

timeseries: Add support for fetching specific data-sources.
[sysdb.git] / src / include / core / timeseries.h
index b19625d1ca21166e5eb75bcb65571f06c8286051..ab74a11b35863c6cf75025ccfa6cca47312f1f81 100644 (file)
@@ -29,6 +29,7 @@
 #define SDB_CORE_TIMESERIES_H 1
 
 #include "sysdb.h"
+#include "core/object.h"
 #include "core/time.h"
 #include "utils/strbuf.h"
 
 extern "C" {
 #endif
 
+/*
+ * sdb_timeseries_info_t:
+ * Information about a timeseries.
+ */
+typedef struct {
+       char **data_names;
+       size_t data_names_len;
+} sdb_timeseries_info_t;
+
+/*
+ * sdb_timeseries_info_create:
+ * Allocate a timeseries information object.
+ *
+ * Returns:
+ *  - a newly allocated timeseries info object on success
+ *  - NULL else
+ */
+sdb_timeseries_info_t *
+sdb_timeseries_info_create(size_t data_names_len, const char * const *data_names);
+
+/*
+ * sdb_timeseries_info_destroy:
+ * Destroy a timeseries info object, freeing all of its memory.
+ */
+void
+sdb_timeseries_info_destroy(sdb_timeseries_info_t *ts_info);
+
 /*
  * A data-point describes a datum at a certain point of time.
  */
@@ -69,6 +97,10 @@ typedef struct {
 typedef struct {
        sdb_time_t start;
        sdb_time_t end;
+
+       /* If specified, only fetch time-series with these names. */
+       const char * const *data_names;
+       size_t data_names_len;
 } sdb_timeseries_opts_t;
 
 /*
@@ -91,6 +123,27 @@ sdb_timeseries_create(size_t data_names_len, const char * const *data_names,
 void
 sdb_timeseries_destroy(sdb_timeseries_t *ts);
 
+/*
+ * A timeseries fetcher fetches data from a timeseries data-store.
+ */
+typedef struct {
+       /*
+        * describe:
+        * Retrieve information about the timeseries from the data-store. The
+        * returned timeseries info object must be freeable using
+        * sdb_timeseries_info_destroy.
+        */
+       sdb_timeseries_info_t *(*describe)(const char *id, sdb_object_t *user_data);
+
+       /*
+        * fetch:
+        * Read timeseries data from the data-store. The returned timeseries
+        * object must be freeable using sdb_timeseries_destroy.
+        */
+       sdb_timeseries_t *(*fetch)(const char *id,
+                       sdb_timeseries_opts_t *opts, sdb_object_t *user_data);
+} sdb_timeseries_fetcher_t;
+
 /*
  * sdb_timeseries_tojson:
  * Serialize a time-series to JSON written to the specified string buffer.