Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:05 2009

## Asterisk developer's documentation

# app_getcpeid.c File Reference

Get ADSI CPE ID. More...

`#include <stdlib.h>`
`#include <stdio.h>`
`#include <unistd.h>`
`#include <string.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/adsi.h"`
`#include "asterisk/options.h"`

Include dependency graph for app_getcpeid.c:

Go to the source code of this file.

## Functions

static int | cpeid_exec (struct ast_channel *chan, void *idata)
static int | cpeid_setstatus (struct ast_channel *chan, char *stuff[], int voice)
char * | description (void)
| Provides a description of the module.
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.

## Variables

static char * | app = "GetCPEID"
static char * | descrip
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | synopsis = "Get ADSI CPE ID"
static char * | tdesc = "Get ADSI CPE ID"

## Detailed Description

Get ADSI CPE ID.

Definition in file app_getcpeid.c.

## Function Documentation

static int cpeid_exec | ( | struct ast_channel * | chan,
|  | void * | idata |
| ) |  |  | `[static]`

Definition at line 69 of file app_getcpeid.c.

References adsi_get_cpeid(), adsi_get_cpeinfo(), adsi_load_session(), adsi_unload_session(), ast_verbose(), ast_waitfordigit(), cpeid_setstatus(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, ast_channel::name, option_verbose, and VERBOSE_PREFIX_3.

Referenced by load_module().

    00070 {
    00071    int res=0;
    00072    struct localuser *u;
    00073    unsigned char cpeid[4];
    00074    int gotgeometry = 0;
    00075    int gotcpeid = 0;
    00076    int width, height, buttons;
    00077    char data[4][80];
    00078    char *stuff[4];
    00079
    00080    LOCAL_USER_ADD(u);
    00081    stuff[0] = data[0];
    00082    stuff[1] = data[1];
    00083    stuff[2] = data[2];
    00084    stuff[3] = data[3];
    00085    memset(data, 0, sizeof(data));
    00086    strncpy(stuff[0], "** CPE Info **", sizeof(data[0]) - 1);
    00087    strncpy(stuff[1], "Identifying CPE...", sizeof(data[1]) - 1);
    00088    strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1);
    00089    res = adsi_load_session(chan, NULL, 0, 1);
    00090    if (res > 0) {
    00091       cpeid_setstatus(chan, stuff, 0);
    00092       res = adsi_get_cpeid(chan, cpeid, 0);
    00093       if (res > 0) {
    00094          gotcpeid = 1;
    00095          if (option_verbose > 2)
    00096             ast_verbose(VERBOSE_PREFIX_3 "Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n", cpeid[0], cpeid[1], cpeid[2], cpeid[3], chan->name);
    00097       }
    00098       if (res > -1) {
    00099          strncpy(stuff[1], "Measuring CPE...", sizeof(data[1]) - 1);
    00100          strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1);
    00101          cpeid_setstatus(chan, stuff, 0);
    00102          res = adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
    00103          if (res > -1) {
    00104             if (option_verbose > 2)
    00105                ast_verbose(VERBOSE_PREFIX_3 "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
    00106             gotgeometry = 1;
    00107          }
    00108       }
    00109       if (res > -1) {
    00110          if (gotcpeid)
    00111             snprintf(stuff[1], sizeof(data[1]), "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
    00112          else
    00113             strncpy(stuff[1], "CPEID Unknown", sizeof(data[1]) - 1);
    00114          if (gotgeometry)
    00115             snprintf(stuff[2], sizeof(data[2]), "Geom: %dx%d, %d buttons", width, height, buttons);
    00116          else
    00117             strncpy(stuff[2], "Geometry unknown", sizeof(data[2]) - 1);
    00118          strncpy(stuff[3], "Press # to exit", sizeof(data[3]) - 1);
    00119          cpeid_setstatus(chan, stuff, 1);
    00120          for(;;) {
    00121             res = ast_waitfordigit(chan, 1000);
    00122             if (res < 0)
    00123                break;
    00124             if (res == '#') {
    00125                res = 0;
    00126                break;
    00127             }
    00128          }
    00129          adsi_unload_session(chan);
    00130       }
    00131    }
    00132    LOCAL_USER_REMOVE(u);
    00133    return res;
    00134 }

static int cpeid_setstatus | ( | struct ast_channel * | chan,
|  | char * | stuff[],
|  | int | voice |
| ) |  |  | `[static]`

Definition at line 58 of file app_getcpeid.c.

References ADSI_JUST_CENT, ADSI_JUST_LEFT, adsi_print(), and justify.

Referenced by cpeid_exec().

    00059 {
    00060    int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
    00061    char *tmp[5];
    00062    int x;
    00063    for (x=0;x<4;x++)
    00064       tmp[x] = stuff[x];
    00065    tmp[4] = NULL;
    00066    return adsi_print(chan, tmp, justify, voice);
    00067 }

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 152 of file app_getcpeid.c.

    00153 {
    00154    return tdesc;
    00155 }

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 164 of file app_getcpeid.c.

References ASTERISK_GPL_KEY.

    00165 {
    00166    return ASTERISK_GPL_KEY;
    00167 }

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 147 of file app_getcpeid.c.

References ast_register_application(), and cpeid_exec().

    00148 {
    00149    return ast_register_application(app, cpeid_exec, synopsis, descrip);
    00150 }

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 136 of file app_getcpeid.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00137 {
    00138    int res;
    00139
    00140    res = ast_unregister_application(app);
    00141
    00142    STANDARD_HANGUP_LOCALUSERS;
    00143
    00144    return res;
    00145 }

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 157 of file app_getcpeid.c.

References STANDARD_USECOUNT.

    00158 {
    00159    int res;
    00160    STANDARD_USECOUNT(res);
    00161    return res;
    00162 }

## Variable Documentation

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

Definition at line 46 of file app_getcpeid.c.

char* descrip`[static]`

Initial value:

    "  GetCPEID: Obtains and displays ADSI CPE ID and other information in order\n"
    "to properly setup zapata.conf for on-hook operations.\n"

Definition at line 50 of file app_getcpeid.c.

LOCAL_USER_DECL

Definition at line 56 of file app_getcpeid.c.

STANDARD_LOCAL_USER

Definition at line 54 of file app_getcpeid.c.

char* synopsis = "Get ADSI CPE ID"`[static]`

Definition at line 48 of file app_getcpeid.c.

char* tdesc = "Get ADSI CPE ID"`[static]`

Definition at line 44 of file app_getcpeid.c.