X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fo1-interface.git;a=blobdiff_plain;f=ntsimulator%2Fsrc%2Fgeneric-notifications%2Fgeneric-notifications.c;h=174b0a2d130b29cbae8190662b92f6e849ccc376;hp=b6b545927531ca0bc904691353905d6e1f666168;hb=223f6b0c729f17d03f41fdbe69c4a8097ea79c03;hpb=3472441e3d90935c770f84c449b6541784afd6a5 diff --git a/ntsimulator/src/generic-notifications/generic-notifications.c b/ntsimulator/src/generic-notifications/generic-notifications.c index b6b5459..174b0a2 100644 --- a/ntsimulator/src/generic-notifications/generic-notifications.c +++ b/ntsimulator/src/generic-notifications/generic-notifications.c @@ -218,6 +218,22 @@ static int op_add_srval(sr_val_t **values, size_t *values_cnt, struct lyd_node * return ret; } +static void add_attrtibutes(sr_val_t **values_list, size_t *values_cnt, struct lyd_node *node) +{ + struct lyd_node *iter = NULL; + + LY_TREE_FOR(node->child, iter) { + if (op_add_srval(values_list, values_cnt, iter)) { + printf("Could not transform libyang into sysrepo values...\n"); + return; + } + if (iter->schema->nodetype == LYS_CONTAINER || iter->schema->nodetype == LYS_LIST) + { + add_attrtibutes(values_list, values_cnt, iter); + } + } +} + static int send_dummy_notif(sr_session_ctx_t *sess, const char *module_name, const char *notif_object) { @@ -263,19 +279,18 @@ static int send_dummy_notif(sr_session_ctx_t *sess, const char *module_name, con } } - data = lyd_parse_mem(ctx, notif_object, LYD_JSON, LYD_OPT_NOTIF); + printf("Successfully loaded schemas, trying now to parse the JSON...\n"); + + data = lyd_parse_mem(ctx, notif_object, LYD_JSON, LYD_OPT_NOTIF, NULL); if (data == NULL) { printf("Could not create JSON object, not valid!\n"); return SR_ERR_VALIDATION_FAILED; } - LY_TREE_FOR(data->child, iter) { - if (op_add_srval(&vnotif, &num_values, iter)) { - printf("Could not transform libyang into sysrepo values...\n"); - return SR_ERR_OPERATION_FAILED; - } - } + printf("Successfully parsed the JSON notification object...\n"); + + add_attrtibutes(&vnotif, &num_values, data); if (num_values == 0) { @@ -290,6 +305,13 @@ static int send_dummy_notif(sr_session_ctx_t *sess, const char *module_name, con return SR_ERR_OPERATION_FAILED; } + lyd_free(data); + ly_ctx_destroy(ctx, NULL); + + sr_free_values(vnotif, num_values); + + printf("Successfully sent notification from module=%s with %d number of atttributes\n", module_name, num_values); + return rc; }