以mod_helloworld(application)类型为例
1> 包含头文件
#include “switch.h”
2> 函数原型
/* Prototypes */
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_helloworld_shutdown);
SWITCH_MODULE_RUNTIME_FUNCTION(mod_helloworld_runtime);
SWITCH_MODULE_LOAD_FUNCTION(mod_helloworld_load);
/* SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime)
* Defines a switch_loadable_module_function_table_t and a static const char[] modname
*/
SWITCH_MODULE_DEFINITION(mod_helloworld, mod_helloworld_load, mod_helloworld_shutdown, NULL);
load: 模块加载函数,主要实现模块资源初始化,并实现APP调用主函数的注册
shutdown: 模块卸载函数,主要执行模块资源释放
runtime: application类型中基本未使用
3> 模块函数
a> load模块加载
/* Macro expands to: switch_status_t mod_helloworld_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */
SWITCH_MODULE_LOAD_FUNCTION(mod_helloworld_load)
{
switch_application_interface_t *app_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_APP(app_interface, "helloworld", "helloworld", "helloworld", helloworld_app, "", SAF_NONE);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "mod_helloworld load successfully!\n");
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
b> shutdown模块卸载函数
/*
Called when the system shuts down
Macro expands to: switch_status_t mod_helloworld_shutdown() */
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_helloworld_shutdown)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "mod_helloworld shutdown successfully!\n");
return SWITCH_STATUS_SUCCESS;
}
c> APP调用主函数
SWITCH_STANDARD_APP(helloworld_app)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "mod_helloworld app!\n");
}
假设此处只有单文件: mod_helloworld
BASE=../../../..
include $(BASE)/build/modmake.rules
如果仅仅是和模块名相同的单源文件,Makefile写成这样就可以了
如果是多文件项目,则需要如下添加(需要忽略模块名相同的源文件):
LOCAL_OBJS=mod_helloworld.o ivr.o utils.o config.o menu.o
FreeSWITCH模块Makefile模板支持C和C++源文件,但是不支持混编
a> 1.2版本下,在模块源文件目录下执行gmake install
b> 1.6版本下,在FreeSWITCH根目录下执行gmake mod_helloworld-install
a> 查看模块是否运行: module_exists mod_helloworld
b> 动态加载: load mod_helloworld
c> 动态卸载: unload mod_helloworld
d> 重新加载: reload mod_helloworld
vi $FreeSWITCH_INSTALL/conf/autoload_configs/modules.conf.xml
在application处添加
a> 添加拨号规则,拨号固定号码时,调用相关的APP调用主函数
vi $FreeSWITCH_INSTALL/conf/dialplan/default.xml
b> 手工加载mod_helloworld模块,可以看到类似输出
2015-12-16 10:40:42.073966 [INFO] mod_helloworld.c:98 mod_helloworld load successfully!
c> 客户端软件话测试
客户端软电话配置注册到FreeSWITCH,然后拨打之前配好的8519,可以看到类似输出
2015-12-16 10:43:37.714916 [INFO] mod_helloworld.c:59 mod_helloword app!
d> 手工卸载mod_helloworld模块,可以看到类似输出
2015-12-16 10:40:37.702197 [INFO] mod_hellworld.c:109 mod_helloworld shutdown successfully!