Thu Jul 9 13:41:19 2009

Asterisk developer's documentation


func_channel.c File Reference

Channel info dialplan function. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/indications.h"
#include "asterisk/stringfields.h"

Go to the source code of this file.

Defines

#define locked_copy_string(chan, dest, source, len)
#define locked_string_field_set(chan, field, source)

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int func_channel_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
static int func_channel_write (struct ast_channel *chan, const char *function, char *data, const char *value)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Channel information dialplan function" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, }
static const struct ast_module_infoast_module_info = &__mod_info
static struct ast_custom_function channel_function
char * transfercapability_table [0x20]


Detailed Description

Channel info dialplan function.

Author:
Kevin P. Fleming <kpfleming@digium.com>

Definition in file func_channel.c.


Define Documentation

#define locked_copy_string ( chan,
dest,
source,
len   ) 

Value:

do { \
      ast_channel_lock(chan); \
      ast_copy_string(dest, source, len); \
      ast_channel_unlock(chan); \
   } while (0)

Definition at line 38 of file func_channel.c.

Referenced by func_channel_read().

#define locked_string_field_set ( chan,
field,
source   ) 

Value:

do { \
      ast_channel_lock(chan); \
      ast_string_field_set(chan, field, source); \
      ast_channel_unlock(chan); \
   } while (0)

Definition at line 44 of file func_channel.c.

Referenced by func_channel_write().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 232 of file func_channel.c.

static void __unreg_module ( void   )  [static]

Definition at line 232 of file func_channel.c.

static int func_channel_read ( struct ast_channel chan,
const char *  function,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 57 of file func_channel.c.

References ast_channel::_state, ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, ast_getformatname(), ast_log(), ast_print_group(), ast_state2str(), ast_channel::callgroup, chan, tone_zone::country, ast_channel_tech::func_channel_read, ast_channel::language, locked_copy_string, LOG_WARNING, ast_channel::musicclass, ast_channel::nativeformats, ast_channel::readformat, ast_channel::tech, ast_channel::transfercapability, ast_channel_tech::type, ast_channel::writeformat, and ast_channel::zone.

00059 {
00060    int ret = 0;
00061 
00062    if (!strcasecmp(data, "audionativeformat"))
00063       /* use the _multiple version when chan->nativeformats holds multiple formats */
00064       /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_AUDIO_MASK); */
00065       ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_AUDIO_MASK), len);
00066    else if (!strcasecmp(data, "videonativeformat"))
00067       /* use the _multiple version when chan->nativeformats holds multiple formats */
00068       /* ast_getformatname_multiple(buf, len, chan->nativeformats & AST_FORMAT_VIDEO_MASK); */
00069       ast_copy_string(buf, ast_getformatname(chan->nativeformats & AST_FORMAT_VIDEO_MASK), len);
00070    else if (!strcasecmp(data, "audioreadformat"))
00071       ast_copy_string(buf, ast_getformatname(chan->readformat), len);
00072    else if (!strcasecmp(data, "audiowriteformat"))
00073       ast_copy_string(buf, ast_getformatname(chan->writeformat), len);
00074 #ifdef CHANNEL_TRACE
00075    else if (!strcasecmp(data, "trace")) {
00076       ast_channel_lock(chan);
00077       ast_copy_string(buf, ast_channel_trace_is_enabled(chan) ? "1" : "0", len);
00078       ast_channel_unlock(chan);
00079    }
00080 #endif
00081    else if (!strcasecmp(data, "tonezone") && chan->zone)
00082       locked_copy_string(chan, buf, chan->zone->country, len);
00083    else if (!strcasecmp(data, "language"))
00084       locked_copy_string(chan, buf, chan->language, len);
00085    else if (!strcasecmp(data, "musicclass"))
00086       locked_copy_string(chan, buf, chan->musicclass, len);
00087    else if (!strcasecmp(data, "state"))
00088       locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
00089    else if (!strcasecmp(data, "channeltype"))
00090       locked_copy_string(chan, buf, chan->tech->type, len);
00091    else if (!strcasecmp(data, "transfercapability"))
00092       locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len);
00093    else if (!strcasecmp(data, "callgroup")) {
00094       char groupbuf[256];
00095       locked_copy_string(chan, buf,  ast_print_group(groupbuf, sizeof(groupbuf), chan->callgroup), len);
00096    } else if (!chan->tech->func_channel_read
00097        || chan->tech->func_channel_read(chan, function, data, buf, len)) {
00098       ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n", data);
00099       ret = -1;
00100    }
00101 
00102    return ret;
00103 }

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

