Version 0.1.7 from FTP
[asterisk/asterisk.git] / apps / app_echo.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Echo application -- play back what you hear to evaluate latency
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <asterisk/file.h>
15 #include <asterisk/logger.h>
16 #include <asterisk/channel.h>
17 #include <asterisk/pbx.h>
18 #include <asterisk/module.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <stdlib.h>
23
24 #include <pthread.h>
25
26
27 static char *tdesc = "Simple Echo Application";
28
29 static char *app = "Echo";
30
31 STANDARD_LOCAL_USER;
32
33 LOCAL_USER_DECL;
34
35 static int skel_exec(struct ast_channel *chan, void *data)
36 {
37         int res=-1;
38         struct localuser *u;
39         struct ast_frame *f;
40         LOCAL_USER_ADD(u);
41         /* Do our thing here */
42         while((f = ast_read(chan))) {
43                 if (f->frametype == AST_FRAME_VOICE) {
44                         if (ast_write(chan, f)) 
45                                 break;
46                 } else if (f->frametype == AST_FRAME_DTMF) {
47                         if (f->subclass == '#') {
48                                 res = 0;
49                                 break;
50                         } else
51                                 if (ast_write(chan, f))
52                                         break;
53                 }
54         }
55         LOCAL_USER_REMOVE(u);
56         return res;
57 }
58
59 int unload_module(void)
60 {
61         STANDARD_HANGUP_LOCALUSERS;
62         return ast_unregister_application(app);
63 }
64
65 int load_module(void)
66 {
67         return ast_register_application(app, skel_exec);
68 }
69
70 char *description(void)
71 {
72         return tdesc;
73 }
74
75 int usecount(void)
76 {
77         int res;
78         STANDARD_USECOUNT(res);
79         return res;
80 }
81
82 char *key()
83 {
84         return ASTERISK_GPL_KEY;
85 }