#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.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 dependency graph for app_echo.c:
Go to the source code of this file.
Functions | |
char * | description (void) |
Provides a description of the module. | |
static int | echo_exec (struct ast_channel *chan, void *data) |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static char * | app = "Echo" |
static char * | descrip |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | synopsis = "Echo audio read back to the user" |
static char * | tdesc = "Simple Echo Application" |
Definition in file app_echo.c.
char* description | ( | void | ) |
Provides a description of the module.
Definition at line 108 of file app_echo.c.
00109 { 00110 return tdesc; 00111 }
static int echo_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 57 of file app_echo.c.
References ast_best_codec(), AST_FRAME_DTMF, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree(), ast_read(), ast_set_read_format(), ast_set_write_format(), ast_waitfor(), ast_write(), ast_frame::delivery, ast_frame::frametype, LOCAL_USER_ADD, LOCAL_USER_REMOVE, ast_channel::nativeformats, and ast_frame::subclass.
Referenced by load_module().
00058 { 00059 int res=-1; 00060 struct localuser *u; 00061 struct ast_frame *f; 00062 LOCAL_USER_ADD(u); 00063 ast_set_write_format(chan, ast_best_codec(chan->nativeformats)); 00064 ast_set_read_format(chan, ast_best_codec(chan->nativeformats)); 00065 /* Do our thing here */ 00066 while(ast_waitfor(chan, -1) > -1) { 00067 f = ast_read(chan); 00068 if (!f) 00069 break; 00070 f->delivery.tv_sec = 0; 00071 f->delivery.tv_usec = 0; 00072 if (f->frametype == AST_FRAME_VOICE) { 00073 if (ast_write(chan, f)) 00074 break; 00075 } else if (f->frametype == AST_FRAME_VIDEO) { 00076 if (ast_write(chan, f)) 00077 break; 00078 } else if (f->frametype == AST_FRAME_DTMF) { 00079 if (f->subclass == '#') { 00080 res = 0; 00081 break; 00082 } else 00083 if (ast_write(chan, f)) 00084 break; 00085 } 00086 ast_frfree(f); 00087 } 00088 LOCAL_USER_REMOVE(u); 00089 return res; 00090 }
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; }
Definition at line 120 of file app_echo.c.
References ASTERISK_GPL_KEY.
00121 { 00122 return ASTERISK_GPL_KEY; 00123 }
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.
Definition at line 103 of file app_echo.c.
References ast_register_application(), and echo_exec().
00104 { 00105 return ast_register_application(app, echo_exec, synopsis, descrip); 00106 }
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).
Definition at line 92 of file app_echo.c.
References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.
00093 { 00094 int res; 00095 00096 res = ast_unregister_application(app); 00097 00098 STANDARD_HANGUP_LOCALUSERS; 00099 00100 return res; 00101 }
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.
Definition at line 113 of file app_echo.c.
References STANDARD_USECOUNT.
00114 { 00115 int res; 00116 STANDARD_USECOUNT(res); 00117 return res; 00118 }
char* app = "Echo" [static] |
Definition at line 44 of file app_echo.c.
char* descrip [static] |
Initial value:
" Echo(): Echo audio read from channel back to the channel. \n" "User can exit the application by either pressing the '#' key, \n" "or hanging up.\n"
Definition at line 48 of file app_echo.c.
Definition at line 55 of file app_echo.c.
Definition at line 53 of file app_echo.c.
Definition at line 46 of file app_echo.c.
char* tdesc = "Simple Echo Application" [static] |
Definition at line 42 of file app_echo.c.