Minor formatting change to test a mantis change ...
[asterisk-bristuff.git] / apps / app_flash.c
blobd57feeb916f6107779e1e19aad7ee829b01ca5a3
1 /*
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.
19 /*! \file
21 * \brief App to flash a zap trunk
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
28 /*** MODULEINFO
29 <depend>zaptel</depend>
30 ***/
32 #include "asterisk.h"
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36 #include "asterisk/zapata.h"
38 #include "asterisk/lock.h"
39 #include "asterisk/file.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
43 #include "asterisk/translate.h"
44 #include "asterisk/image.h"
46 static char *app = "Flash";
48 static char *synopsis = "Flashes a Zap Trunk";
50 static char *descrip =
51 "Performs a flash on a zap trunk. This can be used\n"
52 "to access features provided on an incoming analogue circuit\n"
53 "such as conference and call waiting. Use with SendDTMF() to\n"
54 "perform external transfers\n";
57 static inline int zt_wait_event(int fd)
59 /* Avoid the silly zt_waitevent which ignores a bunch of events */
60 int i,j=0;
61 i = ZT_IOMUX_SIGEVENT;
62 if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
63 if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
64 return j;
67 static int flash_exec(struct ast_channel *chan, void *data)
69 int res = -1;
70 int x;
71 struct zt_params ztp;
73 if (strcasecmp(chan->tech->type, "Zap")) {
74 ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
75 return -1;
78 memset(&ztp, 0, sizeof(ztp));
79 res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
80 if (!res) {
81 if (ztp.sigtype & __ZT_SIG_FXS) {
82 x = ZT_FLASH;
83 res = ioctl(chan->fds[0], ZT_HOOK, &x);
84 if (!res || (errno == EINPROGRESS)) {
85 if (res) {
86 /* Wait for the event to finish */
87 zt_wait_event(chan->fds[0]);
89 res = ast_safe_sleep(chan, 1000);
90 ast_verb(3, "Flashed channel %s\n", chan->name);
91 } else
92 ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
93 } else
94 ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
95 } else
96 ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
98 return res;
101 static int unload_module(void)
103 return ast_unregister_application(app);
106 static int load_module(void)
108 return ast_register_application(app, flash_exec, synopsis, descrip);
111 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");