Definition at line 105 of file func_channel.c.

References ast_channel_lock, ast_channel_setoption(), ast_channel_unlock, ast_false(), ast_get_group(), ast_get_indication_zone(), ast_log(), AST_OPTION_RXGAIN, AST_OPTION_TXGAIN, ast_true(), ast_channel::callgroup, chan, ast_channel_tech::func_channel_write, language, locked_string_field_set, LOG_ERROR, LOG_WARNING, musicclass, ast_channel::tech, ast_channel::transfercapability, and ast_channel::zone.

00107 {
00108    int ret = 0;
00109    signed char gainset;
00110 
00111    if (!strcasecmp(data, "language"))
00112       locked_string_field_set(chan, language, value);
00113    else if (!strcasecmp(data, "musicclass"))
00114       locked_string_field_set(chan, musicclass, value);
00115 #ifdef CHANNEL_TRACE
00116    else if (!strcasecmp(data, "trace")) {
00117       ast_channel_lock(chan);
00118       if (ast_true(value)) 
00119          ret = ast_channel_trace_enable(chan);
00120       else if (ast_false(value)) 
00121          ret = ast_channel_trace_disable(chan);
00122       else {
00123          ret = -1;
00124          ast_log(LOG_WARNING, "Invalid value for CHANNEL(trace).");
00125       }
00126       ast_channel_unlock(chan);
00127    }
00128 #endif
00129    else if (!strcasecmp(data, "tonezone")) {
00130       struct tone_zone *new_zone;
00131       if (!(new_zone = ast_get_indication_zone(value))) {
00132          ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
00133          ret = -1;   
00134       } else 
00135          chan->zone = new_zone;
00136    } else if (!strcasecmp(data, "callgroup"))
00137       chan->callgroup = ast_get_group(value);
00138    else if (!strcasecmp(data, "txgain")) {
00139       sscanf(value, "%hhd", &gainset);
00140       ast_channel_setoption(chan, AST_OPTION_TXGAIN, &gainset, sizeof(gainset), 0);
00141    } else if (!strcasecmp(data, "rxgain")) {
00142       sscanf(value, "%hhd", &gainset);
00143       ast_channel_setoption(chan, AST_OPTION_RXGAIN, &gainset, sizeof(gainset), 0);
00144    } else if (!strcasecmp(data, "transfercapability")) {
00145       unsigned short i;
00146       for (i = 0; i < 0x20; i++) {
00147          if (!strcasecmp(transfercapability_table[i], value) && strcmp(value, "UNK")) {
00148             chan->transfercapability = i;
00149             break;
00150          }
00151       }
00152    } else if (!chan->tech->func_channel_write
00153        || chan->tech->func_channel_write(chan, function, data, value)) {
00154       ast_log(LOG_WARNING, "Unknown or unavailable item requested: '%s'\n",
00155             data);
00156       ret = -1;
00157    }
00158 
00159    return ret;
00160 }

static int load_module ( void   )  [static]

Definition at line 227 of file func_channel.c.

References ast_custom_function_register, and channel_function.

00228 {
00229    return ast_custom_function_register(&channel_function);
00230 }

static int unload_module ( void   )  [static]

Definition at line 222 of file func_channel.c.

References ast_custom_function_unregister(), and channel_function.

00223 {
00224    return ast_custom_function_unregister(&channel_function);
00225 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Channel information dialplan function" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static]

Definition at line 232 of file func_channel.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 232 of file func_channel.c.

struct ast_custom_function channel_function [static]

Definition at line 162 of file func_channel.c.

Referenced by load_module(), and unload_module().

char* transfercapability_table[0x20]

Initial value:

 {
   "SPEECH", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
   "DIGITAL", "RESTRICTED_DIGITAL", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
   "3K1AUDIO", "DIGITAL_W_TONES", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK",
   "VIDEO", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", "UNK", }

Definition at line 51 of file func_channel.c.


Generated on Thu Jul 9 13:41:19 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7