Asterisk - The Open Source Telephony Project GIT-master-a358458
Functions
autochan.c File Reference

"smart" channels More...

#include "asterisk.h"
#include "asterisk/autochan.h"
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
Include dependency graph for autochan.c:

Go to the source code of this file.

Functions

void ast_autochan_destroy (struct ast_autochan *autochan)
 destroy an ast_autochan structure More...
 
void ast_autochan_new_channel (struct ast_channel *old_chan, struct ast_channel *new_chan)
 Switch what channel autochans point to. More...
 
struct ast_autochanast_autochan_setup (struct ast_channel *chan)
 set up a new ast_autochan structure More...
 

Detailed Description

"smart" channels

Author
Mark Michelson mmich.nosp@m.elso.nosp@m.n@dig.nosp@m.ium..nosp@m.com

Definition in file autochan.c.

Function Documentation

◆ ast_autochan_destroy()

void ast_autochan_destroy ( struct ast_autochan autochan)

destroy an ast_autochan structure

Removes the passed-in autochan from the list of autochans and unrefs the channel that is pointed to. Also frees the autochan struct itself. This function will unref the channel reference which was made in ast_autochan_setup

Parameters
autochanThe autochan that you wish to destroy

Definition at line 64 of file autochan.c.

65{
66 struct ast_autochan *autochan_iter;
67
70 if (autochan_iter == autochan) {
72 ast_debug(1, "Removed autochan %p from the list, about to free it\n", autochan);
73 break;
74 }
75 }
78
79 autochan->chan = ast_channel_unref(autochan->chan);
80
81 ast_mutex_destroy(&autochan->lock);
82
83 ast_free(autochan);
84}
#define ast_free(a)
Definition: astmm.h:180
#define ast_autochan_channel_lock(autochan)
Lock the autochan's channel lock.
Definition: autochan.h:75
#define ast_autochan_channel_unlock(autochan)
Definition: autochan.h:84
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
struct ast_autochan_list * ast_channel_autochans(struct ast_channel *chan)
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
#define ast_mutex_destroy(a)
Definition: lock.h:188
struct ast_channel * chan
Definition: autochan.h:33
struct ast_autochan::@188 list
ast_mutex_t lock
Definition: autochan.h:35

References ast_autochan_channel_lock, ast_autochan_channel_unlock, ast_channel_autochans(), ast_channel_unref, ast_debug, ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_mutex_destroy, ast_autochan::chan, ast_autochan::list, and ast_autochan::lock.

Referenced by channel_spy(), common_exec(), launch_monitor_thread(), mixmonitor_thread(), and multi_autochan_free().

◆ ast_autochan_new_channel()

void ast_autochan_new_channel ( struct ast_channel old_chan,
struct ast_channel new_chan 
)

Switch what channel autochans point to.

Traverses the list of autochans. All autochans which point to old_chan will be updated to point to new_chan instead. Currently this is only called during an ast_channel_move() operation in channel.c.

Precondition
Both channels must be locked before calling this function.
Parameters
old_chanThe channel that autochans may currently point to
new_chanThe channel that we want to point those autochans to now

Definition at line 86 of file autochan.c.

87{
88 struct ast_autochan *autochan;
89
91
92 /* Deadlock avoidance is not needed since the channels are already locked. */
93 AST_LIST_TRAVERSE(ast_channel_autochans(new_chan), autochan, list) {
94 ast_mutex_lock(&autochan->lock);
95 if (autochan->chan == old_chan) {
96 autochan->chan = ast_channel_ref(new_chan);
97 ast_channel_unref(old_chan);
98
99 ast_debug(1, "Autochan %p used to hold channel %s (%p) but now holds channel %s (%p)\n",
100 autochan, ast_channel_name(old_chan), old_chan, ast_channel_name(new_chan), new_chan);
101 }
102 ast_mutex_unlock(&autochan->lock);
103 }
104}
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_LIST_APPEND_LIST(head, list, field)
Appends a whole list to the tail of a list.
Definition: linkedlists.h:783
#define ast_mutex_unlock(a)
Definition: lock.h:190
#define ast_mutex_lock(a)
Definition: lock.h:189

References ast_channel_autochans(), ast_channel_name(), ast_channel_ref, ast_channel_unref, ast_debug, AST_LIST_APPEND_LIST, AST_LIST_TRAVERSE, ast_mutex_lock, ast_mutex_unlock, ast_autochan::chan, ast_autochan::list, and ast_autochan::lock.

Referenced by channel_do_masquerade().

◆ ast_autochan_setup()

struct ast_autochan * ast_autochan_setup ( struct ast_channel chan)

set up a new ast_autochan structure

Allocates and initializes an ast_autochan, sets the autochan's chan pointer to point to the chan parameter, and adds the autochan to the global list of autochans. The newly- created autochan is returned to the caller. This function will cause the refcount of chan to increase by 1.

Parameters
chanThe channel our new autochan will point to
Note
autochans must be freed using ast_autochan_destroy
Return values
NULLFailure
non-NULLsuccess

Definition at line 38 of file autochan.c.

39{
40 struct ast_autochan *autochan;
41
42 if (!chan) {
43 return NULL;
44 }
45
46 if (!(autochan = ast_calloc(1, sizeof(*autochan)))) {
47 return NULL;
48 }
49 ast_mutex_init(&autochan->lock);
50
51 autochan->chan = ast_channel_ref(chan);
52
53 ast_debug(1, "Created autochan %p to hold channel %s (%p)\n",
54 autochan, ast_channel_name(chan), chan);
55
56 /* autochan is still private, no need for ast_autochan_channel_lock() */
57 ast_channel_lock(autochan->chan);
59 ast_channel_unlock(autochan->chan);
60
61 return autochan;
62}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_channel_lock(chan)
Definition: channel.h:2922
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define ast_mutex_init(pmutex)
Definition: lock.h:186
#define NULL
Definition: resample.c:96

References ast_calloc, ast_channel_autochans(), ast_channel_lock, ast_channel_name(), ast_channel_ref, ast_channel_unlock, ast_debug, AST_LIST_INSERT_TAIL, ast_mutex_init, ast_autochan::chan, ast_autochan::list, ast_autochan::lock, and NULL.

Referenced by attach_barge(), common_exec(), do_broadcast(), launch_monitor_thread(), and next_channel().