diff --git a/src/core/store_json.c b/src/core/store_json.c
index 5d0408a75fee33ad7b0a3718efcd081944ea2013..961e54c0606ae84206d1199758506ad4ff212cbf 100644 (file)
--- a/src/core/store_json.c
+++ b/src/core/store_json.c
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))
return -1;
- {
- obj_t o = {
- obj->type,
- obj->_name,
-
- /* value */ NULL,
- /* timeseries */ -1,
-
- obj->last_update,
- obj->interval,
- obj->backends_num,
- (const char * const *)obj->backends,
- };
-
- if (obj->type == SDB_ATTRIBUTE)
- o.value = &ATTR(obj)->value;
- if (obj->type == SDB_METRIC)
- o.timeseries = METRIC(obj)->store.type != NULL;
-
- return json_emit(f, &o);
+ switch (obj->type) {
+ case SDB_HOST:
+ {
+ sdb_store_host_t host = {
+ obj->_name,
+ obj->last_update,
+ obj->interval,
+ (const char * const *)obj->backends,
+ obj->backends_num,
+ };
+ if (! w->store_host)
+ return -1;
+ return w->store_host(&host, wd);
+ }
+ case SDB_SERVICE:
+ {
+ sdb_store_service_t service = {
+ obj->parent ? obj->parent->_name : NULL,
+ obj->_name,
+ obj->last_update,
+ obj->interval,
+ (const char * const *)obj->backends,
+ obj->backends_num,
+ };
+ if (! w->store_service)
+ return -1;
+ return w->store_service(&service, wd);
+ }
+ case SDB_METRIC:
+ {
+ sdb_store_metric_t metric = {
+ obj->parent ? obj->parent->_name : NULL,
+ obj->_name,
+ {
+ METRIC(obj)->store.type,
+ METRIC(obj)->store.id,
+ },
+ obj->last_update,
+ obj->interval,
+ (const char * const *)obj->backends,
+ obj->backends_num,
+ };
+ if (! w->store_metric)
+ return -1;
+ return w->store_metric(&metric, wd);
+ }
+ case SDB_ATTRIBUTE:
+ {
+ sdb_store_attribute_t attr = {
+ NULL,
+ obj->parent ? obj->parent->type : 0,
+ obj->parent ? obj->parent->_name : NULL,
+ obj->_name,
+ ATTR(obj)->value,
+ obj->last_update,
+ obj->interval,
+ (const char * const *)obj->backends,
+ obj->backends_num,
+ };
+ if (obj->parent && (obj->parent->type != SDB_HOST)
+ && obj->parent->parent)
+ attr.hostname = obj->parent->parent->_name;
+ if (! w->store_attribute)
+ return -1;
+ return w->store_attribute(&attr, wd);
+ }
}
-} /* sdb_store_json_emit */
+
+ return -1;
+} /* 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) {
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;
}
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)