api modify & plugin param schema

get node: add plugin_id in response
get plugin: add query param plugin_id
This commit is contained in:
fengzero
2021-10-21 08:53:36 +00:00
parent 43b5a2de80
commit 21ddcf8bce
10 changed files with 167 additions and 23 deletions
+1
View File
@@ -132,6 +132,7 @@ typedef enum neu_node_type {
typedef struct neu_node_info {
neu_node_id_t node_id;
char * node_name;
plugin_id_t plugin_id;
// TODO: add node attribute
} neu_node_info_t;
+110
View File
@@ -0,0 +1,110 @@
{
"plugins": [
"mqtt-plugin",
"modbus-tcp-plugin",
"opcua-plugin"
],
"mqtt-plugin": {
"params": [
"host",
"port"
],
"host": {
"description": "broker host",
"type": "string",
"default": "127.0.0.1",
"valid": {
"length": 30
}
},
"port": {
"description": "broker port",
"type": "int",
"default": 1883,
"valid": {
"min": 1,
"max": 65535
}
}
},
"opcua-plugin": {
"tag_type": [
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15
],
"params": [
"host",
"port"
],
"host": {
"description": "opcua host",
"type": "string",
"default": "127.0.0.1",
"valid": {
"length": 30
}
},
"port": {
"description": "opcua port",
"type": "int",
"default": 4840,
"valid": {
"min": 1,
"max": 65535
}
}
},
"modbus-tcp-plugin": {
"tag_type": [
4,
5,
6,
7,
8,
9,
10,
11,
14
],
"params": [
"host",
"port",
"server_mode"
],
"host": {
"description": "modbus host",
"type": "string",
"default": "127.0.0.1",
"valid": {
"length": 30
}
},
"port": {
"description": "modbus port",
"type": "int",
"default": 502,
"valid": {
"min": 1,
"max": 65535
}
},
"server_mode": {
"description": "server mode",
"type": "bool",
"default": false,
"valid": {}
}
}
}
+3 -2
View File
@@ -101,8 +101,9 @@ void handle_get_adapter(nng_aio *aio)
{
neu_node_info_t *info = (neu_node_info_t *) iterator_get(&iter);
nodes_res.nodes[index].id = info->node_id;
nodes_res.nodes[index].name = info->node_name;
nodes_res.nodes[index].id = info->node_id;
nodes_res.nodes[index].name = info->node_name;
nodes_res.nodes[index].plugin_id = info->plugin_id.id_val;
index += 1;
}
+15 -5
View File
@@ -83,14 +83,20 @@ void handle_update_plugin(nng_aio *aio)
void handle_get_plugin(nng_aio *aio)
{
neu_plugin_t * plugin = neu_rest_get_plugin();
char * result = NULL;
neu_parse_get_plugins_res_t plugin_res = { 0 };
int index = 0;
neu_plugin_t * plugin = neu_rest_get_plugin();
neu_parse_get_plugins_res_t plugin_res = { 0 };
char * s_plugin_id = http_get_param(aio, "plugin_id");
char * result = NULL;
int index = 0;
uint32_t plugin_id = 0;
vector_t plugin_libs = neu_system_get_plugin(plugin);
vector_t plugin_libs = neu_system_get_plugin(plugin);
plugin_id = atoi(s_plugin_id);
plugin_res.n_plugin = plugin_libs.size;
if (plugin_id > 0) {
plugin_res.n_plugin = 1;
}
plugin_res.plugin_libs =
calloc(plugin_res.n_plugin, sizeof(neu_parse_get_plugins_res_lib_t));
@@ -98,6 +104,10 @@ void handle_get_plugin(nng_aio *aio)
{
plugin_lib_info_t *info = (plugin_lib_info_t *) iterator_get(&iter);
if (plugin_id > 0 && plugin_id != info->plugin_id.id_val) {
continue;
}
plugin_res.plugin_libs[index].node_type = info->node_type;
plugin_res.plugin_libs[index].plugin_id = info->plugin_id.id_val;
plugin_res.plugin_libs[index].kind = info->plugin_kind;
+10
View File
@@ -1052,3 +1052,13 @@ adapter_type_e neu_adapter_get_type(neu_adapter_t *adapter)
return adapter->type;
}
plugin_id_t neu_adapter_get_plugin_id(neu_adapter_t *adapter)
{
if (adapter == NULL) {
plugin_id_t id = { 0 };
return id;
}
return adapter->plugin_id;
}
+1
View File
@@ -37,5 +37,6 @@ neu_manager_t *neu_adapter_get_manager(neu_adapter_t *adapter);
nng_socket neu_adapter_get_sock(neu_adapter_t *adapter);
adapter_id_t neu_adapter_get_id(neu_adapter_t *adapter);
adapter_type_e neu_adapter_get_type(neu_adapter_t *adapter);
plugin_id_t neu_adapter_get_plugin_id(neu_adapter_t *adapter);
#endif
+3 -1
View File
@@ -108,7 +108,7 @@ static const char *const manager_url = "inproc://neu_manager";
#endif
#define WEBSERVER_PLUGIN_NAME "webserver-plugin-proxy"
#define MQTT_PLUGIN_NAME "mqtt-plugin"
#define MODBUS_TCP_PLUGIN_NAME "modbus-plugin-tcp"
#define MODBUS_TCP_PLUGIN_NAME "modbus-tcp-plugin"
#define OPCUA_PLUGIN_NAME "opcua-plugin"
// definition for adapter names
@@ -1538,6 +1538,8 @@ int neu_manager_get_nodes(neu_manager_t *manager, neu_node_type_e node_type,
node_info.node_id =
neu_manager_adapter_id_to_node_id(manager, adapter_id);
node_info.node_name = strdup(adapter_name);
node_info.plugin_id =
neu_adapter_get_plugin_id(reg_entity->adapter);
vector_push_back(result_nodes, &node_info);
}
}
+18 -11
View File
@@ -157,17 +157,24 @@ int neu_parse_encode_get_nodes(void *json_object, void *param)
void * array = NULL;
for (int i = 0; i < res->n_node; i++) {
neu_json_elem_t nodes[] = { {
.name = "name",
.t = NEU_JSON_STR,
.v.val_str = res->nodes[i].name,
},
{
.name = "id",
.t = NEU_JSON_INT,
.v.val_int = res->nodes[i].id,
} };
array = neu_json_encode_array(array, nodes, 2);
neu_json_elem_t nodes[] = {
{
.name = "name",
.t = NEU_JSON_STR,
.v.val_str = res->nodes[i].name,
},
{
.name = "id",
.t = NEU_JSON_INT,
.v.val_int = res->nodes[i].id,
},
{
.name = "plugin_id",
.t = NEU_JSON_INT,
.v.val_int = res->nodes[i].plugin_id,
},
};
array = neu_json_encode_array(array, nodes, NEU_JSON_ELEM_SIZE(nodes));
}
neu_json_elem_t elems[] = { {
.name = "nodes",
+1
View File
@@ -44,6 +44,7 @@ typedef struct {
typedef struct {
uint32_t id;
char * name;
uint32_t plugin_id;
} neu_parse_get_nodes_res_node_t;
typedef struct {
+5 -4
View File
@@ -35,10 +35,11 @@ TEST(JsonNodesTest, GetNodesDecode)
TEST(JsonNodesTest, GetNodesEncode)
{
char *buf = (char *) "{\"nodes\": "
"[{\"name\": \"node1\", \"id\": 123}, "
"{\"name\": \"node2\", \"id\": 456}, "
"{\"name\": \"node3\", \"id\": 789}]}";
char *buf = (char *) "{\"nodes\": [{\"name\": \"node1\", \"id\": 123, "
"\"plugin_id\": 0}, "
"{\"name\": \"node2\", \"id\": 456, \"plugin_id\": "
"0}, {\"name\": "
"\"node3\", \"id\": 789, \"plugin_id\": 0}]}";
char * result = NULL;
neu_parse_get_nodes_res_t res = {
.n_node = 3,