Sun Jun 12 16:37:58 2011

Asterisk developer's documentation


func_devstate.c File Reference

Manually controlled blinky lights. More...

#include "asterisk.h"
#include <stdlib.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"
#include "asterisk/cli.h"
#include "asterisk/astdb.h"

Include dependency graph for func_devstate.c:

Go to the source code of this file.

Functions

static const char * ast_devstate_str (int state)
static int ast_devstate_val (const char *val)
 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Gets or sets a device state in the dialplan")
static int cli_funcdevstate_list (int fd, int argc, char *argv[])
static int custom_devstate_callback (const char *data)
static int devstate_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
static int devstate_write (struct ast_channel *chan, char *function, char *data, const char *value)
static int load_module (void)
static int unload_module (void)

Variables

static const char astdb_family [] = "CustomDevstate"
static struct ast_cli_entry cli_funcdevstate []
static struct ast_custom_function devstate_function


Detailed Description

Manually controlled blinky lights.

Author:
Russell Bryant <russell@digium.com>
Note:
Props go out to Ahrimanes in asterisk for requesting this at 4:30 AM when I couldn't sleep. :)

Definition in file func_devstate.c.


Function Documentation

static const char* ast_devstate_str ( int  state  )  [static]

Definition at line 48 of file func_devstate.c.

References AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_UNAVAILABLE, and AST_DEVICE_UNKNOWN.

Referenced by devstate_read().

00049 {
00050    const char *res = "UNKNOWN";
00051 
00052    switch (state) {
00053    case AST_DEVICE_UNKNOWN:
00054       break;
00055    case AST_DEVICE_NOT_INUSE:
00056       res = "NOT_INUSE";
00057       break;
00058    case AST_DEVICE_INUSE:
00059       res = "INUSE";
00060       break;
00061    case AST_DEVICE_BUSY:
00062       res = "BUSY";
00063       break;
00064    case AST_DEVICE_INVALID:
00065       res = "INVALID";
00066       break;
00067    case AST_DEVICE_UNAVAILABLE:
00068       res = "UNAVAILABLE";
00069       break;
00070    case AST_DEVICE_RINGING:
00071       res = "RINGING";
00072       break;
00073    case AST_DEVICE_RINGINUSE:
00074       res = "RINGINUSE";
00075       break;
00076    case AST_DEVICE_ONHOLD:
00077       res = "ONHOLD";
00078       break;
00079    }
00080 
00081    return res;
00082 }

static int ast_devstate_val ( const char *  val  )  [static]

Definition at line 84 of file func_devstate.c.

References AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_UNAVAILABLE, and AST_DEVICE_UNKNOWN.

Referenced by custom_devstate_callback().

00085 {
00086    if (!strcasecmp(val, "NOT_INUSE"))
00087       return AST_DEVICE_NOT_INUSE;
00088    else if (!strcasecmp(val, "INUSE"))
00089       return AST_DEVICE_INUSE;
00090    else if (!strcasecmp(val, "BUSY"))
00091       return AST_DEVICE_BUSY;
00092    else if (!strcasecmp(val, "INVALID"))
00093       return AST_DEVICE_INVALID;
00094    else if (!strcasecmp(val, "UNAVAILABLE"))
00095       return AST_DEVICE_UNAVAILABLE;
00096    else if (!strcasecmp(val, "RINGING"))
00097       return AST_DEVICE_RINGING;
00098    else if (!strcasecmp(val, "RINGINUSE"))
00099       return AST_DEVICE_RINGINUSE;
00100    else if (!strcasecmp(val, "ONHOLD"))
00101       return AST_DEVICE_ONHOLD;
00102 
00103    return AST_DEVICE_UNKNOWN;
00104 }

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Gets or sets a device state in the dialplan"   
)

static int cli_funcdevstate_list ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 145 of file func_devstate.c.

