Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 288 of file core_local.c.

289{
290 struct local_pvt *p = ast_channel_tech_pvt(ast);
291 struct local_pvt *found;
292 struct ast_channel *peer;
293
294 if (!p) {
295 return NULL;
296 }
297
298 found = p ? ao2_find(locals, p, 0) : NULL;
299 if (!found) {
300 /* ast is either not a local channel or it has already been hungup */
301 return NULL;
302 }
303 ao2_lock(found);
304 if (ast == p->base.owner) {
305 peer = p->base.chan;
306 } else if (ast == p->base.chan) {
307 peer = p->base.owner;
308 } else {
309 peer = NULL;
310 }
311 if (peer) {
312 ast_channel_ref(peer);
313 }
314 ao2_unlock(found);
315 ao2_ref(found, -1);
316 return peer;
317}
#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:2995
static struct ao2_container * locals
Definition: core_local.c:150
#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:235
struct ast_unreal_pvt base
Definition: core_local.c:237

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 253 of file core_local.c.

255{
256 struct local_pvt *p = ast_channel_tech_pvt(chan);
257
258 *tech_pvt = NULL;
259 *base_chan = NULL;
260 *base_owner = NULL;
261
262 if (p) {
263 *tech_pvt = ao2_bump(p);
264 ast_unreal_lock_all(&p->base, base_chan, base_owner);
265 }
266}
#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 613 of file core_local.c.

614{
615 struct local_pvt *p;
616 struct local_pvt *found;
617 int res = -1;
618
619 /* Sanity checks. */
620 if (!ast || !bridge) {
622 return -1;
623 }
624
625 ast_channel_lock(ast);
626 p = ast_channel_tech_pvt(ast);
628
629 found = p ? ao2_find(locals, p, 0) : NULL;
630 if (found) {
631 ao2_lock(found);
632 if (found->type == LOCAL_CALL_ACTION_DIALPLAN
633 && found->base.owner
634 && found->base.chan
636 ao2_ref(bridge, +1);
637 if (swap) {
638 ast_channel_ref(swap);
639 }
641 found->action.bridge.join = bridge;
642 found->action.bridge.swap = swap;
643 found->action.bridge.features = features;
644 res = 0;
645 } else {
647 }
648 ao2_unlock(found);
649 ao2_ref(found, -1);
650 }
651
652 return res;
653}
void ast_bridge_features_destroy(struct ast_bridge_features *features)
Destroy an allocated bridge features struct.
Definition: bridge.c:3743
#define ast_channel_lock(chan)
Definition: channel.h:2970
#define ast_channel_unlock(chan)
Definition: channel.h:2971
@ LOCAL_CALL_ACTION_BRIDGE
Definition: core_local.c:213
@ LOCAL_CALL_ACTION_DIALPLAN
Definition: core_local.c:211
#define AST_UNREAL_CARETAKER_THREAD
Definition: core_unreal.h:107
struct ast_channel * swap
Definition: core_local.c:223
struct ast_bridge * join
Definition: core_local.c:221
struct ast_bridge_features * features
Definition: core_local.c:225
struct local_bridge bridge
Definition: core_local.c:241
union local_pvt::@341 action
enum local_call_action type
Definition: core_local.c:246
#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 655 of file core_local.c.

656{
657 struct local_pvt *p;
658 struct local_pvt *found;
659 int res = -1;
660
661 /* Sanity checks. */
662 if (!ast || !masq) {
663 return -1;
664 }
665
666 ast_channel_lock(ast);
667 p = ast_channel_tech_pvt(ast);
669
670 found = p ? ao2_find(locals, p, 0) : NULL;
671 if (found) {
672 ao2_lock(found);
673 if (found->type == LOCAL_CALL_ACTION_DIALPLAN
674 && found->base.owner
675 && found->base.chan
679 found->action.masq = masq;
680 res = 0;
681 }
682 ao2_unlock(found);
683 ao2_ref(found, -1);
684 }
685
686 return res;
687}
@ LOCAL_CALL_ACTION_MASQUERADE
Definition: core_local.c:215
struct ast_channel * masq
Definition: core_local.c:243

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 268 of file core_local.c.

270{
271 if (base_chan) {
272 ast_channel_unlock(base_chan);
273 ast_channel_unref(base_chan);
274 }
275
276 if (base_owner) {
277 ast_channel_unlock(base_owner);
278 ast_channel_unref(base_owner);
279 }
280
281 if (tech_pvt) {
282 struct local_pvt *p = tech_pvt;
283 ao2_unlock(&p->base);
284 ao2_ref(tech_pvt, -1);
285 }
286}
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3006

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

Referenced by attended_transfer_bridge().