X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Finclude%2Fcore%2Fstore.h;h=99b2ead200cce151cc6775882903b6235fe042fc;hp=cadbfe47dbf861939168c3558ddbb6c7bd53c650;hb=ebc8f66f721bbe6a23e32f6712003b34f588b508;hpb=8b621cd1a68f011c2935d2cb2c23e8476d624699 diff --git a/src/include/core/store.h b/src/include/core/store.h index cadbfe4..99b2ead 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/core/store.h + * SysDB - src/include/core/store.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,13 +25,14 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_CORE_STORE_H -#define SC_CORE_STORE_H 1 +#ifndef SDB_CORE_STORE_H +#define SDB_CORE_STORE_H 1 -#include "syscollector.h" +#include "sysdb.h" #include "core/object.h" -#include "utils/time.h" +#include "core/time.h" #include "utils/llist.h" +#include "utils/strbuf.h" #include @@ -39,60 +40,21 @@ extern "C" { #endif -typedef struct { - sc_object_t parent; - - sc_time_t last_update; - char *name; -} sc_store_obj_t; -#define SC_STORE_OBJ_INIT { SC_OBJECT_INIT, 0, NULL } -#define SC_STORE_OBJ(obj) ((sc_store_obj_t *)(obj)) - -typedef struct { - sc_store_obj_t parent; -#define svc_last_update parent.last_update -#define svc_name parent.name - - char *hostname; -} sc_service_t; -#define SC_SVC_INIT { SC_STORE_OBJ_INIT, NULL } -#define SC_SVC(obj) ((sc_service_t *)(obj)) - -typedef struct { - sc_store_obj_t parent; -#define attr_last_update parent.last_update -#define attr_name parent.name - - char *attr_value; - char *hostname; -} sc_attribute_t; -#define SC_ATTR_INIT { SC_STORE_OBJ_INIT, NULL, NULL } -#define SC_ATTR(obj) ((sc_attribute_t *)(obj)) - -typedef struct { - sc_store_obj_t parent; -#define host_last_update parent.last_update -#define host_name parent.name - - sc_llist_t *attributes; - sc_llist_t *services; -} sc_host_t; -#define SC_HOST_INIT { SC_STORE_OBJ_INIT, NULL, NULL } -#define SC_HOST(obj) ((sc_host_t *)(obj)) - -sc_host_t * -sc_host_create(const char *name); - -sc_host_t * -sc_host_clone(const sc_host_t *host); +/* + * sdb_store_base_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 + * object to access its name. + */ +struct sdb_store_base; +typedef struct sdb_store_base sdb_store_base_t; /* - * sc_store_host: - * Add/update a host in the store. If the host, identified by its name, - * already exists, it will be updated according to the specified 'host' - * object. Else, a new entry will be created in the store. Any memory required - * for storing the entry will be allocated an managed by the store itself. The - * specified host-object will not be referenced or further accessed. + * sdb_store_host: + * Add/update a host in the store. If the host, identified by its + * canonicalized name, already exists, it will be updated according to the + * specified name and timestamp. Else, a new entry will be created in the + * store. Any memory required for storing the entry will be allocated an + * managed by the store itself. * * Returns: * - 0 on success @@ -101,27 +63,19 @@ sc_host_clone(const sc_host_t *host); * - a negative value on error */ int -sc_store_host(const sc_host_t *host); +sdb_store_host(const char *name, sdb_time_t last_update); -const sc_host_t * -sc_store_get_host(const char *name); - -sc_attribute_t * -sc_attribute_create(const char *hostname, - const char *name, const char *value); - -sc_attribute_t * -sc_attribute_clone(const sc_attribute_t *attr); +_Bool +sdb_store_has_host(const char *name); /* - * sc_store_attribute: + * sdb_store_attribute: * Add/update a host's attribute in the store. If the attribute, identified by - * its name, already exists for the specified host, it will be updated - * according to the specified 'attr' object. If the referenced host does not - * exist, an error will be reported. Else, a new entry will be created in the - * store. Any memory required for storing the entry will be allocated and - * managed by the store itself. The specified attribute-object will not be - * referenced or further accessed. + * its key, already exists for the specified host, it will be updated to the + * specified values. If the referenced host does not exist, an error will be + * reported. Else, a new entry will be created in the store. Any memory + * required for storing the entry will be allocated and managed by the store + * itself. * * Returns: * - 0 on success @@ -130,16 +84,11 @@ sc_attribute_clone(const sc_attribute_t *attr); * - a negative value on error */ int -sc_store_attribute(const sc_attribute_t *attr); - -sc_service_t * -sc_service_create(const char *hostname, const char *name); - -sc_service_t * -sc_service_clone(const sc_service_t *svc); +sdb_store_attribute(const char *hostname, const char *key, const char *value, + sdb_time_t last_update); /* - * sc_store_service: + * sdb_store_service: * Add/update a store in the store. If the service, identified by its name, * already exists for the specified host, it will be updated according to the * specified 'service' object. If the referenced host does not exist, an error @@ -155,19 +104,38 @@ sc_service_clone(const sc_service_t *svc); * - a negative value on error */ int -sc_store_service(const sc_service_t *svc); +sdb_store_service(const char *hostname, const char *name, + sdb_time_t last_update); -const sc_service_t * -sc_store_get_service(const sc_host_t *host, const char *name); +/* + * sdb_store_tojson: + * Serialize the entire store to JSON and append the result to the specified + * buffer. + * + * Returns: + * - 0 on success + * - a negative value on error + */ +int +sdb_store_tojson(sdb_strbuf_t *buf); +/* + * sdb_store_host_tojson: + * Serialize a host object to JSON and append the result to the specified + * buffer. + * + * Returns: + * - 0 on success + * - a negative value on error + */ int -sc_store_dump(FILE *fh); +sdb_store_host_tojson(sdb_store_base_t *host, sdb_strbuf_t *buf); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_CORE_STORE_H */ +#endif /* ! SDB_CORE_STORE_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */