X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Finclude%2Fcore%2Ftimeseries.h;h=ce4f0d24c974d89f8e7f6af8fa41ac4c5dac4821;hp=3a4029d8be4b2d46e8365d3904e9fcbfe1706a9f;hb=562eaff4241f9b2428fdec9e26a10f41f681053d;hpb=c67634d0683a42c1e5457279de98958cbacc679d diff --git a/src/include/core/timeseries.h b/src/include/core/timeseries.h index 3a4029d..ce4f0d2 100644 --- a/src/include/core/timeseries.h +++ b/src/include/core/timeseries.h @@ -30,11 +30,39 @@ #include "sysdb.h" #include "core/time.h" +#include "utils/strbuf.h" #ifdef __cplusplus 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. */ @@ -56,8 +84,9 @@ typedef struct { sdb_time_t end; sdb_data_point_t **data; - char **data_names; size_t data_len; + char **data_names; + size_t data_names_len; } sdb_timeseries_t; /* @@ -69,6 +98,37 @@ typedef struct { sdb_time_t end; } sdb_timeseries_opts_t; +/* + * sdb_timeseries_create: + * Allocate a time-series object, pre-populating the data_names information + * and allocating the data field. + * + * Returns: + * - a newly allocated time-series object on success + * - NULL else + */ +sdb_timeseries_t * +sdb_timeseries_create(size_t data_names_len, const char * const *data_names, + size_t data_len); + +/* + * sdb_timeseries_destroy: + * Destroy a time-series object, freeing all of its memory. + */ +void +sdb_timeseries_destroy(sdb_timeseries_t *ts); + +/* + * sdb_timeseries_tojson: + * Serialize a time-series to JSON written to the specified string buffer. + * + * Returns: + * - 0 on success + * - a negative value else + */ +int +sdb_timeseries_tojson(sdb_timeseries_t *ts, sdb_strbuf_t *buf); + #ifdef __cplusplus } /* extern "C" */ #endif