Make neu_manager to add license adapter if license plugin found

This commit is contained in:
eeff
2022-02-28 16:09:14 +08:00
committed by Parker Liu
parent 630b40e98a
commit b00ab299b0
+29
View File
@@ -95,6 +95,7 @@ static const char *const manager_url = "inproc://neu_manager";
#define WEBSERVER_PLUGIN_LIB_NAME "libplugin-webserver-proxy.dylib"
#define MQTT_PLUGIN_LIB_NAME "libplugin-mqtt.dylib"
#define MODBUS_TCP_PLUGIN_LIB_NAME "libplugin-modbus-tcp.dylib"
#define LICENSE_PLUGIN_LIB_NAME "libplugin-license.dylib"
#else
@@ -105,6 +106,7 @@ static const char *const manager_url = "inproc://neu_manager";
#define WEBSERVER_PLUGIN_LIB_NAME "libplugin-webserver-proxy.so"
#define MQTT_PLUGIN_LIB_NAME "libplugin-mqtt.so"
#define MODBUS_TCP_PLUGIN_LIB_NAME "libplugin-modbus-tcp.so"
#define LICENSE_PLUGIN_LIB_NAME "libplugin-license.so"
#endif
@@ -116,6 +118,7 @@ static const char *const manager_url = "inproc://neu_manager";
#define WEBSERVER_PLUGIN_NAME "webserver-plugin-proxy"
#define MQTT_PLUGIN_NAME "mqtt-plugin"
#define MODBUS_TCP_PLUGIN_NAME "modbus-tcp-plugin"
#define LICENSE_PLUGIN_NAME "license-plugin"
// definition for adapter names
#ifdef NEU_HAS_SAMPLE_ADAPTER
@@ -124,6 +127,7 @@ static const char *const manager_url = "inproc://neu_manager";
#endif
#define DEFAULT_DASHBOARD_ADAPTER_NAME "default-dashboard-adapter"
#define DEFAULT_PERSIST_ADAPTER_NAME "default-persist-adapter"
#define DEFAULT_LICENSE_ADAPTER_NAME "default-license-adapter"
#define WEBSERVER_ADAPTER_NAME "webserver-adapter"
#define MQTT_ADAPTER_NAME "mqtt-adapter"
#define MODBUS_TCP_ADAPTER_NAME "modbus-tcp-adapter"
@@ -1136,6 +1140,29 @@ static void manager_loop(void *arg)
}
nng_mtx_unlock(manager->mtx);
// begin add license adapter
// TODO: move to persistence data instead
plugin_id_t plugin_id = {};
neu_cmd_add_plugin_lib_t add_plugin_cmd = {
.plugin_lib_name = LICENSE_PLUGIN_LIB_NAME,
};
rv = neu_manager_add_plugin_lib(manager, &add_plugin_cmd, &plugin_id);
if (0 == rv) {
neu_cmd_add_node_t add_node_cmd = {
.node_type = NEU_NODE_TYPE_LICENSE,
.adapter_name = DEFAULT_LICENSE_ADAPTER_NAME,
.plugin_name = LICENSE_PLUGIN_NAME,
};
neu_node_id_t node_id = 0;
rv = neu_manager_add_node(manager, &add_node_cmd, &node_id);
if (rv != 0) {
neu_panic("Neuron manager can't add license adapter");
}
}
// end add license adapter
log_info("Register and start all default adapters");
register_default_plugins(manager);
reg_and_start_default_adapters(manager);
@@ -1144,6 +1171,8 @@ static void manager_loop(void *arg)
nng_mtx_lock(manager->adapters_mtx);
adapter_reg_entity_t *persist_reg_entity = find_reg_adapter_by_name(
&manager->reg_adapters, DEFAULT_PERSIST_ADAPTER_NAME);
adapter_reg_entity_t *license_reg_entity = find_reg_adapter_by_name(
&manager->reg_adapters, DEFAULT_LICENSE_ADAPTER_NAME);
nng_mtx_unlock(manager->adapters_mtx);
nng_pipe persist_pipe = persist_reg_entity->adapter_pipe;