diff options
Diffstat (limited to 'src/lua_plugin_manage.c')
| -rw-r--r-- | src/lua_plugin_manage.c | 78 |
1 files changed, 76 insertions, 2 deletions
diff --git a/src/lua_plugin_manage.c b/src/lua_plugin_manage.c index d983a20..657ad33 100644 --- a/src/lua_plugin_manage.c +++ b/src/lua_plugin_manage.c @@ -29,6 +29,12 @@ * 08-06 * 1. 实现函数 * int script_execute; + * + * 08-13 + * 1. 修改部分创建列表使用的结构 + * 2. 实现函数 + * struct lua_plugin * search_plugin_by_id + * struct lua_message_mq * search_message_mq_by_id ************************************************************************/ #include "lua_plugin_manage_internal.h" @@ -39,6 +45,68 @@ struct lua_plugin_manage_schema * global_schema = NULL; +#if 0 +void lua_message_mq_destory(void * elt) +{ + if (!elt) return; + struct lua_message_mq * mq = (struct lua_message_mq *)elt; + if ( mq->topic_name ) + free(mq->topic_name); + return; +} +#endif +static UT_icd lua_message_mq_icd = {sizeof(struct lua_message_mq), NULL, NULL, NULL}; + +void lua_plugin_destory(void *elt) +{ + if ( !elt ) return; + struct lua_plugin * plugin = (struct lua_plugin *)elt; + if ( plugin->sub_topic_array ) + utarray_free(plugin->sub_topic_array); + return; +} +static UT_icd lua_plugin_icd = {sizeof(struct lua_plugin), NULL, NULL, lua_plugin_destory}; + +/* + * Function: search_plugin_by_id + * Input: | int | plugin_id | 需要查找plugin数据的id + * Output: + * Return: 查找得到的plugin结构 + * Description: 在global schema中根据plugin_id查找一个plugin + */ +struct lua_plugin * search_plugin_by_id(int plugin_id) +{ + for ( int i = 0; i < global_schema->model_count; ++i) { + struct lua_model * model = &global_schema->model[i]; + + struct lua_plugin * plugin = NULL; + while ( (plugin = utarray_next(model->plugin_array, plugin)) ) { + if ( plugin->plugin_id == plugin_id ) + return plugin; + else if (plugin->plugin_id > plugin_id) + return NULL; + } + } + return NULL; +} + +/* + * Function: search_message_mq_by_id + * Input: | int | topic_id | 需要查找的topic_id + * Output: + * Return: 查找得到的message_mq结构 + * Description: 在global schema中根据topic_id查找一个message_mq + */ +struct lua_message_mq * search_message_mq_by_id(int topic_id) +{ + struct lua_message_mq * mq = NULL; + while ((mq = utarray_next(global_schema->message_mq_array, mq))) { + if ( mq->topic_id == topic_id ) + return mq; + } + return NULL; +} + /* * Function: thread_state_init * Input: | int | thread_id | 创建状态机的线程号 @@ -166,8 +234,6 @@ int thread_state_load_specific( return SUCCESS; } -static UT_icd lua_plugin_icd = {sizeof(struct lua_plugin), NULL, NULL, NULL}; - /* * Function: thread_state_call_load * Input: | lua_State * | state | 进行模块加载的状态机 @@ -313,6 +379,11 @@ struct lua_plugin_manage_schema *lua_plugin_manage_init( } } } + + /* 可能运行过程中创建新的topic, 此处进行初始化 */ + new_schema->mq_count = 0; + utarray_new(new_schema->message_mq_array, &lua_message_mq_icd); + debug_lua_plugin_manage_schema(new_schema); global_schema = new_schema; @@ -355,6 +426,9 @@ void lua_plugin_manage_exit(struct lua_plugin_manage_schema *lua_plug_mgr) } free(lua_plug_mgr->model); + if ( lua_plug_mgr->message_mq_array ) + utarray_free(lua_plug_mgr->message_mq_array); + free(lua_plug_mgr); return; } |
