Sat Aug 6 00:39:20 2011

Asterisk developer's documentation


app_flash.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief App to flash a DAHDI trunk
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027  
00028 /*** MODULEINFO
00029    <depend>dahdi</depend>
00030  ***/
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 182652 $")
00035 
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <errno.h>
00040 #include <sys/ioctl.h>
00041 
00042 #include "asterisk/lock.h"
00043 #include "asterisk/file.h"
00044 #include "asterisk/logger.h"
00045 #include "asterisk/channel.h"
00046 #include "asterisk/pbx.h"
00047 #include "asterisk/module.h"
00048 #include "asterisk/translate.h"
00049 #include "asterisk/image.h"
00050 #include "asterisk/options.h"
00051 
00052 #include "asterisk/dahdi_compat.h"
00053 
00054 static char *app = "Flash";
00055 
00056 static char *dahdi_synopsis = "Flashes a DAHDI trunk";
00057 
00058 static char *dahdi_descrip = 
00059 "Performs a flash on a DAHDI trunk.  This can be used\n"
00060 "to access features provided on an incoming analogue circuit\n"
00061 "such as conference and call waiting. Use with SendDTMF() to\n"
00062 "perform external transfers\n";
00063 
00064 static char *zap_synopsis = "Flashes a Zap trunk";
00065 
00066 static char *zap_descrip = 
00067 "Performs a flash on a Zap trunk.  This can be used\n"
00068 "to access features provided on an incoming analogue circuit\n"
00069 "such as conference and call waiting. Use with SendDTMF() to\n"
00070 "perform external transfers\n";
00071 
00072 static inline int zt_wait_event(int fd)
00073 {
00074    /* Avoid the silly zt_waitevent which ignores a bunch of events */
00075    int i,j=0;
00076    i = DAHDI_IOMUX_SIGEVENT;
00077    if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
00078    if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
00079    return j;
00080 }
00081 
00082 static int flash_exec(struct ast_channel *chan, void *data)
00083 {
00084    int res = -1;
00085    int x;
00086    struct ast_module_user *u;
00087    struct dahdi_params ztp;
00088    u = ast_module_user_add(chan);
00089    if (!strcasecmp(chan->tech->type, dahdi_chan_name)) {
00090       memset(&ztp, 0, sizeof(ztp));
00091       res = ioctl(chan->fds[0], DAHDI_GET_PARAMS, &ztp);
00092       if (!res) {
00093          if (ztp.sigtype & __DAHDI_SIG_FXS) {
00094             x = DAHDI_FLASH;
00095             res = ioctl(chan->fds[0], DAHDI_HOOK, &x);
00096             if (!res || (errno == EINPROGRESS)) {
00097                if (res) {
00098                   /* Wait for the event to finish */
00099                   zt_wait_event(chan->fds[0]);
00100                }
00101                res = ast_safe_sleep(chan, 1000);
00102                if (option_verbose > 2)
00103                   ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
00104             } else
00105                ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
00106          } else
00107             ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
00108       } else
00109          ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
00110    } else
00111       ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", chan->name);
00112    ast_module_user_remove(u);
00113    return res;
00114 }
00115 
00116 static int unload_module(void)
00117 {
00118    int res;
00119 
00120    res = ast_unregister_application(app);
00121 
00122    ast_module_user_hangup_all();
00123 
00124    return res;
00125 }
00126 
00127 static int load_module(void)
00128 {
00129    if (*dahdi_chan_mode == CHAN_ZAP_MODE) {
00130       return ast_register_application(app, flash_exec, zap_synopsis, zap_descrip);
00131    } else {
00132       return ast_register_application(app, flash_exec, dahdi_synopsis, dahdi_descrip);
00133    }
00134 }
00135 
00136 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");

Generated on Sat Aug 6 00:39:20 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7