unfinished work
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
#include "uthash/utarray.h"
|
||||
#include "log/log.h"
|
||||
#include "rcu_hash.h"
|
||||
#include "utils.h"
|
||||
#include "maat_utils.h"
|
||||
#include "maat_ex_data.h"
|
||||
|
||||
@@ -48,8 +47,9 @@ void cache_row_free(void *p)
|
||||
|
||||
UT_icd ut_cache_row_icd = {sizeof(char*), NULL, NULL, cache_row_free};
|
||||
|
||||
struct ex_data_runtime *ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
|
||||
struct log_handle *logger)
|
||||
struct ex_data_runtime *
|
||||
ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
|
||||
struct log_handle *logger)
|
||||
{
|
||||
struct ex_data_runtime *ex_data_rt = ALLOC(struct ex_data_runtime, 1);
|
||||
|
||||
@@ -149,26 +149,31 @@ void ex_data_schema_free(struct ex_data_schema *ex_schema)
|
||||
FREE(ex_schema);
|
||||
}
|
||||
|
||||
void ex_data_runtime_set_schema(struct ex_data_runtime *ex_data_rt, struct ex_data_schema *schema)
|
||||
void ex_data_runtime_set_schema(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_schema *schema)
|
||||
{
|
||||
ex_data_rt->ex_schema = schema;
|
||||
}
|
||||
|
||||
void ex_data_runtime_set_ex_container_ctx(struct ex_data_runtime *ex_data_rt, struct ex_container_ctx *container_ctx)
|
||||
void ex_data_runtime_set_ex_container_ctx(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container_ctx *container_ctx)
|
||||
{
|
||||
rcu_hash_set_user_ctx(ex_data_rt->htable, container_ctx);
|
||||
}
|
||||
|
||||
struct ex_container_ctx *ex_data_runtime_get_ex_container_ctx(struct ex_data_runtime *ex_data_rt)
|
||||
struct ex_container_ctx *
|
||||
ex_data_runtime_get_ex_container_ctx(struct ex_data_runtime *ex_data_rt)
|
||||
{
|
||||
return (struct ex_container_ctx *)rcu_hash_get_user_ctx(ex_data_rt->htable);
|
||||
}
|
||||
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt, const char *row, const char *key, size_t key_len)
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt, const char *row,
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
void *ex_data = NULL;
|
||||
struct ex_data_schema *ex_schema = ex_data_rt->ex_schema;
|
||||
ex_schema->new_func(ex_data_rt->table_id, key, row, &ex_data, ex_schema->argl, ex_schema->argp);
|
||||
ex_schema->new_func(ex_data_rt->table_id, key, row, &ex_data,
|
||||
ex_schema->argl, ex_schema->argp);
|
||||
|
||||
return ex_data;
|
||||
}
|
||||
@@ -194,11 +199,14 @@ void ex_data_container_free(void *ctx, void *data)
|
||||
void *argp = container_ctx->ex_schema->argp;
|
||||
|
||||
struct ex_data_container *ex_container = (struct ex_data_container *)data;
|
||||
if (ex_container->ex_data != NULL && container_ctx->ex_schema->free_func != NULL) {
|
||||
container_ctx->ex_schema->free_func(container_ctx->table_id, &(ex_container->ex_data), argl, argp);
|
||||
if (ex_container->ex_data != NULL
|
||||
&& container_ctx->ex_schema->free_func != NULL) {
|
||||
container_ctx->ex_schema->free_func(container_ctx->table_id,
|
||||
&(ex_container->ex_data), argl, argp);
|
||||
}
|
||||
|
||||
if (ex_container->custom_data != NULL && container_ctx->custom_data_free != NULL) {
|
||||
if (ex_container->custom_data != NULL
|
||||
&& container_ctx->custom_data_free != NULL) {
|
||||
container_ctx->custom_data_free(ex_container->custom_data);
|
||||
}
|
||||
|
||||
@@ -211,10 +219,12 @@ int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
{
|
||||
struct ex_data_container *tmp_container = NULL;
|
||||
|
||||
tmp_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable, key, key_len);
|
||||
tmp_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
if (tmp_container != NULL) {
|
||||
log_error(ex_data_rt->logger, MODULE_EX_DATA,
|
||||
"ex_data_runtime add ex container error: already exist same key:%s", key);
|
||||
"ex_data_runtime add ex container error: already exist same key:%s",
|
||||
key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -227,10 +237,12 @@ int ex_data_runtime_del_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
struct ex_data_container *tmp_container = NULL;
|
||||
tmp_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable, key, key_len);
|
||||
tmp_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
if (NULL == tmp_container) {
|
||||
log_error(ex_data_rt->logger, MODULE_EX_DATA,
|
||||
"ex_data_runtime del ex container error: no such key:%s", key);
|
||||
"ex_data_runtime del ex container error: no such key:%s",
|
||||
key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -239,22 +251,30 @@ int ex_data_runtime_del_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *ex_data_runtime_get_ex_data(struct ex_data_runtime *ex_data_rt, const char *key, size_t key_len)
|
||||
void *ex_data_runtime_get_ex_data(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
struct ex_data_container *ex_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable, key, key_len);
|
||||
struct ex_data_container *ex_container = NULL;
|
||||
ex_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
if (NULL == ex_container) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *dup_ex_data = NULL;
|
||||
ex_data_rt->ex_schema->dup_func(ex_data_rt->table_id, &dup_ex_data, &(ex_container->ex_data),
|
||||
ex_data_rt->ex_schema->argl, ex_data_rt->ex_schema->argp);
|
||||
ex_data_rt->ex_schema->dup_func(ex_data_rt->table_id, &dup_ex_data,
|
||||
&(ex_container->ex_data),
|
||||
ex_data_rt->ex_schema->argl,
|
||||
ex_data_rt->ex_schema->argp);
|
||||
return dup_ex_data;
|
||||
}
|
||||
|
||||
void *ex_data_runtime_get_custom_data(struct ex_data_runtime *ex_data_rt, const char *key, size_t key_len)
|
||||
void *ex_data_runtime_get_custom_data(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
struct ex_data_container *ex_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable, key, key_len);
|
||||
struct ex_data_container *ex_container = NULL;
|
||||
ex_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
if (NULL == ex_container) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -267,12 +287,8 @@ size_t ex_data_runtime_ex_container_count(struct ex_data_runtime *ex_data_rt)
|
||||
return rcu_hash_count(ex_data_rt->htable);
|
||||
}
|
||||
|
||||
size_t ex_data_runtime_list_updating_ex_container(struct ex_data_runtime *ex_data_rt, struct ex_data_container ***ex_container)
|
||||
size_t ex_data_runtime_list_updating_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_container ***ex_container)
|
||||
{
|
||||
return rcu_hash_list_updating_data(ex_data_rt->htable, (void ***)ex_container);
|
||||
}
|
||||
|
||||
int ex_data_runtime_updating_flag(struct ex_data_runtime *ex_data_rt)
|
||||
{
|
||||
return rcu_hash_updating_flag(ex_data_rt->htable);
|
||||
}
|
||||
Reference in New Issue
Block a user