freeswitch.Session的实现过程

本文详细介绍了Freeswitch中Session对象的创建过程,包括lua中通过freeswitch.Session()创建Session对象的四种方式,以及在C++层面的实现细节。接着讨论了呼叫字符串的解析步骤,主要由switch_event_create_brackets()完成,解析后的键值对存储在switch_event_t对象中。最后,探讨了回调函数的使用,当channel被应答时,如何触发预设的回调app并执行相应的操作。
摘要由CSDN通过智能技术生成

一.创建Session

在lua中通过调用 freeswitch.Session()可以创建一个Session对象。按源码里的注释,他包括四个原型:
LUA::Session::Session()
LUA::Session::Session(char ,CoreSession )
LUA::Session::Session(char *)
LUA::Session::Session(switch_core_session_t *)
所以他有四个初始化的方式。

mod_lua_wrap.cpp这个文件主要是将C++的函数接口封装成lua接口,在这里面:

static swig_lua_class _wrap_class_LUA_Session = { "Session", &SWIGTYPE_p_LUA__Session,_wrap_new_Session, swig_delete_Session, swig_LUA_Session_methods, swig_LUA_Session_attributes, { "Session", swig_LUA_Session_cls_methods, swig_LUA_Session_cls_attributes, swig_LUA_Session_cls_constants }, swig_LUA_Session_bases, swig_LUA_Session_base_names };

创建了一个swig_lua_class

typedef struct swig_lua_class {
  const char    *name;
  swig_type_info   **type;
  lua_CFunction  constructor;
  void    (*destructor)(void *);
  swig_lua_method   *methods;
  swig_lua_attribute     *attributes;
  struct swig_lua_class **bases;
  const char **base_names;
} swig_lua_class;

这个是表示一个注册lua对象的结构体。其实就是通过注册一个个swig_lua_class,使得lua脚本可以想调用对象一样调用C++里面的对象的方法。

name 是在lua中的名字
constructor 可以理解为构造函数
destructor 自然是析构函数
methods 这个对象的方法
attributes这个对象的属性

所以构造函数是:_wrap_new_Session()也是在执行freeswitch.Session的时候会调用_wrap_new_Session()这个函数。

static int _wrap_new_Session(lua_State* L) {
  int argc;
  int argv[3]={
    1,2,3
  };

  argc = lua_gettop(L);
  if (argc == 0) {
    return _wrap_new_Session__SWIG_0(L);
  }
  if (argc == 1) {
    int _v;
    {
      void *ptr;
      if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_switch_core_session_t, 0)) {
        _v = 0;
      } else {
        _v = 1;
      }
    }
    if (_v) {
      return _wrap_new_Session__SWIG_3(L);
    }
  }
  if (argc == 1) {
    int _v;
    {
      _v = SWIG_lua_isnilstring(L,argv[0]);
    }
    if (_v) {
      return _wrap_new_Session__SWIG_2(L);
    }
  }
  if (argc == 2) {
    int _v;
    {
      _v = SWIG_lua_isnilstring(L,argv[0]);
    }
    if (_v) {
      {
        void *ptr;
        if (SWIG_isptrtype(L,argv[1])==0 || SWIG_ConvertPtr(L,argv[1], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) {
          _v = 0;
        } else {
          _v = 1;
        }
      }
      if (_v) {
        return _wrap_new_Session__SWIG_1(L);
      }
    }
  }

  SWIG_Lua_pusherrstring(L,"Wrong arguments for overloaded function 'new_Session'\n"
    "  Possible C/C++ prototypes are:\n"
    "    LUA::Session::Session()\n"
    "    LUA::Session::Session(char *,CoreSession *)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值