【新增】增加一些和session相关的注册函数
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
* int lua_cbinding_data_remove;
|
||||
* int lua_cbinding_functions;
|
||||
* int lua_cbinding_datas;
|
||||
* int lua_plugin_manage_session_regist;
|
||||
* int lua_plugin_manage_regist;
|
||||
* ** 注册函数lua_plugin_manage_session_regist还需要补充
|
||||
************************************************************************/
|
||||
#include "lua_plugin_manage_internal.h"
|
||||
@@ -25,11 +25,19 @@
|
||||
#include <string.h>
|
||||
|
||||
/* 需要注册至lua中供lua调用的所有函数原型 */
|
||||
int lua_plugin_manage_session_regist(lua_State * state);
|
||||
int lua_plugin_manage_regist(lua_State * state);
|
||||
int lua_session_get_id(lua_State * state);
|
||||
int lua_session_set_id(lua_State * state);
|
||||
int lua_session_get_type(lua_State * state);
|
||||
int lua_session_set_type(lua_State * state);
|
||||
|
||||
/* 需要注册至状态机中的函数定义在链表中, 会依次完成注册 */
|
||||
struct lua_binding_function lua_bind_functions[] = {
|
||||
{lua_plugin_manage_session_regist, "register", "plugin_manage"},
|
||||
{lua_plugin_manage_regist, "register", "plugin_manage"},
|
||||
{lua_session_get_id, "getid", "session"},
|
||||
{lua_session_set_id, "setid", "session"},
|
||||
{lua_session_get_type, "gettype", "session"},
|
||||
{lua_session_set_type, "settype", "session"},
|
||||
{NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -465,14 +473,8 @@ int lua_cbinding_datas(lua_State *state)
|
||||
return failed_count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function:
|
||||
* Input:
|
||||
* Output:
|
||||
* Return:
|
||||
* Description:
|
||||
*/
|
||||
int lua_plugin_manage_session_regist(lua_State *state)
|
||||
/* ***** ***** ***** ***** ***** ***** */
|
||||
int lua_plugin_manage_regist(lua_State *state)
|
||||
{
|
||||
/* 参数个数检查 */
|
||||
if (lua_gettop(state) != 4)
|
||||
@@ -525,7 +527,7 @@ int lua_plugin_manage_session_regist(lua_State *state)
|
||||
/* 在stellar中注册, 获取注册id */
|
||||
int plugin_id = stellar_session_plugin_register(st, lpm_ctx_new_func, lpm_ctx_free_func, (void *)plugin_env);
|
||||
#ifdef LUAPLUGIN_BASIC_UNITTEST
|
||||
printf("now regist new plugin, plugin id is %d\n", plugin_id);
|
||||
LOGDEBUG("now regist new plugin, plugin id is %d\n", plugin_id);
|
||||
#endif
|
||||
|
||||
/* 将注册完成的新插件插入到队列中 */
|
||||
@@ -540,3 +542,107 @@ int lua_plugin_manage_session_regist(lua_State *state)
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_session_get_id(lua_State * state)
|
||||
{
|
||||
/* 参数个数检查 */
|
||||
if (lua_gettop(state) != 1)
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 参数类型检查 */
|
||||
if (lua_type(state, -1) != LUA_TLIGHTUSERDATA )
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct session * sess = (struct session *)lua_topointer(state, -1);
|
||||
if ( !sess ) {
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
lua_pop(state, 1);
|
||||
|
||||
lua_pushinteger(state, session_get_id(sess));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_session_set_id(lua_State * state)
|
||||
{
|
||||
/* 参数个数检查 */
|
||||
if (lua_gettop(state) != 2)
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 参数类型检查 */
|
||||
if (lua_type(state, -1) != LUA_TNUMBER || lua_type(state, -2) != LUA_TLIGHTUSERDATA )
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setid = lua_tointeger(state, -1);
|
||||
lua_pop(state, 1);
|
||||
struct session * sess = (struct session *)lua_topointer(state, -1);
|
||||
lua_pop(state, 1);
|
||||
|
||||
session_set_id(sess, setid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_session_get_type(lua_State * state)
|
||||
{
|
||||
/* 参数个数检查 */
|
||||
if (lua_gettop(state) != 1)
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 参数类型检查 */
|
||||
if (lua_type(state, -1) != LUA_TLIGHTUSERDATA )
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct session * sess = (struct session *)lua_topointer(state, -1);
|
||||
if ( !sess ) {
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
lua_pop(state, 1);
|
||||
|
||||
lua_pushinteger(state, session_get_type(sess));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_session_set_type(lua_State * state)
|
||||
{
|
||||
/* 参数个数检查 */
|
||||
if (lua_gettop(state) != 2)
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 参数类型检查 */
|
||||
if (lua_type(state, -1) != LUA_TNUMBER || lua_type(state, -2) != LUA_TLIGHTUSERDATA )
|
||||
{
|
||||
lua_settop(state, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int settype = lua_tointeger(state, -1);
|
||||
lua_pop(state, 1);
|
||||
struct session * sess = (struct session *)lua_topointer(state, -1);
|
||||
lua_pop(state, 1);
|
||||
|
||||
session_set_id(sess, settype);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user