From 500215fd59da676bef6dbb9c95b08804a727444b Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Fri, 4 Apr 2025 10:26:07 +0200 Subject: [PATCH] Debug --- libbbfdm-api/legacy/dmapi.h | 1 + libbbfdm-api/legacy/dmbbf.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/libbbfdm-api/legacy/dmapi.h b/libbbfdm-api/legacy/dmapi.h index 21b9ed59..c69e8aa0 100644 --- a/libbbfdm-api/legacy/dmapi.h +++ b/libbbfdm-api/legacy/dmapi.h @@ -215,6 +215,7 @@ typedef struct dmnode { DMOBJ *obj; struct dmnode *parent; struct uci_section *idb_s; + json_object *idb_json; char *current_object; void *prev_data; char *prev_instance; diff --git a/libbbfdm-api/legacy/dmbbf.c b/libbbfdm-api/legacy/dmbbf.c index f1c69a47..52f17e61 100644 --- a/libbbfdm-api/legacy/dmbbf.c +++ b/libbbfdm-api/legacy/dmbbf.c @@ -1999,7 +1999,17 @@ static struct uci_section *get_uci_instance_db_section(const char *object, const static int mobj_get_instances_db(DMOBJECT_ARGS) { - //BBF_ERR("#### OBJ: node->current_object=%s && node->is_instanceobj=%d && node->obj->obj=%s ####", node->current_object, node->is_instanceobj, node->obj->obj); + BBF_ERR("#### OBJ: node->current_object=%s && node->is_instanceobj=%d && node->obj->obj=%s &&& node->parent=%p && node->parent->current_object=%s &&& node->parent->idb_json=%p &&& node->idb_json=%p && instance=%s ####", + node->current_object, node->is_instanceobj, + node->obj->obj, node->parent, node->parent->current_object, node->parent->idb_json, node->idb_json, instance); + + + if (node->parent->idb_json == NULL) node->parent->idb_json = json_object_new_object(); + + + if (node->idb_json == NULL) node->idb_json = json_object_new_object(); + + json_object_object_add(node->parent->idb_json, (node->is_instanceobj == 1) ? instance : node->obj->obj, node->idb_json); if (node->is_instanceobj == 0 && node->obj->browseinstobj != NULL) { node->idb_s = get_uci_instance_db_section(node->current_object, "idb_parent"); @@ -2025,28 +2035,32 @@ static int mparam_get_instances_db(DMPARAM_ARGS) if (node->is_instanceobj == 0) return 0; + BBF_ERR("LEAF: node->current_object=%s && leaf->parameter=%s && node->is_instanceobj=%d && node->obj->obj=%s && node->idb_json=%p", + node->current_object, leaf->parameter, node->is_instanceobj, node->obj->obj, node->idb_json); + char full_param[MAX_DM_PATH] = {0}; char *value = dmstrdup(""); snprintf(full_param, sizeof(full_param), "%s%s", node->current_object, leaf->parameter); - //BBF_ERR("LEAF: node->current_object=%s && leaf->parameter=%s && node->is_instanceobj=%d && node->obj->obj=%s", node->current_object, leaf->parameter, node->is_instanceobj, node->obj->obj); - (leaf->getvalue)(full_param, dmctx, data, instance, &value); if (leaf->dm_flags & DM_FLAG_UNIQUE) { + if (node->idb_json) json_object_object_add(node->idb_json, leaf->parameter, json_object_new_string(value)); dmuci_set_value_by_section_bbfdm(node->idb_s, leaf->parameter, value); } return 0; } - +#define JSON_FILE "/etc/bbfdm/data.json" int dm_entry_instances_db(struct dmctx *ctx) { DMOBJ *root = ctx->dm_entryobj; DMNODE node = {.current_object = ""}; int err = 0; + BBF_ERR("root->obj=%s && node->current_object=%s", root->obj, node.current_object); + ctx->inparam_isparam = 0; ctx->findparam = 1; ctx->stop = 0; @@ -2057,5 +2071,14 @@ int dm_entry_instances_db(struct dmctx *ctx) err = dm_browse(ctx, &node, root, NULL, NULL); + BBF_ERR("++++++++++++++++++++++++ END ++++++++++++++++++++++++++++"); + BBF_ERR("&&& node.idb_json=%p &&&", node.idb_json); + + FILE *fp = fopen(JSON_FILE, "w"); + if (fp) { + fprintf(fp, "%s", json_object_to_json_string_ext(node.idb_json, JSON_C_TO_STRING_PRETTY)); + fclose(fp); + } + return (ctx->findparam == 0) ? err : 0; }