Asterisk - The Open Source Telephony Project  21.4.1
Functions
core_local.h File Reference

Local proxy channel special access. More...

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

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().

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.

References ao2_ref, ast_channel_ref, local_pvt::base, ast_unreal_pvt::chan, and ast_unreal_pvt::owner.

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 }
Main Channel structure associated with a channel.
struct ast_channel * owner
Definition: core_unreal.h:93
struct ast_unreal_pvt base
Definition: core_local.c:225
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_channel * chan
Definition: core_unreal.h:94
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947
the local pvt structure for all channels
Definition: core_local.c:223
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.

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

Referenced by attended_transfer_bridge().

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
struct ast_unreal_pvt base
Definition: core_local.c:225
the local pvt structure for all channels
Definition: core_local.c:223
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
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(), create_routes(), and local_optimization_started_cb().

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(), create_routes(), and local_optimization_finished_cb().

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.

References local_pvt::action, ao2_ref, ast_bridge_features_destroy(), ast_channel_ref, AST_UNREAL_CARETAKER_THREAD, local_pvt::base, local_pvt::bridge, ast_unreal_pvt::chan, local_bridge::features, local_bridge::join, ast_unreal_pvt::owner, local_bridge::swap, and local_pvt::type.

Referenced by attended_transfer_bridge().

602 {
603  struct local_pvt *p;
604  struct local_pvt *found;
605  int res = -1;
606 
607  /* Sanity checks. */
608  if (!ast || !bridge) {
609  ast_bridge_features_destroy(features);
610  return -1;
611  }
612 
613  ast_channel_lock(ast);
614  p = ast_channel_tech_pvt(ast);
615  ast_channel_unlock(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
623  && !ast_test_flag(&found->base, AST_UNREAL_CARETAKER_THREAD)) {
624  ao2_ref(bridge, +1);
625  if (swap) {
626  ast_channel_ref(swap);
627  }
628  found->type = LOCAL_CALL_ACTION_BRIDGE;
629  found->action.bridge.join = bridge;
630  found->action.bridge.swap = swap;
631  found->action.bridge.features = features;
632  res = 0;
633  } else {
634  ast_bridge_features_destroy(features);
635  }
636  ao2_unlock(found);
637  ao2_ref(found, -1);
638  }
639 
640  return res;
641 }
struct ast_channel * owner
Definition: core_unreal.h:93
struct ast_channel * swap
Definition: core_local.c:211
#define AST_UNREAL_CARETAKER_THREAD
Definition: core_unreal.h:107
void ast_bridge_features_destroy(struct ast_bridge_features *features)
Destroy an allocated bridge features struct.
Definition: bridge.c:3674
struct ast_unreal_pvt base
Definition: core_local.c:225
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_bridge_features * features
Definition: core_local.c:213
struct ast_channel * chan
Definition: core_unreal.h:94
enum local_call_action type
Definition: core_local.c:234
union local_pvt::@342 action
struct ast_bridge * join
Definition: core_local.c:209
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947
the local pvt structure for all channels
Definition: core_local.c:223
struct local_bridge bridge
Definition: core_local.c:229
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.

References local_pvt::action, ao2_ref, ast_channel_ref, AST_UNREAL_CARETAKER_THREAD, local_pvt::base, ast_unreal_pvt::chan, local_pvt::masq, ast_unreal_pvt::owner, and local_pvt::type.

Referenced by attended_transfer_bridge().

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);
656  ast_channel_unlock(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
664  && !ast_test_flag(&found->base, AST_UNREAL_CARETAKER_THREAD)) {
665  ast_channel_ref(masq);
666  found->type = LOCAL_CALL_ACTION_MASQUERADE;
667  found->action.masq = masq;
668  res = 0;
669  }
670  ao2_unlock(found);
671  ao2_ref(found, -1);
672  }
673 
674  return res;
675 }
struct ast_channel * owner
Definition: core_unreal.h:93
#define AST_UNREAL_CARETAKER_THREAD
Definition: core_unreal.h:107
struct ast_unreal_pvt base
Definition: core_local.c:225
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_channel * chan
Definition: core_unreal.h:94
enum local_call_action type
Definition: core_local.c:234
union local_pvt::@342 action
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947
the local pvt structure for all channels
Definition: core_local.c:223
struct ast_channel * masq
Definition: core_local.c:231
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.

References ao2_ref, ast_channel_unref, and local_pvt::base.

Referenced by attended_transfer_bridge().

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
struct ast_unreal_pvt base
Definition: core_local.c:225
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
the local pvt structure for all channels
Definition: core_local.c:223