環境:CentOS6.2 + Asterisk 1.8.7.1
一、添加源文件
復制app_verbose.c為app_testApp.c
復制app_verbose.exports為app_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調用接口
注冊command:e->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!?
好,就這些了,希望對你有幫助。