X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finclude%2Fcore%2Fstore.h;h=40374dd2057a34e4443d111258254786c513a33a;hb=ea5d74f9f19a7a00ed993e6d6a5a5c9e03ab6ff8;hp=c25c278a327f5904ec8252cdee65ac9dc3da15d8;hpb=914549be3bfffdd3ad4b2599ed1e771d857512da;p=sysdb.git diff --git a/src/include/core/store.h b/src/include/core/store.h index c25c278..40374dd 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -49,6 +49,15 @@ enum { SDB_SERVICE, SDB_METRIC, SDB_ATTRIBUTE, + + /* + * Queryable fields of a stored object. + */ + SDB_FIELD_NAME = 1 << 8, /* type: string */ + SDB_FIELD_LAST_UPDATE, /* type: datetime */ + SDB_FIELD_AGE, /* type: datetime */ + SDB_FIELD_INTERVAL, /* type: datetime */ + SDB_FIELD_BACKEND, /* type: array of strings */ }; #define SDB_STORE_TYPE_TO_NAME(t) \ (((t) == SDB_HOST) ? "host" \ @@ -56,6 +65,21 @@ enum { : ((t) == SDB_METRIC) ? "metric" \ : ((t) == SDB_ATTRIBUTE) ? "attribute" : "unknown") +#define SDB_FIELD_TO_NAME(f) \ + (((f) == SDB_FIELD_NAME) ? "name" \ + : ((f) == SDB_FIELD_LAST_UPDATE) ? "last-update" \ + : ((f) == SDB_FIELD_AGE) ? "age" \ + : ((f) == SDB_FIELD_INTERVAL) ? "interval" \ + : ((f) == SDB_FIELD_BACKEND) ? "backend" : "unknown") + +#define SDB_FIELD_TYPE(f) \ + (((f) == SDB_FIELD_NAME) ? SDB_TYPE_STRING \ + : ((f) == SDB_FIELD_LAST_UPDATE) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_AGE) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_INTERVAL) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_BACKEND) ? (SDB_TYPE_ARRAY | SDB_TYPE_STRING) \ + : -1) + /* * sdb_store_obj_t represents the super-class of any object stored in the * database. It inherits from sdb_object_t and may safely be cast to a generic @@ -95,32 +119,6 @@ typedef struct sdb_store_matcher sdb_store_matcher_t; struct sdb_store_json_formatter; typedef struct sdb_store_json_formatter sdb_store_json_formatter_t; -/* - * Queryable fields of a stored object. - */ -enum { - SDB_FIELD_NAME = 1, /* string */ - SDB_FIELD_LAST_UPDATE, /* datetime */ - SDB_FIELD_AGE, /* datetime */ - SDB_FIELD_INTERVAL, /* datetime */ - SDB_FIELD_BACKEND, /* string */ -}; - -#define SDB_FIELD_TO_NAME(f) \ - (((f) == SDB_FIELD_NAME) ? "name" \ - : ((f) == SDB_FIELD_LAST_UPDATE) ? "last-update" \ - : ((f) == SDB_FIELD_AGE) ? "age" \ - : ((f) == SDB_FIELD_INTERVAL) ? "interval" \ - : ((f) == SDB_FIELD_BACKEND) ? "backend" : "unknown") - -#define SDB_FIELD_TYPE(f) \ - (((f) == SDB_FIELD_NAME) ? SDB_TYPE_STRING \ - : ((f) == SDB_FIELD_LAST_UPDATE) ? SDB_TYPE_DATETIME \ - : ((f) == SDB_FIELD_AGE) ? SDB_TYPE_DATETIME \ - : ((f) == SDB_FIELD_INTERVAL) ? SDB_TYPE_DATETIME \ - : ((f) == SDB_FIELD_BACKEND) ? (SDB_TYPE_ARRAY | SDB_TYPE_STRING) \ - : -1) - /* * sdb_store_clear: * Clear the entire store and remove all stored objects. @@ -216,6 +214,20 @@ int sdb_store_service_attr(const char *hostname, const char *service, const char *key, const sdb_data_t *value, sdb_time_t last_update); +/* + * sdb_store_get_child: + * Retrieve a host's child object of the specified type and name. The + * reference count of the child object will be incremented before returning + * it. The caller is responsible for releasing the object once it's no longer + * used. + * + * Returns: + * - the child object on success + * - NULL else + */ +sdb_store_obj_t * +sdb_store_get_child(sdb_store_obj_t *host, int type, const char *name); + /* * A metric store describes how to access a metric's data. */ @@ -570,57 +582,12 @@ sdb_store_scan(int type, sdb_store_matcher_t *m, sdb_store_matcher_t *filter, sdb_store_lookup_cb cb, void *user_data); /* - * Flags for serialization functions. - * - * By default, the full host object will be included in the serialized output. - * When specifying any of the flags, the respective information will be left - * out. The SKIP_EMPTY flags may be used to skip host objects entirely. + * Flags for JSON formatting. */ enum { - SDB_WANT_ARRAY = 1 << 0, - - SDB_SKIP_ATTRIBUTES = 1 << 0, - SDB_SKIP_SERVICES = 1 << 1, - SDB_SKIP_METRICS = 1 << 2, - SDB_SKIP_SERVICE_ATTRIBUTES = 1 << 3, - - SDB_SKIP_ALL = (1 << 8) - 1, - - /* skip hosts if they do not reference any services/metrics */ - SDB_SKIP_EMPTY_SERVICES = 1 << 8, - SDB_SKIP_EMPTY_METRICS = 1 << 9, + SDB_WANT_ARRAY = 1 << 0, }; -/* - * sdb_store_tojson: - * Serialize the entire store to JSON and append the result to the specified - * buffer. If specified, only objects matching the filter will be included in - * the result (see sdb_store_host_tojson for details). - * - * Returns: - * - 0 on success - * - a negative value on error - */ -int -sdb_store_tojson(sdb_strbuf_t *buf, sdb_store_matcher_t *filter, int flags); - -/* - * sdb_store_host_tojson: - * Serialize a host object to JSON and append the result to the specified - * buffer. If specified, only objects matching the filter will be included in - * the result. The filter is applied to each object individually and, thus, - * should not be of any object-type specific kind. The filter is never applied - * to the specified host object; the caller is responsible for this and for - * correctly handling skipped hosts. - * - * Returns: - * - 0 on success - * - a negative value on error - */ -int -sdb_store_host_tojson(sdb_store_obj_t *host, sdb_strbuf_t *buf, - sdb_store_matcher_t *filter, int flags); - /* * sdb_store_json_formatter: * Create a JSON formatter for the specified object types writing to the