Wed Jan 8 2020 09:49:59

Asterisk developer's documentation


chan_console.c File Reference

Cross-platform console channel driver. More...

#include "asterisk.h"
#include <sys/signal.h>
#include <portaudio.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/causes.h"
#include "asterisk/cli.h"
#include "asterisk/musiconhold.h"
#include "asterisk/callerid.h"
#include "asterisk/astobj2.h"

Go to the source code of this file.

Data Structures

struct  console_pvt
 Console pvt structure. More...
 

Macros

#define console_pvt_lock(pvt)   ao2_lock(pvt)
 lock a console_pvt struct More...
 
#define console_pvt_unlock(pvt)   ao2_unlock(pvt)
 unlock a console_pvt struct More...
 
#define INPUT_CHANNELS   1
 Mono Input. More...
 
#define NUM_PVT_BUCKETS   7
 
#define NUM_SAMPLES   320
 The number of samples to configure the portaudio stream for. More...
 
#define OUTPUT_CHANNELS   1
 Mono Output. More...
 
#define SAMPLE_RATE   16000
 The sample rate to request from PortAudio. More...
 
#define SUPPORTED_FORMATS   ( AST_FORMAT_SLINEAR16 )
 Formats natively supported by this module. More...
 
#define TEXT_SIZE   256
 Maximum text message length. More...
 
#define V_BEGIN   " --- <(\"<) --- "
 Dance, Kirby, Dance! More...
 
#define V_END   " --- (>\")> ---\n"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static char * ast_ext_ctx (struct console_pvt *pvt, const char *src, char **ext, char **ctx)
 
static void build_device (struct ast_config *cfg, const char *name)
 
