Code

store: Exported the store base object type as opaque type.
authorSebastian Harl <sh@tokkee.org>
Fri, 3 Jan 2014 12:17:17 +0000 (13:17 +0100)
committerSebastian Harl <sh@tokkee.org>
Fri, 3 Jan 2014 12:17:17 +0000 (13:17 +0100)
Renamed from store_obj_t to sdb_store_base_t to avoid a name-clash with
sdb_store_obj_t.

src/core/store.c
src/include/core/store.h

index ed5b7ceb5095c683bdb2a3c775c67ff389950ff7..d195b8f0e3d029f4bf853910ba4ce05358e85d58 100644 (file)
@@ -55,19 +55,16 @@ static pthread_rwlock_t obj_lock = PTHREAD_RWLOCK_INITIALIZER;
 static sdb_type_t sdb_store_obj_type;
 static sdb_type_t sdb_attribute_type;
 
 static sdb_type_t sdb_store_obj_type;
 static sdb_type_t sdb_attribute_type;
 
-struct store_obj;
-typedef struct store_obj store_obj_t;
-
-struct store_obj {
+struct sdb_store_base {
        sdb_object_t super;
        sdb_time_t last_update;
        sdb_object_t super;
        sdb_time_t last_update;
-       store_obj_t *parent;
+       sdb_store_base_t *parent;
 };
 };
-#define STORE_OBJ(obj) ((store_obj_t *)(obj))
-#define STORE_CONST_OBJ(obj) ((const store_obj_t *)(obj))
+#define STORE_BASE(obj) ((sdb_store_base_t *)(obj))
+#define STORE_CONST_BASE(obj) ((const sdb_store_base_t *)(obj))
 
 typedef struct {
 
 typedef struct {
-       store_obj_t super;
+       sdb_store_base_t super;
 
        char *value;
 } sdb_attribute_t;
 
        char *value;
 } sdb_attribute_t;
