Asterisk - The Open Source Telephony Project GIT-master-67613d1
Functions
core_local.h File Reference

Local proxy channel special access. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct stasis_message_typeast_local_bridge_type (void)
 Message type for when two local channel halves are bridged together. More...
 
struct ast_channelast_local_get_peer (struct ast_channel *ast)
 Get the other local channel in the pair. More...
 
void ast_local_lock_all (struct ast_channel *chan, void **tech_pvt, struct ast_channel **base_chan, struct ast_channel **base_owner)
 Add a reference to the local channel's private tech, lock the local channel's private base, and add references and lock both sides of the local channel. More...
 
struct stasis_message_typeast_local_optimization_begin_type (void)
 Message type for when a local channel optimization begins. More...
 
struct stasis_message_typeast_local_optimization_end_type (void)
 Message type for when a local channel optimization completes. More...
 
int ast_local_setup_bridge (struct ast_channel *ast, struct ast_bridge *bridge, struct ast_channel *swap, struct ast_bridge_features *features)
 Setup the outgoing local channel to join a bridge on ast_call(). More...
 
int ast_local_setup_masquerade (struct ast_channel *ast, struct ast_channel *masq)
 Setup the outgoing local channel to masquerade into a channel on ast_call(). More...
 
void ast_local_unlock_all (void *tech_pvt, struct ast_channel *base_chan, struct ast_channel *base_owner)
 Remove a reference to the given local channel's private tech, unlock the given local channel's private base, and remove references and unlock both sides of given the local channel. More...
 

Detailed Description

Local proxy channel special access.

Author
Richard Mudgett rmudg.nosp@m.ett@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

See Also:

Definition in file core_local.h.

Function Documentation

◆ ast_local_bridge_type()

struct stasis_message_type * ast_local_bridge_type ( void  )

Message type for when two local channel halves are bridged together.

Since
12.0.0
Note
Payloads for the ast_local_bridge_type are a ast_multi_channel_blob. Roles for the channels in the ast_multi_channel_blob are "1" and "2", reflecting the two halves. Unlike most other bridges, the 'bridge' between two local channels is not part of the bridge framework; as such, the message simply references the two local channel halves that are now bridged.
Return values
AStasis Message Bus API message type

Referenced by ast_local_init(), local_message_to_ami(), local_shutdown(), and publish_local_bridge_message().

◆ ast_local_get_peer()

struct ast_channel * ast_local_get_peer ( struct ast_channel ast)

Get the other local channel in the pair.

Since
12.0.0
Parameters
astLocal channel to get peer.
Note
On entry, ast must be locked.
Return values
peerreffed on success.
NULLif no peer or error.

Definition at line 276 of file core_local.c.

277{
278 struct local_pvt *p = ast_channel_tech_pvt(ast);
279 struct local_pvt *found;
280 struct ast_channel *peer;
281
282 if (!p) {
283 return NULL;
284 }
285
286 found = p ? ao2_find(locals, p, 0) : NULL;
287 if (!found) {
288 /* ast is either not a local channel or it has alredy been hungup */
289 return NULL;
290 }
291 ao2_lock(found);
292 if (ast == p->base.owner) {
293 peer = p->base.chan;
294 } else if (ast == p->base.chan) {
295 peer = p->base.owner;
296 } else {
297 peer = NULL;
298 }
299 if (peer) {
300 ast_channel_ref(peer);
301 }
302 ao2_unlock(found);
303 ao2_ref(found, -1);
304 return peer;
305}
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947
static struct ao2_container * locals
Definition: core_local.c:138
#define NULL
Definition: resample.c:96
Main Channel structure associated with a channel.
struct ast_channel * chan
Definition: core_unreal.h:94
struct ast_channel * owner
Definition: core_unreal.h:93
the local pvt structure for all channels
Definition: core_local.c:223
struct ast_unreal_pvt base
Definition: core_local.c:225

References ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_channel_ref, ast_channel_tech_pvt(), local_pvt::base, ast_unreal_pvt::chan, locals, NULL, and ast_unreal_pvt::owner.

Referenced by ari_channels_handle_originate_with_id(), bridge_channel_internal_join(), and park_local_transfer().

◆ ast_local_lock_all()

void ast_local_lock_all ( struct ast_channel chan,
void **  tech_pvt,
struct ast_channel **  base_chan,
struct ast_channel **  base_owner 
)

