From 5cb150a1ef27514a8eeb4b2ea46cc0779eb8682a Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:19:55 +0800 Subject: [PATCH] feat(restful): tag read api support synchronous mode --- include/neuron/json/neu_json_rw.h | 1 + plugins/restful/rw_handle.c | 3 ++- src/parser/neu_json_rw.c | 24 ++++++++++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/neuron/json/neu_json_rw.h b/include/neuron/json/neu_json_rw.h index 33f2086c..d2a610d0 100644 --- a/include/neuron/json/neu_json_rw.h +++ b/include/neuron/json/neu_json_rw.h @@ -108,6 +108,7 @@ void neu_json_decode_write_free(neu_json_write_t *req); typedef struct { char *group; char *node; + bool sync; } neu_json_read_req_t; int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result); diff --git a/plugins/restful/rw_handle.c b/plugins/restful/rw_handle.c index 9d548430..e153fb21 100644 --- a/plugins/restful/rw_handle.c +++ b/plugins/restful/rw_handle.c @@ -43,7 +43,8 @@ void handle_read(nng_aio *aio) strcpy(cmd.driver, req->node); strcpy(cmd.group, req->group); - ret = neu_plugin_op(plugin, header, &cmd); + cmd.sync = req->sync; + ret = neu_plugin_op(plugin, header, &cmd); if (ret != 0) { NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, { neu_http_response(aio, NEU_ERR_IS_BUSY, result_error); diff --git a/src/parser/neu_json_rw.c b/src/parser/neu_json_rw.c index ef86f656..5fdfddd6 100644 --- a/src/parser/neu_json_rw.c +++ b/src/parser/neu_json_rw.c @@ -413,14 +413,21 @@ int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result) json_obj = neu_json_decode_new(buf); - neu_json_elem_t req_elems[] = { { - .name = "node", - .t = NEU_JSON_STR, - }, - { - .name = "group", - .t = NEU_JSON_STR, - } }; + neu_json_elem_t req_elems[] = { + { + .name = "node", + .t = NEU_JSON_STR, + }, + { + .name = "group", + .t = NEU_JSON_STR, + }, + { + .name = "sync", + .t = NEU_JSON_BOOL, + .attribute = NEU_JSON_ATTRIBUTE_OPTIONAL, + }, + }; ret = neu_json_decode_by_json(json_obj, NEU_JSON_ELEM_SIZE(req_elems), req_elems); if (ret != 0) { @@ -429,6 +436,7 @@ int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result) req->node = req_elems[0].v.val_str; req->group = req_elems[1].v.val_str; + req->sync = req_elems[2].v.val_bool; *result = req; goto decode_exit;