This commit is contained in:
gc87
2022-03-04 11:40:12 +08:00
parent be28d838b3
commit c01225dcda
8 changed files with 67 additions and 73 deletions
-8
View File
@@ -43,18 +43,10 @@ typedef struct {
char *command;
} neu_json_mqtt_t;
typedef struct {
char * config_name;
char * node_name;
uint32_t node_id;
uint64_t timestamp;
} neu_json_mqtt_periodic_t;
int neu_json_decode_mqtt_req(char *buf, neu_json_mqtt_t **result);
void neu_json_decode_mqtt_req_free(neu_json_mqtt_t *req);
int neu_json_encode_mqtt_resp(void *json_object, void *param);
int neu_json_encode_mqtt_periodic_resp(void *json_object, void *param);
#ifdef __cplusplus
}
+9
View File
@@ -31,6 +31,13 @@
extern "C" {
#endif
typedef struct {
char * config_name;
char * node_name;
uint32_t node_id;
uint64_t timestamp;
} neu_json_read_periodic_t;
typedef struct {
int64_t error;
int64_t id;
@@ -69,6 +76,8 @@ typedef struct {
int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result);
void neu_json_decode_read_req_free(neu_json_read_req_t *req);
int neu_json_encode_read_periodic_resp(void *json_object, void *param);
#ifdef __cplusplus
}
#endif
+1 -1
View File
@@ -558,7 +558,7 @@ char *command_read_periodic_response(neu_plugin_t *plugin, uint64_t sender,
neu_taggrp_config_t *config,
neu_data_val_t * resp_val)
{
return command_rw_read_cycle_response(plugin, sender, config, resp_val);
return command_rw_read_periodic_response(plugin, sender, config, resp_val);
}
char *command_write_response(neu_plugin_t * plugin,
+22 -30
View File
@@ -242,28 +242,21 @@ static bool node_match(const void *key, const void *item)
return (id == info->node_id) ? true : false;
}
char *command_rw_read_cycle_response(neu_plugin_t *plugin, uint64_t sender,
neu_taggrp_config_t *config,
neu_data_val_t * resp_val)
char *command_rw_read_periodic_response(neu_plugin_t *plugin, uint64_t sender,
neu_taggrp_config_t *config,
neu_data_val_t * resp_val)
{
UNUSED(plugin);
neu_fixed_array_t *array;
int rc = neu_dvalue_get_ref_array(resp_val, &array);
if (0 != rc) {
log_info("Get array ref error");
return NULL;
}
if (0 >= array->length) {
neu_fixed_array_t *array = NULL;
neu_dvalue_get_ref_array(resp_val, &array);
if (NULL == array || 0 >= array->length) {
log_error("Get array error");
return NULL;
}
char * json_str = NULL;
neu_json_mqtt_periodic_t header = {
neu_json_read_periodic_t header = {
.config_name = (char *) neu_taggrp_cfg_get_name(config),
.node_name = "",
.node_id = neu_plugin_self_node_id(plugin),
.node_id = sender,
.timestamp = current_time()
};
@@ -271,7 +264,15 @@ char *command_rw_read_cycle_response(neu_plugin_t *plugin, uint64_t sender,
neu_node_info_t *info = NULL;
info = vector_find_item(&nodes, (void *) &sender, node_match);
if (NULL != info) {
header.node_name = info->node_name;
header.node_name = strdup(info->node_name);
} else {
header.node_name = strdup("");
}
VECTOR_FOR_EACH(&nodes, iter)
{
neu_node_info_t *info = (neu_node_info_t *) iterator_get(&iter);
free(info->node_name);
}
vector_uninit(&nodes);
@@ -282,21 +283,12 @@ char *command_rw_read_cycle_response(neu_plugin_t *plugin, uint64_t sender,
header.timestamp);
neu_json_read_resp_t json = { 0 };
rc = wrap_read_response_json_object(array, &json);
if (0 != rc) {
return NULL;
}
rc = neu_json_encode_with_mqtt(&json, neu_json_encode_read_resp, &header,
neu_json_encode_mqtt_periodic_resp,
&json_str);
wrap_read_response_json_object(array, &json);
neu_json_encode_with_mqtt(&json, neu_json_encode_read_resp, &header,
neu_json_encode_read_periodic_resp, &json_str);
clean_read_response_json_object(&json);
if (0 != rc) {
log_info("Json string parse error:%d", rc);
return NULL;
}
free(header.node_name);
return json_str;
}
+3 -3
View File
@@ -33,9 +33,9 @@ int command_rw_read_once_request(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt,
char *command_rw_read_once_response(neu_plugin_t * plugin,
neu_json_mqtt_t *parse_header,
neu_data_val_t * resp_val);
char *command_rw_read_cycle_response(neu_plugin_t *plugin, uint64_t sender,
neu_taggrp_config_t *grp_config,
neu_data_val_t * resp_val);
char *command_rw_read_periodic_response(neu_plugin_t *plugin, uint64_t sender,
neu_taggrp_config_t *grp_config,
neu_data_val_t * resp_val);
int command_rw_write_request(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt,
neu_json_write_req_t *write_req, uint32_t req_id);
char *command_rw_write_response(neu_plugin_t * plugin,
+1
View File
@@ -630,6 +630,7 @@ static int mqtt_plugin_request(neu_plugin_t *plugin, neu_request_t *req)
default:
break;
}
return rv;
}
-31
View File
@@ -97,34 +97,3 @@ int neu_json_encode_mqtt_resp(void *json_object, void *param)
return ret;
}
int neu_json_encode_mqtt_periodic_resp(void *json_object, void *param)
{
int ret = 0;
neu_json_mqtt_periodic_t *resp = (neu_json_mqtt_periodic_t *) param;
neu_json_elem_t resp_elems[] = { {
.name = "node_id",
.t = NEU_JSON_INT,
.v.val_int = resp->node_id,
},
{
.name = "node_name",
.t = NEU_JSON_STR,
.v.val_str = resp->node_name,
},
{
.name = "group_config_name",
.t = NEU_JSON_STR,
.v.val_str = resp->config_name,
},
{
.name = "timestamp",
.t = NEU_JSON_INT,
.v.val_int = resp->timestamp,
} };
ret = neu_json_encode_field(json_object, resp_elems,
NEU_JSON_ELEM_SIZE(resp_elems));
return ret;
}
+31
View File
@@ -225,3 +225,34 @@ void neu_json_decode_read_req_free(neu_json_read_req_t *req)
free(req);
}
int neu_json_encode_read_periodic_resp(void *json_object, void *param)
{
int ret = 0;
neu_json_read_periodic_t *resp = (neu_json_read_periodic_t *) param;
neu_json_elem_t resp_elems[] = { {
.name = "node_id",
.t = NEU_JSON_INT,
.v.val_int = resp->node_id,
},
{
.name = "node_name",
.t = NEU_JSON_STR,
.v.val_str = resp->node_name,
},
{
.name = "group_config_name",
.t = NEU_JSON_STR,
.v.val_str = resp->config_name,
},
{
.name = "timestamp",
.t = NEU_JSON_INT,
.v.val_int = resp->timestamp,
} };
ret = neu_json_encode_field(json_object, resp_elems,
NEU_JSON_ELEM_SIZE(resp_elems));
return ret;
}