Add a reference to the local channel's private tech, lock the local channel's private base, and add references and lock both sides of the local channel.

Note
None of these locks should be held prior to calling this function.
To undo this process call ast_local_unlock_all2.
Since
13.17.0, 14.6.0
Parameters
chanMust be a local channel
[out]tech_pvtchannel's private tech (ref and lock added)
[out]base_chanOne side of the local channel (ref and lock added)
[out]base_ownerOther side of the local channel (ref and lock added)

Definition at line 241 of file core_local.c.

243{
244 struct local_pvt *p = ast_channel_tech_pvt(chan);
245
246 *tech_pvt = NULL;
247 *base_chan = NULL;
248 *base_owner = NULL;
249
250 if (p) {
251 *tech_pvt = ao2_bump(p);
252 ast_unreal_lock_all(&p->base, base_chan, base_owner);
253 }
254}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
void ast_unreal_lock_all(struct ast_unreal_pvt *p, struct ast_channel **outchan, struct ast_channel **outowner)
Send an unreal pvt in with no locks held and get all locks.
Definition: core_unreal.c:47

References ao2_bump, ast_channel_tech_pvt(), ast_unreal_lock_all(), local_pvt::base, and NULL.

Referenced by attended_transfer_bridge().

◆ ast_local_optimization_begin_type()

struct stasis_message_type * ast_local_optimization_begin_type ( void  )

Message type for when a local channel optimization begins.

Since
12.0.0
Note
Payloads for the ast_local_optimization_begin_type are a ast_multi_channel_blob. Roles for the channels in the ast_multi_channel_blob are "1" and "2", reflecting the two halves.
Return values
AStasis Message Bus API message type

Referenced by ast_local_init(), AST_TEST_DEFINE(), create_routes(), local_message_to_ami(), local_optimization_started_cb(), local_shutdown(), and setup_stasis_subs().

◆ ast_local_optimization_end_type()

struct stasis_message_type * ast_local_optimization_end_type ( void  )

Message type for when a local channel optimization completes.

Since
12.0.0
Note
Payloads for the ast_local_optimization_end_type are a ast_multi_channel_blob. Roles for the channels in the ast_multi_channel_blob are "1" and "2", reflecting the two halves.
Return values
AStasis Message Bus API message type

Referenced by ast_local_init(), AST_TEST_DEFINE(), create_routes(), local_message_to_ami(), local_optimization_finished_cb(), local_shutdown(), and setup_stasis_subs().

◆ ast_local_setup_bridge()

int ast_local_setup_bridge ( struct ast_channel ast,
struct ast_bridge bridge,
struct ast_channel swap,
struct ast_bridge_features features 
)

Setup the outgoing local channel to join a bridge on ast_call().

Since
12.0.0
Parameters
astEither channel of a local channel pair.
bridgeBridge to join.
swapChannel to swap with when joining.
featuresBridge features structure.
Note
The features parameter must be NULL or obtained by ast_bridge_features_new(). You must not dereference features after calling even if the call fails.
Intended to be called after ast_request() and before ast_call() on a local channel.
Return values
0on success.
-1on error.

Definition at line 601 of file core_local.c.

602{
603 struct local_pvt *p;
604 struct local_pvt *found;
605 int res = -1;
606
607 /* Sanity checks. */
608 if (!ast || !bridge) {
610 return -1;
611 }
612
613 ast_channel_lock(ast);
614 p = ast_channel_tech_pvt(ast);
616
617 found = p ? ao2_find(locals, p, 0) : NULL;
618 if (found) {
619 ao2_lock(found);
620 if (found->type == LOCAL_CALL_ACTION_DIALPLAN
621 && found->base.owner
622 && found->base.chan
624 ao2_ref(bridge, +1);
625 if (swap) {
626 ast_channel_ref(swap);
627 }
629 found->action.bridge.join = bridge;
630 found->action.bridge.swap = swap;
631 found->action.bridge.features = features;
632 res = 0;
633 } else {
635 }
636 ao2_unlock(found);
637 ao2_ref(found, -1);
638 }
639
640 return res;
641}
void ast_bridge_features_destroy(struct ast_bridge_features *features)
Destroy an allocated bridge features struct.
Definition: bridge.c:3674
#define ast_channel_lock(chan)
Definition: channel.h:2922
#define ast_channel_unlock(chan)
Definition: channel.h:2923
@ LOCAL_CALL_ACTION_BRIDGE
Definition: core_local.c:201
@ LOCAL_CALL_ACTION_DIALPLAN
Definition: core_local.c:199
#define AST_UNREAL_CARETAKER_THREAD
Definition: core_unreal.h:107
struct ast_channel * swap
Definition: core_local.c:211
struct ast_bridge * join
Definition: core_local.c:209
struct ast_bridge_features * features
Definition: core_local.c:213
struct local_bridge bridge
Definition: core_local.c:229
union local_pvt::@338 action
enum local_call_action type
Definition: core_local.c:234
#define ast_test_flag(p, flag)
Definition: utils.h:63

