#include "asterisk.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/utils.h"
#include "asterisk/options.h"
#include "asterisk/app.h"
#include "asterisk/cli.h"
#include "asterisk/localtime.h"
#include "asterisk/say.h"
Include dependency graph for app_cycle.c:
Go to the source code of this file.
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Sound File Playback Application") | |
static int | load_module (void) |
static int | playback_exec (struct ast_channel *chan, void *data) |
static int | unload_module (void) |
Variables | |
static char * | app = "Cycle" |
static int | counter = 0 |
static char * | descrip = "\n" |
static ast_mutex_t | lock |
static char * | synopsis = "" |
Definition in file app_cycle.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Sound File Playback Application" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 118 of file app_cycle.c.
References app, ast_register_application(), descrip, playback_exec(), and synopsis.
00119 { 00120 return ast_register_application(app, playback_exec, synopsis, descrip); 00121 }
static int playback_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 37 of file app_cycle.c.
References ast_channel::_state, asprintf, ast_answer(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), ast_module_user_add, ast_module_user_remove, ast_mutex_lock(), ast_mutex_unlock(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_waitstream(), ast_module_user::chan, counter, lock, LOG_ERROR, and pbx_builtin_setvar_helper().
Referenced by load_module().
00038 { 00039 int res = 0; 00040 struct ast_module_user *u; 00041 char *tmp; 00042 00043 ast_log(LOG_ERROR, "Cycle(%s)\n", (char*)data); 00044 00045 AST_DECLARE_APP_ARGS(args, 00046 AST_APP_ARG(fnprefix); 00047 AST_APP_ARG(maxnum); 00048 AST_APP_ARG(opts); 00049 ); 00050 00051 if (ast_strlen_zero(data)) { 00052 ast_log(LOG_ERROR, "Cycle requires 2 args: fnprefix and maxnum\n"); 00053 return -1; 00054 } 00055 00056 AST_STANDARD_APP_ARGS(args, data); 00057 00058 00059 if (args.fnprefix == NULL ) 00060 { 00061 ast_log(LOG_ERROR, "Cycle: fnprefix not set\n"); 00062 return -1; 00063 } 00064 00065 int maxnum = atoi(args.maxnum); 00066 00067 if (maxnum < 1) 00068 { 00069 ast_log(LOG_ERROR, "Cycle: maxnum must be integer >= 1, but set to '%d' ('%s')\n", maxnum, args.maxnum); 00070 return -1; 00071 } 00072 00073 tmp = ast_strdupa(data); 00074 u = ast_module_user_add(chan); 00075 00076 /* Answer if not answered before */ 00077 if (chan->_state != AST_STATE_UP) 00078 res = ast_answer(chan); 00079 if( res ) 00080 goto done; 00081 00082 if (!res) { 00083 char *str; /* filename for play */ 00084 char *cycle; /* CYCLE channel variable */ 00085 00086 ast_mutex_lock(&lock); 00087 { 00088 counter++; 00089 if (counter > maxnum) 00090 counter = 1; 00091 asprintf(&str, "%s%d", args.fnprefix, counter); 00092 asprintf(&cycle, "%d", counter); 00093 } 00094 ast_mutex_unlock(&lock); 00095 00096 ast_stopstream(chan); 00097 res = ast_streamfile(chan, str, chan->language); 00098 if (!res) { 00099 res = ast_waitstream(chan, ""); 00100 ast_stopstream(chan); 00101 } else 00102 res = 0; 00103 pbx_builtin_setvar_helper(chan, "CYCLE", cycle); 00104 } 00105 done: 00106 ast_module_user_remove(u); 00107 return res; 00108 }
static int unload_module | ( | void | ) | [static] |
Definition at line 110 of file app_cycle.c.
References app, ast_module_user_hangup_all, and ast_unregister_application().
00111 { 00112 int res; 00113 res = ast_unregister_application(app); 00114 ast_module_user_hangup_all(); 00115 return res; 00116 }
char* app = "Cycle" [static] |
Definition at line 30 of file app_cycle.c.
int counter = 0 [static] |
char* descrip = "\n" [static] |
Definition at line 32 of file app_cycle.c.
ast_mutex_t lock [static] |
Definition at line 35 of file app_cycle.c.
char* synopsis = "" [static] |
Definition at line 31 of file app_cycle.c.