【新增】增加新增单个配置的接口

This commit is contained in:
niubinghui
2024-08-19 18:38:22 +08:00
parent 99fbd77198
commit cfe51e7c9a
4 changed files with 60 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ path = "./plugin/example_plugin-1.lua"
init = "plugin_load"
exit = "plugin_unload"
[[plugin]]
path = "./plugin/example_plugin-2.lua"
init = "plugin_load"
exit = "plugin_unload"
# [[plugin]]
# path = "./plugin/example_plugin-2.lua"
# init = "plugin_load"
# exit = "plugin_unload"

View File

@@ -32,6 +32,13 @@ int main()
/* 初始化lua插件 */
struct lua_plugin_manage_schema *lua_schema = lua_plugin_manage_init(&st, num, specific);
st.lua_plug_mgr = lua_schema;
struct lua_config_specific add_specific = {NULL, NULL, NULL};
add_specific.config_specific_file = "./plugin/example_plugin-2.lua";
add_specific.config_specific_load_func = "plugin_load";
add_specific.config_specific_unload_func = "plugin_unload";
lua_plugin_manage_load_one_specific(st.lua_plug_mgr, &add_specific);
#ifdef DEBUG_PLUGIN_SCHEMA
debug_plugin_manage_schema(plug_mgr);
#endif

View File

@@ -35,4 +35,5 @@ struct lua_config_specific
struct lua_plugin_manage_schema;
struct lua_plugin_manage_schema *lua_plugin_manage_init(struct stellar *st, int specific_count, struct lua_config_specific *specifics);
int lua_plugin_manage_load_one_specific(struct lua_plugin_manage_schema *schema, struct lua_config_specific *specific);
void lua_plugin_manage_exit(struct lua_plugin_manage_schema *lua_plug_mgr);

View File

@@ -338,6 +338,9 @@ struct lua_plugin_manage_schema *lua_plugin_manage_init(
memset(new_schema->thread_state, 0, thread_count * sizeof(lua_State *));
/* 为将要加载的模块预分配内存 */
new_schema->model_count = specific_count;
/* 如果没有配置, 也应该算是创建成功 */
if ( specific_count == 0 )
return new_schema;
new_schema->model = (struct lua_model *)calloc(specific_count, sizeof(struct lua_model));
if (__glibc_unlikely(!new_schema->model))
{
@@ -389,6 +392,51 @@ struct lua_plugin_manage_schema *lua_plugin_manage_init(
return new_schema;
}
/*
* Function:
* Input:
* Output:
* Return:
* Description:
*/
int lua_plugin_manage_load_one_specific(
struct lua_plugin_manage_schema *schema,
struct lua_config_specific *specific)
{
if (__glibc_unlikely(!schema || !specific))
return -1;
if ( schema->model ) {
schema->model = (struct lua_model *)realloc(schema->model, (schema->model_count + 1) * sizeof(struct lua_model));
schema->model_count += 1;
}
for (int thread_index = 0; thread_index < schema->state_count; ++thread_index)
{
/* 在状态机中加载specific中的配置 */
int load_ret = thread_state_load_specific(schema->thread_state[thread_index],
&schema->model[schema->model_count - 1],
specific);
if (load_ret)
{
LOGERROR("state load specific failed, ret is %d", load_ret);
return -1;
}
/* 调用该模块中的load函数 */
int call_load_ret = thread_state_call_load(schema->thread_state[thread_index],
&schema->model[schema->model_count - 1],
specific,
schema->st);
if (call_load_ret)
{
LOGERROR("call state load function failed, ret is %d", call_load_ret);
return -1;
}
}
return 0;
}
/*
* Function:
* Input: