summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJusung Son <jusung07.son@samsung.com>2019-11-19 19:36:43 +0900
committerjusung son <jusung07.son@samsung.com>2019-11-21 07:58:52 +0000
commit595a94d8fc3926126a1fd09e7899f0b0a12bc034 (patch)
treec2057266aa9d1364c57ca607cdddd157eaca25fa
parent10db222e49463174f16e0cc494f90bf87cb4b5f2 (diff)
downloadbuxton2-595a94d8fc3926126a1fd09e7899f0b0a12bc034.tar.gz
buxton2-595a94d8fc3926126a1fd09e7899f0b0a12bc034.tar.bz2
buxton2-595a94d8fc3926126a1fd09e7899f0b0a12bc034.zip
Reduce module circular dependency
Change-Id: I021334085ffd219e6669b9561425999a4f3ae692 Signed-off-by: Jusung Son <jusung07.son@samsung.com>
-rw-r--r--common/cache.c29
-rw-r--r--common/cache.h12
-rw-r--r--common/common.c20
-rw-r--r--common/common.h38
-rw-r--r--common/direct.c72
-rw-r--r--common/direct.h2
-rw-r--r--common/serialize.c56
-rw-r--r--common/serialize.h2
-rw-r--r--lib/buxton2.c4
9 files changed, 139 insertions, 96 deletions
diff --git a/common/cache.c b/common/cache.c
index feaf410..160f9e7 100644
--- a/common/cache.c
+++ b/common/cache.c
@@ -23,7 +23,6 @@
#include <glib.h>
-#include "buxton2.h"
#include "log.h"
#include "cache.h"
#include "buxton_error.h"
@@ -38,13 +37,13 @@
typedef struct _cache {
GHashTable *hash_table;
- enum buxton_layer_type layer_type;
+ enum layer_attribute_type layer_type;
int count;
int size;
} bxt_cache;
typedef struct _cache_data {
- enum buxton_layer_type layer_type;
+ enum layer_attribute_type layer_type;
int len; /* data size */
void *data; /* raw data */
} cache_data;
@@ -52,9 +51,9 @@ typedef struct _cache_data {
static bxt_cache *g_base_db_cache;
static bxt_cache *g_normal_db_cache;
-static bxt_cache *get_cache(enum buxton_layer_type layer_type)
+static bxt_cache *get_cache(enum layer_attribute_type layer_type)
{
- return (layer_type == BUXTON_LAYER_NORMAL) ?
+ return (layer_type == LAYER_ATTRIBUTE_RW) ?
g_normal_db_cache : g_base_db_cache;
}
@@ -116,7 +115,7 @@ void cache_init(void)
g_normal_db_cache->count = 0;
}
-void cache_remove(enum buxton_layer_type layer_type, const char *key)
+void cache_remove(enum layer_attribute_type layer_type, const char *key)
{
GHashTable *hash_table = NULL;
@@ -132,13 +131,13 @@ void cache_remove(enum buxton_layer_type layer_type, const char *key)
if (g_hash_table_remove(hash_table, key)) {
bxt_dbg("[%s cache] removed (%s)/count(%d)/total size(%d)",
- (layer_type == BUXTON_LAYER_NORMAL) ?
+ (layer_type == LAYER_ATTRIBUTE_RW) ?
"NORMAL" : "BASE",
key, cache->count, cache->size);
}
}
-void cache_update_data(enum buxton_layer_type layer_type,
+void cache_update_data(enum layer_attribute_type layer_type,
const char *key, uint8_t *data, int len)
{
GHashTable *hash_table = NULL;
@@ -173,7 +172,7 @@ void cache_update_data(enum buxton_layer_type layer_type,
cdata->len = len;
}
-static void cache_drop(enum buxton_layer_type layer_type, int size)
+static void cache_drop(enum layer_attribute_type layer_type, int size)
{
GHashTableIter iter;
gpointer key;
@@ -193,7 +192,7 @@ static void cache_drop(enum buxton_layer_type layer_type, int size)
while (g_hash_table_iter_next(&iter, &key, &value)) {
if (remain > 0) {
bxt_dbg("[%s cache][%d] removed (%s)",
- (layer_type == BUXTON_LAYER_NORMAL) ?
+ (layer_type == LAYER_ATTRIBUTE_RW) ?
"NORMAL" : "BASE", remain, (char *)key);
g_hash_table_iter_remove(&iter);
remain--;
@@ -201,7 +200,7 @@ static void cache_drop(enum buxton_layer_type layer_type, int size)
}
}
-void cache_insert(enum buxton_layer_type layer_type, const char *key,
+void cache_insert(enum layer_attribute_type layer_type, const char *key,
uint8_t *data, int len)
{
GHashTable *hash_table = NULL;
@@ -250,12 +249,12 @@ void cache_insert(enum buxton_layer_type layer_type, const char *key,
cache->size += len;
bxt_dbg("[%s cache] inserted (%s)/size(%d)/count(%d)/total size(%d)",
- (layer_type == BUXTON_LAYER_NORMAL) ?
+ (layer_type == LAYER_ATTRIBUTE_RW) ?
"NORMAL" : "BASE", key, len, cache->count, cache->size);
}
-int cache_get(enum buxton_layer_type layer_type, const char *key,
+int cache_get(enum layer_attribute_type layer_type, const char *key,
void **data, int *data_len)
{
GHashTable *hash_table = NULL;
@@ -284,13 +283,13 @@ int cache_get(enum buxton_layer_type layer_type, const char *key,
*data_len = cdata->len;
bxt_dbg("[%s cache] get (%s)/size(%d)",
- (layer_type == BUXTON_LAYER_NORMAL) ?
+ (layer_type == LAYER_ATTRIBUTE_RW) ?
"NORMAL" : "BASE", key, cdata->len);
return BUXTON_ERROR_NONE;
}
-void cache_clear(enum buxton_layer_type layer_type)
+void cache_clear(enum layer_attribute_type layer_type)
{
bxt_cache *cache = get_cache(layer_type);
diff --git a/common/cache.h b/common/cache.h
index 47ffbe6..4e4a800 100644
--- a/common/cache.h
+++ b/common/cache.h
@@ -18,13 +18,15 @@
#pragma once
+#include "common.h"
+
void cache_init(void);
-void cache_insert(enum buxton_layer_type layer_type, const char *key,
+void cache_insert(enum layer_attribute_type layer_type, const char *key,
uint8_t *data, int len);
-void cache_remove(enum buxton_layer_type layer_type, const char *key);
-void cache_update_data(enum buxton_layer_type layer_type, const char *key,
+void cache_remove(enum layer_attribute_type layer_type, const char *key);
+void cache_update_data(enum layer_attribute_type layer_type, const char *key,
uint8_t *data, int len);
-int cache_get(enum buxton_layer_type layer_type, const char *key,
+int cache_get(enum layer_attribute_type layer_type, const char *key,
void **data, int *data_len);
-void cache_clear(enum buxton_layer_type layer_type);
+void cache_clear(enum layer_attribute_type layer_type);
diff --git a/common/common.c b/common/common.c
index 47e928b..77172da 100644
--- a/common/common.c
+++ b/common/common.c
@@ -51,7 +51,7 @@ int layer_create(const char *layer_name, struct buxton_layer **layer)
tmp_layer->refcnt = 1;
tmp_layer->uid = getuid();
- tmp_layer->type = BUXTON_LAYER_NORMAL;
+ tmp_layer->type = LAYER_ATTRIBUTE_RW;
*layer = tmp_layer;
@@ -102,7 +102,7 @@ void value_free(struct buxton_value *val)
return;
switch (val->type) {
- case BUXTON_TYPE_STRING:
+ case VALUE_TYPE_STRING:
if (val->value.s) {
free(val->value.s);
val->value.s = NULL;
@@ -113,6 +113,22 @@ void value_free(struct buxton_value *val)
}
}
+void key_list_free(char **keys)
+{
+ char **key;
+
+ if (!keys)
+ return;
+
+ key = keys;
+ while (*key) {
+ free(*key);
+ key++;
+ }
+
+ free(keys);
+}
+
int get_search_key(const struct buxton_layer *layer, const char *key,
const char *uid, char **layer_key)
{
diff --git a/common/common.h b/common/common.h
index 01de423..4aca294 100644
--- a/common/common.h
+++ b/common/common.h
@@ -56,6 +56,16 @@
# define SOCKPATH "/run/buxton-0"
#endif
+
+/*
+ LAYER_SYSTEM - STORAGE_PERSISTENT - LAYER_ATTRIBUTE_RO
+ \ - LAYER_ATTRIBUTE_RW
+ STORAGE_VOLATILE - LAYER_ATTRIBUTE_RO
+ - LAYER_ATTRIBUTE_RW
+
+LAYER_USER - ...
+
+*/
enum layer_type {
LAYER_UNKNWON = 0,
LAYER_SYSTEM,
@@ -70,6 +80,12 @@ enum storage_type {
STORAGE_MAX, /* sentinel value */
};
+enum layer_attribute_type {
+ LAYER_ATTRIBUTE_RW = BUXTON_LAYER_NORMAL,
+ LAYER_ATTRIBUTE_RO = BUXTON_LAYER_BASE,
+ LAYER_ATTRIBUTE_MAX = BUXTON_LAYER_MAX, /* sentinel value */
+};
+
struct layer {
gchar *name;
enum layer_type type;
@@ -78,6 +94,23 @@ struct layer {
gchar *description;
};
+enum value_type {
+ VALUE_TYPE_UNKNOWN = BUXTON_TYPE_UNKNOWN, /**< Unknown type */
+ VALUE_TYPE_STRING = BUXTON_TYPE_STRING, /**< String type */
+ VALUE_TYPE_INT32 = BUXTON_TYPE_INT32, /**< 32bit integer type */
+ VALUE_TYPE_UINT32 = BUXTON_TYPE_UINT32, /**< 32bit unsigned integer type */
+ VALUE_TYPE_INT64 = BUXTON_TYPE_INT64, /**< 64bit integer type */
+ VALUE_TYPE_UINT64 = BUXTON_TYPE_UINT64, /**< 64bit unsigned integer type */
+ VALUE_TYPE_DOUBLE = BUXTON_TYPE_DOUBLE, /**< double-precision float type */
+ VALUE_TYPE_BOOLEAN = BUXTON_TYPE_BOOLEAN, /**< boolean type */
+ VALUE_TYPE_MAX = BUXTON_TYPE_MAX /* sentinel value */
+};
+
+enum priv_type {
+ PRIV_READ = BUXTON_PRIV_READ, /**< Read privilege type */
+ PRIV_WRITE = BUXTON_PRIV_WRITE, /**< Write privilege type */
+};
+
enum message_type {
MSG_UNKNOWN = 0,
/* basic request */
@@ -103,7 +136,7 @@ struct buxton_layer {
int refcnt;
char *name;
uid_t uid;
- enum buxton_layer_type type;
+ enum layer_attribute_type type;
};
int layer_create(const char *layer_name, struct buxton_layer **layer);
@@ -113,7 +146,7 @@ struct buxton_layer *layer_ref(struct buxton_layer *layer);
struct buxton_layer *layer_unref(struct buxton_layer *layer);
struct buxton_value {
- enum buxton_key_type type;
+ enum value_type type;
union {
char *s;
int32_t i;
@@ -126,6 +159,7 @@ struct buxton_value {
};
void value_free(struct buxton_value *val);
+void key_list_free(char **keys);
int get_search_key(const struct buxton_layer *layer, const char *key,
const char *uid, char **layer_key);
diff --git a/common/direct.c b/common/direct.c
index 80b2aaf..525e7a2 100644
--- a/common/direct.c
+++ b/common/direct.c
@@ -26,8 +26,6 @@
#include <glib.h>
-#include "buxton2.h"
-
#include "common.h"
#include "log.h"
#include "direct.h"
@@ -36,7 +34,7 @@
#include "serialize.h"
#include "cache.h"
-static int get_path(uid_t uid, enum buxton_layer_type type,
+static int get_path(uid_t uid, enum layer_attribute_type type,
const struct layer *ly, char *path, int sz)
{
const char *prefix;
@@ -47,12 +45,12 @@ static int get_path(uid_t uid, enum buxton_layer_type type,
return BUXTON_ERROR_INVALID_PARAMETER;
}
- if (type == BUXTON_LAYER_NORMAL)
+ if (type == LAYER_ATTRIBUTE_RW)
prefix = (ly->storage == STORAGE_VOLATILE) ? TMPFS_DIR : DB_DIR;
else
prefix = BASE_DB_DIR;
- if (type == BUXTON_LAYER_NORMAL && ly->type == LAYER_USER)
+ if (type == LAYER_ATTRIBUTE_RW && ly->type == LAYER_USER)
snprintf(suffix, sizeof(suffix), "-%u", uid);
else
suffix[0] = '\0';
@@ -63,7 +61,7 @@ static int get_path(uid_t uid, enum buxton_layer_type type,
}
static int get_raw(const struct layer *ly, uid_t uid,
- enum buxton_layer_type type, const char *key,
+ enum layer_attribute_type type, const char *key,
uint8_t **data, int *len)
{
int r;
@@ -92,7 +90,7 @@ static int get_raw(const struct layer *ly, uid_t uid,
return r;
r = backend->get_value(path, key, (void **)data, len,
- (type == BUXTON_LAYER_BASE) ? true : false);
+ (type == LAYER_ATTRIBUTE_RO) ? true : false);
if (r != BUXTON_ERROR_NONE)
return r;
@@ -102,7 +100,7 @@ static int get_raw(const struct layer *ly, uid_t uid,
}
static int get_val(const struct layer *ly, uid_t uid,
- enum buxton_layer_type type, const char *key,
+ enum layer_attribute_type type, const char *key,
char **rpriv, char **wpriv, struct buxton_value *val)
{
int r;
@@ -142,17 +140,17 @@ int direct_get(const struct buxton_layer *layer,
return r;
/* First, refer to base db */
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, NULL, NULL,
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, NULL, NULL,
&base_val);
if (r != BUXTON_ERROR_NONE)
return r;
- if (layer->type == BUXTON_LAYER_BASE) {
+ if (layer->type == LAYER_ATTRIBUTE_RO) {
*val = base_val;
return BUXTON_ERROR_NONE;
}
- r = get_val(ly, layer->uid, BUXTON_LAYER_NORMAL, key, NULL, NULL,
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RW, key, NULL, NULL,
&db_val);
if (r != BUXTON_ERROR_NONE) {
if (r == BUXTON_ERROR_NOT_EXIST) {
@@ -184,7 +182,7 @@ int direct_check(const struct buxton_layer *layer, const char *key)
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, NULL, NULL, &val);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, NULL, NULL, &val);
if (r != BUXTON_ERROR_NONE)
return r;
@@ -193,7 +191,7 @@ int direct_check(const struct buxton_layer *layer, const char *key)
return BUXTON_ERROR_NONE;
}
-static bool is_updated_data(enum buxton_layer_type type, const char *key,
+static bool is_updated_data(enum layer_attribute_type type, const char *key,
uint8_t *data, int len)
{
uint8_t *cur_data;
@@ -221,7 +219,7 @@ static bool is_updated_data(enum buxton_layer_type type, const char *key,
}
static int set_raw(const struct layer *ly, uid_t uid,
- enum buxton_layer_type type, const char *key,
+ enum layer_attribute_type type, const char *key,
uint8_t *data, int len)
{
int r;
@@ -261,7 +259,7 @@ static int set_raw(const struct layer *ly, uid_t uid,
}
static int set_val(const struct layer *ly, uid_t uid,
- enum buxton_layer_type type, const char *key,
+ enum layer_attribute_type type, const char *key,
const char *rpriv, const char *wpriv,
const struct buxton_value *val)
{
@@ -303,7 +301,7 @@ int direct_set(const struct buxton_layer *layer,
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, &rp, &wp, NULL);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, &rp, &wp, NULL);
if (r != BUXTON_ERROR_NONE)
return r;
@@ -336,7 +334,7 @@ static int direct_close(const struct buxton_layer *layer, const struct layer *ly
return BUXTON_ERROR_INVALID_OPERATION;
}
- r = get_path(layer->uid, BUXTON_LAYER_BASE, ly, path, sizeof(path));
+ r = get_path(layer->uid, LAYER_ATTRIBUTE_RO, ly, path, sizeof(path));
if (r != BUXTON_ERROR_NONE)
return r;
@@ -371,7 +369,7 @@ int direct_create(const struct buxton_layer *layer, const char *key,
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, NULL, NULL, NULL);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, NULL, NULL, NULL);
if (r == BUXTON_ERROR_NONE)
return BUXTON_ERROR_EXIST;
@@ -382,18 +380,18 @@ int direct_create(const struct buxton_layer *layer, const char *key,
return r;
}
- r = set_val(ly, layer->uid, BUXTON_LAYER_BASE, key, rpriv, wpriv, val);
+ r = set_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, rpriv, wpriv, val);
if (r != BUXTON_ERROR_NONE) {
bxt_err("failed to create (%s: %s) %d", ly->name, key, r);
return r;
}
if (ly->storage == STORAGE_PERSISTENT) {
- r = set_val(ly, layer->uid, BUXTON_LAYER_NORMAL, key, rpriv, wpriv, val);
+ r = set_val(ly, layer->uid, LAYER_ATTRIBUTE_RW, key, rpriv, wpriv, val);
if (r != BUXTON_ERROR_NONE) {
bxt_err("failed to create (%s: %s) %d", ly->name, key, r);
unset_layer = *layer;
- unset_layer.type = BUXTON_LAYER_BASE;
+ unset_layer.type = LAYER_ATTRIBUTE_RO;
direct_unset(&unset_layer, key);
}
}
@@ -479,7 +477,7 @@ int direct_list(const struct buxton_layer *layer,
}
r = get_path(layer->uid, is_base ?
- BUXTON_LAYER_BASE : BUXTON_LAYER_NORMAL,
+ LAYER_ATTRIBUTE_RO : LAYER_ATTRIBUTE_RW,
ly, path, sizeof(path));
if (r != BUXTON_ERROR_NONE)
return r;
@@ -534,7 +532,7 @@ int direct_dump(const struct buxton_layer *layer,
return BUXTON_ERROR_INVALID_OPERATION;
}
- ret = get_path(layer->uid, BUXTON_LAYER_BASE,
+ ret = get_path(layer->uid, LAYER_ATTRIBUTE_RO,
ly, path, sizeof(path));
if (ret != BUXTON_ERROR_NONE)
return ret;
@@ -546,7 +544,7 @@ int direct_dump(const struct buxton_layer *layer,
return ret;
}
- ret = get_path(layer->uid, BUXTON_LAYER_NORMAL,
+ ret = get_path(layer->uid, LAYER_ATTRIBUTE_RW,
ly, path, sizeof(path));
if (ret != BUXTON_ERROR_NONE) {
bxt_err("dump: get_path failed");
@@ -593,14 +591,14 @@ int direct_dump(const struct buxton_layer *layer,
*len = base_len;
out:
- buxton_free_keys((char **)base_values);
- buxton_free_keys(normal_keys);
- buxton_free_keys((char **)normal_values);
+ key_list_free((char **)base_values);
+ key_list_free(normal_keys);
+ key_list_free((char **)normal_values);
free(base_value_len);
free(normal_value_len);
if (ret != BUXTON_ERROR_NONE) {
- buxton_free_keys(base_keys);
+ key_list_free(base_keys);
if (_value_list)
free(_value_list);
@@ -622,11 +620,11 @@ int direct_get_priv(const struct buxton_layer *layer,
}
switch (type) {
- case BUXTON_PRIV_READ:
+ case PRIV_READ:
rp = priv;
wp = NULL;
break;
- case BUXTON_PRIV_WRITE:
+ case PRIV_WRITE:
rp = NULL;
wp = priv;
break;
@@ -639,7 +637,7 @@ int direct_get_priv(const struct buxton_layer *layer,
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, rp, wp, NULL);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, rp, wp, NULL);
return r;
}
@@ -660,8 +658,8 @@ int direct_set_priv(const struct buxton_layer *layer,
}
switch (type) {
- case BUXTON_PRIV_READ:
- case BUXTON_PRIV_WRITE:
+ case PRIV_READ:
+ case PRIV_WRITE:
break;
default:
bxt_err("Invalid parameter");
@@ -672,16 +670,16 @@ int direct_set_priv(const struct buxton_layer *layer,
if (r != BUXTON_ERROR_NONE)
return r;
- r = get_val(ly, layer->uid, BUXTON_LAYER_BASE, key, &rp, &wp, &val);
+ r = get_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, &rp, &wp, &val);
if (r != BUXTON_ERROR_NONE)
return r;
switch (type) {
- case BUXTON_PRIV_READ:
+ case PRIV_READ:
t_rp = priv;
t_wp = wp;
break;
- case BUXTON_PRIV_WRITE:
+ case PRIV_WRITE:
t_rp = rp;
t_wp = priv;
break;
@@ -691,7 +689,7 @@ int direct_set_priv(const struct buxton_layer *layer,
break;
}
- r = set_val(ly, layer->uid, BUXTON_LAYER_BASE, key, t_rp, t_wp, &val);
+ r = set_val(ly, layer->uid, LAYER_ATTRIBUTE_RO, key, t_rp, t_wp, &val);
value_free(&val);
free(rp);
diff --git a/common/direct.h b/common/direct.h
index 62bf869..b8f3385 100644
--- a/common/direct.h
+++ b/common/direct.h
@@ -18,8 +18,6 @@
#pragma once
-#include "buxton2.h"
-
int direct_init(const char *moddir, const char *confpath, bool *log_on, int *max_line);
void direct_exit(void);
diff --git a/common/serialize.c b/common/serialize.c
index d3152e2..0f42b89 100644
--- a/common/serialize.c
+++ b/common/serialize.c
@@ -23,8 +23,6 @@
#include <glib.h>
-#include "buxton2.h"
-
#include "serialize.h"
#include "log.h"
@@ -83,7 +81,7 @@ static int check_values(const char *rpriv, const char *wpriv,
return r;
}
- if (val && val->type == BUXTON_TYPE_STRING) {
+ if (val && val->type == VALUE_TYPE_STRING) {
r = check_val(val->value.s);
if (r != BUXTON_ERROR_NONE) {
bxt_err("Value string length is too long");
@@ -102,7 +100,7 @@ static GVariant *val_to_gv(const struct buxton_value *val)
return g_variant_new_tuple(NULL, 0);
switch (val->type) {
- case BUXTON_TYPE_STRING:
+ case VALUE_TYPE_STRING:
if (!val->value.s) {
bxt_err("Serialize: value has NULL string");
return NULL;
@@ -110,22 +108,22 @@ static GVariant *val_to_gv(const struct buxton_value *val)
gv = g_variant_new_string(val->value.s);
break;
- case BUXTON_TYPE_INT32:
+ case VALUE_TYPE_INT32:
gv = g_variant_new_int32(val->value.i);
break;
- case BUXTON_TYPE_UINT32:
+ case VALUE_TYPE_UINT32:
gv = g_variant_new_uint32(val->value.u);
break;
- case BUXTON_TYPE_INT64:
+ case VALUE_TYPE_INT64:
gv = g_variant_new_int64(val->value.i64);
break;
- case BUXTON_TYPE_UINT64:
+ case VALUE_TYPE_UINT64:
gv = g_variant_new_uint64(val->value.u64);
break;
- case BUXTON_TYPE_DOUBLE:
+ case VALUE_TYPE_DOUBLE:
gv = g_variant_new_double(val->value.d);
break;
- case BUXTON_TYPE_BOOLEAN:
+ case VALUE_TYPE_BOOLEAN:
gv = g_variant_new_boolean(val->value.b);
break;
default:
@@ -249,13 +247,13 @@ static int gv_to_val(GVariant *v, struct buxton_value *val)
if (!strncmp(t, "()", sizeof("()"))) {
- val->type = BUXTON_TYPE_UNKNOWN;
+ val->type = VALUE_TYPE_UNKNOWN;
return BUXTON_ERROR_NONE;
}
switch (*t) {
case 's':
- val->type = BUXTON_TYPE_STRING;
+ val->type = VALUE_TYPE_STRING;
s = g_variant_get_string(v, NULL);
if (!s) {
@@ -269,27 +267,27 @@ static int gv_to_val(GVariant *v, struct buxton_value *val)
}
break;
case 'i':
- val->type = BUXTON_TYPE_INT32;
+ val->type = VALUE_TYPE_INT32;
val->value.i = g_variant_get_int32(v);
break;
case 'u':
- val->type = BUXTON_TYPE_UINT32;
+ val->type = VALUE_TYPE_UINT32;
val->value.u = g_variant_get_uint32(v);
break;
case 'x':
- val->type = BUXTON_TYPE_INT64;
+ val->type = VALUE_TYPE_INT64;
val->value.i64 = g_variant_get_int64(v);
break;
case 't':
- val->type = BUXTON_TYPE_UINT64;
+ val->type = VALUE_TYPE_UINT64;
val->value.u64 = g_variant_get_uint64(v);
break;
case 'd':
- val->type = BUXTON_TYPE_DOUBLE;
+ val->type = VALUE_TYPE_DOUBLE;
val->value.d = g_variant_get_double(v);
break;
case 'b':
- val->type = BUXTON_TYPE_BOOLEAN;
+ val->type = VALUE_TYPE_BOOLEAN;
val->value.b = g_variant_get_boolean(v);
break;
default:
@@ -447,18 +445,18 @@ static int check_value(const struct buxton_value *val)
}
switch (val->type) {
- case BUXTON_TYPE_STRING:
+ case VALUE_TYPE_STRING:
if (!val->value.s) {
bxt_err("Serialize: value has NULL string");
return BUXTON_ERROR_INVALID_PARAMETER;
}
break;
- case BUXTON_TYPE_INT32:
- case BUXTON_TYPE_UINT32:
- case BUXTON_TYPE_INT64:
- case BUXTON_TYPE_UINT64:
- case BUXTON_TYPE_DOUBLE:
- case BUXTON_TYPE_BOOLEAN:
+ case VALUE_TYPE_INT32:
+ case VALUE_TYPE_UINT32:
+ case VALUE_TYPE_INT64:
+ case VALUE_TYPE_UINT64:
+ case VALUE_TYPE_DOUBLE:
+ case VALUE_TYPE_BOOLEAN:
break;
default:
bxt_err("Serialize: buxton_value has unknown type");
@@ -684,7 +682,7 @@ static int gv_to_req(GVariant *gv, struct request *req)
return r;
}
- if (val->type == BUXTON_TYPE_UNKNOWN) {
+ if (val->type == VALUE_TYPE_UNKNOWN) {
free(val);
val = NULL;
}
@@ -748,7 +746,7 @@ void free_response(struct response *res)
value_free(res->val);
free(res->val);
- buxton_free_keys(res->names);
+ key_list_free(res->names);
}
static int check_response(enum message_type type, int32_t res,
@@ -942,7 +940,7 @@ static int gv_to_res_list(GVariant *gv, struct response *res)
res->names[i] = NULL;
if (i < len || ret != BUXTON_ERROR_NONE) {
- buxton_free_keys(res->names);
+ key_list_free(res->names);
return ret == BUXTON_ERROR_NONE ? BUXTON_ERROR_INVALID_PARAMETER : ret;
}
@@ -996,7 +994,7 @@ static int gv_to_res(GVariant *gv, struct response *res)
g_variant_unref(v);
- if (val->type == BUXTON_TYPE_UNKNOWN) {
+ if (val->type == VALUE_TYPE_UNKNOWN) {
free(val);
val = NULL;
}
diff --git a/common/serialize.h b/common/serialize.h
index e5ef8ef..81ac760 100644
--- a/common/serialize.h
+++ b/common/serialize.h
@@ -20,8 +20,6 @@
#include <stdint.h>
-#include "buxton2.h"
-
#include "common.h"
int check_key_name(const char *key);
diff --git a/lib/buxton2.c b/lib/buxton2.c
index c9fc9d7..7bde41c 100644
--- a/lib/buxton2.c
+++ b/lib/buxton2.c
@@ -271,7 +271,7 @@ static int value_get(const struct buxton_value *val, void *dest,
return BUXTON_ERROR_INVALID_PARAMETER;
}
- if (val->type != type) {
+ if (val->type != (enum value_type)type) {
bxt_err("Invalid parameter : type mismatch %d %d", val->type, type);
return BUXTON_ERROR_INVALID_PARAMETER;
}
@@ -412,7 +412,7 @@ EXPORT struct buxton_value *buxton_value_duplicate(
*_val = *val;
- if (val->type == BUXTON_TYPE_STRING && val->value.s) {
+ if (val->type == (enum value_type)BUXTON_TYPE_STRING && val->value.s) {
_val->value.s = strdup(val->value.s);
if (!_val->value.s) {
free(_val);