.yang 文件
rpc insert-food {
description "Operation to order the oven to put the prepared food inside.";
input {
leaf time {
description "Parameter determining when to perform the operation.";
type enumeration {
enum now {
description "Put the food in the oven immediately.";
}
enum on-oven-ready {
description
"Put the food in once the temperature inside
the oven is at least the configured one. If it
is already, the behaviour is similar to 'now'.";
}
}
}
}
output{
container result {
list user_module {
key "name";
leaf name {
type string;
}
leaf age {
type uint8;
}
}
}
}
}
plugin 实现
1. 回调函数设置
rc = sr_rpc_subscribe_tree(session,"/oven:insert-food",oven_insert_food_tree_cb,NULL,SR_SUBSCR_CTX_REUSE,&subscription);
if (rc != SR_ERR_OK)
{
goto error;
}
2. 回调函数实现
static int oven_insert_food_tree_cb(const char *xpath, const sr_node_t *input, const size_t input_cnt,
sr_node_t **output, size_t *output_cnt, void *private_ctx)
{
sr_node_t *list = NULL, *leaf = NULL;
int rc = SR_ERR_OK;
rc = sr_new_trees(1, &(*output));
if (SR_ERR_OK != rc) {
return rc;
}
rc = sr_node_set_name(&(*output)[0], "result");
if (SR_ERR_OK != rc) {
return rc;
}
(*output)[0].type = SR_CONTAINER_T;
for (size_t i = 0; i < 5; ++i) {
/* - list instance */
rc = sr_node_add_child(&(*output)[0], "user_module", NULL, &list);
if (SR_ERR_OK != rc) {
return rc;
}
list->type = SR_LIST_T;
rc = sr_node_add_child(list, "name", NULL, &leaf);
if (SR_ERR_OK != rc) {
return rc;
}
sr_node_build_str_data(leaf, SR_STRING_T, "%c", 'A'+i);
rc = sr_node_add_child(list, "age", NULL, &leaf);
if (SR_ERR_OK != rc) {
return rc;
}
leaf->type = SR_UINT8_T;
leaf->data.uint8_val = i;
}
*output_cnt = 1;
return rc;
}
NetOpeer2 调用以及返回
输入:
user-rpc
<insert-food xmlns="urn:sysrepo:oven">
<time>on-oven-ready</time>
</insert-food>
输出: