This rather large commit changes the way modules are loaded.
[asterisk/asterisk.git] / apps / app_echo.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief Echo application -- play back what you hear to evaluate latency
22  *
23  * \author Mark Spencer <markster@digium.com>
24  * 
25  * \ingroup applications
26  */
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <string.h>
32
33 #include "asterisk.h"
34
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36
37 #include "asterisk/lock.h"
38 #include "asterisk/file.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
43
44 static char *tdesc = "Simple Echo Application";
45
46 static char *app = "Echo";
47
48 static char *synopsis = "Echo audio, video, or DTMF back to the calling party";
49
50 static char *descrip = 
51 "  Echo(): This application will echo any audio, video, or DTMF frames read from\n"
52 "the calling channel back to itself. If the DTMF digit '#' is received, the\n"
53 "application will exit.\n";
54
55 LOCAL_USER_DECL;
56
57 static int echo_exec(struct ast_channel *chan, void *data)
58 {
59         int res = -1;
60         int format;
61         struct localuser *u;
62
63         LOCAL_USER_ADD(u);
64
65         format = ast_best_codec(chan->nativeformats);
66         ast_set_write_format(chan, format);
67         ast_set_read_format(chan, format);
68
69         while (ast_waitfor(chan, -1) > -1) {
70                 struct ast_frame *f = ast_read(chan);
71                 if (!f)
72                         break;
73                 f->delivery.tv_sec = 0;
74                 f->delivery.tv_usec = 0;
75                 if (f->frametype == AST_FRAME_VOICE) {
76                         if (ast_write(chan, f)) 
77                                 break;
78                 } else if (f->frametype == AST_FRAME_VIDEO) {
79                         if (ast_write(chan, f)) 
80                                 break;
81                 } else if (f->frametype == AST_FRAME_DTMF) {
82                         if (f->subclass == '#') {
83                                 res = 0;
84                                 break;
85                         } else {
86                                 if (ast_write(chan, f))
87                                         break;
88                         }
89                 }
90                 ast_frfree(f);
91         }
92
93         LOCAL_USER_REMOVE(u);
94
95         return res;
96 }
97
98 static int unload_module(void *mod)
99 {
100         int res;
101
102         res = ast_unregister_application(app);
103
104         STANDARD_HANGUP_LOCALUSERS;
105
106         return res;
107 }
108
109 static int load_module(void *mod)
110 {
111         return ast_register_application(app, echo_exec, synopsis, descrip);
112 }
113
114 static const char *description(void)
115 {
116         return tdesc;
117 }
118
119 static const char *key(void)
120 {
121         return ASTERISK_GPL_KEY;
122 }
123
124 STD_MOD1;