Added dependency of DM objects in json plugin

This commit is contained in:
suvendhu 2022-06-22 12:29:46 +05:30 committed by Amin Ben Ramdhane
parent eb4e1c4cf7
commit a4c67d5a05
2 changed files with 61 additions and 3 deletions

View file

@ -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);

View file

@ -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)