Add dummy plugin

This commit is contained in:
eeff
2022-01-13 18:04:20 +08:00
committed by Parker Liu
parent a2cca4a90d
commit 75a3ab32f2
7 changed files with 214 additions and 1 deletions
+1
View File
@@ -108,6 +108,7 @@ set(NEURON_SOURCES
plugins/restful/plugin_handle.c
plugins/restful/rest.c
plugins/restful/http.c
plugins/dummy/dummy.c
${PERSIST_SOURCES})
set(NEURON_INCLUDE_DIRECTORIES include src plugins)
+160
View File
@@ -0,0 +1,160 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2021 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
#include "config.h"
#include "dummy.h"
#include "neu_log.h"
#include "neu_plugin.h"
#define neu_plugin_module default_dummy_plugin_module
struct neu_plugin {
neu_plugin_common_t common;
};
static neu_plugin_t *dummy_plugin_open(neu_adapter_t * adapter,
const adapter_callbacks_t *callbacks)
{
neu_plugin_t *plugin;
if (adapter == NULL || callbacks == NULL) {
log_error("Open plugin with NULL adapter or callbacks");
return NULL;
}
plugin = (neu_plugin_t *) malloc(sizeof(neu_plugin_t));
if (plugin == NULL) {
log_error("Failed to allocate plugin %s",
neu_plugin_module.module_name);
return NULL;
}
neu_plugin_common_init(&plugin->common);
plugin->common.adapter = adapter;
plugin->common.adapter_callbacks = callbacks;
log_info("Success to create plugin: %s", neu_plugin_module.module_name);
return plugin;
}
static int dummy_plugin_close(neu_plugin_t *plugin)
{
free(plugin);
log_info("Success to free plugin: %s", neu_plugin_module.module_name);
return 0;
}
static int dummy_plugin_init(neu_plugin_t *plugin)
{
int rv = 0;
(void) plugin;
log_info("Initialize plugin: %s", neu_plugin_module.module_name);
return rv;
}
static int dummy_plugin_uninit(neu_plugin_t *plugin)
{
int rv = 0;
(void) plugin;
log_info("Uninitialize plugin: %s", neu_plugin_module.module_name);
return rv;
}
static int dummy_plugin_config(neu_plugin_t *plugin, neu_config_t *configs)
{
int rv = 0;
(void) plugin;
(void) configs;
log_info("config plugin: %s", neu_plugin_module.module_name);
return rv;
}
static int dummy_plugin_request(neu_plugin_t *plugin, neu_request_t *req)
{
int rv = 0;
if (plugin == NULL || req == NULL) {
log_warn("The plugin pointer or request is NULL");
return (-1);
}
log_info("send request to plugin: %s", neu_plugin_module.module_name);
log_info("%s received request %d\n", neu_plugin_module.module_name,
req->req_type);
return rv;
}
static int dummy_plugin_event_reply(neu_plugin_t * plugin,
neu_event_reply_t *reply)
{
int rv = 0;
(void) plugin;
(void) reply;
log_info("reply event to plugin: %s", neu_plugin_module.module_name);
return rv;
}
static int dummy_plugin_start(neu_plugin_t *plugin)
{
(void) plugin;
return 0;
}
static int dummy_plugin_stop(neu_plugin_t *plugin)
{
(void) plugin;
return 0;
}
static const neu_plugin_intf_funs_t plugin_intf_funs = {
.open = dummy_plugin_open,
.close = dummy_plugin_close,
.init = dummy_plugin_init,
.uninit = dummy_plugin_uninit,
.start = dummy_plugin_start,
.stop = dummy_plugin_stop,
.config = dummy_plugin_config,
.request = dummy_plugin_request,
.event_reply = dummy_plugin_event_reply
};
#define DEFAULT_DUMMY_PLUGIN_DESCR "A plugin that does nothing"
const neu_plugin_module_t default_dummy_plugin_module = {
.version = NEURON_PLUGIN_VER_1_0,
.module_name = "neuron-default-dummy",
.module_descr = DEFAULT_DUMMY_PLUGIN_DESCR,
.intf_funs = &plugin_intf_funs
};
+27
View File
@@ -0,0 +1,27 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2021 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.
**/
#ifndef _NEU_PLUGIN_DUMMY_H_
#define _NEU_PLUGIN_DUMMY_H_
#include "neu_plugin.h"
extern const neu_plugin_module_t default_dummy_plugin_module;
#endif
+6
View File
@@ -232,6 +232,12 @@ static const plugin_reg_param_t default_plugin_infos[] = {
.plugin_name = DEFAULT_DASHBOARD_PLUGIN_NAME,
.plugin_lib_name = DEFAULT_DASHBOARD_PLUGIN_LIB_NAME
},
{
.plugin_kind = PLUGIN_KIND_STATIC,
.adapter_type = ADAPTER_TYPE_APP,
.plugin_name = DEFAULT_DUMMY_PLUGIN_NAME,
.plugin_lib_name = DEFAULT_DUMMY_PLUGIN_LIB_NAME
},
/*
{
.plugin_kind = PLUGIN_KIND_SYSTEM,
+13
View File
@@ -29,6 +29,7 @@
#include <nng/supplemental/util/platform.h>
#include "adapter/adapter_internal.h"
#include "dummy/dummy.h"
#include "neu_panic.h"
#include "neu_vector.h"
#include "plugin_manager.h"
@@ -62,6 +63,13 @@ static const plugin_reg_entity_t builtin_static_plugins[] = {
.plugin_name = DEFAULT_DASHBOARD_PLUGIN_NAME,
.plugin_lib_name = DEFAULT_DASHBOARD_PLUGIN_LIB_NAME,
},
{
.plugin_id = { 2 },
.plugin_kind = PLUGIN_KIND_STATIC,
.adapter_type = ADAPTER_TYPE_APP,
.plugin_name = DEFAULT_DUMMY_PLUGIN_NAME,
.plugin_lib_name = DEFAULT_DUMMY_PLUGIN_LIB_NAME,
},
};
#define BUILTIN_STATIC_PLUGIN_COUNT \
(sizeof(builtin_static_plugins) / sizeof(builtin_static_plugins[0]))
@@ -620,6 +628,11 @@ static const plugin_module_map_t plugin_module_maps[] = {
{
DEFAULT_DASHBOARD_PLUGIN_LIB_NAME,
&default_dashboard_plugin_module,
},
{
DEFAULT_DUMMY_PLUGIN_LIB_NAME,
&default_dummy_plugin_module,
},
};
#define PLUGIN_MODULE_MAPS_COUNT \
+2
View File
@@ -32,6 +32,8 @@ extern "C" {
#define DEFAULT_DASHBOARD_PLUGIN_NAME "default-dashboard-plugin"
#define DEFAULT_DASHBOARD_PLUGIN_LIB_NAME "libplugin_default_dashboard"
#define DEFAULT_DUMMY_PLUGIN_NAME "default-dummy-plugin"
#define DEFAULT_DUMMY_PLUGIN_LIB_NAME "libplugin_default_dummy"
typedef struct plugin_reg_param {
plugin_kind_e plugin_kind;
+5 -1
View File
@@ -84,7 +84,11 @@ target_include_directories(data_val_test PRIVATE
target_link_libraries(data_val_test neuron-base gtest_main gtest pthread jansson)
aux_source_directory(${CMAKE_SOURCE_DIR}/plugins/restful SRC_RESTFUL)
add_executable(plugin_manager_test plugin_manager_test.cc ${CMAKE_SOURCE_DIR}/src/core/plugin_manager.c ${SRC_RESTFUL} ${SRC_PARSER} ${CMAKE_SOURCE_DIR}/src/config.c)
aux_source_directory(${CMAKE_SOURCE_DIR}/plugins/dummy SRC_DUMMY)
add_executable(plugin_manager_test plugin_manager_test.cc
${CMAKE_SOURCE_DIR}/src/core/plugin_manager.c
${SRC_RESTFUL} ${SRC_DUMMY} ${SRC_PARSER}
${CMAKE_SOURCE_DIR}/src/config.c)
target_include_directories(plugin_manager_test PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/include