Thu Jul 9 13:40:18 2009

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: 125146 $")
00035 
00036 #include <sys/ioctl.h>
00037 #include <dahdi/user.h>
00038 
00039 #include "asterisk/lock.h"
00040 #include "asterisk/file.h"
00041 #include "asterisk/channel.h"
00042 #include "asterisk/pbx.h"
00043 #include "asterisk/module.h"
00044 #include "asterisk/translate.h"
00045 #include "asterisk/image.h"
00046 
00047 static char *app = "Flash";
00048 
00049 static char *synopsis = "Flashes a DAHDI Trunk";
00050 
00051 static char *descrip = 
00052 "Performs a flash on a DAHDI trunk.  This can be used\n"
00053 "to access features provided on an incoming analogue circuit\n"
00054 "such as conference and call waiting. Use with SendDTMF() to\n"
00055 "perform external transfers\n";
00056 
00057 
00058 static inline int dahdi_wait_event(int fd)
00059 {
00060    /* Avoid the silly dahdi_waitevent which ignores a bunch of events */
00061    int i,j=0;
00062    i = DAHDI_IOMUX_SIGEVENT;
00063    if (ioctl(fd, DAHDI_IOMUX, &i) == -1) return -1;
00064    if (ioctl(fd, DAHDI_GETEVENT, &j) == -1) return -1;
00065    return j;
00066 }
00067 
00068 static int flash_exec(struct ast_channel *chan, void *data)
00069 {
00070    int res = -1;
00071    int x;
00072    struct dahdi_params dahdip;
00073 
00074    if (strcasecmp(chan->tech->type, "DAHDI")) {
00075       ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", chan->name);
00076       return -1;
00077    }
00078    
00079    memset(&dahdip, 0, sizeof(dahdip));
00080    res = ioctl(chan->fds[0], DAHDI_GET_PARAMS, &dahdip);
00081    if (!res) {
00082       if (dahdip.sigtype & __DAHDI_SIG_FXS) {
00083          x = DAHDI_FLASH;
00084          res = ioctl(chan->fds[0], DAHDI_HOOK, &x);
00085          if (!res || (errno == EINPROGRESS)) {
00086             if (res) {
00087                /* Wait for the event to finish */
00088                dahdi_wait_event(chan->fds[0]);
00089             }
00090             res = ast_safe_sleep(chan, 1000);
00091             ast_verb(3, "Flashed channel %s\n", chan->name);
00092          } else
00093             ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
00094       } else
00095          ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
00096    } else
00097       ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
00098 
00099    return res;
00100 }
00101 
00102 static int unload_module(void)
00103 {
00104    return ast_unregister_application(app);
00105 }
00106 
00107 static int load_module(void)
00108 {
00109    return ast_register_application(app, flash_exec, synopsis, descrip);
00110 }
00111 
00112 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");
00113 

Generated on Thu Jul 9 13:40:18 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7