【修改】基础功能验证
This commit is contained in:
@@ -34,10 +34,10 @@ struct arg_config
|
||||
|
||||
struct arg_config global_arg_config = {SESSION_COUNT, PACKET_COUNT, 10, 1, 1, 1, 1, 1, LUA_CONFIG_PATH};
|
||||
|
||||
static struct lua_config_specific *config_load(const char *config_file_name, int *specific_num);
|
||||
static struct lua_config_spec *config_load(const char *config_file_name, int *specific_num);
|
||||
static void parse_args(int argc, char *argv[]);
|
||||
// #ifdef DEBUG_PLUGIN_SCHEMA
|
||||
static void debug_plugin_manage_specifics(struct lua_config_specific *specifics, int num);
|
||||
static void debug_plugin_manage_specific(struct lua_config_spec *specific, int num);
|
||||
static void debug_plugin_manage_schema(struct plugin_manager_schema *schema);
|
||||
// #endif
|
||||
|
||||
@@ -66,42 +66,30 @@ int main(int argc, char *argv[])
|
||||
assert(plug_mgr);
|
||||
/* 初始化lua插件 */
|
||||
|
||||
printf("now wait time to compute memory ... ...\n");
|
||||
sleep(global_arg_config.wait_time);
|
||||
// printf("now wait time to compute memory ... ...\n");
|
||||
// sleep(global_arg_config.wait_time);
|
||||
|
||||
struct lua_plugin_manage_schema *lua_schema = NULL;
|
||||
struct lua_plugin_manage *lua_schema = NULL;
|
||||
if (global_arg_config.lua_mod)
|
||||
{
|
||||
int num = 0;
|
||||
struct lua_config_specific *specific = config_load(LUA_CONFIG_PATH, &num);
|
||||
struct lua_config_spec *specific = config_load(LUA_CONFIG_PATH, &num);
|
||||
assert(specific);
|
||||
if (global_arg_config.print_mod)
|
||||
debug_plugin_manage_specifics(specific, num);
|
||||
debug_plugin_manage_specific(specific, num);
|
||||
|
||||
lua_schema = lua_plugin_manage_init(&st, num, specific);
|
||||
lua_schema = lua_plugin_manage_init(&st, specific, num);
|
||||
st.lua_plug_mgr = lua_schema;
|
||||
assert(lua_schema);
|
||||
if (specific)
|
||||
free(specific);
|
||||
|
||||
/* 测试单个插件加载函数 */
|
||||
struct lua_config_specific add_specific = {NULL, NULL, NULL};
|
||||
add_specific.config_specific_file = "./plugin/example_plugin_load.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);
|
||||
|
||||
if (global_arg_config.print_mod)
|
||||
debug_lua_plugin_manage_schema(lua_schema);
|
||||
|
||||
printf("now wait time to compute memory ... ...\n");
|
||||
sleep(global_arg_config.wait_time);
|
||||
// printf("now wait time to compute memory ... ...\n");
|
||||
// sleep(global_arg_config.wait_time);
|
||||
}
|
||||
|
||||
// #ifdef DEBUG_PLUGIN_SCHEMA
|
||||
if (global_arg_config.print_mod)
|
||||
debug_plugin_manage_schema(plug_mgr);
|
||||
// #endif
|
||||
/* ***** ***** 初始化完成 ***** ***** */
|
||||
|
||||
/* ***** ***** 会话相关测试 ***** ***** */
|
||||
@@ -163,7 +151,7 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct lua_config_specific *config_load(const char *config_file_name, int *specific_count)
|
||||
static struct lua_config_spec *config_load(const char *config_file_name, int *specific_count)
|
||||
{
|
||||
if (__glibc_unlikely(!config_file_name))
|
||||
return NULL;
|
||||
@@ -189,10 +177,10 @@ static struct lua_config_specific *config_load(const char *config_file_name, int
|
||||
return NULL;
|
||||
|
||||
specific_num = toml_array_nelem(plugin_array);
|
||||
struct lua_config_specific *new_spec = (struct lua_config_specific *)calloc(specific_num, sizeof(struct lua_config_specific));
|
||||
struct lua_config_spec *new_spec = (struct lua_config_spec *)calloc(specific_num, sizeof(struct lua_config_spec));
|
||||
if (!new_spec)
|
||||
return NULL;
|
||||
struct lua_config_specific *specific = NULL;
|
||||
struct lua_config_spec *specific = NULL;
|
||||
|
||||
for (int i = 0; i < specific_num; ++i)
|
||||
{
|
||||
@@ -202,9 +190,9 @@ static struct lua_config_specific *config_load(const char *config_file_name, int
|
||||
const char *raw_unload_func_name = toml_raw_in(plugin, "exit");
|
||||
specific = &new_spec[i];
|
||||
|
||||
if (toml_rtos(raw_filepath, &specific->config_specific_file) ||
|
||||
toml_rtos(raw_load_func_name, &specific->config_specific_load_func) ||
|
||||
toml_rtos(raw_unload_func_name, &specific->config_specific_unload_func))
|
||||
if (toml_rtos(raw_filepath, &specific->spec_file_path) ||
|
||||
toml_rtos(raw_load_func_name, &specific->spec_load_func_name) ||
|
||||
toml_rtos(raw_unload_func_name, &specific->spec_unload_func_name))
|
||||
{
|
||||
toml_free(conf);
|
||||
free(specific);
|
||||
@@ -271,15 +259,15 @@ static void parse_args(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// #ifdef DEBUG_PLUGIN_SCHEMA
|
||||
static void debug_plugin_manage_specifics(struct lua_config_specific *specifics, int num)
|
||||
static void debug_plugin_manage_specific(struct lua_config_spec *specific, int num)
|
||||
{
|
||||
printf("***** ***** ***** ***** ***** *****\n");
|
||||
printf("load config specifics count is %d\n", num);
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
printf("[%d]file path: %s\n", i, specifics[i].config_specific_file);
|
||||
printf("[%d]load func: %s\n", i, specifics[i].config_specific_load_func);
|
||||
printf("[%d]unload func: %s\n", i, specifics[i].config_specific_unload_func);
|
||||
printf("[%d]file path: %s\n", i, specific[i].spec_file_path);
|
||||
printf("[%d]load func: %s\n", i, specific[i].spec_load_func_name);
|
||||
printf("[%d]unload func: %s\n", i, specific[i].spec_unload_func_name);
|
||||
}
|
||||
printf("***** ***** ***** ***** ***** *****\n\n");
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ end
|
||||
|
||||
function on_message(sess, topic_id, msg, sess_context, env)
|
||||
-- print("message call on message function, id", topic_id)
|
||||
-- print("message is", msg.data)
|
||||
print("message is", msg.data)
|
||||
end
|
||||
|
||||
function plugin_load(stellar, plug_env)
|
||||
@@ -16,12 +16,12 @@ function plugin_load(stellar, plug_env)
|
||||
print("this example aims to test topic functions")
|
||||
|
||||
plug_env.st = stellar
|
||||
plug_env.id = plugin_manage.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env)
|
||||
plug_env.id = session_plugin.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env)
|
||||
plug_env.data = "this is message example plug env data"
|
||||
|
||||
--[[ 订阅TOPIC_SESSION_STAT, 并完成函数注册 ]]
|
||||
test_topic_id = message.gettopicid(stellar, "TOPIC_SESSION_STAT")
|
||||
message.subscribetopic(stellar, test_topic_id, on_message, plug_env.id)
|
||||
test_topic_id = session_mq.get_topic_id(stellar, "TOPIC_SESSION_STAT")
|
||||
session_mq.subscribe_topic(stellar, test_topic_id, on_message, plug_env.id)
|
||||
end
|
||||
|
||||
function plugin_unload(plug_env)
|
||||
|
||||
@@ -14,7 +14,7 @@ function plugin_load(stellar, plug_env)
|
||||
print("this example aims to test regist function")
|
||||
plug_env.data = "my example regist plugin env"
|
||||
--[[ 由于未订阅消息, 注册函数应该永远不会触发 ]]
|
||||
plug_env.id = plugin_manage.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env)
|
||||
plug_env.id = session_plugin.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env)
|
||||
print("plugin env data is", plug_env.data)
|
||||
print("after regist, plugin id is", plug_env.id)
|
||||
end
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
function plugin_ctx_new(sess, plug_env, sess_context)
|
||||
-- print("now create new ctx example topic, plugin id", plug_env.id)
|
||||
print("now create new ctx example topic, plugin id", plug_env.id)
|
||||
sess_context.count = 0
|
||||
msg = {}
|
||||
msg.data = "this is message"
|
||||
message.publishmessage(sess, plug_env.topic_id, msg)
|
||||
session_mq.publish_message(sess, plug_env.topic_id, msg)
|
||||
end
|
||||
|
||||
function plugin_ctx_free(sess, sess_context, plug_env)
|
||||
-- print("now begin to free ctx context example topic")
|
||||
print("now begin to free ctx context example topic")
|
||||
print(sess_context.count)
|
||||
end
|
||||
|
||||
function on_message(sess, topic_id, msg, sess_context, env)
|
||||
-- print("topic call on message function, id", topic_id)
|
||||
sess_context.count = sess_context.count + 1
|
||||
print("topic call on message function, id", topic_id)
|
||||
end
|
||||
|
||||
function free_message(sess, msg, private_env)
|
||||
-- print("message need to free is", msg.data)
|
||||
-- print("env id is ", private_env.id)
|
||||
print("message need to free is", msg.data)
|
||||
print("env id is ", private_env.id)
|
||||
end
|
||||
|
||||
function plugin_load(stellar, plug_env)
|
||||
@@ -23,26 +26,27 @@ function plugin_load(stellar, plug_env)
|
||||
print("this example aims to test topic functions")
|
||||
|
||||
plug_env.st = stellar
|
||||
plug_env.id = plugin_manage.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env)
|
||||
plug_env.id = session_plugin.register(stellar, plugin_ctx_new, plugin_ctx_free, plug_env)
|
||||
plug_env.data = "this is topic example plug env data"
|
||||
|
||||
--[[ 获取TCP topic, 并完成订阅 ]]
|
||||
tcp_topic_id = message.gettopicid(stellar, "TCP")
|
||||
tcp_topic_id = session_mq.get_topic_id(stellar, "TCP")
|
||||
print("get TCP topic id is", tcp_topic_id)
|
||||
message.subscribetopic(stellar, tcp_topic_id, on_message, plug_env.id)
|
||||
session_mq.subscribe_topic(stellar, tcp_topic_id, on_message, plug_env.id)
|
||||
plug_env.tcp_topic_id = tcp_topic_id
|
||||
|
||||
--[[ 创建TOPIC_SESSION_STAT, 并完成函数注册 ]]
|
||||
msg_private_table = {}
|
||||
msg_private_table.data = "this is example topic msg private data"
|
||||
test_topic_id = message.gettopicid(stellar, "TOPIC_SESSION_STAT")
|
||||
test_topic_id = session_mq.get_topic_id(stellar, "TOPIC_SESSION_STAT")
|
||||
if (test_topic_id < 0)
|
||||
then
|
||||
--[[ 该消息未创建, 创建该topic ]]
|
||||
test_topic_id = message.createtopic(stellar, "TOPIC_SESSION_STAT", free_message, msg_private_table)
|
||||
test_topic_id = session_mq.create_topic(stellar, "TOPIC_SESSION_STAT", free_message, msg_private_table)
|
||||
print("create topic is", test_topic_id)
|
||||
else
|
||||
--[[ 如果该消息已经注册, 更新其注册函数 ]]
|
||||
message.updatetopic(stellar, test_topic_id, free_message, msg_private_table)
|
||||
session_mq.update_topic(stellar, test_topic_id, free_message, msg_private_table)
|
||||
print("topic already created, id is", test_topic_id)
|
||||
end
|
||||
plug_env.tcp_topic_id = tcp_topic_id
|
||||
@@ -53,5 +57,5 @@ function plugin_unload(plug_env)
|
||||
print("now unload lua plugin example topic")
|
||||
print("plugin env data is", plug_env.data)
|
||||
print("now destory topic id is", plug_env.topic_id)
|
||||
message.destorytopic(plug_env.st, plug_env.topic_id)
|
||||
session_mq.destory_topic(plug_env.st, plug_env.topic_id)
|
||||
end
|
||||
@@ -303,7 +303,7 @@ void simple_session_packet_plugin_exit(void *plugin_env)
|
||||
|
||||
static void simple_plugin_sub_session_stat_on_msg(struct session *sess, int topic_id, const void *data, void *plugin_ctx , void *plugin_env)
|
||||
{
|
||||
// printf("get message, %d\n", topic_id);
|
||||
printf("get message, %d\n", topic_id);
|
||||
struct simple_stellar_plugin_env *env = (struct simple_stellar_plugin_env *)plugin_env;
|
||||
if(topic_id == env->egress_topic_id)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user