Sun Aug 6 15:04:01 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

app_playback.c File Reference

Trivial application to playback a sound file. More...

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "asterisk.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 dependency graph for app_playback.c:

Go to the source code of this file.

Functions

char * description (void)
 Provides a description of the module.
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module (void)
 Initialize the module.
static int playback_exec (struct ast_channel *chan, void *data)
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.

Variables

static char * app = "Playback"
static char * descrip
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
static char * synopsis = "Play a file"
static char * tdesc = "Sound File Playback Application"


Detailed Description

Trivial application to playback a sound file.

Definition in file app_playback.c.


Function Documentation

char* description void   ) 
 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 165 of file app_playback.c.

References tdesc.

00166 {
00167    return tdesc;
00168 }

char* key void   ) 
 

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

 char *key(void) {
         return ASTERISK_GPL_KEY;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 177 of file app_playback.c.

References ASTERISK_GPL_KEY.

00178 {
00179    return ASTERISK_GPL_KEY;
00180 }

int load_module void   ) 
 

Initialize the module.

Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
int Always 0.

Definition at line 160 of file app_playback.c.

References app, ast_register_application(), descrip, playback_exec(), and synopsis.

00161 {
00162    return ast_register_application(app, playback_exec, synopsis, descrip);
00163 }

static int playback_exec struct ast_channel chan,
void *  data
[static]
 

Definition at line 71 of file app_playback.c.

References ast_channel::_state, ast_answer(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_waitstream(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, option_priority_jumping, pbx_builtin_setvar_helper(), and strcasestr().

Referenced by load_module().

00072 {
00073    int res = 0, mres = 0;
00074    struct localuser *u;
00075    char *tmp = NULL;
00076    int option_skip=0;
00077    int option_noanswer = 0;
00078    char *front = NULL, *back = NULL;
00079    int priority_jump = 0;
00080    AST_DECLARE_APP_ARGS(args,
00081       AST_APP_ARG(filenames);
00082       AST_APP_ARG(options);
00083    );
00084    
00085    if (ast_strlen_zero(data)) {
00086       ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
00087       return -1;
00088    }
00089 
00090    LOCAL_USER_ADD(u);
00091 
00092    tmp = ast_strdupa(data);
00093    if (!tmp) {
00094       ast_log(LOG_ERROR, "Out of memory!\n");
00095       LOCAL_USER_REMOVE(u);
00096       return -1;  
00097    }
00098 
00099    AST_STANDARD_APP_ARGS(args, tmp);
00100 
00101    if (args.options) {
00102       if (strcasestr(args.options, "skip"))
00103          option_skip = 1;
00104       if (strcasestr(args.options, "noanswer"))
00105          option_noanswer = 1;
00106       if (strchr(args.options, 'j'))
00107          priority_jump = 1;
00108    }
00109    
00110    if (chan->_state != AST_STATE_UP) {
00111       if (option_skip) {
00112          /* At the user's option, skip if the line is not up */
00113          LOCAL_USER_REMOVE(u);
00114          return 0;
00115       } else if (!option_noanswer)
00116          /* Otherwise answer unless we're supposed to send this while on-hook */
00117          res = ast_answer(chan);
00118    }
00119    if (!res) {
00120       ast_stopstream(chan);
00121       front = tmp;
00122       while (!res && front) {
00123          if ((back = strchr(front, '&'))) {
00124             *back = '\0';
00125             back++;
00126          }
00127          res = ast_streamfile(chan, front, chan->language);
00128          if (!res) { 
00129             res = ast_waitstream(chan, "");  
00130             ast_stopstream(chan);
00131          } else {
00132             ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
00133             if (priority_jump || option_priority_jumping)
00134                ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00135             res = 0;
00136             mres = 1;
00137          }
00138          front = back;
00139       }
00140       if (mres)
00141          pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", "FAILED");
00142       else
00143          pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", "SUCCESS");
00144    }
00145    LOCAL_USER_REMOVE(u);
00146    return res;
00147 }

int unload_module void   ) 
 

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
Zero on success, or non-zero on error.

Definition at line 149 of file app_playback.c.

References app, ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

00150 {
00151    int res;
00152 
00153    res = ast_unregister_application(app);
00154 
00155    STANDARD_HANGUP_LOCALUSERS;
00156 
00157    return res; 
00158 }

int usecount void   ) 
 

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
The module's usecount.

Definition at line 170 of file app_playback.c.

References STANDARD_USECOUNT.

00171 {
00172    int res;
00173    STANDARD_USECOUNT(res);
00174    return res;
00175 }


Variable Documentation

char* app = "Playback" [static]
 

Definition at line 47 of file app_playback.c.

char* descrip [static]
 

Definition at line 51 of file app_playback.c.

LOCAL_USER_DECL
 

Definition at line 69 of file app_playback.c.

STANDARD_LOCAL_USER
 

Definition at line 67 of file app_playback.c.

char* synopsis = "Play a file" [static]
 

Definition at line 49 of file app_playback.c.

char* tdesc = "Sound File Playback Application" [static]
 

Definition at line 45 of file app_playback.c.


Generated on Sun Aug 6 15:04:02 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.2