Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:15 2009

## Asterisk developer's documentation

# app_skel.c File Reference

Skeleton application. More...

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <unistd.h>`
`#include <string.h>`
`#include "asterisk.h"`
`#include "asterisk/file.h"`
`#include "asterisk/logger.h"`
`#include "asterisk/channel.h"`
`#include "asterisk/pbx.h"`
`#include "asterisk/module.h"`
`#include "asterisk/lock.h"`
`#include "asterisk/app.h"`

Include dependency graph for app_skel.c:

Go to the source code of this file.

## Defines

#define | OPTION_A (1 << 0)
#define | OPTION_B (1 << 1)
#define | OPTION_C (1 << 2)
#define | OPTION_NULL (1 << 3)

## Functions

static int | app_exec (struct ast_channel *chan, void *data)
| AST_APP_OPTIONS (app_opts,{['a']={OPTION_A},['b']={OPTION_B, 1},['c']={OPTION_C, 2}})
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 = "Skel"
static char * | descrip
| LOCAL_USER_DECL
| STANDARD_LOCAL_USER
static char * | synopsis
static char * | tdesc = "Trivial skeleton Application"

## Detailed Description

Skeleton application.

This is a skeleton for development of an Asterisk application

Definition in file app_skel.c.

## Define Documentation

#define OPTION_A (1 << 0)

Definition at line 51 of file app_skel.c.

Referenced by app_exec().

#define OPTION_B (1 << 1)

Definition at line 52 of file app_skel.c.

Referenced by app_exec().

#define OPTION_C (1 << 2)

Definition at line 53 of file app_skel.c.

Referenced by app_exec().

#define OPTION_NULL (1 << 3)

Definition at line 54 of file app_skel.c.

## Function Documentation

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

Definition at line 66 of file app_skel.c.

References ast_app_parse_options(), ast_app_separate_args(), ast_log(), ast_strdupa, ast_strlen_zero(), ast_test_flag, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_NOTICE, LOG_WARNING, OPTION_A, OPTION_B, and OPTION_C.

    00067 {
    00068    int res = 0;
    00069    struct ast_flags flags;
    00070    struct localuser *u;
    00071    char *options=NULL;
    00072    char *dummy = NULL;
    00073    char *args;
    00074    int argc = 0;
    00075    char *opts[2];
    00076    char *argv[2];
    00077
    00078    if (ast_strlen_zero(data)) {
    00079       ast_log(LOG_WARNING, "%s requires an argument (dummy|[options])\n",app);
    00080       return -1;
    00081    }
    00082
    00083    LOCAL_USER_ADD(u);
    00084
    00085    /* Do our thing here */
    00086
    00087    /* We need to make a copy of the input string if we are going to modify it! */
    00088    args = ast_strdupa(data);
    00089    if (!args) {
    00090       ast_log(LOG_ERROR, "Out of memory!\n");
    00091       LOCAL_USER_REMOVE(u);
    00092       return -1;
    00093    }
    00094
    00095    if ((argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
    00096       dummy = argv[0];
    00097       options = argv[1];
    00098       ast_app_parse_options(app_opts, &flags, opts, options);
    00099    }
    00100
    00101    if (!ast_strlen_zero(dummy))
    00102       ast_log(LOG_NOTICE, "Dummy value is : %s\n", dummy);
    00103
    00104    if (ast_test_flag(&flags, OPTION_A))
    00105       ast_log(LOG_NOTICE, "Option A is set\n");
    00106
    00107    if (ast_test_flag(&flags, OPTION_B))
    00108       ast_log(LOG_NOTICE,"Option B is set with : %s\n", opts[0] ? opts[0] : "<unspecified>");
    00109
    00110    if (ast_test_flag(&flags, OPTION_C))
    00111       ast_log(LOG_NOTICE,"Option C is set with : %s\n", opts[1] ? opts[1] : "<unspecified>");
    00112
    00113    LOCAL_USER_REMOVE(u);
    00114
    00115    return res;
    00116 }

AST_APP_OPTIONS | ( | app_opts |  | ) |

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 134 of file app_skel.c.

    00135 {
    00136    return tdesc;
    00137 }

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 146 of file app_skel.c.

References ASTERISK_GPL_KEY.

    00147 {
    00148    return ASTERISK_GPL_KEY;
    00149 }

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 129 of file app_skel.c.

References app_exec, and ast_register_application().

    00130 {
    00131    return ast_register_application(app, app_exec, synopsis, descrip);
    00132 }

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 118 of file app_skel.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

    00119 {
    00120    int res;
    00121
    00122    res = ast_unregister_application(app);
    00123
    00124    STANDARD_HANGUP_LOCALUSERS;
    00125
    00126    return res;
    00127 }

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 139 of file app_skel.c.

References STANDARD_USECOUNT.

    00140 {
    00141    int res;
    00142    STANDARD_USECOUNT(res);
    00143    return res;
    00144 }

## Variable Documentation

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

Definition at line 45 of file app_skel.c.

char* descrip`[static]`

Initial value:

     "This application is a template to build other applications from.\n"
     " It shows you the basic structure to create your own Asterisk applications.\n"

Definition at line 48 of file app_skel.c.

LOCAL_USER_DECL

Definition at line 64 of file app_skel.c.

STANDARD_LOCAL_USER

Definition at line 62 of file app_skel.c.

char* synopsis`[static]`

Initial value:

    "Skeleton application."

Definition at line 46 of file app_skel.c.

char* tdesc = "Trivial skeleton Application"`[static]`

Definition at line 44 of file app_skel.c.