mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
feat(plugin):update plugin manager policy and update ft case
This commit is contained in:
@@ -22,6 +22,15 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define NEU_VERSION_MAJOR 2
|
||||
#define NEU_VERSION_MINOR 7
|
||||
#define NEU_VERSION_FIX 0
|
||||
|
||||
#define NEU_GET_VERSION_MAJOR(V) ((0xffff0000 & V) >> 16)
|
||||
#define NEU_GET_VERSION_MINOR(V) ((0x0000ff00 & V) >> 8)
|
||||
#define NEU_GET_VERSION_FIX(V) ((0x000000ff & V))
|
||||
#define NEU_VERSION(MAJOR, MINOR, FIX) ((MAJOR << 16) | (MINOR << 8) | FIX)
|
||||
|
||||
#define NEU_TAG_NAME_LEN 64
|
||||
#define NEU_TAG_ADDRESS_LEN 128
|
||||
#define NEU_TAG_DESCRIPTION_LEN 128
|
||||
|
||||
@@ -97,6 +97,9 @@ typedef enum {
|
||||
NEU_ERR_LIBRARY_MODULE_ALREADY_EXIST = 2311,
|
||||
NEU_ERR_LIBRARY_MODULE_NOT_EXISTS = 2312,
|
||||
NEU_ERR_LIBRARY_MODULE_KIND_NOT_SUPPORT = 2313,
|
||||
NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH = 2314,
|
||||
NEU_ERR_LIBRARY_NAME_NOT_CONFORM = 2315,
|
||||
NEU_ERR_LIBRARY_CLIB_NOT_MATCH = 2316,
|
||||
|
||||
NEU_ERR_LICENSE_NOT_FOUND = 2400,
|
||||
NEU_ERR_LICENSE_INVALID = 2401,
|
||||
|
||||
@@ -33,8 +33,8 @@ extern "C" {
|
||||
#include "define.h"
|
||||
#include "type.h"
|
||||
|
||||
#define NEURON_PLUGIN_VER_1_0 100
|
||||
#define NEURON_PLUGIN_VER_2_0 200
|
||||
#define NEURON_PLUGIN_VER_1_0 \
|
||||
NEU_VERSION(NEU_VERSION_MAJOR, NEU_VERSION_MINOR, NEU_VERSION_FIX)
|
||||
|
||||
extern int64_t global_timestamp;
|
||||
|
||||
|
||||
+79
-65
@@ -259,6 +259,18 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
neu_resp_error_t e = { 0 };
|
||||
neu_plugin_kind_e kind = -1;
|
||||
char schema[64] = { 0 };
|
||||
char buffer[65] = { 0 };
|
||||
|
||||
if (sscanf(cmd->library, "libplugin-%64s.so", buffer) != 1) {
|
||||
nlog_warn("library %s no conform", cmd->library);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_LIBRARY_NAME_NOT_CONFORM;
|
||||
strcpy(header->receiver, header->sender);
|
||||
reply(manager, header, &e);
|
||||
free(cmd->so_file);
|
||||
free(cmd->schema_file);
|
||||
break;
|
||||
}
|
||||
|
||||
if (neu_persister_library_exists(cmd->library)) {
|
||||
nlog_warn("library %s had exited", cmd->library);
|
||||
@@ -284,10 +296,11 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
break;
|
||||
}
|
||||
|
||||
neu_plugin_instance_t ins = { 0 };
|
||||
neu_plugin_instance_t ins = { 0 };
|
||||
int error = NEU_ERR_SUCCESS;
|
||||
|
||||
if (neu_plugin_manager_create_instance_by_path(manager->plugin_manager,
|
||||
so_tmp_path, &ins)) {
|
||||
if (neu_plugin_manager_create_instance_by_path(
|
||||
manager->plugin_manager, so_tmp_path, &ins, &error)) {
|
||||
char module_name[64] = { 0 };
|
||||
kind = ins.module->kind;
|
||||
strncpy(module_name, ins.module->module_name, sizeof(module_name));
|
||||
@@ -296,8 +309,24 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
nlog_debug("library %s, module_name %s, schema:%s", cmd->library,
|
||||
module_name, schema);
|
||||
|
||||
uint32_t major = NEU_GET_VERSION_MAJOR(ins.module->version);
|
||||
uint32_t minor = NEU_GET_VERSION_MINOR(ins.module->version);
|
||||
|
||||
neu_plugin_manager_destroy_instance(manager->plugin_manager, &ins);
|
||||
|
||||
if (NEU_VERSION_MAJOR != major || NEU_VERSION_MINOR != minor) {
|
||||
nlog_warn("library %s plugin version error, major:%d minor:%d",
|
||||
module_name, major, minor);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH;
|
||||
strcpy(header->receiver, header->sender);
|
||||
reply(manager, header, &e);
|
||||
free(cmd->so_file);
|
||||
free(cmd->schema_file);
|
||||
free(so_tmp_path);
|
||||
break;
|
||||
}
|
||||
|
||||
if (neu_plugin_manager_exists(manager->plugin_manager,
|
||||
module_name)) {
|
||||
|
||||
@@ -315,7 +344,7 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
} else {
|
||||
nlog_warn("library %s so file is not a vaild file", cmd->library);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_LIBRARY_MODULE_INVALID;
|
||||
e.error = error;
|
||||
strcpy(header->receiver, header->sender);
|
||||
reply(manager, header, &e);
|
||||
free(cmd->so_file);
|
||||
@@ -376,7 +405,7 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
break;
|
||||
}
|
||||
|
||||
int error = neu_manager_add_plugin(manager, cmd->library);
|
||||
error = neu_manager_add_plugin(manager, cmd->library);
|
||||
|
||||
if (error == NEU_ERR_SUCCESS) {
|
||||
manager_strorage_plugin(manager);
|
||||
@@ -442,6 +471,18 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
neu_plugin_kind_e kind = -1;
|
||||
char module_name[64] = { 0 };
|
||||
char schema[64] = { 0 };
|
||||
char buffer[65] = { 0 };
|
||||
|
||||
if (sscanf(cmd->library, "libplugin-%64s.so", buffer) != 1) {
|
||||
nlog_warn("library %s no conform", cmd->library);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_LIBRARY_NAME_NOT_CONFORM;
|
||||
strcpy(header->receiver, header->sender);
|
||||
reply(manager, header, &e);
|
||||
free(cmd->so_file);
|
||||
free(cmd->schema_file);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!neu_persister_library_exists(cmd->library)) {
|
||||
nlog_warn("library %s no exited", cmd->library);
|
||||
@@ -467,10 +508,11 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
break;
|
||||
}
|
||||
|
||||
neu_plugin_instance_t ins = { 0 };
|
||||
neu_plugin_instance_t ins = { 0 };
|
||||
int error = NEU_ERR_SUCCESS;
|
||||
|
||||
if (neu_plugin_manager_create_instance_by_path(manager->plugin_manager,
|
||||
so_tmp_path, &ins)) {
|
||||
if (neu_plugin_manager_create_instance_by_path(
|
||||
manager->plugin_manager, so_tmp_path, &ins, &error)) {
|
||||
kind = ins.module->kind;
|
||||
strncpy(module_name, ins.module->module_name, sizeof(module_name));
|
||||
strncpy(schema, ins.module->schema, sizeof(schema));
|
||||
@@ -478,8 +520,24 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
nlog_debug("library %s, module_name %s, schema:%s", cmd->library,
|
||||
module_name, schema);
|
||||
|
||||
uint32_t major = NEU_GET_VERSION_MAJOR(ins.module->version);
|
||||
uint32_t minor = NEU_GET_VERSION_MINOR(ins.module->version);
|
||||
|
||||
neu_plugin_manager_destroy_instance(manager->plugin_manager, &ins);
|
||||
|
||||
if (NEU_VERSION_MAJOR != major || NEU_VERSION_MINOR != minor) {
|
||||
nlog_warn("library %s plugin version error, major:%d minor:%d",
|
||||
module_name, major, minor);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH;
|
||||
strcpy(header->receiver, header->sender);
|
||||
reply(manager, header, &e);
|
||||
free(cmd->so_file);
|
||||
free(cmd->schema_file);
|
||||
free(so_tmp_path);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!neu_plugin_manager_exists(manager->plugin_manager,
|
||||
module_name)) {
|
||||
|
||||
@@ -497,7 +555,7 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
} else {
|
||||
nlog_warn("library %s so file is not a vaild file", cmd->library);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_LIBRARY_MODULE_INVALID;
|
||||
e.error = error;
|
||||
strcpy(header->receiver, header->sender);
|
||||
reply(manager, header, &e);
|
||||
free(cmd->so_file);
|
||||
@@ -535,24 +593,21 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
UT_array *nodes = neu_manager_get_nodes(
|
||||
manager, NEU_NA_TYPE_DRIVER | NEU_NA_TYPE_APP, module_name, "");
|
||||
|
||||
UT_array *running_adapters = NULL;
|
||||
UT_icd icd = { sizeof(neu_adapter_t *), NULL, NULL, NULL };
|
||||
utarray_new(running_adapters, &icd);
|
||||
|
||||
if (nodes != NULL) {
|
||||
if (utarray_len(nodes) > 0) {
|
||||
utarray_foreach(nodes, neu_resp_node_info_t *, node)
|
||||
{
|
||||
neu_adapter_t *adapter = neu_node_manager_find(
|
||||
manager->node_manager, node->node);
|
||||
if (neu_adapter_get_state(adapter).running ==
|
||||
NEU_NODE_RUNNING_STATE_RUNNING) {
|
||||
neu_adapter_stop(adapter);
|
||||
utarray_push_back(running_adapters, &adapter);
|
||||
}
|
||||
neu_adapter_handle_close(adapter);
|
||||
}
|
||||
utarray_free(nodes);
|
||||
nlog_warn("library %s is using", cmd->library);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_LIBRARY_IN_USE;
|
||||
strcpy(header->receiver, header->sender);
|
||||
reply(manager, header, &e);
|
||||
free(cmd->so_file);
|
||||
free(cmd->schema_file);
|
||||
free(so_tmp_path);
|
||||
free(schema_tmp_path);
|
||||
break;
|
||||
}
|
||||
utarray_free(nodes);
|
||||
}
|
||||
|
||||
if (!neu_plugin_manager_remove_library(manager->plugin_manager,
|
||||
@@ -595,47 +650,6 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
break;
|
||||
}
|
||||
|
||||
if (nodes != NULL) {
|
||||
if (utarray_len(nodes) > 0) {
|
||||
neu_adapter_info_t adapter_info = { 0 };
|
||||
int ret = neu_plugin_manager_create_instance(
|
||||
manager->plugin_manager, module_name, &ins);
|
||||
if (ret != 0) {
|
||||
nlog_warn("library %s open new library fail", cmd->library);
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_LIBRARY_FAILED_TO_OPEN;
|
||||
strcpy(header->receiver, header->sender);
|
||||
reply(manager, header, &e);
|
||||
free(cmd->so_file);
|
||||
free(cmd->schema_file);
|
||||
free(so_tmp_path);
|
||||
free(schema_tmp_path);
|
||||
break;
|
||||
}
|
||||
|
||||
utarray_foreach(nodes, neu_resp_node_info_t *, node)
|
||||
{
|
||||
neu_adapter_t *adapter = neu_node_manager_find(
|
||||
manager->node_manager, node->node);
|
||||
adapter_info.handle = ins.handle;
|
||||
adapter_info.module = ins.module;
|
||||
|
||||
neu_adapter_reset(adapter, &adapter_info);
|
||||
}
|
||||
}
|
||||
utarray_free(nodes);
|
||||
}
|
||||
|
||||
if (running_adapters != NULL) {
|
||||
if (utarray_len(running_adapters) > 0) {
|
||||
utarray_foreach(running_adapters, neu_adapter_t **, adapter)
|
||||
{
|
||||
neu_adapter_start(*adapter);
|
||||
}
|
||||
}
|
||||
utarray_free(running_adapters);
|
||||
}
|
||||
|
||||
header->type = NEU_RESP_ERROR;
|
||||
e.error = NEU_ERR_SUCCESS;
|
||||
strcpy(header->receiver, header->sender);
|
||||
|
||||
@@ -133,6 +133,15 @@ int neu_plugin_manager_add(neu_plugin_manager_t *mgr,
|
||||
return NEU_ERR_LIBRARY_INFO_INVALID;
|
||||
}
|
||||
|
||||
uint32_t major = NEU_GET_VERSION_MAJOR(pm->version);
|
||||
uint32_t minor = NEU_GET_VERSION_MINOR(pm->version);
|
||||
|
||||
if (NEU_VERSION_MAJOR != major || NEU_VERSION_MINOR != minor) {
|
||||
nlog_warn("library %s plugin version error, major:%d minor:%d",
|
||||
lib_path, major, minor);
|
||||
return NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH;
|
||||
}
|
||||
|
||||
HASH_FIND_STR(mgr->plugins, pm->module_name, plugin);
|
||||
if (plugin != NULL) {
|
||||
dlclose(handle);
|
||||
@@ -369,7 +378,8 @@ static void entity_free(plugin_entity_t *entity)
|
||||
|
||||
bool neu_plugin_manager_create_instance_by_path(neu_plugin_manager_t *mgr,
|
||||
const char *plugin_path,
|
||||
neu_plugin_instance_t *instance)
|
||||
neu_plugin_instance_t *instance,
|
||||
int * error)
|
||||
{
|
||||
|
||||
(void) mgr;
|
||||
@@ -377,6 +387,18 @@ bool neu_plugin_manager_create_instance_by_path(neu_plugin_manager_t *mgr,
|
||||
instance->handle = dlopen(plugin_path, RTLD_NOW | RTLD_NODELETE);
|
||||
|
||||
if (instance->handle == NULL) {
|
||||
const char *dl_err = dlerror();
|
||||
if (strstr(dl_err, "cannot open shared object file") != NULL) {
|
||||
*error = NEU_ERR_LIBRARY_ARCH_NOT_SUPPORT;
|
||||
} else if (strstr(dl_err, "GLIBC") != NULL &&
|
||||
strstr(dl_err, "not found") != NULL) {
|
||||
*error = NEU_ERR_LIBRARY_CLIB_NOT_MATCH;
|
||||
} else {
|
||||
*error = NEU_ERR_LIBRARY_MODULE_INVALID;
|
||||
}
|
||||
|
||||
nlog_debug("create instance error:%s", dl_err);
|
||||
(void) dlerror();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -385,6 +407,7 @@ bool neu_plugin_manager_create_instance_by_path(neu_plugin_manager_t *mgr,
|
||||
|
||||
if (instance->module == NULL) {
|
||||
dlclose(instance->handle);
|
||||
*error = NEU_ERR_LIBRARY_MODULE_INVALID;
|
||||
instance->handle = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -63,9 +63,10 @@ void neu_plugin_manager_load_static(neu_plugin_manager_t * mgr,
|
||||
const char * plugin_name,
|
||||
neu_plugin_instance_t *instance);
|
||||
|
||||
bool neu_plugin_manager_create_instance_by_path(
|
||||
neu_plugin_manager_t *mgr, const char *plugin_path,
|
||||
neu_plugin_instance_t *instance);
|
||||
bool neu_plugin_manager_create_instance_by_path(neu_plugin_manager_t *mgr,
|
||||
const char *plugin_path,
|
||||
neu_plugin_instance_t *instance,
|
||||
int * error);
|
||||
|
||||
bool neu_plugin_manager_remove_library(neu_plugin_manager_t *mgr,
|
||||
const char * library);
|
||||
|
||||
+7
-3
@@ -332,7 +332,6 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content)
|
||||
case NEU_ERR_LIBRARY_INFO_INVALID:
|
||||
case NEU_ERR_LICENSE_INVALID:
|
||||
case NEU_ERR_GROUP_PARAMETER_INVALID:
|
||||
case NEU_ERR_LIBRARY_SYSTEM_NOT_ALLOW_DEL:
|
||||
case NEU_ERR_LIBRARY_FAILED_TO_OPEN:
|
||||
case NEU_ERR_LIBRARY_MODULE_INVALID:
|
||||
case NEU_ERR_NODE_NAME_TOO_LONG:
|
||||
@@ -343,11 +342,13 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content)
|
||||
case NEU_ERR_TEMPLATE_NAME_TOO_LONG:
|
||||
case NEU_ERR_PLUGIN_NAME_TOO_LONG:
|
||||
case NEU_ERR_PLUGIN_NOT_SUPPORT_TEMPLATE:
|
||||
case NEU_ERR_LIBRARY_IN_USE:
|
||||
case NEU_ERR_LIBRARY_ADD_FAIL:
|
||||
case NEU_ERR_LIBRARY_MODULE_ALREADY_EXIST:
|
||||
case NEU_ERR_LIBRARY_MODULE_NOT_EXISTS:
|
||||
case NEU_ERR_LIBRARY_MODULE_KIND_NOT_SUPPORT:
|
||||
case NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH:
|
||||
case NEU_ERR_LIBRARY_NAME_NOT_CONFORM:
|
||||
case NEU_ERR_LIBRARY_CLIB_NOT_MATCH:
|
||||
case NEU_ERR_LIBRARY_ARCH_NOT_SUPPORT:
|
||||
status = NNG_HTTP_STATUS_BAD_REQUEST;
|
||||
break;
|
||||
case NEU_ERR_FILE_NOT_EXIST:
|
||||
@@ -378,6 +379,9 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content)
|
||||
case NEU_ERR_LIBRARY_NOT_ALLOW_CREATE_INSTANCE:
|
||||
case NEU_ERR_NODE_NOT_ALLOW_DELETE:
|
||||
case NEU_ERR_TEMPLATE_EXIST:
|
||||
case NEU_ERR_LIBRARY_MODULE_ALREADY_EXIST:
|
||||
case NEU_ERR_LIBRARY_IN_USE:
|
||||
case NEU_ERR_LIBRARY_SYSTEM_NOT_ALLOW_DEL:
|
||||
status = NNG_HTTP_STATUS_CONFLICT;
|
||||
break;
|
||||
case NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT:
|
||||
|
||||
+15
-12
@@ -53,19 +53,22 @@ NEU_ERR_TAG_DESCRIPTION_TOO_LONG = 2208
|
||||
NEU_ERR_TAG_PRECISION_INVALID = 2209
|
||||
NEU_ERR_TAG_EXIST = 2210
|
||||
|
||||
NEU_ERR_LIBRARY_NOT_FOUND = 2301
|
||||
NEU_ERR_LIBRARY_INFO_INVALID = 2302
|
||||
NEU_ERR_LIBRARY_NAME_CONFLICT = 2303
|
||||
NEU_ERR_LIBRARY_FAILED_TO_OPEN = 2304
|
||||
NEU_ERR_LIBRARY_MODULE_INVALID = 2305
|
||||
NEU_ERR_LIBRARY_SYSTEM_NOT_ALLOW_DEL = 2306
|
||||
NEU_ERR_LIBRARY_NOT_FOUND = 2301
|
||||
NEU_ERR_LIBRARY_INFO_INVALID = 2302
|
||||
NEU_ERR_LIBRARY_NAME_CONFLICT = 2303
|
||||
NEU_ERR_LIBRARY_FAILED_TO_OPEN = 2304
|
||||
NEU_ERR_LIBRARY_MODULE_INVALID = 2305
|
||||
NEU_ERR_LIBRARY_SYSTEM_NOT_ALLOW_DEL = 2306
|
||||
NEU_ERR_LIBRARY_NOT_ALLOW_CREATE_INSTANCE = 2307
|
||||
NEU_ERR_LIBRARY_ARCH_NOT_SUPPORT = 2308
|
||||
NEU_ERR_LIBRARY_IN_USE = 2309
|
||||
NEU_ERR_LIBRARY_ADD_FAIL = 2310
|
||||
NEU_ERR_LIBRARY_MODULE_ALREADY_EXIST = 2311
|
||||
NEU_ERR_LIBRARY_MODULE_NOT_EXISTS = 2312
|
||||
NEU_ERR_LIBRARY_MODULE_KIND_NOT_SUPPORT = 2313
|
||||
NEU_ERR_LIBRARY_ARCH_NOT_SUPPORT = 2308
|
||||
NEU_ERR_LIBRARY_IN_USE = 2309
|
||||
NEU_ERR_LIBRARY_ADD_FAIL = 2310
|
||||
NEU_ERR_LIBRARY_MODULE_ALREADY_EXIST = 2311
|
||||
NEU_ERR_LIBRARY_MODULE_NOT_EXISTS = 2312
|
||||
NEU_ERR_LIBRARY_MODULE_KIND_NOT_SUPPORT = 2313
|
||||
NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH = 2314
|
||||
NEU_ERR_LIBRARY_NAME_NOT_CONFORM = 2315
|
||||
NEU_ERR_LIBRARY_CLIB_NOT_MATCH = 2316
|
||||
|
||||
NEU_ERR_LICENSE_NOT_FOUND = 2400
|
||||
NEU_ERR_LICENSE_INVALID = 2401
|
||||
|
||||
@@ -52,4 +52,5 @@ def start_simulator(args, dir='build/simulator'):
|
||||
|
||||
|
||||
def stop_simulator(process):
|
||||
process.terminate()
|
||||
assert process.poll() is None
|
||||
process.terminate()
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+121
-36
@@ -8,25 +8,43 @@ from neuron.config import *
|
||||
from neuron.common import *
|
||||
from neuron.error import *
|
||||
|
||||
|
||||
class TestPlugin:
|
||||
|
||||
with open('tests/ft/plugin/test_library_data.json') as f:
|
||||
test_data = json.load(f)
|
||||
test_data['so_file_c1_err']="asdf"
|
||||
test_data['so_file_c1_err'] = "asdf"
|
||||
with open('build/tests/plugins/libplugin-c1.so', 'rb') as f:
|
||||
test_data['so_file_c1'] = str(base64.b64encode(f.read()),encoding='utf-8')
|
||||
test_data['so_file_c1'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('build/tests/plugins/libplugin-c1_2.so', 'rb') as f:
|
||||
test_data['so_file_c1_2'] = str(base64.b64encode(f.read()),encoding='utf-8')
|
||||
test_data['so_file_c1_2'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('build/tests/plugins/libplugin-c1verr.so', 'rb') as f:
|
||||
test_data['so_file_c1verr'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('build/tests/plugins/libplugin-c1_2verr.so', 'rb') as f:
|
||||
test_data['so_file_c1_2verr'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('build/tests/plugins/libplugin-s1.so', 'rb') as f:
|
||||
test_data['so_file_s1'] = str(base64.b64encode(f.read()),encoding='utf-8')
|
||||
test_data['so_file_s1'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('build/tests/plugins/libplugin-s1_2.so', 'rb') as f:
|
||||
test_data['so_file_s1_2'] = str(base64.b64encode(f.read()),encoding='utf-8')
|
||||
test_data['so_file_s1_2'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('build/tests/plugins/libplugin-sc1.so', 'rb') as f:
|
||||
test_data['so_file_sc1'] = str(base64.b64encode(f.read()),encoding='utf-8')
|
||||
test_data['so_file_sc1'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('build/tests/plugins/libplugin-sc1_2.so', 'rb') as f:
|
||||
test_data['so_file_sc1_2'] = str(base64.b64encode(f.read()),encoding='utf-8')
|
||||
test_data['so_file_sc1_2'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('build/tests/plugins/schema/c1.json', 'rb') as f:
|
||||
test_data['schema_file'] = str(base64.b64encode(f.read()),encoding='utf-8')
|
||||
test_data['schema_file'] = str(
|
||||
base64.b64encode(f.read()), encoding='utf-8')
|
||||
with open('tests/ft/plugin/plugin_data1.txt', 'rb') as f:
|
||||
test_data["so_file_arm64"] = str(f.read(), encoding='utf-8')
|
||||
with open('tests/ft/plugin/plugin_data2.txt', 'rb') as f:
|
||||
test_data["so_file_clib"] = str(f.read(), encoding='utf-8')
|
||||
|
||||
@description(given="incorrect configuration", when="add plugin", then="fail")
|
||||
def test_01_add_plugin_fail0(self):
|
||||
@@ -36,7 +54,8 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_c1_err']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_MODULE_INVALID == response.json().get("error")
|
||||
|
||||
@@ -48,7 +67,8 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = ''
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_BODY_IS_WRONG == response.json().get("error")
|
||||
|
||||
@@ -60,7 +80,8 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_c1']
|
||||
plugin_data['schema_file'] = ''
|
||||
|
||||
response = api.add_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_BODY_IS_WRONG == response.json().get("error")
|
||||
|
||||
@@ -72,7 +93,8 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_sc1']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_MODULE_KIND_NOT_SUPPORT == response.json().get("error")
|
||||
|
||||
@@ -84,7 +106,8 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_c1']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
|
||||
@@ -96,7 +119,8 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_s1']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
|
||||
@@ -108,7 +132,8 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_c1']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 409 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_NAME_CONFLICT == response.json().get("error")
|
||||
|
||||
@@ -120,9 +145,49 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_c1']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_MODULE_ALREADY_EXIST == response.json().get("error")
|
||||
assert NEU_ERR_LIBRARY_NAME_NOT_CONFORM == response.json().get("error")
|
||||
|
||||
@description(given="incorrect configuration", when="add plugin", then="fail")
|
||||
def test_04_add_plugin_fail6(self):
|
||||
test_data = TestPlugin.test_data
|
||||
plugin_data = {}
|
||||
plugin_data['library'] = "libplugin-test.so"
|
||||
plugin_data['so_file'] = test_data['so_file_arm64']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_ARCH_NOT_SUPPORT == response.json().get("error")
|
||||
|
||||
@description(given="incorrect configuration", when="add plugin", then="fail")
|
||||
def test_04_add_plugin_fail7(self):
|
||||
test_data = TestPlugin.test_data
|
||||
plugin_data = {}
|
||||
plugin_data['library'] = "libplugin-test.so"
|
||||
plugin_data['so_file'] = test_data['so_file_clib']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_CLIB_NOT_MATCH == response.json().get("error")
|
||||
|
||||
@description(given="incorrect configuration", when="add plugin", then="fail")
|
||||
def test_04_add_plugin_fail8(self):
|
||||
test_data = TestPlugin.test_data
|
||||
plugin_data = {}
|
||||
plugin_data['library'] = "libplugin-test.so"
|
||||
plugin_data['so_file'] = test_data['so_file_c1verr']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.add_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH == response.json().get("error")
|
||||
|
||||
@description(given="incorrect configuration", when="update plugin", then="fail")
|
||||
def test_07_update_plugin_fail0(self):
|
||||
@@ -132,11 +197,12 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_sc1']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.updata_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.updata_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_MODULE_NOT_EXISTS == response.json().get("error")
|
||||
|
||||
@description(given="incorrect configuration", when="update plugin", then="fail")
|
||||
@description(given="incorrect configuration", when="update plugin", then="fail")
|
||||
def test_08_update_plugin_fail1(self):
|
||||
test_data = TestPlugin.test_data
|
||||
plugin_data = {}
|
||||
@@ -144,9 +210,10 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_c1_2']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.updata_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 404 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_NOT_FOUND == response.json().get("error")
|
||||
response = api.updata_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_NAME_NOT_CONFORM == response.json().get("error")
|
||||
|
||||
@description(given="incorrect configuration", when="update plugin", then="fail")
|
||||
def test_09_update_plugin_fail2(self):
|
||||
@@ -156,7 +223,8 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_c1_2']
|
||||
plugin_data['schema_file'] = ''
|
||||
|
||||
response = api.updata_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.updata_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_BODY_IS_WRONG == response.json().get("error")
|
||||
|
||||
@@ -168,10 +236,24 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = ''
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.updata_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.updata_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_BODY_IS_WRONG == response.json().get("error")
|
||||
|
||||
@description(given="incorrect configuration", when="update plugin", then="fail")
|
||||
def test_10_update_plugin_fail4(self):
|
||||
test_data = TestPlugin.test_data
|
||||
plugin_data = {}
|
||||
plugin_data['library'] = test_data['library_c1']
|
||||
plugin_data['so_file'] = test_data['so_file_c1_2verr']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.updata_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH == response.json().get("error")
|
||||
|
||||
@description(given="correct configuration", when="update plugin", then="success")
|
||||
def test_11_update_plugin_success0(self):
|
||||
test_data = TestPlugin.test_data
|
||||
@@ -180,19 +262,20 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_s1_2']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.updata_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
response = api.updata_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
|
||||
@description(given="correct configuration", when="add south node", then="success")
|
||||
def test_12_add_node_success(self):
|
||||
def test_12_add_node_success(self):
|
||||
node_data = {}
|
||||
node_data['name'] = 'c1-a'
|
||||
node_data['plugin'] = 'c1'
|
||||
|
||||
response = api.add_node(node_data['name'], node_data['plugin'])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
|
||||
@description(given="correct configuration", when="config node", then="success")
|
||||
def test_13_configure_node_success(self):
|
||||
@@ -211,9 +294,10 @@ class TestPlugin:
|
||||
plugin_data['so_file'] = test_data['so_file_c1_2']
|
||||
plugin_data['schema_file'] = test_data['schema_file']
|
||||
|
||||
response = api.updata_plugin(library_name=plugin_data['library'],so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
response = api.updata_plugin(
|
||||
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
|
||||
assert 409 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_IN_USE == response.json().get("error")
|
||||
|
||||
@description(given="correct configuration", when="del plugin", then="fail")
|
||||
def test_15_del_plugin_fail0(self):
|
||||
@@ -222,7 +306,7 @@ class TestPlugin:
|
||||
plugin_data['plugin'] = 'c1'
|
||||
|
||||
response = api.del_plugin(plugin_name=plugin_data['plugin'])
|
||||
assert 400 == response.status_code
|
||||
assert 409 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_IN_USE == response.json().get("error")
|
||||
|
||||
@description(given="correct configuration", when="del plugin", then="fail")
|
||||
@@ -232,7 +316,7 @@ class TestPlugin:
|
||||
plugin_data['plugin'] = 's1'
|
||||
|
||||
response = api.del_plugin(plugin_name=plugin_data['plugin'])
|
||||
assert 400 == response.status_code
|
||||
assert 409 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_SYSTEM_NOT_ALLOW_DEL == response.json().get("error")
|
||||
|
||||
@description(given="correct configuration", when="del south node", then="success")
|
||||
@@ -242,14 +326,15 @@ class TestPlugin:
|
||||
|
||||
response = api.del_node(node_data['name'])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
|
||||
@description(given="correct configuration", when="add template", then="success")
|
||||
def test_18_add_template_success(self):
|
||||
test_data = TestPlugin.test_data
|
||||
template_data = test_data['template_config']
|
||||
|
||||
response = api.add_template(name=template_data['name'], plugin=template_data['plugin'], groups=template_data['groups'])
|
||||
response = api.add_template(
|
||||
name=template_data['name'], plugin=template_data['plugin'], groups=template_data['groups'])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
|
||||
@@ -260,7 +345,7 @@ class TestPlugin:
|
||||
plugin_data['plugin'] = 'c1'
|
||||
|
||||
response = api.del_plugin(plugin_name=plugin_data['plugin'])
|
||||
assert 400 == response.status_code
|
||||
assert 409 == response.status_code
|
||||
assert NEU_ERR_LIBRARY_IN_USE == response.json().get("error")
|
||||
|
||||
@description(given="correct configuration", when="del template", then="success")
|
||||
@@ -279,4 +364,4 @@ class TestPlugin:
|
||||
|
||||
response = api.del_plugin(plugin_name=plugin_data['plugin'])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
assert NEU_ERR_SUCCESS == response.json().get("error")
|
||||
|
||||
@@ -19,3 +19,19 @@ add_library(${PLUGIN_NAME_2} SHARED)
|
||||
target_include_directories(${PLUGIN_NAME_2} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
|
||||
target_sources(${PLUGIN_NAME_2} PRIVATE ${PLUGIN_SOURCES_2})
|
||||
target_link_libraries(${PLUGIN_NAME_2} neuron-base)
|
||||
|
||||
# v1_v_err
|
||||
set(PLUGIN_NAME plugin-c1verr)
|
||||
set(PLUGIN_SOURCES c1_v_err.c )
|
||||
add_library(${PLUGIN_NAME} SHARED)
|
||||
target_include_directories(${PLUGIN_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
|
||||
target_sources(${PLUGIN_NAME} PRIVATE ${PLUGIN_SOURCES})
|
||||
target_link_libraries(${PLUGIN_NAME} neuron-base)
|
||||
|
||||
# v2_v_err
|
||||
set(PLUGIN_NAME_2 plugin-c1_2verr)
|
||||
set(PLUGIN_SOURCES_2 c1_2_v_err.c )
|
||||
add_library(${PLUGIN_NAME_2} SHARED)
|
||||
target_include_directories(${PLUGIN_NAME_2} PRIVATE ${CMAKE_SOURCE_DIR}/include/neuron)
|
||||
target_sources(${PLUGIN_NAME_2} PRIVATE ${PLUGIN_SOURCES_2})
|
||||
target_link_libraries(${PLUGIN_NAME_2} neuron-base)
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <neuron.h>
|
||||
|
||||
#include "errcodes.h"
|
||||
|
||||
#include "c1.h"
|
||||
|
||||
static neu_plugin_t *driver_open(void);
|
||||
|
||||
static int driver_close(neu_plugin_t *plugin);
|
||||
static int driver_init(neu_plugin_t *plugin, bool load);
|
||||
static int driver_uninit(neu_plugin_t *plugin);
|
||||
static int driver_start(neu_plugin_t *plugin);
|
||||
static int driver_stop(neu_plugin_t *plugin);
|
||||
static int driver_config(neu_plugin_t *plugin, const char *config);
|
||||
static int driver_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
|
||||
void *data);
|
||||
|
||||
static int driver_tag_validator(const neu_datatag_t *tag);
|
||||
static int driver_validate_tag(neu_plugin_t *plugin, neu_datatag_t *tag);
|
||||
static int driver_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group);
|
||||
static int driver_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
|
||||
neu_value_u value);
|
||||
static int driver_write_tags(neu_plugin_t *plugin, void *req, UT_array *tags);
|
||||
|
||||
static const neu_plugin_intf_funs_t plugin_intf_funs = {
|
||||
.open = driver_open,
|
||||
.close = driver_close,
|
||||
.init = driver_init,
|
||||
.uninit = driver_uninit,
|
||||
.start = driver_start,
|
||||
.stop = driver_stop,
|
||||
.setting = driver_config,
|
||||
.request = driver_request,
|
||||
|
||||
.driver.validate_tag = driver_validate_tag,
|
||||
.driver.group_timer = driver_group_timer,
|
||||
.driver.write_tag = driver_write,
|
||||
.driver.tag_validator = driver_tag_validator,
|
||||
.driver.write_tags = driver_write_tags,
|
||||
.driver.add_tags = NULL,
|
||||
.driver.load_tags = NULL,
|
||||
.driver.del_tags = NULL,
|
||||
};
|
||||
|
||||
const neu_plugin_module_t neu_plugin_module = {
|
||||
.version = NEU_VERSION(2, 2, 3),
|
||||
.schema = "c1",
|
||||
.module_name = "c1",
|
||||
.module_descr = "c1 v2",
|
||||
.module_descr_zh = "c1 v2",
|
||||
.intf_funs = &plugin_intf_funs,
|
||||
.kind = NEU_PLUGIN_KIND_CUSTOM,
|
||||
.type = NEU_NA_TYPE_DRIVER,
|
||||
.display = true,
|
||||
.single = false,
|
||||
};
|
||||
|
||||
static neu_plugin_t *driver_open(void)
|
||||
{
|
||||
neu_plugin_t *plugin = calloc(1, sizeof(neu_plugin_t));
|
||||
|
||||
neu_plugin_common_init(&plugin->common);
|
||||
|
||||
return plugin;
|
||||
}
|
||||
|
||||
static int driver_close(neu_plugin_t *plugin)
|
||||
{
|
||||
free(plugin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_init(neu_plugin_t *plugin, bool load)
|
||||
{
|
||||
(void) load;
|
||||
(void) plugin;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_uninit(neu_plugin_t *plugin)
|
||||
{
|
||||
(void) plugin;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_start(neu_plugin_t *plugin)
|
||||
{
|
||||
(void) plugin;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_stop(neu_plugin_t *plugin)
|
||||
{
|
||||
(void) plugin;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_config(neu_plugin_t *plugin, const char *config)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) config;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
|
||||
void *data)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) head;
|
||||
(void) data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_tag_validator(const neu_datatag_t *tag)
|
||||
{
|
||||
(void) tag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_validate_tag(neu_plugin_t *plugin, neu_datatag_t *tag)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) tag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) group;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
|
||||
neu_value_u value)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) req;
|
||||
(void) tag;
|
||||
(void) value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_write_tags(neu_plugin_t *plugin, void *req, UT_array *tags)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) req;
|
||||
(void) tags;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2022 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <neuron.h>
|
||||
|
||||
#include "errcodes.h"
|
||||
|
||||
#include "c1.h"
|
||||
|
||||
static neu_plugin_t *driver_open(void);
|
||||
|
||||
static int driver_close(neu_plugin_t *plugin);
|
||||
static int driver_init(neu_plugin_t *plugin, bool load);
|
||||
static int driver_uninit(neu_plugin_t *plugin);
|
||||
static int driver_start(neu_plugin_t *plugin);
|
||||
static int driver_stop(neu_plugin_t *plugin);
|
||||
static int driver_config(neu_plugin_t *plugin, const char *config);
|
||||
static int driver_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
|
||||
void *data);
|
||||
|
||||
static int driver_tag_validator(const neu_datatag_t *tag);
|
||||
static int driver_validate_tag(neu_plugin_t *plugin, neu_datatag_t *tag);
|
||||
static int driver_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group);
|
||||
static int driver_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
|
||||
neu_value_u value);
|
||||
static int driver_write_tags(neu_plugin_t *plugin, void *req, UT_array *tags);
|
||||
|
||||
static const neu_plugin_intf_funs_t plugin_intf_funs = {
|
||||
.open = driver_open,
|
||||
.close = driver_close,
|
||||
.init = driver_init,
|
||||
.uninit = driver_uninit,
|
||||
.start = driver_start,
|
||||
.stop = driver_stop,
|
||||
.setting = driver_config,
|
||||
.request = driver_request,
|
||||
|
||||
.driver.validate_tag = driver_validate_tag,
|
||||
.driver.group_timer = driver_group_timer,
|
||||
.driver.write_tag = driver_write,
|
||||
.driver.tag_validator = driver_tag_validator,
|
||||
.driver.write_tags = driver_write_tags,
|
||||
.driver.add_tags = NULL,
|
||||
.driver.load_tags = NULL,
|
||||
.driver.del_tags = NULL,
|
||||
};
|
||||
|
||||
const neu_plugin_module_t neu_plugin_module = {
|
||||
.version = NEU_VERSION(1, 2, 3),
|
||||
.schema = "c1",
|
||||
.module_name = "c1",
|
||||
.module_descr = "c1 v1",
|
||||
.module_descr_zh = "c1 v1",
|
||||
.intf_funs = &plugin_intf_funs,
|
||||
.kind = NEU_PLUGIN_KIND_CUSTOM,
|
||||
.type = NEU_NA_TYPE_DRIVER,
|
||||
.display = true,
|
||||
.single = false,
|
||||
};
|
||||
|
||||
static neu_plugin_t *driver_open(void)
|
||||
{
|
||||
neu_plugin_t *plugin = calloc(1, sizeof(neu_plugin_t));
|
||||
|
||||
neu_plugin_common_init(&plugin->common);
|
||||
|
||||
return plugin;
|
||||
}
|
||||
|
||||
static int driver_close(neu_plugin_t *plugin)
|
||||
{
|
||||
free(plugin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_init(neu_plugin_t *plugin, bool load)
|
||||
{
|
||||
(void) load;
|
||||
(void) plugin;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_uninit(neu_plugin_t *plugin)
|
||||
{
|
||||
(void) plugin;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_start(neu_plugin_t *plugin)
|
||||
{
|
||||
(void) plugin;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_stop(neu_plugin_t *plugin)
|
||||
{
|
||||
(void) plugin;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_config(neu_plugin_t *plugin, const char *config)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) config;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
|
||||
void *data)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) head;
|
||||
(void) data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_tag_validator(const neu_datatag_t *tag)
|
||||
{
|
||||
(void) tag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_validate_tag(neu_plugin_t *plugin, neu_datatag_t *tag)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) tag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) group;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
|
||||
neu_value_u value)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) req;
|
||||
(void) tag;
|
||||
(void) value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_write_tags(neu_plugin_t *plugin, void *req, UT_array *tags)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) req;
|
||||
(void) tags;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user