Wed Aug 18 22:33:41 2010

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

Generated on Wed Aug 18 22:33:41 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7