/* * Asterisk -- A telephony toolkit for Linux. * * Test app for ast_playlist stuff * * Copyright (C) 2005, Marc Olivier Chouinard * * Marc Olivier Chouinard * * This program is free software, distributed under the terms of * the GNU General Public License */ #include #include #include #include #include #include #include #include #include static char *tdesc = "Playlist test Application"; static char *app = "playlist"; static char *synopsis = " This is a test for the ast_playlist\n"; struct ast_playlist { char filename[AST_MAX_EXTENSION]; unsigned int delay; char language[MAX_LANGUAGE]; struct ast_playlist *next; struct ast_playlist *last; }; struct ast_playlist *ast_playlist(struct ast_playlist *pl,char *filename,unsigned int delay,char *language); int ast_streamplaylist(struct ast_channel *chan, struct ast_playlist *pl, char *brakeon); STANDARD_LOCAL_USER; LOCAL_USER_DECL; static int playlist_exec(struct ast_channel *chan, void *data) { struct ast_playlist *pl=NULL; int res=0; struct localuser *u; LOCAL_USER_ADD(u); pl = ast_playlist(pl,"digits/1",1000,chan->language); pl = ast_playlist(pl,"digits/2",2000,chan->language); pl = ast_playlist(pl,"digits/3",3000,chan->language); pl = ast_playlist(pl,"digits/4",4000,chan->language); ast_streamplaylist(chan,pl,""); LOCAL_USER_REMOVE(u); return res; } int ast_streamplaylist(struct ast_channel *chan, struct ast_playlist *pl, char *brakeon) { int res=0; while(pl) { if (!ast_streamfile(chan, pl->filename, pl->language)) res = ast_waitstream(chan, brakeon); if (res) break; if (pl->delay) res = ast_waitfordigit(chan,pl->delay); pl = pl->next; } return res; } struct ast_playlist *ast_playlist(struct ast_playlist *pl,char *filename,unsigned int delay,char *language) { struct ast_playlist *tmp; tmp = malloc(sizeof(struct ast_playlist)); if (!tmp) { ast_log(LOG_WARNING, "Out of memory\n"); goto out; } memset(tmp, 0, sizeof(struct ast_playlist)); snprintf(tmp->filename,sizeof(tmp->filename),"%s",filename); snprintf(tmp->language,sizeof(tmp->language),"%s",language); tmp->delay = delay; if (pl == NULL) { pl = tmp; pl->next = NULL; pl->last = tmp; } else { pl->last->next = tmp; pl->last = tmp; } out: return pl; } int unload_module(void) { STANDARD_HANGUP_LOCALUSERS; return ast_unregister_application(app); } int load_module(void) { return ast_register_application(app, playlist_exec, synopsis, tdesc); } char *description(void) { return tdesc; } int usecount(void) { int res; STANDARD_USECOUNT(res); return res; } char *key() { return ASTERISK_GPL_KEY; }