static char * cli_console_active (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_console_answer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 answer command from the console More...
 
static char * cli_console_autoanswer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_console_dial (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_console_flash (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_console_hangup (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_console_mute (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_console_sendtext (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Console send text CLI command. More...
 
static char * cli_list_available (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_list_devices (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static struct ast_channelconsole_new (struct console_pvt *pvt, const char *ext, const char *ctx, int state, const char *linkedid)
 
static void destroy_pvts (void)
 
static struct console_pvtfind_pvt (const char *name)
 
static struct console_pvtget_active_pvt (void)
 
static int init_pvt (struct console_pvt *pvt, const char *name)
 
static int load_config (int reload)
 Load the configuration. More...
 
static int load_module (void)
 
static int open_stream (struct console_pvt *pvt)
 
static int pvt_cmp_cb (void *obj, void *arg, int flags)
 
static void pvt_destructor (void *obj)
 
static int pvt_hash_cb (const void *obj, const int flags)
 
static int pvt_mark_destroy_cb (void *obj, void *arg, int flags)
 
static struct console_pvtref_pvt (struct console_pvt *pvt)
 
static int reload (void)
 
static void set_active (struct console_pvt *pvt, const char *value)
 
static void set_pvt_defaults (struct console_pvt *pvt)
 Set default values for a pvt struct. More...
 
static int start_stream (struct console_pvt *pvt)
 
static int stop_stream (struct console_pvt *pvt)
 
static void stop_streams (void)
 
static void store_callerid (struct console_pvt *pvt, const char *value)
 
static void store_config_core (struct console_pvt *pvt, const char *var, const char *value)
 Store a configuration parameter in a pvt struct. More...
 
static void * stream_monitor (void *data)
 Stream monitor thread. More...
 
static int unload_module (void)
 
static struct console_pvtunref_pvt (struct console_pvt *pvt)
 
static struct ast_channelconsole_request (const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
 
static int console_digit_begin (struct ast_channel *c, char digit)
 
static int console_digit_end (struct ast_channel *c, char digit, unsigned int duration)
 
static int console_text (struct ast_channel *c, const char *text)
 
static int console_hangup (struct ast_channel *c)
 
static int console_answer (struct ast_channel *c)
 
static struct ast_frameconsole_read (struct ast_channel *chan)
 
static int console_call (struct ast_channel *c, char *dest, int timeout)
 
static int console_write (struct ast_channel *chan, struct ast_frame *f)
 
static int console_indicate (struct ast_channel *chan, int cond, const void *data, size_t datalen)
 
static int console_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Console Channel Driver" , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DRIVER, }
 
static ast_rwlock_t active_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, 1 }
 
static struct console_pvtactive_pvt
 
static struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_console []
 
static const char config_file [] = "console.conf"
 
static struct ast_channel_tech console_tech
 
static struct ast_jb_conf default_jbconf
 Global jitterbuffer configuration. More...
 
static struct ast_jb_conf global_jbconf
 
static struct console_pvt globals
 
static ast_mutex_t globals_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
 
static struct ao2_containerpvts
 

Detailed Description

Cross-platform console channel driver.

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com
Note
Some of the code in this file came from chan_oss and chan_alsa. chan_oss, Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m chan_oss, Luigi Rizzo chan_alsa, Matthew Fredrickson cresl.nosp@m.in@d.nosp@m.igium.nosp@m..com
ExtRef:
Portaudio http://www.portaudio.com/

To install portaudio v19 from svn, check it out using the following command:

Note
Since this works with any audio system that libportaudio supports, including ALSA and OSS, this may someday deprecate chan_alsa and chan_oss. However, before that can be done, it needs to at least have all of the features that these other channel drivers have. The features implemented in at least one of the other console channel drivers that are not yet implemented here are:
  • Set Auto-answer from the dialplan
  • transfer CLI command
  • boost CLI command and .conf option
  • console_video support

Definition in file chan_console.c.

Macro Definition Documentation

#define console_pvt_lock (   pvt)    ao2_lock(pvt)
#define console_pvt_unlock (   pvt)    ao2_unlock(pvt)
#define INPUT_CHANNELS   1

Mono Input.

Definition at line 93 of file chan_console.c.

Referenced by open_stream().

#define NUM_PVT_BUCKETS   7

Definition at line 167 of file chan_console.c.

Referenced by load_module().

#define NUM_SAMPLES   320

The number of samples to configure the portaudio stream for.

320 samples (20 ms) is the most common frame size in Asterisk. So, the code in this module reads 320 sample frames from the portaudio stream and queues them up on the Asterisk channel. Frames of any size can be written to a portaudio stream, but the portaudio documentation does say that for high performance applications, the data should be written to Pa_WriteStream in the same size as what is used to initialize the stream.

Definition at line 90 of file chan_console.c.

Referenced by open_stream(), and stream_monitor().

#define OUTPUT_CHANNELS   1

Mono Output.

Definition at line 96 of file chan_console.c.

Referenced by open_stream().

#define SAMPLE_RATE   16000

The sample rate to request from PortAudio.

Todo:
Make this optional. If this is only going to talk to 8 kHz endpoints, then it makes sense to use 8 kHz natively.

Definition at line 78 of file chan_console.c.

Referenced by open_stream().

#define SUPPORTED_FORMATS   ( AST_FORMAT_SLINEAR16 )

Formats natively supported by this module.

Definition at line 206 of file chan_console.c.

Referenced by console_request().

#define TEXT_SIZE   256

Maximum text message length.

Note
This should be changed if there is a common definition somewhere that defines the maximum length of a text message.

Definition at line 103 of file chan_console.c.

Referenced by cli_console_sendtext().

#define V_BEGIN   " --- <(\"<) --- "
#define V_END   " --- (>\")> ---\n"

Function Documentation

static void __reg_module ( void  )
static

Definition at line 1532 of file chan_console.c.

static void __unreg_module ( void  )
static

Definition at line 1532 of file chan_console.c.

static char* ast_ext_ctx ( struct console_pvt pvt,
const char *  src,
char **  ext,
char **  ctx 
)
static

split a string in extension-context, returns pointers to malloc'ed strings. If we do not have 'overridecontext' then the last @ is considered as a context separator, and the context is overridden. This is usually not very necessary as you can play with the dialplan, and it is nice not to need it because you have '@' in SIP addresses. Return value is the buffer address.

Note
came from chan_oss

Definition at line 660 of file chan_console.c.

References ast_strdup, ext, and console_pvt::overridecontext.

Referenced by cli_console_dial().

661 {
662  if (ext == NULL || ctx == NULL)
663  return NULL; /* error */
664 
665  *ext = *ctx = NULL;
666 
667  if (src && *src != '\0')
668  *ext = ast_strdup(src);
669 
670  if (*ext == NULL)
671  return NULL;
672 
673  if (!pvt->overridecontext) {
674  /* parse from the right */
675  *ctx = strrchr(*ext, '@');
676  if (*ctx)
677  *(*ctx)++ = '\0';
678  }
679 
680  return *ext;
681 }
#define ast_strdup(a)
Definition: astmm.h:109
unsigned int overridecontext
Definition: chan_console.c:156
const char * ext
Definition: http.c:112
static void build_device ( struct ast_config cfg,
const char *  name 
)
static

Definition at line 1332 of file chan_console.c.

References ao2_alloc, ao2_link, ast_variable_browse(), console_pvt_lock, console_pvt_unlock, console_pvt::destroy, find_pvt(), init_pvt(), ast_variable::name, ast_variable::next, pvt_destructor(), set_pvt_defaults(), store_config_core(), unref_pvt(), and ast_variable::value.

Referenced by load_config().

1333 {
1334  struct ast_variable *v;
1335  struct console_pvt *pvt;
1336  int new = 0;
1337 
1338  if ((pvt = find_pvt(name))) {
1339  console_pvt_lock(pvt);
1340  set_pvt_defaults(pvt);
1341  pvt->destroy = 0;
1342  } else {
1343  if (!(pvt = ao2_alloc(sizeof(*pvt), pvt_destructor)))
1344  return;
1345  init_pvt(pvt, name);
1346  set_pvt_defaults(pvt);
1347  new = 1;
1348  }
1349 
1350  for (v = ast_variable_browse(cfg, name); v; v = v->next)
1351  store_config_core(pvt, v->name, v->value);
1352 
1353  if (new)
1354  ao2_link(pvts, pvt);
1355  else
1356  console_pvt_unlock(pvt);
1357 
1358  unref_pvt(pvt);
1359 }
#define ao2_link(arg1, arg2)
Definition: astobj2.h:785
static void set_pvt_defaults(struct console_pvt *pvt)
Set default values for a pvt struct.
unsigned int destroy
Definition: chan_console.c:159
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
Console pvt structure.
Definition: chan_console.c:118
const char * value
Definition: config.h:79
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
Definition: chan_console.c:229
const char * name
Definition: config.h:77
static struct ao2_container * pvts
Definition: chan_console.c:166
static void store_config_core(struct console_pvt *pvt, const char *var, const char *value)
Store a configuration parameter in a pvt struct.
static int init_pvt(struct console_pvt *pvt, const char *name)
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
static const char name[]
#define console_pvt_lock(pvt)
lock a console_pvt struct
Definition: chan_console.c:226
struct ast_variable * next
Definition: config.h:82
static struct console_pvt * find_pvt(const char *name)
Definition: chan_console.c:244
static void pvt_destructor(void *obj)
static char* cli_console_active ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 1155 of file chan_console.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ast_strdup, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, console_pvt_lock, console_pvt_unlock, ast_cli_args::fd, find_pvt(), get_active_pvt(), ast_cli_args::n, console_pvt::name, ast_cli_args::pos, set_active(), unref_pvt(), ast_cli_entry::usage, and ast_cli_args::word.

1156 {
1157  struct console_pvt *pvt;
1158 
1159  switch (cmd) {
1160  case CLI_INIT:
1161  e->command = "console {set|show} active";
1162  e->usage =
1163  "Usage: console {set|show} active [<device>]\n"
1164  " Set or show the active console device for the Asterisk CLI.\n";
1165  return NULL;
1166  case CLI_GENERATE:
1167  if (a->pos == e->args) {
1168  struct ao2_iterator i;
1169  int x = 0;
1170  char *res = NULL;
1171  i = ao2_iterator_init(pvts, 0);
1172  while ((pvt = ao2_iterator_next(&i))) {
1173  if (++x > a->n && !strncasecmp(pvt->name, a->word, strlen(a->word)))
1174  res = ast_strdup(pvt->name);
1175  unref_pvt(pvt);
1176  if (res) {
1178  return res;
1179  }
1180  }
1182  }
1183  return NULL;
1184  }
1185 
1186  if (a->argc < e->args)
1187  return CLI_SHOWUSAGE;
1188 
1189  if (a->argc == 3) {
1190  pvt = get_active_pvt();
1191 
1192  if (!pvt)
1193  ast_cli(a->fd, "No device is currently set as the active console device.\n");
1194  else {
1195  console_pvt_lock(pvt);
1196  ast_cli(a->fd, "The active console device is '%s'.\n", pvt->name);
1197  console_pvt_unlock(pvt);
1198  pvt = unref_pvt(pvt);
1199  }
1200 
1201  return CLI_SUCCESS;
1202  }
1203 
1204  if (!(pvt = find_pvt(a->argv[e->args - 1]))) {
1205  ast_cli(a->fd, "Could not find a device called '%s'.\n", a->argv[e->args]);
1206  return CLI_FAILURE;
1207  }
1208 
1209  set_active(pvt, "yes");
1210 
1211  console_pvt_lock(pvt);
1212  ast_cli(a->fd, "The active console device has been set to '%s'\n", pvt->name);
1213  console_pvt_unlock(pvt);
1214 
1215  unref_pvt(pvt);
1216 
1217  return CLI_SUCCESS;
1218 }
#define ast_strdup(a)
Definition: astmm.h:109
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
const int argc
Definition: cli.h:154
Definition: cli.h:146
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
const int fd
Definition: cli.h:153
const int n
Definition: cli.h:159
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
Definition: chan_console.c:229
static struct ao2_container * pvts
Definition: chan_console.c:166
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
static void set_active(struct console_pvt *pvt, const char *value)
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
const char * word
Definition: cli.h:157
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Definition: astobj2.c:833
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1053
const int pos
Definition: cli.h:158
static struct console_pvt * get_active_pvt(void)
Definition: chan_console.c:683
#define console_pvt_lock(pvt)
lock a console_pvt struct
Definition: chan_console.c:226
static struct console_pvt * find_pvt(const char *name)
Definition: chan_console.c:244
const ast_string_field name
Definition: chan_console.c:140
static char* cli_console_answer ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

answer command from the console

Definition at line 1036 of file chan_console.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli(), AST_CONTROL_ANSWER, ast_indicate(), ast_queue_control(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, get_active_pvt(), console_pvt::hookstate, console_pvt::owner, unref_pvt(), and ast_cli_entry::usage.

1037 {
1038  struct console_pvt *pvt = get_active_pvt();
1039 
1040  switch (cmd) {
1041  case CLI_INIT:
1042  e->command = "console answer";
1043  e->usage =
1044  "Usage: console answer\n"
1045  " Answers an incoming call on the console channel.\n";
1046  return NULL;
1047 
1048  case CLI_GENERATE:
1049  return NULL; /* no completion */
1050  }
1051 
1052  if (!pvt) {
1053  ast_cli(a->fd, "No console device is set as active\n");
1054  return CLI_FAILURE;
1055  }
1056 
1057  if (a->argc != e->args) {
1058  unref_pvt(pvt);
1059  return CLI_SHOWUSAGE;
1060  }
1061 
1062  if (!pvt->owner) {
1063  ast_cli(a->fd, "No one is calling us\n");
1064  unref_pvt(pvt);
1065  return CLI_FAILURE;
1066  }
1067 
1068  pvt->hookstate = 1;
1069 
1070  ast_indicate(pvt->owner, -1);
1071 
1073 
1074  unref_pvt(pvt);
1075 
1076  return CLI_SUCCESS;
1077 }
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
const int argc
Definition: cli.h:154
Definition: cli.h:146
struct ast_channel * owner
Definition: chan_console.c:142
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
const int fd
Definition: cli.h:153
unsigned int hookstate
Definition: chan_console.c:150
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static struct console_pvt * get_active_pvt(void)
Definition: chan_console.c:683
static char* cli_console_autoanswer ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 694 of file chan_console.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), console_pvt::autoanswer, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, get_active_pvt(), unref_pvt(), and ast_cli_entry::usage.

696 {
697  struct console_pvt *pvt = get_active_pvt();
698  char *res = CLI_SUCCESS;
699 
700  switch (cmd) {
701  case CLI_INIT:
702  e->command = "console {set|show} autoanswer [on|off]";
703  e->usage =
704  "Usage: console {set|show} autoanswer [on|off]\n"
705  " Enables or disables autoanswer feature. If used without\n"
706  " argument, displays the current on/off status of autoanswer.\n"
707  " The default value of autoanswer is in 'oss.conf'.\n";
708  return NULL;
709 
710  case CLI_GENERATE:
711  return NULL;
712  }
713 
714  if (!pvt) {
715  ast_cli(a->fd, "No console device is set as active.\n");
716  return CLI_FAILURE;
717  }
718 
719  if (a->argc == e->args - 1) {
720  ast_cli(a->fd, "Auto answer is %s.\n", pvt->autoanswer ? "on" : "off");
721  unref_pvt(pvt);
722  return CLI_SUCCESS;
723  }
724 
725  if (a->argc != e->args) {
726  unref_pvt(pvt);
727  return CLI_SHOWUSAGE;
728  }
729 
730  if (!strcasecmp(a->argv[e->args-1], "on"))
731  pvt->autoanswer = 1;
732  else if (!strcasecmp(a->argv[e->args - 1], "off"))
733  pvt->autoanswer = 0;
734  else
735  res = CLI_SHOWUSAGE;
736 
737  unref_pvt(pvt);
738 
739  return res;
740 }
const int argc
Definition: cli.h:154
Definition: cli.h:146
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
unsigned int autoanswer
Definition: chan_console.c:154
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static struct console_pvt * get_active_pvt(void)
Definition: chan_console.c:683
static char* cli_console_dial ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 778 of file chan_console.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ast_debug, ast_exists_extension(), ast_ext_ctx(), AST_FRAME_DTMF, ast_queue_frame(), AST_STATE_RINGING, ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, console_new(), console_pvt_lock, console_pvt_unlock, console_pvt::context, ext, console_pvt::exten, ast_cli_args::fd, free, get_active_pvt(), console_pvt::hookstate, ast_frame_subclass::integer, console_pvt::owner, ast_frame::subclass, unref_pvt(), and ast_cli_entry::usage.

779 {
780  char *s = NULL;
781  const char *mye = NULL, *myc = NULL;
782  struct console_pvt *pvt = get_active_pvt();
783 
784  if (cmd == CLI_INIT) {
785  e->command = "console dial";
786  e->usage =
787  "Usage: console dial [extension[@context]]\n"
788  " Dials a given extension (and context if specified)\n";
789  return NULL;
790  } else if (cmd == CLI_GENERATE)
791  return NULL;
792 
793  if (!pvt) {
794  ast_cli(a->fd, "No console device is currently set as active\n");
795  return CLI_FAILURE;
796  }
797 
798  if (a->argc > e->args + 1)
799  return CLI_SHOWUSAGE;
800 
801  if (pvt->owner) { /* already in a call */
802  int i;
803  struct ast_frame f = { AST_FRAME_DTMF };
804  const char *s;
805 
806  if (a->argc == e->args) { /* argument is mandatory here */
807  ast_cli(a->fd, "Already in a call. You can only dial digits until you hangup.\n");
808  unref_pvt(pvt);
809  return CLI_FAILURE;
810  }
811  s = a->argv[e->args];
812  /* send the string one char at a time */
813  for (i = 0; i < strlen(s); i++) {
814  f.subclass.integer = s[i];
815  ast_queue_frame(pvt->owner, &f);
816  }
817  unref_pvt(pvt);
818  return CLI_SUCCESS;
819  }
820 
821  /* if we have an argument split it into extension and context */
822  if (a->argc == e->args + 1) {
823  char *ext = NULL, *con = NULL;
824  s = ast_ext_ctx(pvt, a->argv[e->args], &ext, &con);
825  ast_debug(1, "provided '%s', exten '%s' context '%s'\n",
826  a->argv[e->args], mye, myc);
827  mye = ext;
828  myc = con;
829  }
830 
831  /* supply default values if needed */
832  if (ast_strlen_zero(mye))
833  mye = pvt->exten;
834  if (ast_strlen_zero(myc))
835  myc = pvt->context;
836 
837  if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
838  console_pvt_lock(pvt);
839  pvt->hookstate = 1;
840  console_new(pvt, mye, myc, AST_STATE_RINGING, NULL);
841  console_pvt_unlock(pvt);
842  } else
843  ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc);
844 
845  free(s);
846 
847  unref_pvt(pvt);
848 
849  return CLI_SUCCESS;
850 }
union ast_frame_subclass subclass
Definition: frame.h:146
const ast_string_field context
Definition: chan_console.c:140
const int argc
Definition: cli.h:154
#define AST_FRAME_DTMF
Definition: frame.h:128
Definition: cli.h:146
struct ast_channel * owner
Definition: chan_console.c:142
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
const char * ext
Definition: http.c:112
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
static char * ast_ext_ctx(struct console_pvt *pvt, const char *src, char **ext, char **ctx)
Definition: chan_console.c:660
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
const int fd
Definition: cli.h:153
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
Definition: chan_console.c:229
static struct ast_channel * console_new(struct console_pvt *pvt, const char *ext, const char *ctx, int state, const char *linkedid)
Definition: chan_console.c:419
unsigned int hookstate
Definition: chan_console.c:150
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:5400
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1558
const char *const * argv
Definition: cli.h:155
#define free(a)
Definition: astmm.h:94
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
static struct ast_format f[]
Definition: format_g726.c:181
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
Data structure associated with a single frame of data.
Definition: frame.h:142
static struct console_pvt * get_active_pvt(void)
Definition: chan_console.c:683
#define console_pvt_lock(pvt)
lock a console_pvt struct
Definition: chan_console.c:226
const ast_string_field exten
Definition: chan_console.c:140
static char* cli_console_flash ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 742 of file chan_console.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli(), AST_CONTROL_FLASH, ast_queue_control(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, get_active_pvt(), console_pvt::hookstate, console_pvt::owner, unref_pvt(), and ast_cli_entry::usage.

743 {
744  struct console_pvt *pvt = get_active_pvt();
745 
746  if (cmd == CLI_INIT) {
747  e->command = "console flash";
748  e->usage =
749  "Usage: console flash\n"
750  " Flashes the call currently placed on the console.\n";
751  return NULL;
752  } else if (cmd == CLI_GENERATE)
753  return NULL;
754 
755  if (!pvt) {
756  ast_cli(a->fd, "No console device is set as active\n");
757  return CLI_FAILURE;
758  }
759 
760  if (a->argc != e->args)
761  return CLI_SHOWUSAGE;
762 
763  if (!pvt->owner) {
764  ast_cli(a->fd, "No call to flash\n");
765  unref_pvt(pvt);
766  return CLI_FAILURE;
767  }
768 
769  pvt->hookstate = 0;
770 
772 
773  unref_pvt(pvt);
774 
775  return CLI_SUCCESS;
776 }
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
const int argc
Definition: cli.h:154
Definition: cli.h:146
struct ast_channel * owner
Definition: chan_console.c:142
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
const int fd
Definition: cli.h:153
unsigned int hookstate
Definition: chan_console.c:150
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static struct console_pvt * get_active_pvt(void)
Definition: chan_console.c:683
static char* cli_console_hangup ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 852 of file chan_console.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli(), ast_queue_hangup(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, get_active_pvt(), console_pvt::hookstate, console_pvt::owner, unref_pvt(), and ast_cli_entry::usage.

853 {
854  struct console_pvt *pvt = get_active_pvt();
855 
856  if (cmd == CLI_INIT) {
857  e->command = "console hangup";
858  e->usage =
859  "Usage: console hangup\n"
860  " Hangs up any call currently placed on the console.\n";
861  return NULL;
862  } else if (cmd == CLI_GENERATE)
863  return NULL;
864 
865  if (!pvt) {
866  ast_cli(a->fd, "No console device is set as active\n");
867  return CLI_FAILURE;
868  }
869 
870  if (a->argc != e->args)
871  return CLI_SHOWUSAGE;
872 
873  if (!pvt->owner && !pvt->hookstate) {
874  ast_cli(a->fd, "No call to hang up\n");
875  unref_pvt(pvt);
876  return CLI_FAILURE;
877  }
878 
879  pvt->hookstate = 0;
880  if (pvt->owner)
881  ast_queue_hangup(pvt->owner);
882 
883  unref_pvt(pvt);
884 
885  return CLI_SUCCESS;
886 }
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
Definition: channel.c:1569
const int argc
Definition: cli.h:154
Definition: cli.h:146
struct ast_channel * owner
Definition: chan_console.c:142
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
const int fd
Definition: cli.h:153
unsigned int hookstate
Definition: chan_console.c:150
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static struct console_pvt * get_active_pvt(void)
Definition: chan_console.c:683
static char* cli_console_mute ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 888 of file chan_console.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ast_verb, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, get_active_pvt(), console_pvt::muted, unref_pvt(), ast_cli_entry::usage, V_BEGIN, and V_END.

889 {
890  const char *s;
891  struct console_pvt *pvt = get_active_pvt();
892  char *res = CLI_SUCCESS;
893 
894  if (cmd == CLI_INIT) {
895  e->command = "console {mute|unmute}";
896  e->usage =
897  "Usage: console {mute|unmute}\n"
898  " Mute/unmute the microphone.\n";
899  return NULL;
900  } else if (cmd == CLI_GENERATE)
901  return NULL;
902 
903  if (!pvt) {
904  ast_cli(a->fd, "No console device is set as active\n");
905  return CLI_FAILURE;
906  }
907 
908  if (a->argc != e->args)
909  return CLI_SHOWUSAGE;
910 
911  s = a->argv[e->args-1];
912  if (!strcasecmp(s, "mute"))
913  pvt->muted = 1;
914  else if (!strcasecmp(s, "unmute"))
915  pvt->muted = 0;
916  else
917  res = CLI_SHOWUSAGE;
918 
919  ast_verb(1, V_BEGIN "The Console is now %s" V_END,
920  pvt->muted ? "Muted" : "Unmuted");
921 
922  unref_pvt(pvt);
923 
924  return res;
925 }
unsigned int muted
Definition: chan_console.c:152
const int argc
Definition: cli.h:154
Definition: cli.h:146
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
#define ast_verb(level,...)
Definition: logger.h:243
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define V_END
Definition: chan_console.c:107
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
#define V_BEGIN
Dance, Kirby, Dance!
Definition: chan_console.c:106
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static struct console_pvt * get_active_pvt(void)
Definition: chan_console.c:683
static char* cli_console_sendtext ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Console send text CLI command.

Note
concatenate all arguments into a single string. argv is NULL-terminated so we can use it right away

Definition at line 1085 of file chan_console.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), AST_FRAME_TEXT, ast_join(), ast_queue_frame(), ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_frame::datalen, ast_cli_args::fd, ast_frame::frametype, get_active_pvt(), len(), console_pvt::owner, TEXT_SIZE, unref_pvt(), and ast_cli_entry::usage.

1086 {
1087  char buf[TEXT_SIZE];
1088  struct console_pvt *pvt = get_active_pvt();
1089  struct ast_frame f = {
1090  .frametype = AST_FRAME_TEXT,
1091  .data.ptr = buf,
1092  .src = "console_send_text",
1093  };
1094  int len;
1095 
1096  if (cmd == CLI_INIT) {
1097  e->command = "console send text";
1098  e->usage =
1099  "Usage: console send text <message>\n"
1100  " Sends a text message for display on the remote terminal.\n";
1101  return NULL;
1102  } else if (cmd == CLI_GENERATE)
1103  return NULL;
1104 
1105  if (!pvt) {
1106  ast_cli(a->fd, "No console device is set as active\n");
1107  return CLI_FAILURE;
1108  }
1109 
1110  if (a->argc < e->args + 1) {
1111  unref_pvt(pvt);
1112  return CLI_SHOWUSAGE;
1113  }
1114 
1115  if (!pvt->owner) {
1116  ast_cli(a->fd, "Not in a call\n");
1117  unref_pvt(pvt);
1118  return CLI_FAILURE;
1119  }
1120 
1121  ast_join(buf, sizeof(buf) - 1, a->argv + e->args);
1122  if (ast_strlen_zero(buf)) {
1123  unref_pvt(pvt);
1124  return CLI_SHOWUSAGE;
1125  }
1126 
1127  len = strlen(buf);
1128  buf[len] = '\n';
1129  f.datalen = len + 1;
1130 
1131  ast_queue_frame(pvt->owner, &f);
1132 
1133  unref_pvt(pvt);
1134 
1135  return CLI_SUCCESS;
1136 }
const int argc
Definition: cli.h:154
Definition: cli.h:146
struct ast_channel * owner
Definition: chan_console.c:142
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
#define TEXT_SIZE
Maximum text message length.
Definition: chan_console.c:103
const int fd
Definition: cli.h:153
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int datalen
Definition: frame.h:148
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1558
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
void ast_join(char *s, size_t len, const char *const w[])
Definition: utils.c:1690
static struct ast_format f[]
Definition: format_g726.c:181
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
Data structure associated with a single frame of data.
Definition: frame.h:142
static struct console_pvt * get_active_pvt(void)
Definition: chan_console.c:683
static char* cli_list_available ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 927 of file chan_console.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.

928 {
929  PaDeviceIndex idx, num, def_input, def_output;
930 
931  if (cmd == CLI_INIT) {
932  e->command = "console list available";
933  e->usage =
934  "Usage: console list available\n"
935  " List all available devices.\n";
936  return NULL;
937  } else if (cmd == CLI_GENERATE)
938  return NULL;
939 
940  if (a->argc != e->args)
941  return CLI_SHOWUSAGE;
942 
943  ast_cli(a->fd, "\n"
944  "=============================================================\n"
945  "=== Available Devices =======================================\n"
946  "=============================================================\n"
947  "===\n");
948 
949  num = Pa_GetDeviceCount();
950  if (!num) {
951  ast_cli(a->fd, "(None)\n");
952  return CLI_SUCCESS;
953  }
954 
955  def_input = Pa_GetDefaultInputDevice();
956  def_output = Pa_GetDefaultOutputDevice();
957  for (idx = 0; idx < num; idx++) {
958  const PaDeviceInfo *dev = Pa_GetDeviceInfo(idx);
959  if (!dev)
960  continue;
961  ast_cli(a->fd, "=== ---------------------------------------------------------\n"
962  "=== Device Name: %s\n", dev->name);
963  if (dev->maxInputChannels)
964  ast_cli(a->fd, "=== ---> %sInput Device\n", (idx == def_input) ? "Default " : "");
965  if (dev->maxOutputChannels)
966  ast_cli(a->fd, "=== ---> %sOutput Device\n", (idx == def_output) ? "Default " : "");
967  ast_cli(a->fd, "=== ---------------------------------------------------------\n===\n");
968  }
969 
970  ast_cli(a->fd, "=============================================================\n\n");
971 
972  return CLI_SUCCESS;
973 }
const int argc
Definition: cli.h:154
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
int args
This gets set in ast_cli_register()
Definition: cli.h:179
const int fd
Definition: cli.h:153
#define CLI_SHOWUSAGE
Definition: cli.h:44
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static char* cli_list_devices ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 975 of file chan_console.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ast_cli_args::argc, ast_cli_entry::args, ast_cli(), console_pvt::autoanswer, console_pvt::cid_name, console_pvt::cid_num, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, console_pvt_lock, console_pvt_unlock, console_pvt::context, console_pvt::exten, ast_cli_args::fd, console_pvt::input_device, console_pvt::language, console_pvt::mohinterpret, console_pvt::muted, console_pvt::name, console_pvt::output_device, console_pvt::overridecontext, console_pvt::parkinglot, unref_pvt(), and ast_cli_entry::usage.

976 {
977  struct ao2_iterator i;
978  struct console_pvt *pvt;
979 
980  if (cmd == CLI_INIT) {
981  e->command = "console list devices";
982  e->usage =
983  "Usage: console list devices\n"
984  " List all configured devices.\n";
985  return NULL;
986  } else if (cmd == CLI_GENERATE)
987  return NULL;
988 
989  if (a->argc != e->args)
990  return CLI_SHOWUSAGE;
991 
992  ast_cli(a->fd, "\n"
993  "=============================================================\n"
994  "=== Configured Devices ======================================\n"
995  "=============================================================\n"
996  "===\n");
997 
998  i = ao2_iterator_init(pvts, 0);
999  while ((pvt = ao2_iterator_next(&i))) {
1000  console_pvt_lock(pvt);
1001 
1002  ast_cli(a->fd, "=== ---------------------------------------------------------\n"
1003  "=== Device Name: %s\n"
1004  "=== ---> Active: %s\n"
1005  "=== ---> Input Device: %s\n"
1006  "=== ---> Output Device: %s\n"
1007  "=== ---> Context: %s\n"
1008  "=== ---> Extension: %s\n"
1009  "=== ---> CallerID Num: %s\n"
1010  "=== ---> CallerID Name: %s\n"
1011  "=== ---> MOH Interpret: %s\n"
1012  "=== ---> Language: %s\n"
1013  "=== ---> Parkinglot: %s\n"
1014  "=== ---> Muted: %s\n"
1015  "=== ---> Auto-Answer: %s\n"
1016  "=== ---> Override Context: %s\n"
1017  "=== ---------------------------------------------------------\n===\n",
1018  pvt->name, (pvt == active_pvt) ? "Yes" : "No",
1019  pvt->input_device, pvt->output_device, pvt->context,
1020  pvt->exten, pvt->cid_num, pvt->cid_name, pvt->mohinterpret,
1021  pvt->language, pvt->parkinglot, pvt->muted ? "Yes" : "No", pvt->autoanswer ? "Yes" : "No",
1022  pvt->overridecontext ? "Yes" : "No");
1023 
1024  console_pvt_unlock(pvt);
1025  unref_pvt(pvt);
1026  }
1028 
1029  ast_cli(a->fd, "=============================================================\n\n");
1030 
1031  return CLI_SUCCESS;
1032 }
unsigned int muted
Definition: chan_console.c:152
const ast_string_field cid_num
Definition: chan_console.c:140
const ast_string_field context
Definition: chan_console.c:140
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
const int argc
Definition: cli.h:154
unsigned int overridecontext
Definition: chan_console.c:156
Definition: cli.h:146
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
const ast_string_field parkinglot
Definition: chan_console.c:140
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
unsigned int autoanswer
Definition: chan_console.c:154
int args
This gets set in ast_cli_register()
Definition: cli.h:179
Console pvt structure.
Definition: chan_console.c:118
const int fd
Definition: cli.h:153
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
Definition: chan_console.c:229
static struct ao2_container * pvts
Definition: chan_console.c:166
const ast_string_field language
Definition: chan_console.c:140
#define CLI_SHOWUSAGE
Definition: cli.h:44
char * command
Definition: cli.h:180
const ast_string_field input_device
Definition: chan_console.c:140
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Definition: astobj2.c:833
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static struct console_pvt * active_pvt
Definition: chan_console.c:169
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1053
const ast_string_field mohinterpret
Definition: chan_console.c:140
const ast_string_field output_device
Definition: chan_console.c:140
#define console_pvt_lock(pvt)
lock a console_pvt struct
Definition: chan_console.c:226
const ast_string_field name
Definition: chan_console.c:140
const ast_string_field cid_name
Definition: chan_console.c:140
const ast_string_field exten
Definition: chan_console.c:140
static int console_answer ( struct ast_channel c)
static

Definition at line 527 of file chan_console.c.

References ast_setstate(), AST_STATE_UP, ast_verb, start_stream(), ast_channel::tech_pvt, V_BEGIN, and V_END.

528 {
529  struct console_pvt *pvt = c->tech_pvt;
530 
531  ast_verb(1, V_BEGIN "Call from Console has been Answered" V_END);
532 
534 
535  return start_stream(pvt);
536 }
void * tech_pvt
Definition: channel.h:744
static int start_stream(struct console_pvt *pvt)
Definition: chan_console.c:354
#define ast_verb(level,...)
Definition: logger.h:243
Console pvt structure.
Definition: chan_console.c:118
#define V_END
Definition: chan_console.c:107
#define V_BEGIN
Dance, Kirby, Dance!
Definition: chan_console.c:106
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7119
static int console_call ( struct ast_channel c,
char *  dest,
int  timeout 
)
static

Definition at line 565 of file chan_console.c.

References AST_CONTROL_ANSWER, AST_CONTROL_RINGING, ast_indicate(), ast_queue_control(), ast_verb, console_pvt::autoanswer, ast_channel::caller, console_pvt_lock, console_pvt_unlock, console_pvt::hookstate, ast_party_caller::id, ast_party_id::name, ast_party_id::number, S_COR, start_stream(), ast_party_name::str, ast_party_number::str, ast_channel::tech_pvt, V_BEGIN, V_END, ast_party_name::valid, and ast_party_number::valid.

566 {
567  struct console_pvt *pvt = c->tech_pvt;
568  enum ast_control_frame_type ctrl;
569 
570  ast_verb(1, V_BEGIN "Call to device '%s' on console from '%s' <%s>" V_END,
571  dest,
572  S_COR(c->caller.id.name.valid, c->caller.id.name.str, ""),
573  S_COR(c->caller.id.number.valid, c->caller.id.number.str, ""));
574 
575  console_pvt_lock(pvt);
576 
577  if (pvt->autoanswer) {
578  pvt->hookstate = 1;
579  console_pvt_unlock(pvt);
580  ast_verb(1, V_BEGIN "Auto-answered" V_END);
581  ctrl = AST_CONTROL_ANSWER;
582  } else {
583  console_pvt_unlock(pvt);
584  ast_verb(1, V_BEGIN "Type 'console answer' to answer, or use the 'autoanswer' option "
585  "for future calls" V_END);
586  ctrl = AST_CONTROL_RINGING;
588  }
589 
590  ast_queue_control(c, ctrl);
591 
592  return start_stream(pvt);
593 }
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
struct ast_party_name name
Subscriber name.
Definition: channel.h:290
void * tech_pvt
Definition: channel.h:744
char * str
Subscriber name (Malloced)
Definition: channel.h:214
static int start_stream(struct console_pvt *pvt)
Definition: chan_console.c:354
#define ast_verb(level,...)
Definition: logger.h:243
unsigned int autoanswer
Definition: chan_console.c:154
Console pvt structure.
Definition: chan_console.c:118
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:83
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
Definition: chan_console.c:229
unsigned int hookstate
Definition: chan_console.c:150
ast_control_frame_type
Internal control frame subtype field values.
Definition: frame.h:319
#define V_END
Definition: chan_console.c:107
#define V_BEGIN
Dance, Kirby, Dance!
Definition: chan_console.c:106
#define console_pvt_lock(pvt)
lock a console_pvt struct
Definition: chan_console.c:226
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:229
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
static int console_digit_begin ( struct ast_channel c,
char  digit 
)
static

Definition at line 490 of file chan_console.c.

References ast_verb, V_BEGIN, and V_END.

491 {
492  ast_verb(1, V_BEGIN "Console Received Beginning of Digit %c" V_END, digit);
493 
494  return -1; /* non-zero to request inband audio */
495 }
#define ast_verb(level,...)
Definition: logger.h:243
#define V_END
Definition: chan_console.c:107
#define V_BEGIN
Dance, Kirby, Dance!
Definition: chan_console.c:106
static int console_digit_end ( struct ast_channel c,
char  digit,
unsigned int  duration 
)
static

Definition at line 497 of file chan_console.c.

References ast_verb, V_BEGIN, and V_END.

498 {
499  ast_verb(1, V_BEGIN "Console Received End of Digit %c (duration %u)" V_END,
500  digit, duration);
501 
502  return -1; /* non-zero to request inband audio */
503 }
#define ast_verb(level,...)
Definition: logger.h:243
#define V_END
Definition: chan_console.c:107
#define V_BEGIN
Dance, Kirby, Dance!
Definition: chan_console.c:106
static int console_fixup ( struct ast_channel oldchan,
struct ast_channel newchan 
)
static

Definition at line 640 of file chan_console.c.

References console_pvt::owner, and ast_channel::tech_pvt.

641 {
642  struct console_pvt *pvt = newchan->tech_pvt;
643 
644  pvt->owner = newchan;
645 
646  return 0;
647 }
void * tech_pvt
Definition: channel.h:744
struct ast_channel * owner
Definition: chan_console.c:142
Console pvt structure.
Definition: chan_console.c:118
static int console_hangup ( struct ast_channel c)
static

Definition at line 512 of file chan_console.c.

References ast_verb, console_pvt::hookstate, console_pvt::owner, stop_stream(), ast_channel::tech_pvt, unref_pvt(), V_BEGIN, and V_END.

513 {
514  struct console_pvt *pvt = c->tech_pvt;
515 
516  ast_verb(1, V_BEGIN "Hangup on Console" V_END);
517 
518  pvt->hookstate = 0;
519  pvt->owner = NULL;
520  stop_stream(pvt);
521 
522  c->tech_pvt = unref_pvt(pvt);
523 
524  return 0;
525 }
void * tech_pvt
Definition: channel.h:744
struct ast_channel * owner
Definition: chan_console.c:142
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
#define ast_verb(level,...)
Definition: logger.h:243
Console pvt structure.
Definition: chan_console.c:118
unsigned int hookstate
Definition: chan_console.c:150
#define V_END
Definition: chan_console.c:107
#define V_BEGIN
Dance, Kirby, Dance!
Definition: chan_console.c:106
static int stop_stream(struct console_pvt *pvt)
Definition: chan_console.c:397
static int console_indicate ( struct ast_channel chan,
int  cond,
const void *  data,
size_t  datalen 
)
static

Definition at line 604 of file chan_console.c.

References AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_log(), ast_moh_start(), ast_moh_stop(), ast_verb, LOG_WARNING, console_pvt::mohinterpret, ast_channel::name, ast_channel::tech_pvt, V_BEGIN, and V_END.

605 {
606  struct console_pvt *pvt = chan->tech_pvt;
607  int res = 0;
608 
609  switch (cond) {
610  case AST_CONTROL_BUSY:
612  case AST_CONTROL_RINGING:
614  case -1:
615  res = -1; /* Ask for inband indications */
616  break;
621  break;
622  case AST_CONTROL_HOLD:
623  ast_verb(1, V_BEGIN "Console Has Been Placed on Hold" V_END);
624  ast_moh_start(chan, data, pvt->mohinterpret);
625  break;
626  case AST_CONTROL_UNHOLD:
627  ast_verb(1, V_BEGIN "Console Has Been Retrieved from Hold" V_END);
628  ast_moh_stop(chan);
629  break;
630  default:
631  ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n",
632  cond, chan->name);
633  /* The core will play inband indications for us if appropriate */
634  res = -1;
635  }
636 
637  return res;
638 }
void * tech_pvt
Definition: channel.h:744
#define LOG_WARNING
Definition: logger.h:144
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:8051
#define ast_verb(level,...)
Definition: logger.h:243
Console pvt structure.
Definition: chan_console.c:118
ast_cond_t cond
Definition: app_meetme.c:963
const ast_string_field name
Definition: channel.h:787
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:8040
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define V_END
Definition: chan_console.c:107
#define V_BEGIN
Dance, Kirby, Dance!
Definition: chan_console.c:106
const ast_string_field mohinterpret
Definition: chan_console.c:140
static struct ast_channel* console_new ( struct console_pvt pvt,
const char *  ext,
const char *  ctx,
int  state,
const char *  linkedid 
)
static
Note
Called with the pvt struct locked

Definition at line 419 of file chan_console.c.

References AST_CAUSE_SWITCH_CONGESTION, ast_channel_alloc(), AST_FORMAT_SLINEAR16, ast_hangup(), ast_jb_configure(), ast_pbx_start(), AST_STATE_DOWN, ast_string_field_set, ast_strlen_zero(), console_pvt::cid_name, console_pvt::cid_num, console_tech, global_jbconf, ast_channel::hangupcause, language, console_pvt::language, console_pvt::name, ast_channel::nativeformats, console_pvt::owner, ast_channel::readformat, ref_pvt(), start_stream(), ast_channel::tech, ast_channel::tech_pvt, and ast_channel::writeformat.

Referenced by cli_console_dial(), and console_request().

420 {
421  struct ast_channel *chan;
422 
423  if (!(chan = ast_channel_alloc(1, state, pvt->cid_num, pvt->cid_name, NULL,
424  ext, ctx, linkedid, 0, "Console/%s", pvt->name))) {
425  return NULL;
426  }
427 
428  chan->tech = &console_tech;
432  chan->tech_pvt = ref_pvt(pvt);
433 
434  pvt->owner = chan;
435 
436  if (!ast_strlen_zero(pvt->language))
438 
440 
441  if (state != AST_STATE_DOWN) {
442  if (ast_pbx_start(chan)) {
444  ast_hangup(chan);
445  chan = NULL;
446  } else
447  start_stream(pvt);
448  }
449 
450  return chan;
451 }
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
Main Channel structure associated with a channel.
Definition: channel.h:742
const ast_string_field cid_num
Definition: chan_console.c:140
format_t writeformat
Definition: channel.h:854
#define AST_CAUSE_SWITCH_CONGESTION
Definition: causes.h:122
void * tech_pvt
Definition: channel.h:744
static struct ast_jb_conf global_jbconf
Definition: chan_console.c:185
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:5879
static int start_stream(struct console_pvt *pvt)
Definition: chan_console.c:354
struct ast_channel * owner
Definition: chan_console.c:142
format_t nativeformats
Definition: channel.h:852
const ast_string_field linkedid
Definition: channel.h:787
const char * ext
Definition: http.c:112
struct ast_channel * ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const char *linkedid, const int amaflag, const char *name_fmt,...)
Definition: channel.c:9825
static struct ast_channel_tech console_tech
Definition: chan_console.c:208
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static char language[MAX_LANGUAGE]
Definition: chan_alsa.c:108
#define AST_FORMAT_SLINEAR16
Definition: frame.h:272
const ast_string_field language
Definition: chan_console.c:140
static struct console_pvt * ref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:231
void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
Configures a jitterbuffer on a channel.
Definition: abstract_jb.c:616
format_t readformat
Definition: channel.h:853
int hangupcause
Definition: channel.h:849
const ast_string_field name
Definition: chan_console.c:140
struct ast_channel_tech * tech
Definition: channel.h:743
const ast_string_field cid_name
Definition: chan_console.c:140
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:344
static struct ast_frame * console_read ( struct ast_channel chan)
static

Definition at line 558 of file chan_console.c.

References ast_debug, and ast_null_frame.

559 {
560  ast_debug(1, "I should not be called ...\n");
561 
562  return &ast_null_frame;
563 }
struct ast_frame ast_null_frame
Definition: frame.c:131
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static struct ast_channel * console_request ( const char *  type,
format_t  format,
const struct ast_channel requestor,
void *  data,
int *  cause 
)
static

Channel Technology Callbacks

Definition at line 453 of file chan_console.c.

References AST_CAUSE_BUSY, ast_getformatname_multiple(), ast_log(), AST_STATE_DOWN, console_new(), console_pvt_lock, console_pvt_unlock, find_pvt(), format, ast_channel::linkedid, LOG_ERROR, LOG_NOTICE, LOG_WARNING, console_pvt::owner, SUPPORTED_FORMATS, and unref_pvt().

454 {
455  format_t oldformat = format;
456  struct ast_channel *chan = NULL;
457  struct console_pvt *pvt;
458  char buf[512];
459 
460  if (!(pvt = find_pvt(data))) {
461  ast_log(LOG_ERROR, "Console device '%s' not found\n", (char *) data);
462  return NULL;
463  }
464 
466  if (!format) {
467  ast_log(LOG_NOTICE, "Channel requested with unsupported format(s): '%s'\n", ast_getformatname_multiple(buf, sizeof(buf), oldformat));
468  goto return_unref;
469  }
470 
471  if (pvt->owner) {
472  ast_log(LOG_NOTICE, "Console channel already active!\n");
473  *cause = AST_CAUSE_BUSY;
474  goto return_unref;
475  }
476 
477  console_pvt_lock(pvt);
478  chan = console_new(pvt, NULL, NULL, AST_STATE_DOWN, requestor ? requestor->linkedid : NULL);
479  console_pvt_unlock(pvt);
480 
481  if (!chan)
482  ast_log(LOG_WARNING, "Unable to create new Console channel!\n");
483 
484 return_unref:
485  unref_pvt(pvt);
486 
487  return chan;
488 }
Main Channel structure associated with a channel.
Definition: channel.h:742
#define LOG_WARNING
Definition: logger.h:144
struct ast_channel * owner
Definition: chan_console.c:142
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
const ast_string_field linkedid
Definition: channel.h:787
Console pvt structure.
Definition: chan_console.c:118
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
Definition: chan_console.c:229
static struct ast_channel * console_new(struct console_pvt *pvt, const char *ext, const char *ctx, int state, const char *linkedid)
Definition: chan_console.c:419
#define LOG_ERROR
Definition: logger.h:155
int64_t format_t
Definition: frame_defs.h:32
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
#define SUPPORTED_FORMATS
Formats natively supported by this module.
Definition: chan_console.c:206
#define AST_CAUSE_BUSY
Definition: causes.h:148
char * ast_getformatname_multiple(char *buf, size_t size, format_t format)
Get the names of a set of formats.
Definition: frame.c:591
#define console_pvt_lock(pvt)
lock a console_pvt struct
Definition: chan_console.c:226
static struct console_pvt * find_pvt(const char *name)
Definition: chan_console.c:244
static snd_pcm_format_t format
Definition: chan_alsa.c:93
static int console_text ( struct ast_channel c,
const char *  text 
)
static

Definition at line 505 of file chan_console.c.

References ast_verb, V_BEGIN, and V_END.

506 {
507  ast_verb(1, V_BEGIN "Console Received Text '%s'" V_END, text);
508 
509  return 0;
510 }
char * text
Definition: app_queue.c:1091
#define ast_verb(level,...)
Definition: logger.h:243
#define V_END
Definition: chan_console.c:107
#define V_BEGIN
Dance, Kirby, Dance!
Definition: chan_console.c:106
static int console_write ( struct ast_channel chan,
struct ast_frame f 
)
static

Definition at line 595 of file chan_console.c.

References ast_frame::data, ast_frame::ptr, ast_frame::samples, console_pvt::stream, and ast_channel::tech_pvt.

596 {
597  struct console_pvt *pvt = chan->tech_pvt;
598 
599  Pa_WriteStream(pvt->stream, f->data.ptr, f->samples);
600 
601  return 0;
602 }
PaStream * stream
Definition: chan_console.c:144
void * ptr
Definition: frame.h:160
void * tech_pvt
Definition: channel.h:744
Console pvt structure.
Definition: chan_console.c:118
union ast_frame::@172 data
int samples
Definition: frame.h:150
static void destroy_pvts ( void  )
static

Definition at line 1368 of file chan_console.c.

References active_lock, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_unlink, ast_rwlock_unlock, ast_rwlock_wrlock, console_pvt::destroy, and unref_pvt().

Referenced by load_config().

1369 {
1370  struct ao2_iterator i;
1371  struct console_pvt *pvt;
1372 
1373  i = ao2_iterator_init(pvts, 0);
1374  while ((pvt = ao2_iterator_next(&i))) {
1375  if (pvt->destroy) {
1376  ao2_unlink(pvts, pvt);
1378  if (active_pvt == pvt)
1379  active_pvt = unref_pvt(pvt);
1381  }
1382  unref_pvt(pvt);
1383  }
1385 }
unsigned int destroy
Definition: chan_console.c:159
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
#define ast_rwlock_unlock(a)
Definition: lock.h:200
Console pvt structure.
Definition: chan_console.c:118
static struct ao2_container * pvts
Definition: chan_console.c:166
static ast_rwlock_t active_lock
Definition: chan_console.c:170
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Definition: astobj2.c:833
#define ast_rwlock_wrlock(a)
Definition: lock.h:202
static struct console_pvt * active_pvt
Definition: chan_console.c:169
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1053
#define ao2_unlink(arg1, arg2)
Definition: astobj2.h:817
static struct console_pvt* find_pvt ( const char *  name)
static

Definition at line 244 of file chan_console.c.

References ao2_find, name, console_pvt::name, and OBJ_POINTER.

Referenced by build_device(), cli_console_active(), and console_request().

245 {
246  struct console_pvt tmp_pvt = {
247  .name = name,
248  };
249 
250  return ao2_find(pvts, &tmp_pvt, OBJ_POINTER);
251 }
Console pvt structure.
Definition: chan_console.c:118
static struct ao2_container * pvts
Definition: chan_console.c:166
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
static const char name[]
const ast_string_field name
Definition: chan_console.c:140
static struct console_pvt* get_active_pvt ( void  )
static

Definition at line 683 of file chan_console.c.

References active_lock, ast_rwlock_rdlock, ast_rwlock_unlock, and ref_pvt().

Referenced by cli_console_active(), cli_console_answer(), cli_console_autoanswer(), cli_console_dial(), cli_console_flash(), cli_console_hangup(), cli_console_mute(), and cli_console_sendtext().

684 {
685  struct console_pvt *pvt;
686 
688  pvt = ref_pvt(active_pvt);
690 
691  return pvt;
692 }
#define ast_rwlock_rdlock(a)
Definition: lock.h:201
#define ast_rwlock_unlock(a)
Definition: lock.h:200
Console pvt structure.
Definition: chan_console.c:118
static ast_rwlock_t active_lock
Definition: chan_console.c:170
static struct console_pvt * ref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:231
static struct console_pvt * active_pvt
Definition: chan_console.c:169
static int init_pvt ( struct console_pvt pvt,
const char *  name 
)
static

Definition at line 1320 of file chan_console.c.

References AST_PTHREADT_NULL, ast_string_field_init, ast_string_field_set, S_OR, and console_pvt::thread.

Referenced by build_device(), and load_module().

1321 {
1322  pvt->thread = AST_PTHREADT_NULL;
1323 
1324  if (ast_string_field_init(pvt, 32))
1325  return -1;
1326 
1327  ast_string_field_set(pvt, name, S_OR(name, ""));
1328 
1329  return 0;
1330 }
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:249
#define AST_PTHREADT_NULL
Definition: lock.h:65
pthread_t thread
Definition: chan_console.c:161
static const char name[]
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:344
static int load_config ( int  reload)
static

Load the configuration.

Parameters
reloadif this was called due to a reload
Return values
0success
-1failure

Definition at line 1393 of file chan_console.c.

References ao2_callback, ast_category_browse(), ast_config_destroy(), ast_config_load, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_variable_browse(), build_device(), CONFIG_STATUS_FILEINVALID, context, destroy_pvts(), global_jbconf, globals, globals_lock, LOG_NOTICE, ast_variable::name, ast_variable::next, OBJ_NODATA, pvt_mark_destroy_cb(), set_pvt_defaults(), store_config_core(), and ast_variable::value.

Referenced by load_module(), and reload().

1394 {
1395  struct ast_config *cfg;
1396  struct ast_variable *v;
1397  struct ast_flags config_flags = { 0 };
1398  char *context = NULL;
1399 
1400  /* default values */
1401  memcpy(&global_jbconf, &default_jbconf, sizeof(global_jbconf));
1405 
1406  if (!(cfg = ast_config_load(config_file, config_flags))) {
1407  ast_log(LOG_NOTICE, "Unable to open configuration file %s!\n", config_file);
1408  return -1;
1409  } else if (cfg == CONFIG_STATUS_FILEINVALID) {
1410  ast_log(LOG_NOTICE, "Config file %s has an invalid format\n", config_file);
1411  return -1;
1412  }
1413 
1415 
1417  for (v = ast_variable_browse(cfg, "general"); v; v = v->next)
1418  store_config_core(&globals, v->name, v->value);
1420 
1421  while ((context = ast_category_browse(cfg, context))) {
1422  if (strcasecmp(context, "general"))
1423  build_device(cfg, context);
1424  }
1425 
1426  ast_config_destroy(cfg);
1427 
1428  destroy_pvts();
1429 
1430  return 0;
1431 }
static void build_device(struct ast_config *cfg, const char *name)
static void set_pvt_defaults(struct console_pvt *pvt)
Set default values for a pvt struct.
static struct ast_jb_conf global_jbconf
Definition: chan_console.c:185
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:910
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define ast_mutex_lock(a)
Definition: lock.h:155
static ast_mutex_t globals_lock
Definition: chan_console.c:164
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
static struct ast_jb_conf default_jbconf
Global jitterbuffer configuration.
Definition: chan_console.c:178
const char * value
Definition: config.h:79
static int pvt_mark_destroy_cb(void *obj, void *arg, int flags)
#define ast_config_load(filename, flags)
Load a config file.
Definition: config.h:170
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
const char * name
Definition: config.h:77
static struct console_pvt globals
static struct ao2_container * pvts
Definition: chan_console.c:166
static void store_config_core(struct console_pvt *pvt, const char *var, const char *value)
Store a configuration parameter in a pvt struct.
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
Structure used to handle boolean flags.
Definition: utils.h:200
static void destroy_pvts(void)
struct ast_variable * next
Definition: config.h:82
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static const char config_file[]
Definition: chan_console.c:110
#define ast_mutex_unlock(a)
Definition: lock.h:156
static int load_module ( void  )
static

Definition at line 1478 of file chan_console.c.

References ao2_container_alloc, ao2_ref, ARRAY_LEN, ast_channel_register(), ast_channel_unregister(), ast_cli_register_multiple(), ast_cli_unregister_multiple(), ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, globals, init_pvt(), load_config(), LOG_ERROR, LOG_WARNING, NUM_PVT_BUCKETS, pvt_cmp_cb(), pvt_destructor(), and pvt_hash_cb().

1479 {
1480  PaError res;
1481 
1482  init_pvt(&globals, NULL);
1483 
1485  goto return_error;
1486 
1487  if (load_config(0))
1488  goto return_error;
1489 
1490  res = Pa_Initialize();
1491  if (res != paNoError) {
1492  ast_log(LOG_WARNING, "Failed to initialize audio system - (%d) %s\n",
1493  res, Pa_GetErrorText(res));
1494  goto return_error_pa_init;
1495  }
1496 
1498  ast_log(LOG_ERROR, "Unable to register channel type 'Console'\n");
1499  goto return_error_chan_reg;
1500  }
1501 
1503  goto return_error_cli_reg;
1504 
1505  return AST_MODULE_LOAD_SUCCESS;
1506 
1507 return_error_cli_reg:
1509 return_error_chan_reg:
1511 return_error_pa_init:
1512  Pa_Terminate();
1513 return_error:
1514  if (pvts)
1515  ao2_ref(pvts, -1);
1516  pvts = NULL;
1518 
1519  return AST_MODULE_LOAD_DECLINE;
1520 }
static int pvt_hash_cb(const void *obj, const int flags)
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
Definition: channel.c:938
#define LOG_WARNING
Definition: logger.h:144
static int load_config(int reload)
Load the configuration.
int ast_channel_register(const struct ast_channel_tech *tech)
Register a channel technology (a new channel driver) Called by a channel module to register the kind ...
Definition: channel.c:907
static struct ast_channel_tech console_tech
Definition: chan_console.c:208
static struct ast_cli_entry cli_console[]
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static struct console_pvt globals
static struct ao2_container * pvts
Definition: chan_console.c:166
static int init_pvt(struct console_pvt *pvt, const char *name)
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define NUM_PVT_BUCKETS
Definition: chan_console.c:167
#define ao2_container_alloc(arg1, arg2, arg3)
Definition: astobj2.h:734
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
static int pvt_cmp_cb(void *obj, void *arg, int flags)
static void pvt_destructor(void *obj)
static int open_stream ( struct console_pvt pvt)
static

Definition at line 293 of file chan_console.c.

References ast_log(), INPUT_CHANNELS, console_pvt::input_device, LOG_ERROR, console_pvt::name, NUM_SAMPLES, OUTPUT_CHANNELS, console_pvt::output_device, SAMPLE_RATE, and console_pvt::stream.

Referenced by start_stream().

294 {
295  int res = paInternalError;
296 
297  if (!strcasecmp(pvt->input_device, "default") &&
298  !strcasecmp(pvt->output_device, "default")) {
299  res = Pa_OpenDefaultStream(&pvt->stream, INPUT_CHANNELS, OUTPUT_CHANNELS,
300  paInt16, SAMPLE_RATE, NUM_SAMPLES, NULL, NULL);
301  } else {
302  PaStreamParameters input_params = {
303  .channelCount = 1,
304  .sampleFormat = paInt16,
305  .suggestedLatency = (1.0 / 50.0), /* 20 ms */
306  .device = paNoDevice,
307  };
308  PaStreamParameters output_params = {
309  .channelCount = 1,
310  .sampleFormat = paInt16,
311  .suggestedLatency = (1.0 / 50.0), /* 20 ms */
312  .device = paNoDevice,
313  };
314  PaDeviceIndex idx, num_devices, def_input, def_output;
315 
316  if (!(num_devices = Pa_GetDeviceCount()))
317  return res;
318 
319  def_input = Pa_GetDefaultInputDevice();
320  def_output = Pa_GetDefaultOutputDevice();
321 
322  for (idx = 0;
323  idx < num_devices && (input_params.device == paNoDevice
324  || output_params.device == paNoDevice);
325  idx++)
326  {
327  const PaDeviceInfo *dev = Pa_GetDeviceInfo(idx);
328 
329  if (dev->maxInputChannels) {
330  if ( (idx == def_input && !strcasecmp(pvt->input_device, "default")) ||
331  !strcasecmp(pvt->input_device, dev->name) )
332  input_params.device = idx;
333  }
334 
335  if (dev->maxOutputChannels) {
336  if ( (idx == def_output && !strcasecmp(pvt->output_device, "default")) ||
337  !strcasecmp(pvt->output_device, dev->name) )
338  output_params.device = idx;
339  }
340  }
341 
342  if (input_params.device == paNoDevice)
343  ast_log(LOG_ERROR, "No input device found for console device '%s'\n", pvt->name);
344  if (output_params.device == paNoDevice)
345  ast_log(LOG_ERROR, "No output device found for console device '%s'\n", pvt->name);
346 
347  res = Pa_OpenStream(&pvt->stream, &input_params, &output_params,
348  SAMPLE_RATE, NUM_SAMPLES, paNoFlag, NULL, NULL);
349  }
350 
351  return res;
352 }
PaStream * stream
Definition: chan_console.c:144
#define SAMPLE_RATE
The sample rate to request from PortAudio.
Definition: chan_console.c:78
#define NUM_SAMPLES
The number of samples to configure the portaudio stream for.
Definition: chan_console.c:90
#define OUTPUT_CHANNELS
Mono Output.
Definition: chan_console.c:96
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
const ast_string_field input_device
Definition: chan_console.c:140
#define INPUT_CHANNELS
Mono Input.
Definition: chan_console.c:93
const ast_string_field output_device
Definition: chan_console.c:140
const ast_string_field name
Definition: chan_console.c:140
static int pvt_cmp_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1440 of file chan_console.c.

References CMP_MATCH, CMP_STOP, and console_pvt::name.

Referenced by load_module().

1441 {
1442  struct console_pvt *pvt = obj, *pvt2 = arg;
1443 
1444  return !strcasecmp(pvt->name, pvt2->name) ? CMP_MATCH | CMP_STOP : 0;
1445 }
Console pvt structure.
Definition: chan_console.c:118
const ast_string_field name
Definition: chan_console.c:140
static void pvt_destructor ( void *  obj)
static

Definition at line 1313 of file chan_console.c.

References ast_string_field_free_memory.

Referenced by build_device(), load_module(), and unload_module().

1314 {
1315  struct console_pvt *pvt = obj;
1316 
1318 }
Console pvt structure.
Definition: chan_console.c:118
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:253
static int pvt_hash_cb ( const void *  obj,
const int  flags 
)
static

Definition at line 1433 of file chan_console.c.

References ast_str_case_hash(), and console_pvt::name.

Referenced by load_module().

1434 {
1435  const struct console_pvt *pvt = obj;
1436 
1437  return ast_str_case_hash(pvt->name);
1438 }
Console pvt structure.
Definition: chan_console.c:118
const ast_string_field name
Definition: chan_console.c:140
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
Definition: strings.h:989
static int pvt_mark_destroy_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1361 of file chan_console.c.

References console_pvt::destroy.

Referenced by load_config().

1362 {
1363  struct console_pvt *pvt = obj;
1364  pvt->destroy = 1;
1365  return 0;
1366 }
unsigned int destroy
Definition: chan_console.c:159
Console pvt structure.
Definition: chan_console.c:118
static struct console_pvt* ref_pvt ( struct console_pvt pvt)
static

Definition at line 231 of file chan_console.c.

References ao2_ref.

Referenced by console_new(), get_active_pvt(), and set_active().

232 {
233  if (pvt)
234  ao2_ref(pvt, +1);
235  return pvt;
236 }
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static int reload ( void  )
static

Definition at line 1522 of file chan_console.c.

References load_config().

1523 {
1524  return load_config(1);
1525 }
static int load_config(int reload)
Load the configuration.
static void set_active ( struct console_pvt pvt,
const char *  value 
)
static

Definition at line 1138 of file chan_console.c.

References active_lock, ast_log(), ast_rwlock_unlock, ast_rwlock_wrlock, ast_true(), globals, LOG_ERROR, ref_pvt(), and unref_pvt().

Referenced by cli_console_active(), and store_config_core().

1139 {
1140  if (pvt == &globals) {
1141  ast_log(LOG_ERROR, "active is only valid as a per-device setting\n");
1142  return;
1143  }
1144 
1145  if (!ast_true(value))
1146  return;
1147 
1149  if (active_pvt)
1151  active_pvt = ref_pvt(pvt);
1153 }
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
int value
Definition: syslog.c:39
#define ast_rwlock_unlock(a)
Definition: lock.h:200
static struct console_pvt globals
#define LOG_ERROR
Definition: logger.h:155
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is &quot;true&quot;. This function checks to see whether a string passed to it is an indication of an &quot;true&quot; value. It checks to see if the string is &quot;yes&quot;, &quot;true&quot;, &quot;y&quot;, &quot;t&quot;, &quot;on&quot; or &quot;1&quot;.
Definition: utils.c:1533
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static ast_rwlock_t active_lock
Definition: chan_console.c:170
static struct console_pvt * ref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:231
#define ast_rwlock_wrlock(a)
Definition: lock.h:202
static struct console_pvt * active_pvt
Definition: chan_console.c:169
static void set_pvt_defaults ( struct console_pvt pvt)
static

Set default values for a pvt struct.

Note
This function expects the pvt lock to be held.

Definition at line 1238 of file chan_console.c.

References ast_mutex_lock, ast_mutex_unlock, ast_string_field_set, console_pvt::autoanswer, console_pvt::cid_name, cid_name, console_pvt::cid_num, cid_num, context, console_pvt::context, exten, console_pvt::exten, globals, globals_lock, language, console_pvt::language, mohinterpret, console_pvt::mohinterpret, console_pvt::overridecontext, console_pvt::parkinglot, and parkinglot.

Referenced by build_device(), and load_config().

1239 {
1240  if (pvt == &globals) {
1241  ast_string_field_set(pvt, mohinterpret, "default");
1242  ast_string_field_set(pvt, context, "default");
1243  ast_string_field_set(pvt, exten, "s");
1244  ast_string_field_set(pvt, language, "");
1245  ast_string_field_set(pvt, cid_num, "");
1246  ast_string_field_set(pvt, cid_name, "");
1247  ast_string_field_set(pvt, parkinglot, "");
1248 
1249  pvt->overridecontext = 0;
1250  pvt->autoanswer = 0;
1251  } else {
1253 
1261 
1263  pvt->autoanswer = globals.autoanswer;
1264 
1266  }
1267 }
static char mohinterpret[MAX_MUSICCLASS]
Definition: chan_alsa.c:110
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static char parkinglot[AST_MAX_CONTEXT]
Definition: chan_mgcp.c:156
const ast_string_field cid_num
Definition: chan_console.c:140
const ast_string_field context
Definition: chan_console.c:140
unsigned int overridecontext
Definition: chan_console.c:156
#define ast_mutex_lock(a)
Definition: lock.h:155
const ast_string_field parkinglot
Definition: chan_console.c:140
static ast_mutex_t globals_lock
Definition: chan_console.c:164
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:157
unsigned int autoanswer
Definition: chan_console.c:154
static char language[MAX_LANGUAGE]
Definition: chan_alsa.c:108
static struct console_pvt globals
const ast_string_field language
Definition: chan_console.c:140
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:158
const ast_string_field mohinterpret
Definition: chan_console.c:140
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
const ast_string_field cid_name
Definition: chan_console.c:140
const ast_string_field exten
Definition: chan_console.c:140
#define ast_mutex_unlock(a)
Definition: lock.h:156
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:344
static int start_stream ( struct console_pvt pvt)
static

Definition at line 354 of file chan_console.c.

References ast_debug, ast_log(), ast_pthread_create_background, console_pvt_lock, console_pvt_unlock, LOG_ERROR, LOG_WARNING, open_stream(), console_pvt::owner, console_pvt::stream, stream_monitor(), console_pvt::streamstate, and console_pvt::thread.

Referenced by console_answer(), console_call(), and console_new().

355 {
356  PaError res;
357  int ret_val = 0;
358 
359  console_pvt_lock(pvt);
360 
361  /* It is possible for console_hangup to be called before the
362  * stream is started, if this is the case pvt->owner will be NULL
363  * and start_stream should be aborted. */
364  if (pvt->streamstate || !pvt->owner)
365  goto return_unlock;
366 
367  pvt->streamstate = 1;
368  ast_debug(1, "Starting stream\n");
369 
370  res = open_stream(pvt);
371  if (res != paNoError) {
372  ast_log(LOG_WARNING, "Failed to open stream - (%d) %s\n",
373  res, Pa_GetErrorText(res));
374  ret_val = -1;
375  goto return_unlock;
376  }
377 
378  res = Pa_StartStream(pvt->stream);
379  if (res != paNoError) {
380  ast_log(LOG_WARNING, "Failed to start stream - (%d) %s\n",
381  res, Pa_GetErrorText(res));
382  ret_val = -1;
383  goto return_unlock;
384  }
385 
386  if (ast_pthread_create_background(&pvt->thread, NULL, stream_monitor, pvt)) {
387  ast_log(LOG_ERROR, "Failed to start stream monitor thread\n");
388  ret_val = -1;
389  }
390 
391 return_unlock:
392  console_pvt_unlock(pvt);
393 
394  return ret_val;
395 }
static int open_stream(struct console_pvt *pvt)
Definition: chan_console.c:293
PaStream * stream
Definition: chan_console.c:144
#define LOG_WARNING
Definition: logger.h:144
struct ast_channel * owner
Definition: chan_console.c:142
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:426
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
Definition: chan_console.c:229
static void * stream_monitor(void *data)
Stream monitor thread.
Definition: chan_console.c:263
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
pthread_t thread
Definition: chan_console.c:161
unsigned int streamstate
Definition: chan_console.c:148
#define console_pvt_lock(pvt)
lock a console_pvt struct
Definition: chan_console.c:226
static int stop_stream ( struct console_pvt pvt)
static

Definition at line 397 of file chan_console.c.

References AST_PTHREADT_NULL, console_pvt_lock, console_pvt_unlock, console_pvt::stream, console_pvt::streamstate, and console_pvt::thread.

Referenced by console_hangup(), and stop_streams().

398 {
399  if (!pvt->streamstate || pvt->thread == AST_PTHREADT_NULL)
400  return 0;
401 
402  pthread_cancel(pvt->thread);
403  pthread_kill(pvt->thread, SIGURG);
404  pthread_join(pvt->thread, NULL);
405 
406  console_pvt_lock(pvt);
407  Pa_AbortStream(pvt->stream);
408  Pa_CloseStream(pvt->stream);
409  pvt->stream = NULL;
410  pvt->streamstate = 0;
411  console_pvt_unlock(pvt);
412 
413  return 0;
414 }
PaStream * stream
Definition: chan_console.c:144
#define AST_PTHREADT_NULL
Definition: lock.h:65
#define console_pvt_unlock(pvt)
unlock a console_pvt struct
Definition: chan_console.c:229
pthread_t thread
Definition: chan_console.c:161
unsigned int streamstate
Definition: chan_console.c:148
#define console_pvt_lock(pvt)
lock a console_pvt struct
Definition: chan_console.c:226
static void stop_streams ( void  )
static

Definition at line 1447 of file chan_console.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, console_pvt::hookstate, stop_stream(), and unref_pvt().

Referenced by unload_module().

1448 {
1449  struct console_pvt *pvt;
1450  struct ao2_iterator i;
1451 
1452  i = ao2_iterator_init(pvts, 0);
1453  while ((pvt = ao2_iterator_next(&i))) {
1454  if (pvt->hookstate)
1455  stop_stream(pvt);
1456  unref_pvt(pvt);
1457  }
1459 }
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
static struct console_pvt * unref_pvt(struct console_pvt *pvt)
Definition: chan_console.c:238
Console pvt structure.
Definition: chan_console.c:118
static struct ao2_container * pvts
Definition: chan_console.c:166
unsigned int hookstate
Definition: chan_console.c:150
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Definition: astobj2.c:833
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1053
static int stop_stream(struct console_pvt *pvt)
Definition: chan_console.c:397
static void store_callerid ( struct console_pvt pvt,
const char *  value 
)
static

Definition at line 1269 of file chan_console.c.

References ast_callerid_split(), ast_string_field_set, cid_name, and cid_num.

Referenced by store_config_core().

1270 {
1271  char cid_name[256];
1272  char cid_num[256];
1273 
1274  ast_callerid_split(value, cid_name, sizeof(cid_name),
1275  cid_num, sizeof(cid_num));
1276 
1277  ast_string_field_set(pvt, cid_name, cid_name);
1278  ast_string_field_set(pvt, cid_num, cid_num);
1279 }
int ast_callerid_split(const char *src, char *name, int namelen, char *num, int numlen)
Definition: callerid.c:1093
int value
Definition: syslog.c:39
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:157
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:158
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:344
static void store_config_core ( struct console_pvt pvt,
const char *  var,
const char *  value 
)
static

Store a configuration parameter in a pvt struct.

Note
This function expects the pvt lock to be held.

Definition at line 1286 of file chan_console.c.

References ast_jb_read_conf(), ast_log(), console_pvt::autoanswer, context, CV_BOOL, CV_END, CV_F, CV_START, CV_STRFIELD, exten, global_jbconf, globals, language, LOG_WARNING, mohinterpret, console_pvt::overridecontext, parkinglot, set_active(), and store_callerid().

Referenced by build_device(), and load_config().

1287 {
1288  if (pvt == &globals && !ast_jb_read_conf(&global_jbconf, var, value))
1289  return;
1290 
1291  CV_START(var, value);
1292 
1293  CV_STRFIELD("context", pvt, context);
1294  CV_STRFIELD("extension", pvt, exten);
1295  CV_STRFIELD("mohinterpret", pvt, mohinterpret);
1296  CV_STRFIELD("language", pvt, language);
1297  CV_F("callerid", store_callerid(pvt, value));
1298  CV_BOOL("overridecontext", pvt->overridecontext);
1299  CV_BOOL("autoanswer", pvt->autoanswer);
1300  CV_STRFIELD("parkinglot", pvt, parkinglot);
1301 
1302  if (pvt != &globals) {
1303  CV_F("active", set_active(pvt, value))
1304  CV_STRFIELD("input_device", pvt, input_device);
1305  CV_STRFIELD("output_device", pvt, output_device);
1306  }
1307 
1308  ast_log(LOG_WARNING, "Unknown option '%s'\n", var);
1309 
1310  CV_END;
1311 }
static char mohinterpret[MAX_MUSICCLASS]
Definition: chan_alsa.c:110
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static char parkinglot[AST_MAX_CONTEXT]
Definition: chan_mgcp.c:156
static struct ast_jb_conf global_jbconf
Definition: chan_console.c:185
#define LOG_WARNING
Definition: logger.h:144
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value)
Sets jitterbuffer configuration property.
Definition: abstract_jb.c:577
unsigned int overridecontext
Definition: chan_console.c:156
#define var
Definition: ast_expr2f.c:606
int value
Definition: syslog.c:39
unsigned int autoanswer
Definition: chan_console.c:154
static void store_callerid(struct console_pvt *pvt, const char *value)
#define CV_END
close a variable parsing block
Definition: config.h:733
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
Definition: config.h:727
static char language[MAX_LANGUAGE]
Definition: chan_alsa.c:108
static struct console_pvt globals
#define CV_BOOL(__x, __dst)
helper macros to assign the value to a BOOL, UINT, static string and dynamic string ...
Definition: config.h:742
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void set_active(struct console_pvt *pvt, const char *value)
#define CV_F(__pattern, __body)
call a generic function if the name matches.
Definition: config.h:736
#define CV_STRFIELD(__x, __obj, __field)
Definition: config.h:746
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static void* stream_monitor ( void *  data)
static

Stream monitor thread.

  • data A pointer to the console_pvt structure that contains the portaudio stream that needs to be monitored.

This function runs in its own thread to monitor data coming in from a portaudio stream. When enough data is available, it is queued up to be read from the Asterisk channel.

Definition at line 263 of file chan_console.c.

References AST_FORMAT_SLINEAR16, AST_FRAME_VOICE, ast_queue_frame(), ast_frame::frametype, NUM_SAMPLES, console_pvt::owner, ast_frame::samples, and console_pvt::stream.

Referenced by start_stream().

264 {
265  struct console_pvt *pvt = data;
266  char buf[NUM_SAMPLES * sizeof(int16_t)];
267  PaError res;
268  struct ast_frame f = {
269  .frametype = AST_FRAME_VOICE,
270  .subclass.codec = AST_FORMAT_SLINEAR16,
271  .src = "console_stream_monitor",
272  .data.ptr = buf,
273  .datalen = sizeof(buf),
274  .samples = sizeof(buf) / sizeof(int16_t),
275  };
276 
277  for (;;) {
278  pthread_testcancel();
279  res = Pa_ReadStream(pvt->stream, buf, sizeof(buf) / sizeof(int16_t));
280  pthread_testcancel();
281 
282  if (!pvt->owner) {
283  return NULL;
284  }
285 
286  if (res == paNoError)
287  ast_queue_frame(pvt->owner, &f);
288  }
289 
290  return NULL;
291 }
PaStream * stream
Definition: chan_console.c:144
struct ast_channel * owner
Definition: chan_console.c:142
Console pvt structure.
Definition: chan_console.c:118
#define NUM_SAMPLES
The number of samples to configure the portaudio stream for.
Definition: chan_console.c:90
#define AST_FORMAT_SLINEAR16
Definition: frame.h:272
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1558
static struct ast_format f[]
Definition: format_g726.c:181
Data structure associated with a single frame of data.
Definition: frame.h:142
int samples
Definition: frame.h:150
static int unload_module ( void  )
static

Definition at line 1461 of file chan_console.c.

References ao2_ref, ARRAY_LEN, ast_channel_unregister(), ast_cli_unregister_multiple(), globals, pvt_destructor(), and stop_streams().

1462 {
1465 
1466  stop_streams();
1467 
1468  Pa_Terminate();
1469 
1470  /* Will unref all the pvts so they will get destroyed, too */
1471  ao2_ref(pvts, -1);
1472 
1474 
1475  return 0;
1476 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static void stop_streams(void)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
Definition: channel.c:938
static struct ast_channel_tech console_tech
Definition: chan_console.c:208
static struct ast_cli_entry cli_console[]
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static struct console_pvt globals
static struct ao2_container * pvts
Definition: chan_console.c:166
static void pvt_destructor(void *obj)
static struct console_pvt* unref_pvt ( struct console_pvt pvt)
static

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Console Channel Driver" , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DRIVER, }
static

Definition at line 1532 of file chan_console.c.

ast_rwlock_t active_lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, 1 }
static

Definition at line 170 of file chan_console.c.

Referenced by destroy_pvts(), get_active_pvt(), and set_active().

struct console_pvt* active_pvt
static

Definition at line 169 of file chan_console.c.

Definition at line 1532 of file chan_console.c.

struct ast_cli_entry cli_console[]
static

Definition at line 1220 of file chan_console.c.

const char config_file[] = "console.conf"
static

Definition at line 110 of file chan_console.c.

struct ast_channel_tech console_tech
static

Definition at line 208 of file chan_console.c.

Referenced by console_new().

struct ast_jb_conf default_jbconf
static

Global jitterbuffer configuration.

Note
Disabled by default.
Values shown here match the defaults shown in console.conf.sample

Definition at line 178 of file chan_console.c.

struct ast_jb_conf global_jbconf
static

Definition at line 185 of file chan_console.c.

Referenced by console_new(), load_config(), and store_config_core().

ast_mutex_t globals_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
static

Definition at line 164 of file chan_console.c.

Referenced by load_config(), and set_pvt_defaults().

struct ao2_container* pvts
static

Definition at line 166 of file chan_console.c.