Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Functions | Variables
pbx_switch.c File Reference

PBX switch routines. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/cli.h"
#include "asterisk/linkedlists.h"
#include "asterisk/pbx.h"
#include "pbx_private.h"

Go to the source code of this file.

Data Structures

struct  switches
 

Functions

int ast_register_switch (struct ast_switch *sw)
 Register an alternative dialplan switch. More...
 
void ast_unregister_switch (struct ast_switch *sw)
 Unregister an alternative switch. More...
 
static char * handle_show_switches (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 handle_show_switches: CLI support for listing registered dial plan switches
 
int load_pbx_switch (void)
 
struct ast_switchpbx_findswitch (const char *sw)
 
static void unload_pbx_switch (void)
 

Variables

static struct ast_cli_entry sw_cli []
 
static struct switches switches = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 

Detailed Description

PBX switch routines.

Author
Corey Farrell git@c.nosp@m.fwar.nosp@m.e.com

Definition in file pbx_switch.c.

Function Documentation

int ast_register_switch ( struct ast_switch sw)

Register an alternative dialplan switch.

Parameters
swswitch to register

This function registers a populated ast_switch structure with the asterisk switching architecture.

Return values
0success
non-zerofailure

Definition at line 58 of file pbx_switch.c.

References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_switch::name.

Referenced by load_module(), and lua_find_extension().

59 {
60  struct ast_switch *tmp;
61 
63  AST_RWLIST_TRAVERSE(&switches, tmp, list) {
64  if (!strcasecmp(tmp->name, sw->name)) {
66  ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name);
67  return -1;
68  }
69  }
70  AST_RWLIST_INSERT_TAIL(&switches, sw, list);
72 
73  return 0;
74 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
const char * name
Definition: pbx.h:162
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
void ast_unregister_switch ( struct ast_switch sw)

Unregister an alternative switch.

Parameters
swswitch to unregister

Unregisters a switch from asterisk.

Definition at line 76 of file pbx_switch.c.

References AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by lua_find_extension().

77 {
79  AST_RWLIST_REMOVE(&switches, sw, list);
81 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
int load_pbx_switch ( void  )

Provided by pbx_switch.c

Definition at line 125 of file pbx_switch.c.

References ast_cli_register_multiple, and ast_register_cleanup().

126 {
127  ast_cli_register_multiple(sw_cli, ARRAY_LEN(sw_cli));
128  ast_register_cleanup(unload_pbx_switch);
129 
130  return 0;
131 }
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
struct ast_switch* pbx_findswitch ( const char *  sw)

pbx_switch.c functions needed by pbx.c

Definition at line 40 of file pbx_switch.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and ast_switch::name.

41 {
42  struct ast_switch *asw;
43 
45  AST_RWLIST_TRAVERSE(&switches, asw, list) {
46  if (!strcasecmp(asw->name, sw))
47  break;
48  }
50 
51  return asw;
52 }
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
const char * name
Definition: pbx.h:162
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151

Variable Documentation

struct ast_cli_entry sw_cli[]
static
Initial value:
= {
{ .handler = handle_show_switches , .summary = "Show alternative switches" ,},
}
static char * handle_show_switches(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
handle_show_switches: CLI support for listing registered dial plan switches
Definition: pbx_switch.c:84

Definition at line 116 of file pbx_switch.c.