2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
21 * Wait for Ring Application
29 #include <sys/types.h>
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35 #include "asterisk/file.h"
36 #include "asterisk/logger.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/options.h"
41 #include "asterisk/lock.h"
43 static char *synopsis = "Wait for Ring Application";
45 static char *tdesc = "Waits until first ring after time";
47 static char *desc = " WaitForRing(timeout)\n"
48 "Returns 0 after waiting at least timeout seconds. and\n"
49 "only after the next ring has completed. Returns 0 on\n"
50 "success or -1 on hangup\n";
52 static char *app = "WaitForRing";
58 static int waitforring_exec(struct ast_channel *chan, void *data)
65 if (!data || (sscanf(data, "%d", &ms) != 1)) {
66 ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
74 ms = ast_waitfor(chan, ms);
85 if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
86 if (option_verbose > 2)
87 ast_verbose(VERBOSE_PREFIX_3 "Got a ring but still waiting for timeout\n");
92 /* Now we're really ready for the ring */
96 ms = ast_waitfor(chan, ms);
107 if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) {
108 if (option_verbose > 2)
109 ast_verbose(VERBOSE_PREFIX_3 "Got a ring after the timeout\n");
117 LOCAL_USER_REMOVE(u);
122 int unload_module(void)
126 res = ast_unregister_application(app);
128 STANDARD_HANGUP_LOCALUSERS;
133 int load_module(void)
135 return ast_register_application(app, waitforring_exec, synopsis, desc);
138 char *description(void)
146 STANDARD_USECOUNT(res);
152 return ASTERISK_GPL_KEY;