Mon May 14 04:42:52 2007

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 zap trunk
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027  
00028 /*** MODULEINFO
00029    <depend>zaptel</depend>
00030  ***/
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
00035 
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <errno.h>
00040 #include <sys/ioctl.h>
00041 #include <zaptel/zaptel.h>
00042 
00043 #include "asterisk/lock.h"
00044 #include "asterisk/file.h"
00045 #include "asterisk/logger.h"
00046 #include "asterisk/channel.h"
00047 #include "asterisk/pbx.h"
00048 #include "asterisk/module.h"
00049 #include "asterisk/translate.h"
00050 #include "asterisk/image.h"
00051 #include "asterisk/options.h"
00052 
00053 static char *app = "Flash";
00054 
00055 static char *synopsis = "Flashes a Zap Trunk";
00056 
00057 static char *descrip = 
00058 "  Flash(): Sends a flash on a zap trunk.  This is only a hack for\n"
00059 "people who want to perform transfers and such via AGI and is generally\n"
00060 "quite useless oths application will only work on Zap trunks.\n";
00061 
00062 
00063 static inline int zt_wait_event(int fd)
00064 {
00065    /* Avoid the silly zt_waitevent which ignores a bunch of events */
00066    int i,j=0;
00067    i = ZT_IOMUX_SIGEVENT;
00068    if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
00069    if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
00070    return j;
00071 }
00072 
00073 static int flash_exec(struct ast_channel *chan, void *data)
00074 {
00075    int res = -1;
00076    int x;
00077    struct ast_module_user *u;
00078    struct zt_params ztp;
00079    u = ast_module_user_add(chan);
00080    if (!strcasecmp(chan->tech->type, "Zap")) {
00081       memset(&ztp, 0, sizeof(ztp));
00082       res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
00083       if (!res) {
00084          if (ztp.sigtype & __ZT_SIG_FXS) {
00085             x = ZT_FLASH;
00086             res = ioctl(chan->fds[0], ZT_HOOK, &x);
00087             if (!res || (errno == EINPROGRESS)) {
00088                if (res) {
00089                   /* Wait for the event to finish */
00090                   zt_wait_event(chan->fds[0]);
00091                }
00092                res = ast_safe_sleep(chan, 1000);
00093                if (option_verbose > 2)
00094                   ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
00095             } else
00096                ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
00097          } else
00098             ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
00099       } else
00100          ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
00101    } else
00102       ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
00103    ast_module_user_remove(u);
00104    return res;
00105 }
00106 
00107 static int unload_module(void)
00108 {
00109    int res;
00110 
00111    res = ast_unregister_application(app);
00112 
00113    ast_module_user_hangup_all();
00114 
00115    return res;
00116 }
00117 
00118 static int load_module(void)
00119 {
00120    return ast_register_application(app, flash_exec, synopsis, descrip);
00121 }
00122 
00123 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Flash channel application");
00124 

Generated on Mon May 14 04:42:52 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1