Thu Apr 28 2011 17:13:28

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