Skip to content

Commit

Permalink
feat: Update configlib
Browse files Browse the repository at this point in the history
  • Loading branch information
iqyx committed Nov 20, 2024
1 parent c4d7b5c commit fc4d1b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 13 additions & 3 deletions lib/plumcore-configlib/src/configlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ static conf_ret_t configlib_walk(Conf *self, enum conf_dir direction, Conf **nex
}


static conf_ret_t configlib_stat(Conf *self, const char **name, enum conf_type *type) {
static conf_ret_t configlib_stat(Conf *self, const char **name, enum conf_type *type, enum conf_flag *flags) {
ConfiglibValue *value = self->parent;

*name = value->name;
*type = value->type;
/** @todo add flags */
*flags = value->flags;

return CONF_RET_OK;
}
Expand Down Expand Up @@ -116,6 +116,15 @@ configlib_ret_t configlib_map(ConfiglibValue *self, void *var, enum conf_type ty
}


configlib_ret_t configlib_map_string(ConfiglibValue *self, char *str, size_t size) {
self->var = str;
self->size = size;
self->type = CONF_STR;

return CONFIGLIB_RET_OK;
}


configlib_ret_t configlib_append(ConfiglibValue *self, ConfiglibValue *parent, enum conf_dir dir) {
if (dir == CONF_DIR_CHILD) {
if (parent->child == NULL) {
Expand Down Expand Up @@ -172,7 +181,8 @@ static void configlib_log_walk_subtree(Conf *self, uint32_t indent) {

const char *conf_name = NULL;
enum conf_type conf_type = CONF_SUBTREE;
self->vmt->stat(self, &conf_name, &conf_type);
enum conf_flag conf_flags;
self->vmt->stat(self, &conf_name, &conf_type, &conf_flags);

union conf_val val = {0};
self->vmt->read(self, &val);
Expand Down
6 changes: 5 additions & 1 deletion lib/plumcore-configlib/src/configlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ typedef struct configlib_value {
ConfiglibValue *parent;

void *var;
size_t *len;
size_t size;

const char *name;
enum conf_type type;

enum conf_flag flags;

} ConfiglibValue;


configlib_ret_t configlib_init(ConfiglibValue *self, const char *name);
configlib_ret_t configlib_map(ConfiglibValue *self, void *var, enum conf_type type);
configlib_ret_t configlib_map_string(ConfiglibValue *self, char *str, size_t size);
configlib_ret_t configlib_append(ConfiglibValue *self, ConfiglibValue *parent, enum conf_dir dir);


Expand Down

0 comments on commit fc4d1b5

Please sign in to comment.