随笔 - 272  文章 - 0  评论 - 283  阅读 - 142万

给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   Mike_Zhang  阅读(1726)  评论(2编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2012年4月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 1 2 3 4 5
6 7 8 9 10 11 12

点击右上角即可分享
微信分享提示