X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fcore%2Fstore_json.c;h=4fd309b3ec4ac6fa81f982fd9e71b2d3226d0af7;hp=a069d8543872ea79e20edd8f31c0355f372488dd;hb=3e4817902cb7285e5ab7a4f546861194f6e4ea1c;hpb=ed2c9fc3e4ca6840a5a31c735f0cfc02fd21d4fc diff --git a/src/core/store_json.c b/src/core/store_json.c index a069d85..4fd309b 100644 --- a/src/core/store_json.c +++ b/src/core/store_json.c @@ -379,10 +379,14 @@ sdb_store_json_formatter(sdb_strbuf_t *buf, int type, int flags) buf, type, flags)); } /* sdb_store_json_formatter */ +/* TODO: Move sdb_store_emit* somewhere else. */ + int -sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj) +sdb_store_emit(sdb_store_obj_t *obj, sdb_store_writer_t *w, sdb_object_t *wd) { - if ((! f) || (! obj)) + if ((! obj) || (! w) + || (! w->store_host) || (! w->store_service) + || (! w->store_metric) || (! w->store_attribute)) return -1; switch (obj->type) { @@ -395,7 +399,7 @@ sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj) (const char * const *)obj->backends, obj->backends_num, }; - return sdb_store_json_writer.store_host(&host, SDB_OBJ(f)); + return w->store_host(&host, wd); } case SDB_SERVICE: { @@ -407,7 +411,7 @@ sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj) (const char * const *)obj->backends, obj->backends_num, }; - return sdb_store_json_writer.store_service(&service, SDB_OBJ(f)); + return w->store_service(&service, wd); } case SDB_METRIC: { @@ -423,7 +427,7 @@ sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj) (const char * const *)obj->backends, obj->backends_num, }; - return sdb_store_json_writer.store_metric(&metric, SDB_OBJ(f)); + return w->store_metric(&metric, wd); } case SDB_ATTRIBUTE: { @@ -441,21 +445,21 @@ sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj) if (obj->parent && (obj->parent->type != SDB_HOST) && obj->parent->parent) attr.hostname = obj->parent->parent->_name; - return sdb_store_json_writer.store_attribute(&attr, SDB_OBJ(f)); + return w->store_attribute(&attr, wd); } } return -1; -} /* sdb_store_json_emit */ +} /* sdb_store_emit */ int -sdb_store_json_emit_full(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj, - sdb_store_matcher_t *filter) +sdb_store_emit_full(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, + sdb_store_writer_t *w, sdb_object_t *wd) { sdb_avltree_t *trees[] = { NULL, NULL, NULL }; size_t i; - if (sdb_store_json_emit(f, obj)) + if (sdb_store_emit(obj, w, wd)) return -1; if (obj->type == SDB_HOST) { @@ -486,7 +490,7 @@ sdb_store_json_emit_full(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj, if (filter && (! sdb_store_matcher_matches(filter, child, NULL))) continue; - if (sdb_store_json_emit_full(f, child, filter)) { + if (sdb_store_emit_full(child, filter, w, wd)) { sdb_avltree_iter_destroy(iter); return -1; } @@ -494,7 +498,7 @@ sdb_store_json_emit_full(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj, sdb_avltree_iter_destroy(iter); } return 0; -} /* sdb_store_json_emit_full */ +} /* sdb_store_emit_full */ int sdb_store_json_finish(sdb_store_json_formatter_t *f)