Review Board 1.7.16


Add ability to call a function when a channel leaves the bridging system.

Review Request #2535 - Created May 13, 2013 and submitted

rmudgett
team/group/bridge_construction
ASTERISK-21640
Reviewers
asterisk-dev
dlee, mjordan, mmichelson
Asterisk
There are times when a module would like to gain control of a channel that is already in the bridging system but the module does not want the channel in the bridging system when it gains control.

1) The mythical app_queue holding priority bridge when the channel is selected to dial an agent.
2) Stasis-HTTP when it needs to gain control before it initiates dialing.
3) Attended transferring a bridged channel to an application.

Example usage:
ast_after_bridge_callback_set(chan, callback_fn, failed_fn, data);
ast_bridge_remove(bridge, chan)

When the channel leaves the bridge the callback_fn(chan, data) will be made.
Added test code to add a callback when a channel leaves a bridge.
1) The callback was called when the channel left the bridge and was not hung up.
2) The failed callback was called when the channel simply hung up.

Added an explicit remove of the callback datastore.
The failed callback was called as expected.
/team/group/bridge_construction/include/asterisk/bridging.h
Revision 388574 New Change
[20] 1416 lines
[+20] [+] void ast_after_bridge_goto_run(struct ast_channel *chan);
1417
 *
1417
 *
1418
 * \return Nothing
1418
 * \return Nothing
1419
 */
1419
 */
1420
void ast_after_bridge_goto_discard(struct ast_channel *chan);
1420
void ast_after_bridge_goto_discard(struct ast_channel *chan);
1421

    
   
1421

   

    
   
1422
/*! Reason the the after bridge callback will not be called. */

    
   
1423
enum ast_after_bridge_cb_reason {

    
   
1424
	/*! The datastore is being destroyed.  Likely due to hangup. */

    
   
1425
	AST_AFTER_BRIDGE_CB_REASON_DESTROY,

    
   
1426
	/*! Something else replaced the callback with another. */

    
   
1427
	AST_AFTER_BRIDGE_CB_REASON_REPLACED,

    
   
1428
	/*! The callback was removed because of a masquerade. (fixup) */

    
   
1429
	AST_AFTER_BRIDGE_CB_REASON_MASQUERADE,

    
   
1430
	/*! The channel departed bridge. */

    
   
1431
	AST_AFTER_BRIDGE_CB_REASON_DEPART,

    
   
1432
	/*! Was explicitly removed by external code. */

    
   
1433
	AST_AFTER_BRIDGE_CB_REASON_REMOVED,

    
   
1434
};

    
   
1435

   

    
   
1436
/*!

    
   
1437
 * \brief After bridge callback failed.

    
   
1438
 * \since 12.0.0

    
   
1439
 *

    
   
1440
 * \param reason Reason callback is failing.

    
   
1441
 * \param data Extra data what setup the callback wanted to pass.

    
   
1442
 *

    
   
1443
 * \return Nothing

    
   
1444
 */

    
   
1445
typedef void (*ast_after_bridge_cb_failed)(enum ast_after_bridge_cb_reason reason, void *data);

    
   
1446

   

    
   
1447
/*!

    
   
1448
 * \brief After bridge callback function.

    
   
1449
 * \since 12.0.0

    
   
1450
 *

    
   
1451
 * \param chan Channel just leaving bridging system.

    
   
1452
 * \param data Extra data what setup the callback wanted to pass.

    
   
1453
 *

    
   
1454
 * \return Nothing

    
   
1455
 */

    
   
1456
typedef void (*ast_after_bridge_cb)(struct ast_channel *chan, void *data);

    
   
1457

   

    
   
1458
/*!

    
   
1459
 * \brief Discard channel after bridge callback.

    
   
1460
 * \since 12.0.0

    
   
1461
 *

    
   
1462
 * \param chan Channel to discard after bridge callback.

    
   
1463
 * \param reason Why are we doing this.

    
   
1464
 *

    
   
1465
 * \return Nothing

    
   
1466
 */

    
   
1467
void ast_after_bridge_callback_discard(struct ast_channel *chan, enum ast_after_bridge_cb_reason reason);

    
   
1468

   

    
   
1469
/*!

    
   
1470
 * \brief Setup an after bridge callback for when the channel leaves the bridging system.

    
   
1471
 * \since 12.0.0

    
   
1472
 *

    
   
1473
 * \param chan Channel to setup an after bridge callback on.

    
   
1474
 * \param callback Function to call when the channel leaves the bridging system.

    
   
1475
 * \param failed Function to call when will not be calling the callback.

    
   
1476
 * \param data Extra data to pass with the callback.

    
   
1477
 *

    
   
1478
 * \retval 0 on success.

    
   
1479
 * \retval -1 on error.

    
   
1480
 */

    
   
1481
int ast_after_bridge_callback_set(struct ast_channel *chan, ast_after_bridge_cb callback, ast_after_bridge_cb_failed failed, void *data);

    
   
1482

   
1422
/*!
1483
/*!
1423
 * \brief Get a container of all channels in the bridge
1484
 * \brief Get a container of all channels in the bridge
1424
 * \since 12.0.0
1485
 * \since 12.0.0
1425
 *
1486
 *
1426
 * \param bridge The bridge which is already locked.
1487
 * \param bridge The bridge which is already locked.
[+20] [20] 55 lines
/team/group/bridge_construction/main/bridging.c
Revision 388574 New Change
 
  1. /team/group/bridge_construction/include/asterisk/bridging.h: Loading...
  2. /team/group/bridge_construction/main/bridging.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.