@@ -75,7 +72,7 @@ typedef struct {
 #define SDB_CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
 
 typedef struct {
 #define SDB_CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
 
 typedef struct {
-       store_obj_t super;
+       sdb_store_base_t super;
 
        int type;
        sdb_llist_t *children;
 
        int type;
        sdb_llist_t *children;
@@ -100,23 +97,23 @@ enum {
 #define _last_update super.last_update
 
 static int
 #define _last_update super.last_update
 
 static int
-store_obj_init(sdb_object_t *obj, va_list ap)
+store_base_init(sdb_object_t *obj, va_list ap)
 {
 {
-       store_obj_t *sobj = STORE_OBJ(obj);
+       sdb_store_base_t *sobj = STORE_BASE(obj);
        sobj->last_update = va_arg(ap, sdb_time_t);
 
        sobj->parent = NULL;
        return 0;
        sobj->last_update = va_arg(ap, sdb_time_t);
 
        sobj->parent = NULL;
        return 0;
-} /* store_obj_init */
+} /* store_base_init */
 
 static void
 
 static void
-store_obj_destroy(sdb_object_t *obj)
+store_base_destroy(sdb_object_t *obj)
 {
 {
-       const store_obj_t *sobj = STORE_OBJ(obj);
+       const sdb_store_base_t *sobj = STORE_CONST_BASE(obj);
 
        if (sobj->parent)
                sdb_object_deref(SDB_OBJ(sobj->parent));
 
        if (sobj->parent)
                sdb_object_deref(SDB_OBJ(sobj->parent));
-} /* store_obj_destroy */
+} /* store_base_destroy */
 
 static int
 sdb_store_obj_init(sdb_object_t *obj, va_list ap)
 
 static int
 sdb_store_obj_init(sdb_object_t *obj, va_list ap)
@@ -124,7 +121,7 @@ sdb_store_obj_init(sdb_object_t *obj, va_list ap)
        sdb_store_obj_t *sobj = SDB_STORE_OBJ(obj);
        int ret;
 
        sdb_store_obj_t *sobj = SDB_STORE_OBJ(obj);
        int ret;
 
-       ret = store_obj_init(obj, ap);
+       ret = store_base_init(obj, ap);
        if (ret)
                return ret;
 
        if (ret)
                return ret;
 
@@ -146,7 +143,7 @@ sdb_store_obj_destroy(sdb_object_t *obj)
 
        assert(obj);
 
 
        assert(obj);
 
-       store_obj_destroy(obj);
+       store_base_destroy(obj);
 
        if (sobj->children)
                sdb_llist_destroy(sobj->children);
 
        if (sobj->children)
                sdb_llist_destroy(sobj->children);
@@ -160,7 +157,7 @@ sdb_attr_init(sdb_object_t *obj, va_list ap)
        const char *value;
        int ret;
 
        const char *value;
        int ret;
 
-       ret = store_obj_init(obj, ap);
+       ret = store_base_init(obj, ap);
        if (ret)
                return ret;
        value = va_arg(ap, const char *);
        if (ret)
                return ret;
        value = va_arg(ap, const char *);
@@ -178,7 +175,7 @@ sdb_attr_destroy(sdb_object_t *obj)
 {
        assert(obj);
 
 {
        assert(obj);
 
-       store_obj_destroy(obj);
+       store_base_destroy(obj);
 
        if (SDB_ATTR(obj)->value)
                free(SDB_ATTR(obj)->value);
 
        if (SDB_ATTR(obj)->value)
                free(SDB_ATTR(obj)->value);
@@ -248,12 +245,12 @@ sdb_store_lookup(int type, const char *name)
 static int
 store_obj(int parent_type, const char *parent_name,
                int type, const char *name, sdb_time_t last_update,
 static int
 store_obj(int parent_type, const char *parent_name,
                int type, const char *name, sdb_time_t last_update,
-               store_obj_t **updated_obj)
+               sdb_store_base_t **updated_obj)
 {
        char *parent_cname = NULL, *cname = NULL;
 
        sdb_llist_t *parent_list;
 {
        char *parent_cname = NULL, *cname = NULL;
 
        sdb_llist_t *parent_list;
-       store_obj_t *old;
+       sdb_store_base_t *old;
        int status = 0;
 
        if (last_update <= 0)
        int status = 0;
 
        if (last_update <= 0)
@@ -314,14 +311,14 @@ store_obj(int parent_type, const char *parent_name,
 
        if (type == SDB_HOST)
                /* make sure that each host is unique */
 
        if (type == SDB_HOST)
                /* make sure that each host is unique */
-               old = STORE_OBJ(sdb_store_lookup_in_list(obj_list, type, name));
+               old = STORE_BASE(sdb_store_lookup_in_list(obj_list, type, name));
        else if (type == SDB_ATTRIBUTE)
                /* look into attributes of this host */
        else if (type == SDB_ATTRIBUTE)
                /* look into attributes of this host */
-               old = STORE_OBJ(sdb_llist_search_by_name(parent_list, name));
+               old = STORE_BASE(sdb_llist_search_by_name(parent_list, name));
        else
                /* look into services assigned to this host (sdb_store_lookup_in_list
                 * does not look up services from hierarchical hosts) */
        else
                /* look into services assigned to this host (sdb_store_lookup_in_list
                 * does not look up services from hierarchical hosts) */
-               old = STORE_OBJ(sdb_store_lookup_in_list(parent_list, type, name));
+               old = STORE_BASE(sdb_store_lookup_in_list(parent_list, type, name));
 
        if (old) {
                if (old->last_update > last_update) {
 
        if (old) {
                if (old->last_update > last_update) {
@@ -340,14 +337,14 @@ store_obj(int parent_type, const char *parent_name,
                        *updated_obj = old;
        }
        else {
                        *updated_obj = old;
        }
        else {
-               store_obj_t *new;
+               sdb_store_base_t *new;
 
                if (type == SDB_ATTRIBUTE)
                        /* the value will be updated by the caller */
 
                if (type == SDB_ATTRIBUTE)
                        /* the value will be updated by the caller */
-                       new = STORE_OBJ(sdb_object_create(name, sdb_attribute_type,
+                       new = STORE_BASE(sdb_object_create(name, sdb_attribute_type,
                                                last_update, NULL));
                else
                                                last_update, NULL));
                else
-                       new = STORE_OBJ(sdb_object_create(name, sdb_store_obj_type,
+                       new = STORE_BASE(sdb_object_create(name, sdb_store_obj_type,
                                                last_update, type));
 
                if (! new) {
                                                last_update, type));
 
                if (! new) {
@@ -414,7 +411,7 @@ sdb_store_attribute(const char *hostname, const char *key, const char *value,
 {
        int status;
 
 {
        int status;
 
-       store_obj_t *updated_attr = NULL;
+       sdb_store_base_t *updated_attr = NULL;
 
        if ((! hostname) || (! key))
                return -1;
 
        if ((! hostname) || (! key))
                return -1;
index bc4de1090f6d4a95e980835cf7c4033002776e79..5558e77154f32f00e9d59edf75ea3d1f0a014119 100644 (file)
 extern "C" {
 #endif
 
 extern "C" {
 #endif
 
+/*
+ * 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;
+
 /*
  * sdb_store_host:
  * Add/update a host in the store. If the host, identified by its
 /*
  * sdb_store_host:
  * Add/update a host in the store. If the host, identified by its