Lines Matching refs:impl

196 void loop_all_children(MppCfgIoImpl *impl, MppCfgIoFunc func, void *data)  in loop_all_children()  argument
200 func(impl, data); in loop_all_children()
202 list_for_each_entry_safe(pos, n, &impl->child, MppCfgIoImpl, list) { in loop_all_children()
209 MppCfgIoImpl *impl = NULL; in mpp_cfg_get_object() local
236 impl = mpp_calloc_size(MppCfgIoImpl, buf_size); in mpp_cfg_get_object()
238 if (!impl) { in mpp_cfg_get_object()
243 INIT_LIST_HEAD(&impl->list); in mpp_cfg_get_object()
244 INIT_LIST_HEAD(&impl->child); in mpp_cfg_get_object()
247 impl->name = (char *)(impl + 1); in mpp_cfg_get_object()
248 memcpy(impl->name, name, name_len); in mpp_cfg_get_object()
249 impl->name[name_len] = '\0'; in mpp_cfg_get_object()
250 impl->name_len = name_len; in mpp_cfg_get_object()
251 impl->name_buf_len = name_buf_len; in mpp_cfg_get_object()
255 impl->string = (char *)(impl + 1) + name_buf_len; in mpp_cfg_get_object()
256 strncpy(impl->string, val->str, str_len); in mpp_cfg_get_object()
257 impl->str_len = str_len; in mpp_cfg_get_object()
260 impl->type = type; in mpp_cfg_get_object()
262 impl->val = *val; in mpp_cfg_get_object()
263 impl->buf_size = buf_size; in mpp_cfg_get_object()
265 impl->info.data_type = CFG_FUNC_TYPE_BUTT; in mpp_cfg_get_object()
268 impl->val.str = impl->string; in mpp_cfg_get_object()
270 *obj = impl; in mpp_cfg_get_object()
277 MppCfgIoImpl *impl = NULL; in mpp_cfg_get_array() local
298 impl = mpp_calloc_size(MppCfgIoImpl, buf_size); in mpp_cfg_get_array()
300 if (!impl) { in mpp_cfg_get_array()
305 INIT_LIST_HEAD(&impl->list); in mpp_cfg_get_array()
306 INIT_LIST_HEAD(&impl->child); in mpp_cfg_get_array()
309 impl->name = (char *)(impl + 1); in mpp_cfg_get_array()
310 memcpy(impl->name, name, name_len); in mpp_cfg_get_array()
311 impl->name[name_len] = '\0'; in mpp_cfg_get_array()
312 impl->name_len = name_len; in mpp_cfg_get_array()
313 impl->name_buf_len = name_buf_len; in mpp_cfg_get_array()
316 impl->type = MPP_CFG_TYPE_ARRAY; in mpp_cfg_get_array()
317 impl->buf_size = buf_size; in mpp_cfg_get_array()
319 impl->info.data_type = CFG_FUNC_TYPE_BUTT; in mpp_cfg_get_array()
322 impl->elems = (MppCfgIoImpl **)((char *)(impl + 1) + name_buf_len); in mpp_cfg_get_array()
323 impl->array_size = count; in mpp_cfg_get_array()
326 *obj = impl; in mpp_cfg_get_array()
333 MppCfgIoImpl *impl = (MppCfgIoImpl *)obj; in mpp_cfg_put() local
340 list_del_init(&impl->list); in mpp_cfg_put()
345 list_for_each_entry_safe(pos, n, &impl->child, MppCfgIoImpl, list) { in mpp_cfg_put()
350 impl->parent = NULL; in mpp_cfg_put()
352 mpp_free(impl); in mpp_cfg_put()
357 static void mpp_cfg_put_all_child(MppCfgIoImpl *impl) in mpp_cfg_put_all_child() argument
362 impl->depth, impl, impl->type, impl->name); in mpp_cfg_put_all_child()
364 list_for_each_entry_safe(pos, n, &impl->child, MppCfgIoImpl, list) { in mpp_cfg_put_all_child()
368 impl->depth, impl, pos, pos->type, pos->name); in mpp_cfg_put_all_child()
374 impl->depth, impl, impl->type, impl->name); in mpp_cfg_put_all_child()
376 mpp_free(impl); in mpp_cfg_put_all_child()
381 MppCfgIoImpl *impl = (MppCfgIoImpl *)obj; in mpp_cfg_put_all() local
389 if (impl->trie) { in mpp_cfg_put_all()
390 mpp_trie_deinit(impl->trie); in mpp_cfg_put_all()
391 impl->trie = NULL; in mpp_cfg_put_all()
394 root = impl->parent; in mpp_cfg_put_all()
396 mpp_cfg_put_all_child(impl); in mpp_cfg_put_all()
401 impl = root; in mpp_cfg_put_all()
402 root = impl->parent; in mpp_cfg_put_all()
403 } while (impl); in mpp_cfg_put_all()
408 static void update_depth(MppCfgIoImpl *impl, void *data) in update_depth() argument
412 if (impl->parent) in update_depth()
413 impl->depth = impl->parent->depth + 1; in update_depth()
452 MppCfgIoImpl *impl = (MppCfgIoImpl *)obj; in mpp_cfg_del() local
460 parent = impl->parent; in mpp_cfg_del()
462 list_del_init(&impl->list); in mpp_cfg_del()
468 if (parent->elems[i] == impl) { in mpp_cfg_del()
475 impl->parent = NULL; in mpp_cfg_del()
476 impl->depth = 0; in mpp_cfg_del()
477 loop_all_children(impl, update_depth, NULL); in mpp_cfg_del()
485 MppCfgIoImpl *impl = (MppCfgIoImpl *)root; in mpp_cfg_find() local
508 list_for_each_entry_safe(pos, n, &impl->child, MppCfgIoImpl, list) { in mpp_cfg_find()
510 impl = pos; in mpp_cfg_find()
516 … if (impl->type == MPP_CFG_TYPE_ARRAY && pos->type == MPP_CFG_TYPE_OBJECT && !pos->name) in mpp_cfg_find()
525 impl = array_pos; in mpp_cfg_find()
543 *obj = impl; in mpp_cfg_find()
549 MppCfgIoImpl *impl = (MppCfgIoImpl *)obj; in mpp_cfg_set_info() local
551 if (impl && info) { in mpp_cfg_set_info()
553 impl->name, strof_cfg_type(info->data_type), in mpp_cfg_set_info()
557 memcpy(&impl->info, info, sizeof(impl->info)); in mpp_cfg_set_info()
561 impl->type = MPP_CFG_TYPE_s32; in mpp_cfg_set_info()
564 impl->type = MPP_CFG_TYPE_u32; in mpp_cfg_set_info()
567 impl->type = MPP_CFG_TYPE_s64; in mpp_cfg_set_info()
570 impl->type = MPP_CFG_TYPE_u64; in mpp_cfg_set_info()
576 impl->info.data_type = CFG_FUNC_TYPE_BUTT; in mpp_cfg_set_info()
587 MppCfgIoImpl *impl = (MppCfgIoImpl *)obj; in mpp_cfg_set_cond() local
589 if (impl) in mpp_cfg_set_cond()
590 impl->cond = cond; in mpp_cfg_set_cond()
600 static void add_obj_info(MppCfgIoImpl *impl, void *data) in add_obj_info() argument
603 if (impl->info.data_type < CFG_FUNC_TYPE_BUTT && impl->parent) { in add_obj_info()
606 get_full_name(impl, ctx->buf, ctx->buf_size); in add_obj_info()
607 mpp_trie_add_info(ctx->trie, ctx->buf, &impl->info, sizeof(impl->info)); in add_obj_info()
613 MppCfgIoImpl *impl = (MppCfgIoImpl *)obj; in mpp_cfg_to_trie() local
621 if (!impl) { in mpp_cfg_to_trie()
622 mpp_loge_f("invalid param obj\n", impl); in mpp_cfg_to_trie()
626 if (impl->parent) { in mpp_cfg_to_trie()
627 mpp_loge_f("invalid param obj %p not root\n", impl); in mpp_cfg_to_trie()
631 if (impl->trie) { in mpp_cfg_to_trie()
632 p = impl->trie; in mpp_cfg_to_trie()
636 ret = mpp_trie_init(&p, impl->name ? impl->name : "cfg_io"); in mpp_cfg_to_trie()
638 mpp_loge_f("failed to init obj %s trie\n", impl->name ? impl->name : "cfg_io"); in mpp_cfg_to_trie()
646 loop_all_children(impl, add_obj_info, &ctx); in mpp_cfg_to_trie()
648 impl->trie = p; in mpp_cfg_to_trie()
830 static rk_s32 mpp_cfg_to_log(MppCfgIoImpl *impl, MppCfgStrBuf *str) in mpp_cfg_to_log() argument
841 if (impl->type < MPP_CFG_TYPE_OBJECT) { in mpp_cfg_to_log()
842 cfg_io_dbg_to("depth %d leaf write name %s type %d\n", str->depth, impl->name, impl->type); in mpp_cfg_to_log()
844 if (impl->name) in mpp_cfg_to_log()
845 len += snprintf(buf + len, total - len, "%s : ", impl->name); in mpp_cfg_to_log()
847 switch (impl->type) { in mpp_cfg_to_log()
852 len += snprintf(buf + len, total - len, "%s\n", impl->val.b1 ? "true" : "false"); in mpp_cfg_to_log()
855 len += snprintf(buf + len, total - len, "%d\n", impl->val.s32); in mpp_cfg_to_log()
858 len += snprintf(buf + len, total - len, "%u\n", impl->val.u32); in mpp_cfg_to_log()
861 len += snprintf(buf + len, total - len, "%lld\n", impl->val.s64); in mpp_cfg_to_log()
864 len += snprintf(buf + len, total - len, "%llu\n", impl->val.u64); in mpp_cfg_to_log()
867 len += snprintf(buf + len, total - len, "%f\n", impl->val.f32); in mpp_cfg_to_log()
870 len += snprintf(buf + len, total - len, "%lf\n", impl->val.f64); in mpp_cfg_to_log()
874 len += snprintf(buf + len, total - len, "\"%s\"\n", (char *)impl->val.str); in mpp_cfg_to_log()
877 mpp_loge("invalid type %d\n", impl->type); in mpp_cfg_to_log()
884 cfg_io_dbg_to("depth %d branch write name %s type %d\n", str->depth, impl->name, impl->type); in mpp_cfg_to_log()
886 if (impl->name) in mpp_cfg_to_log()
887 len += snprintf(buf + len, total - len, "%s : ", impl->name); in mpp_cfg_to_log()
889 if (list_empty(&impl->child)) { in mpp_cfg_to_log()
891 impl->type == MPP_CFG_TYPE_OBJECT ? "{}" : "[]"); in mpp_cfg_to_log()
896 impl->type == MPP_CFG_TYPE_OBJECT ? '{' : '['); in mpp_cfg_to_log()
904 list_for_each_entry_safe(pos, n, &impl->child, MppCfgIoImpl, list) { in mpp_cfg_to_log()
916 impl->type == MPP_CFG_TYPE_OBJECT ? '}' : ']'); in mpp_cfg_to_log()
921 static rk_s32 mpp_cfg_to_json(MppCfgIoImpl *impl, MppCfgStrBuf *str) in mpp_cfg_to_json() argument
932 if (impl->type < MPP_CFG_TYPE_OBJECT) { in mpp_cfg_to_json()
933 cfg_io_dbg_to("depth %d leaf write name %s type %d\n", str->depth, impl->name, impl->type); in mpp_cfg_to_json()
935 if (impl->name) in mpp_cfg_to_json()
936 len += snprintf(buf + len, total - len, "\"%s\" : ", impl->name); in mpp_cfg_to_json()
938 switch (impl->type) { in mpp_cfg_to_json()
943 len += snprintf(buf + len, total - len, "%s,\n", impl->val.b1 ? "true" : "false"); in mpp_cfg_to_json()
946 len += snprintf(buf + len, total - len, "%d,\n", impl->val.s32); in mpp_cfg_to_json()
949 len += snprintf(buf + len, total - len, "%u,\n", impl->val.u32); in mpp_cfg_to_json()
952 len += snprintf(buf + len, total - len, "%lld,\n", impl->val.s64); in mpp_cfg_to_json()
955 len += snprintf(buf + len, total - len, "%llu,\n", impl->val.u64); in mpp_cfg_to_json()
958 len += snprintf(buf + len, total - len, "%f,\n", impl->val.f32); in mpp_cfg_to_json()
961 len += snprintf(buf + len, total - len, "%lf,\n", impl->val.f64); in mpp_cfg_to_json()
965 len += snprintf(buf + len, total - len, "\"%s\",\n", (char *)impl->val.str); in mpp_cfg_to_json()
968 mpp_loge("invalid type %d\n", impl->type); in mpp_cfg_to_json()
975 cfg_io_dbg_to("depth %d branch write name %s type %d\n", str->depth, impl->name, impl->type); in mpp_cfg_to_json()
977 if (impl->name) in mpp_cfg_to_json()
978 len += snprintf(buf + len, total - len, "\"%s\" : ", impl->name); in mpp_cfg_to_json()
980 if (list_empty(&impl->child)) { in mpp_cfg_to_json()
982 impl->type == MPP_CFG_TYPE_OBJECT ? "{}" : "[]"); in mpp_cfg_to_json()
987 impl->type == MPP_CFG_TYPE_OBJECT ? '{' : '['); in mpp_cfg_to_json()
995 list_for_each_entry_safe(pos, n, &impl->child, MppCfgIoImpl, list) { in mpp_cfg_to_json()
1010 impl->type == MPP_CFG_TYPE_OBJECT ? '}' : ']'); in mpp_cfg_to_json()
1013 impl->type == MPP_CFG_TYPE_OBJECT ? '}' : ']'); in mpp_cfg_to_json()
1018 static rk_s32 mpp_toml_parent_is_array_table(MppCfgIoImpl *impl, MppCfgStrBuf *str) in mpp_toml_parent_is_array_table() argument
1020 return str->depth == 1 && impl->type == MPP_CFG_TYPE_OBJECT && in mpp_toml_parent_is_array_table()
1021 !impl->name && impl->parent->type == MPP_CFG_TYPE_ARRAY; in mpp_toml_parent_is_array_table()
1024 static rk_s32 mpp_toml_top(MppCfgIoImpl *impl, MppCfgStrBuf *str) in mpp_toml_top() argument
1030 if (impl->name && impl->type == MPP_CFG_TYPE_OBJECT) in mpp_toml_top()
1031 len += snprintf(buf + len, total - len, "\n[%s]\n", impl->name); in mpp_toml_top()
1036 static rk_s32 mpp_toml_non_top(MppCfgIoImpl *impl, MppCfgStrBuf *str) in mpp_toml_non_top() argument
1042 if (impl->name) in mpp_toml_non_top()
1043 len += snprintf(buf + len, total - len, "%s = ", impl->name); in mpp_toml_non_top()
1045 if (list_empty(&impl->child)) { in mpp_toml_non_top()
1047 impl->type == MPP_CFG_TYPE_OBJECT ? "{}" : "[]"); in mpp_toml_non_top()
1051 if (mpp_toml_parent_is_array_table(impl, str)) in mpp_toml_non_top()
1052 len += snprintf(buf + len, total - len, "\n[[%s]]\n", impl->parent->name); in mpp_toml_non_top()
1055 impl->type == MPP_CFG_TYPE_OBJECT ? '{' : '['); in mpp_toml_non_top()
1060 static rk_s32 mpp_cfg_to_toml(MppCfgIoImpl *impl, MppCfgStrBuf *str, rk_s32 first_time) in mpp_cfg_to_toml() argument
1071 if (impl->type < MPP_CFG_TYPE_OBJECT) { in mpp_cfg_to_toml()
1072 cfg_io_dbg_to("depth %d leaf write name %s type %d\n", str->depth, impl->name, impl->type); in mpp_cfg_to_toml()
1074 if (impl->name) in mpp_cfg_to_toml()
1075 len += snprintf(buf + len, total - len, "%s = ", impl->name); in mpp_cfg_to_toml()
1077 switch (impl->type) { in mpp_cfg_to_toml()
1082 len += snprintf(buf + len, total - len, "%s", impl->val.b1 ? "true" : "false"); in mpp_cfg_to_toml()
1085 len += snprintf(buf + len, total - len, "%d", impl->val.s32); in mpp_cfg_to_toml()
1088 len += snprintf(buf + len, total - len, "%u", impl->val.u32); in mpp_cfg_to_toml()
1091 len += snprintf(buf + len, total - len, "%lld", impl->val.s64); in mpp_cfg_to_toml()
1094 len += snprintf(buf + len, total - len, "%llu", impl->val.u64); in mpp_cfg_to_toml()
1097 len += snprintf(buf + len, total - len, "%f", impl->val.f32); in mpp_cfg_to_toml()
1100 len += snprintf(buf + len, total - len, "%lf", impl->val.f64); in mpp_cfg_to_toml()
1104 len += snprintf(buf + len, total - len, "\"%s\"", (char *)impl->val.str); in mpp_cfg_to_toml()
1107 mpp_loge("invalid type %d\n", impl->type); in mpp_cfg_to_toml()
1119 cfg_io_dbg_to("depth %d branch write name %s type %d\n", str->depth, impl->name, impl->type); in mpp_cfg_to_toml()
1122 ret = mpp_toml_top(impl, str); in mpp_cfg_to_toml()
1124 ret = mpp_toml_non_top(impl, str); in mpp_cfg_to_toml()
1129 if (list_empty(&impl->child)) in mpp_cfg_to_toml()
1132 if (!mpp_toml_parent_is_array_table(impl, str) && !first_time) in mpp_cfg_to_toml()
1135 list_for_each_entry_safe(pos, n, &impl->child, MppCfgIoImpl, list) { in mpp_cfg_to_toml()
1145 if (!mpp_toml_parent_is_array_table(impl, str) && !first_time) in mpp_cfg_to_toml()
1150 if (str->depth > 0 && !mpp_toml_parent_is_array_table(impl, str)) { in mpp_cfg_to_toml()
1153 impl->type == MPP_CFG_TYPE_OBJECT ? '}' : ']'); in mpp_cfg_to_toml()
1156 impl->type == MPP_CFG_TYPE_OBJECT ? '}' : ']'); in mpp_cfg_to_toml()
2937 MppCfgIoImpl *impl = (MppCfgIoImpl *)obj; in mpp_cfg_dump() local
2946 mpp_logi_f("obj %s - %p at %s\n", impl->name ? impl->name : "n/a", impl, func); in mpp_cfg_dump()
2954 ret = mpp_cfg_to_log(impl, &str); in mpp_cfg_dump()
2965 MppCfgIoImpl *impl = (MppCfgIoImpl *)obj; in mpp_cfg_to_string() local
2984 ret = mpp_cfg_to_log(impl, &str); in mpp_cfg_to_string()
2987 ret = mpp_cfg_to_json(impl, &str); in mpp_cfg_to_string()
2990 ret = mpp_cfg_to_toml(impl, &str, 1); in mpp_cfg_to_string()
2998 mpp_loge_f("%p %s failed to get string buffer\n", impl, impl->name); in mpp_cfg_to_string()
3110 MppCfgIoImpl *impl; in mpp_cfg_to_struct() local
3120 impl = (MppCfgIoImpl *)obj; in mpp_cfg_to_struct()
3129 write_struct(impl, trie, &str, st + orig->info.data_offset); in mpp_cfg_to_struct()
3134 static MppCfgObj read_struct(MppCfgIoImpl *impl, MppCfgObj parent, void *st) in read_struct() argument
3136 MppCfgInfo *info = &impl->info; in read_struct()
3140 ret = mpp_calloc_size(MppCfgIoImpl, impl->buf_size); in read_struct()
3142 mpp_loge_f("failed to alloc impl size %d\n", impl->buf_size); in read_struct()
3149 ret->type = impl->type; in read_struct()
3150 ret->buf_size = impl->buf_size; in read_struct()
3152 if (impl->name_buf_len) { in read_struct()
3154 memcpy(ret->name, impl->name, impl->name_buf_len); in read_struct()
3155 ret->name_len = impl->name_len; in read_struct()
3156 ret->name_buf_len = impl->name_buf_len; in read_struct()
3167 mpp_assert(impl->type == MPP_CFG_TYPE_s32); in read_struct()
3171 mpp_assert(impl->type == MPP_CFG_TYPE_u32); in read_struct()
3175 mpp_assert(impl->type == MPP_CFG_TYPE_s64); in read_struct()
3179 mpp_assert(impl->type == MPP_CFG_TYPE_u64); in read_struct()
3188 ret->val = impl->val; in read_struct()
3203 list_for_each_entry_safe(pos, n, &impl->child, MppCfgIoImpl, list) { in read_struct()