References ast_cli(), ast_db_freetree(), ast_db_gettree(), ast_db_entry::data, ast_db_entry::key, ast_db_entry::next, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00146 {
00147    struct ast_db_entry *db_entry, *db_tree;
00148 
00149    if (argc != 2)
00150       return RESULT_SHOWUSAGE;
00151 
00152    ast_cli(fd, "\n"
00153            "---------------------------------------------------------------------\n"
00154            "--- Custom Device States --------------------------------------------\n"
00155            "---------------------------------------------------------------------\n"
00156            "---\n");
00157 
00158    db_entry = db_tree = ast_db_gettree(astdb_family, NULL);
00159    for (; db_entry; db_entry = db_entry->next) {
00160       const char *dev_name = strrchr(db_entry->key, '/') + 1;
00161       if (dev_name <= (const char *) 1)
00162          continue;
00163       ast_cli(fd, "--- name: 'custom:%s'  state: '%s'\n"
00164                      "---\n", dev_name, db_entry->data);
00165    }
00166    ast_db_freetree(db_tree);
00167    db_tree = NULL;
00168 
00169    ast_cli(fd,
00170            "---------------------------------------------------------------------\n"
00171            "---------------------------------------------------------------------\n"
00172            "\n");
00173 
00174    return RESULT_SUCCESS;
00175 }

static int custom_devstate_callback ( const char *  data  )  [static]

Definition at line 136 of file func_devstate.c.

References ast_db_get(), and ast_devstate_val().

Referenced by load_module().

00137 {
00138    char buf[256] = "";
00139 
00140    ast_db_get(astdb_family, data, buf, sizeof(buf));
00141 
00142    return ast_devstate_val(buf);
00143 }

static int devstate_read ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 106 of file func_devstate.c.

References ast_device_state(), and ast_devstate_str().

00108 {
00109    ast_copy_string(buf, ast_devstate_str(ast_device_state(data)), len);
00110 
00111    return 0;
00112 }

static int devstate_write ( struct ast_channel chan,
char *  function,
char *  data,
const char *  value 
) [static]

Definition at line 114 of file func_devstate.c.

References ast_db_put(), ast_device_state_changed(), ast_log(), ast_strlen_zero(), len, and LOG_WARNING.

00116 {
00117    size_t len = strlen("Custom:");
00118 
00119    if (strncasecmp(data, "Custom:", len)) {
00120       ast_log(LOG_WARNING, "The DEVSTATE function can only be used to set 'Custom:' device state!\n");
00121       return -1;
00122    }
00123    data += len;
00124    if (ast_strlen_zero(data)) {
00125       ast_log(LOG_WARNING, "DEVSTATE function called with no custom device name!\n");
00126       return -1;
00127    }
00128 
00129    ast_db_put(astdb_family, data, (char *) value);
00130 
00131    ast_device_state_changed("Custom:%s", data);
00132 
00133    return 0;
00134 }

static int load_module ( void   )  [static]

static int unload_module ( void   )  [static]

Definition at line 206 of file func_devstate.c.

References ARRAY_LEN, ast_cli_unregister_multiple(), ast_custom_function_unregister(), and ast_devstate_prov_del().

00207 {
00208    int res = 0;
00209 
00210    res |= ast_custom_function_unregister(&devstate_function);
00211    ast_devstate_prov_del("Custom");
00212    ast_cli_unregister_multiple(cli_funcdevstate, ARRAY_LEN(cli_funcdevstate));
00213 
00214    return res;
00215 }


Variable Documentation

const char astdb_family[] = "CustomDevstate" [static]

Definition at line 46 of file func_devstate.c.

struct ast_cli_entry cli_funcdevstate[] [static]

Initial value:

 {
   { { "funcdevstate", "list", }, cli_funcdevstate_list, NULL, NULL },
}

Definition at line 177 of file func_devstate.c.

Definition at line 181 of file func_devstate.c.


Generated on Sun Jun 12 16:37:58 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.6