From a4c67d5a055f8fb65a929bfe352e34853190a513 Mon Sep 17 00:00:00 2001 From: suvendhu Date: Wed, 22 Jun 2022 12:29:46 +0530 Subject: [PATCH] Added dependency of DM objects in json plugin --- dmdynamicjson.c | 10 +++++--- docs/json_plugin_v1.md | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/dmdynamicjson.c b/dmdynamicjson.c index fc04bc1e..30891705 100644 --- a/dmdynamicjson.c +++ b/dmdynamicjson.c @@ -1735,6 +1735,8 @@ static void parse_obj(char *object, json_object *jobj, DMOBJ *pobj, int index, i //permission: Define object as readable by default pobj[index].permission = &DMREAD; + //checkdep: Define object dependency NULL by default + pobj[index].checkdep = NULL; json_object_object_foreach(jobj, key, json_obj) { //bbfdm_type @@ -1776,9 +1778,6 @@ static void parse_obj(char *object, json_object *jobj, DMOBJ *pobj, int index, i } if (strcmp(key, "array") == 0) { - //checkdep - pobj[index].checkdep = NULL; - //browseinstobj pobj[index].browseinstobj = json_object_get_boolean(json_obj) ? browse_obj : NULL; @@ -1786,6 +1785,11 @@ static void parse_obj(char *object, json_object *jobj, DMOBJ *pobj, int index, i pobj[index].nextdynamicobj = NULL; } + //checkdep + if (strcmp(key, "dependency") == 0) { + pobj[index].checkdep = dm_dynamic_strdup(&json_memhead, json_object_get_string(json_obj)); + } + //Version if (strcmp(key,"version") == 0) DM_STRNCPY(pobj[index].version, json_object_get_string(json_obj), 10); diff --git a/docs/json_plugin_v1.md b/docs/json_plugin_v1.md index ccfe9efd..ab0a8a94 100644 --- a/docs/json_plugin_v1.md +++ b/docs/json_plugin_v1.md @@ -72,6 +72,60 @@ It is often the case, that the supported mapping might not handle all the scenar ``` > Note: If the `json_plugin_version` is omitted in the json then it means, it is having legacy mapping and considered as `json_plugin_version` 0. +## How to add object dependency using Json plugin +In some cases we may need to set a dependency on datamodel object. In such cases the object will only populate if its dependencies are fulfilled. +The json object `dependency` is used to define the same. Below is an example of how to add object dependency: +```json +{ + "json_plugin_version": 1, + "Device.CWMPManagementServer.": { + "type": "object", + "version": "2.15", + "protocols": [ + "usp" + ], + "access": false, + "array": false, + "dependency": "file:/etc/config/cwmp", + "EnableCWMP": { + "type": "boolean", + "version": "2.15", + "read": true, + "write": true, + "protocols": [ + "usp" + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "cwmp", + "section": { + "name": "cpe" + }, + "option": { + "name": "enable" + } + } + } + ] + } + } +} +``` +In above example the object `CWMPManagementServer` has a dependency over the UCI file of cwmp (/etc/config/cwmp), that means if the cwmp UCI file is present in the device then only `Device.CWMPManagementServer.` object will populate. + +### Possible values for dependency +one file => "file:/etc/config/network" +multiple files => "file:/etc/config/network,/lib/netifd/proto/dhcp.sh" +one ubus => "ubus:router.network" (with method : "ubus:router.network->hosts") +multiple ubus => "ubus:router.system->info,dsl->status,wifi" +one package => "opkg:icwmp" +multiple packages => "opkg:icwmp,obuspa" +common (files, ubus and package) => "file:/etc/config/network,/etc/config/dhcp;ubus:router.system,dsl->status;opkg:icwmp" + +> Note: `dependency` can only be defined for datamodel objects and it can't be used for any leaf components (parameters/commands/events). + Now, If we consider the datamodel tree of usp, we have - Non-leaf components(Objects/Multi-instance objects) - Leaf components (Parameters/commands/events)