References local_pvt::action, ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_bridge_features_destroy(), ast_channel_lock, ast_channel_ref, ast_channel_tech_pvt(), ast_channel_unlock, ast_test_flag, AST_UNREAL_CARETAKER_THREAD, local_pvt::base, local_pvt::bridge, ast_unreal_pvt::chan, local_bridge::features, local_bridge::join, LOCAL_CALL_ACTION_BRIDGE, LOCAL_CALL_ACTION_DIALPLAN, locals, NULL, ast_unreal_pvt::owner, local_bridge::swap, and local_pvt::type.

Referenced by attended_transfer_bridge().

◆ ast_local_setup_masquerade()

int ast_local_setup_masquerade ( struct ast_channel ast,
struct ast_channel masq 
)

Setup the outgoing local channel to masquerade into a channel on ast_call().

Since
12.0.0
Parameters
astEither channel of a local channel pair.
masqChannel to masquerade into.
Note
Intended to be called after ast_request() and before ast_call() on a local channel.
Return values
0on success.
-1on error.

Definition at line 643 of file core_local.c.

644{
645 struct local_pvt *p;
646 struct local_pvt *found;
647 int res = -1;
648
649 /* Sanity checks. */
650 if (!ast || !masq) {
651 return -1;
652 }
653
654 ast_channel_lock(ast);
655 p = ast_channel_tech_pvt(ast);
657
658 found = p ? ao2_find(locals, p, 0) : NULL;
659 if (found) {
660 ao2_lock(found);
661 if (found->type == LOCAL_CALL_ACTION_DIALPLAN
662 && found->base.owner
663 && found->base.chan
667 found->action.masq = masq;
668 res = 0;
669 }
670 ao2_unlock(found);
671 ao2_ref(found, -1);
672 }
673
674 return res;
675}
@ LOCAL_CALL_ACTION_MASQUERADE
Definition: core_local.c:203
struct ast_channel * masq
Definition: core_local.c:231

References local_pvt::action, ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_channel_lock, ast_channel_ref, ast_channel_tech_pvt(), ast_channel_unlock, ast_test_flag, AST_UNREAL_CARETAKER_THREAD, local_pvt::base, ast_unreal_pvt::chan, LOCAL_CALL_ACTION_DIALPLAN, LOCAL_CALL_ACTION_MASQUERADE, locals, local_pvt::masq, NULL, ast_unreal_pvt::owner, and local_pvt::type.

Referenced by attended_transfer_bridge().

◆ ast_local_unlock_all()

void ast_local_unlock_all ( void *  tech_pvt,
struct ast_channel base_chan,
struct ast_channel base_owner 
)

Remove a reference to the given local channel's private tech, unlock the given local channel's private base, and remove references and unlock both sides of given the local channel.

Note
This function should be used in conjunction with ast_local_lock_all2.
Since
13.17.0, 14.6.0
Parameters
tech_pvtchannel's private tech (ref and lock removed)
base_chanOne side of the local channel (ref and lock removed)
base_ownerOther side of the local channel (ref and lock removed)

Definition at line 256 of file core_local.c.

258{
259 if (base_chan) {
260 ast_channel_unlock(base_chan);
261 ast_channel_unref(base_chan);
262 }
263
264 if (base_owner) {
265 ast_channel_unlock(base_owner);
266 ast_channel_unref(base_owner);
267 }
268
269 if (tech_pvt) {
270 struct local_pvt *p = tech_pvt;
271 ao2_unlock(&p->base);
272 ao2_ref(tech_pvt, -1);
273 }
274}
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958

References ao2_ref, ao2_unlock, ast_channel_unlock, ast_channel_unref, and local_pvt::base.

Referenced by attended_transfer_bridge().