X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fcore%2Fstore.c;h=7671e9800f13a0ac0a81e2b24817d95b0f0a83ef;hp=22e965ff1858c9891cbf862e3f1af7e91d50a6c8;hb=742c60b383c9373b2156c3af5ff9e7605c056e60;hpb=9345a64b2fa015c30d6b3fcba76211f8d0d7cfd6 diff --git a/src/core/store.c b/src/core/store.c index 22e965f..7671e98 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -831,6 +831,31 @@ static sdb_store_writer_t store_writer = { store_attribute, store_service_attr, store_metric_attr, }; +/* + * TODO: let prepare and execute accept a store object as their user_data + * object + */ + +static sdb_object_t * +prepare_query(sdb_ast_node_t *ast, + sdb_strbuf_t __attribute__((unused)) *errbuf, + sdb_object_t __attribute__((unused)) *user_data) +{ + return SDB_OBJ(sdb_store_query_prepare(ast)); +} /* prepare_query */ + +static int +execute_query(sdb_object_t *q, + sdb_strbuf_t *buf, sdb_strbuf_t *errbuf, + sdb_object_t __attribute__((unused)) *user_data) +{ + return sdb_store_query_execute(QUERY(q), buf, errbuf); +} /* execute_query */ + +static sdb_store_reader_t store_reader = { + prepare_query, execute_query, +}; + /* * public API */ @@ -846,8 +871,11 @@ sdb_store_init(void) sdb_log(SDB_LOG_ERR, "store: Failed to allocate store"); return -1; } - return sdb_plugin_register_writer("memstore", - &store_writer, SDB_OBJ(global_store)); + if (sdb_plugin_register_writer("memstore", + &store_writer, SDB_OBJ(global_store))) + return -1; + return sdb_plugin_register_reader("memstore", + &store_reader, SDB_OBJ(global_store)); } /* sdb_store_init */ void @@ -858,19 +886,6 @@ sdb_store_clear(void) sdb_avltree_clear(global_store->hosts); } /* sdb_store_clear */ -bool -sdb_store_has_host(const char *name) -{ - sdb_host_t *host; - - if ((! global_store) || (! name)) - return false; - - host = lookup_host(global_store, name, /* canonicalize = */ 0); - sdb_object_deref(SDB_OBJ(host)); - return host != NULL; -} /* sdb_store_has_host */ - sdb_store_obj_t * sdb_store_get_host(const char *name) { @@ -990,6 +1005,8 @@ sdb_store_get_attr(sdb_store_obj_t *obj, const char *name, sdb_data_t *res, return 0; } /* sdb_store_get_attr */ +/* TODO: sdb_store_fetch_timeseries should move into the plugin module */ + int sdb_store_fetch_timeseries(const char *hostname, const char *metric, sdb_timeseries_opts_t *opts, sdb_strbuf_t *buf)