Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:04 2009

## Asterisk developer's documentation

# app_flash.c File Reference

App to flash a zap trunk. More...

`#include <stdlib.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include <errno.h>`
`#include <sys/ioctl.h>`
`#include <zaptel.h>`
`#include "asterisk.h"`
`#include "asterisk/lock.h"`
`#include "asterisk/file.h"`
`#include "asterisk/logger.h"`
`#include "asterisk/channel.h"`
`#include "asterisk/pbx.h"`
`#include "asterisk/module.h"`
`#include "asterisk/translate.h"`
`#include "asterisk/image.h"`
`#include "asterisk/options.h"`

Include dependency graph for app_flash.c:

Go to the source code of this file.

## Functions

char * | description (void)
| Provides a description of the module.
static int | flash_exec (struct ast_channel *chan, void *data)
char * | key ()
| Returns the ASTERISK_GPL_KEY.
int | load_module (void)
| Initialize the module.
int | unload_module (void)
| Cleanup all module structures, sockets, etc.
int | usecount (void)
| Provides a usecount.
static int | zt_wait_event (int fd)

## Variables

static char * | app = "Flash"
static char * | descrip
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | synopsis = "Flashes a Zap Trunk"
static char * | tdesc = "Flash zap trunk application"

## Detailed Description

App to flash a zap trunk.

Definition in file app_flash.c.

## Function Documentation

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 126 of file app_flash.c.

    00127 {
    00128    return tdesc;
    00129 }

static int flash_exec | ( | struct ast_channel * | chan,
|  | void * | data |
| ) |  |  | `[static]`

Definition at line 76 of file app_flash.c.

References ast_log(), ast_safe_sleep(), ast_verbose(), ast_channel::fds, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_WARNING, ast_channel::name, option_verbose, ast_channel::type, VERBOSE_PREFIX_3, and zt_wait_event().

Referenced by load_module().

    00077 {
    00078    int res = -1;
    00079    int x;
    00080    struct localuser *u;
    00081    struct zt_params ztp;
    00082    LOCAL_USER_ADD(u);
    00083    if (!strcasecmp(chan->type, "Zap")) {
    00084       memset(&ztp, 0, sizeof(ztp));
    00085       res = ioctl(chan->fds[0], ZT_GET_PARAMS, &ztp);
    00086       if (!res) {
    00087          if (ztp.sigtype & __ZT_SIG_FXS) {
    00088             x = ZT_FLASH;
    00089             res = ioctl(chan->fds[0], ZT_HOOK, &x);
    00090             if (!res || (errno == EINPROGRESS)) {
    00091                if (res) {
    00092                   /* Wait for the event to finish */
    00093                   zt_wait_event(chan->fds[0]);
    00094                }
    00095                res = ast_safe_sleep(chan, 1000);
    00096                if (option_verbose > 2)
    00097                   ast_verbose(VERBOSE_PREFIX_3 "Flashed channel %s\n", chan->name);
    00098             } else
    00099                ast_log(LOG_WARNING, "Unable to flash channel %s: %s\n", chan->name, strerror(errno));
    00100          } else
    00101             ast_log(LOG_WARNING, "%s is not an FXO Channel\n", chan->name);
    00102       } else
    00103          ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", chan->name, strerror(errno));
    00104    } else
    00105       ast_log(LOG_WARNING, "%s is not a Zap channel\n", chan->name);
    00106    LOCAL_USER_REMOVE(u);
    00107    return res;
    00108 }

char* key | ( | void |  | ) |

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

     char *key(void) {
             return ASTERISK_GPL_KEY;
     }

Returns:
  ASTERISK_GPL_KEY

Definition at line 138 of file app_flash.c.

References ASTERISK_GPL_KEY.

    00139 {
    00140    return ASTERISK_GPL_KEY;
    00141 }

int load_module | ( | void |  | ) |

Initialize the module.

This function is called at module load time. Put all code in here that needs to set up your module's hardware, software, registrations, etc.

Returns:
  This function should return 0 on success and non-zero on failure. If the module is not loaded successfully, Asterisk will call its unload_module() function.

Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
  int Always 0.

TE STUFF END

Definition at line 121 of file app_flash.c.

References ast_register_application(), and flash_exec().

    00122 {
    00123    return ast_register_application(app, flash_exec, synopsis, descrip);
    00124 }

int unload_module | ( | void |  | ) |

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
  Zero on success, or non-zero on error.

Definition at line 110 of file app_flash.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00111 {
    00112    int res;
    00113
    00114    res = ast_unregister_application(app);
    00115
    00116    STANDARD_HANGUP_LOCALUSERS;
    00117
    00118    return res;
    00119 }

int usecount | ( | void |  | ) |

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
  The module's usecount.

Definition at line 131 of file app_flash.c.

References STANDARD_USECOUNT.

    00132 {
    00133    int res;
    00134    STANDARD_USECOUNT(res);
    00135    return res;
    00136 }

static int zt_wait_event | ( | int | fd | ) | `[inline, static]`

Definition at line 66 of file app_flash.c.

    00067 {
    00068    /* Avoid the silly zt_waitevent which ignores a bunch of events */
    00069    int i,j=0;
    00070    i = ZT_IOMUX_SIGEVENT;
    00071    if (ioctl(fd, ZT_IOMUX, &i) == -1) return -1;
    00072    if (ioctl(fd, ZT_GETEVENT, &j) == -1) return -1;
    00073    return j;
    00074 }

## Variable Documentation

char* app = "Flash"`[static]`

Definition at line 53 of file app_flash.c.

char* descrip`[static]`

Initial value:

    "  Flash(): Sends a flash on a zap trunk.  This is only a hack for\n"
    "people who want to perform transfers and such via AGI and is generally\n"
    "quite useless oths application will only work on Zap trunks.\n"

Definition at line 57 of file app_flash.c.

LOCAL_USER_DECL

Definition at line 64 of file app_flash.c.

STANDARD_LOCAL_USER

Definition at line 62 of file app_flash.c.

char* synopsis = "Flashes a Zap Trunk"`[static]`

Definition at line 55 of file app_flash.c.

char* tdesc = "Flash zap trunk application"`[static]`

Definition at line 51 of file app_flash.c.