给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! 

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

转载于:https://www.cnblogs.com/MikeZhang/archive/2012/04/14/asteriskCLIAppTest20120414.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值