给asterisk写app供CLI调用

环境:CentOS6.2 + Asterisk 1.8.7.1

一、添加源文件

复制app_verbose.capp_testApp.c

复制app_verbose.exportsapp_testApp.exports

主要是修改一些标识,编译不会出错就行,这里列出我进行的主要修改。

1、添加头文件

#include "asterisk/cli.h"

2、修改变量

static char *app_testApp = "testApp";
static char *app_testApplog = "testAppLog";

3、在load_module中进行注册

res |= ast_register_application_xml(app_testApp, testApp_exec);

4、添加功能函数

static int testApp_exec(struct ast_channel *chan, const char *data)
{
        ast_verb(2,"testApp_exec : %s\r\n",data);
        return0;
}

5、添加cli调用接口

注册commande->command = "testApp {print}";

调用command

if (!strcasecmp(a->argv[1], "print")) {

                testApp_exec(chan, a->argv[2]);
}

6、在unload_module中进行反注册

res = ast_unregister_application(app_testApp);

二、编译并安装

asterisk -rx "core stop now" && make && make install && asterisk && asterisk -rvvvvvvvvvvvvv 

三、测试

运行asterisk -rvvvvvvvv进入CLI模式

输入:core show help testApp

会输出帮助文档

输入:core show help testApp "something to test!"

会输出:something to test! 

好,就这些了,希望对你有帮助。

posted on 2012-04-14 17:05  Mike_Zhang  阅读(1700)  评论(2编辑  收藏  举报