mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
support dmmap for bbfdm_get_reference_linker
This commit is contained in:
parent
21f4b19cda
commit
165deef400
1 changed files with 54 additions and 4 deletions
|
|
@ -455,9 +455,11 @@ int bbfdm_get_references(struct dmctx *ctx, int match_action, const char *base_p
|
||||||
|
|
||||||
char *external_reference = NULL;
|
char *external_reference = NULL;
|
||||||
|
|
||||||
if (ctx->bbfdm_api_version == BBFDM_API_V1)
|
// Try dmmap first
|
||||||
external_reference = bbfdm_resolve_external_reference_via_dmmap(ctx, base_path, key_name, key_value);
|
external_reference = bbfdm_resolve_external_reference_via_dmmap(ctx, base_path, key_name, key_value);
|
||||||
else
|
|
||||||
|
// Fall back to JSON if dmmap failed
|
||||||
|
if (external_reference == NULL)
|
||||||
external_reference = bbfdm_resolve_external_reference_via_json(ctx, param_path, key_value);
|
external_reference = bbfdm_resolve_external_reference_via_json(ctx, param_path, key_value);
|
||||||
|
|
||||||
if (external_reference != NULL) {
|
if (external_reference != NULL) {
|
||||||
|
|
@ -504,10 +506,36 @@ static json_object *get_node(json_object *root, const char *path)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return curr;
|
return curr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *construct_section_name_from_path(char **parts, int count)
|
||||||
|
{
|
||||||
|
char section_name[256] = {0};
|
||||||
|
int offset = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// Start from index 2 (skip "Device" and top-level like "IP")
|
||||||
|
// Build section name: Type_Instance pairs
|
||||||
|
// Example: Device.IP.Interface.1.IPv4Address.2 -> Interface_1IPv4Address_2
|
||||||
|
for (i = 2; i < count; i++) {
|
||||||
|
if (isdigit_str(parts[i])) {
|
||||||
|
// This is an instance number, append it with underscore
|
||||||
|
offset += snprintf(section_name + offset, sizeof(section_name) - offset, "_%s", parts[i]);
|
||||||
|
} else {
|
||||||
|
// This is an object type, only append if followed by an index number
|
||||||
|
if (i + 1 < count && isdigit_str(parts[i + 1])) {
|
||||||
|
offset += snprintf(section_name + offset, sizeof(section_name) - offset, "%s", parts[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset > 0)
|
||||||
|
return dmstrdup(section_name);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int bbfdm_get_reference_linker(struct dmctx *ctx, char *reference_path, struct dm_reference *reference_args)
|
int bbfdm_get_reference_linker(struct dmctx *ctx, char *reference_path, struct dm_reference *reference_args)
|
||||||
{
|
{
|
||||||
char file_path[256] = {0};
|
char file_path[256] = {0};
|
||||||
|
|
@ -525,6 +553,28 @@ int bbfdm_get_reference_linker(struct dmctx *ctx, char *reference_path, struct d
|
||||||
if (count < 2)
|
if (count < 2)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
// Try to resolve from dmmap first (UCI)
|
||||||
|
char *section_name = construct_section_name_from_path(parts, count);
|
||||||
|
|
||||||
|
if (section_name) {
|
||||||
|
// Package name is the second level in the path (e.g., "IP" in Device.IP.Interface.1)
|
||||||
|
const char *package_name = parts[1];
|
||||||
|
char *name_value = NULL;
|
||||||
|
|
||||||
|
// Get the Name option value directly using package name and section name
|
||||||
|
int ret = dmuci_get_option_value_string_bbfdm(package_name, section_name, "Name", &name_value);
|
||||||
|
|
||||||
|
if (ret == 0 && DM_STRLEN(name_value) > 0) {
|
||||||
|
reference_args->value = dmstrdup(name_value);
|
||||||
|
reference_args->is_valid_path = true;
|
||||||
|
dmfree(section_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dmfree(section_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to JSON resolution
|
||||||
snprintf(file_path, sizeof(file_path), "%s/%s.json", DATA_MODEL_DB_PATH, parts[1]);
|
snprintf(file_path, sizeof(file_path), "%s/%s.json", DATA_MODEL_DB_PATH, parts[1]);
|
||||||
if (strlen(file_path) == 0)
|
if (strlen(file_path) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue