Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Typedefs | Functions
stasis_app_impl.h File Reference

Backend API for implementing components of res_stasis. More...

#include "asterisk/stasis_app.h"
Include dependency graph for stasis_app_impl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* command_data_destructor_fn) (void *data)
 Typedef for data destructor for stasis app commands. More...
 
typedef int(* stasis_app_command_cb) (struct stasis_app_control *control, struct ast_channel *chan, void *data)
 

Functions

int stasis_app_exec (struct ast_channel *chan, const char *app_name, int argc, char *argv[])
 Control a channel using stasis_app. More...
 
int stasis_app_send_command (struct stasis_app_control *control, stasis_app_command_cb command, void *data, command_data_destructor_fn data_destructor)
 Invokes a command on a control's channel. More...
 
int stasis_app_send_command_async (struct stasis_app_control *control, stasis_app_command_cb command, void *data, command_data_destructor_fn data_destructor)
 Asynchronous version of stasis_app_send_command(). More...
 

Detailed Description

Backend API for implementing components of res_stasis.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m
Since
12

This file defines functions useful for defining new commands to execute on channels while they are in Stasis.

Definition in file stasis_app_impl.h.

Typedef Documentation

◆ command_data_destructor_fn

typedef void(* command_data_destructor_fn) (void *data)

Typedef for data destructor for stasis app commands.

This is called during destruction of the command or if we fail to schedule a command. It is passed a pointer to the user-defined data of the command.

Parameters
dataData to destroy.

Definition at line 59 of file stasis_app_impl.h.

◆ stasis_app_command_cb

typedef int(* stasis_app_command_cb) (struct stasis_app_control *control, struct ast_channel *chan, void *data)

Callback type for stasis app commands

Definition at line 62 of file stasis_app_impl.h.

Function Documentation

◆ stasis_app_exec()

int stasis_app_exec ( struct ast_channel chan,
const char *  app_name,
int  argc,
char *  argv[] 
)

Control a channel using stasis_app.

Since
12

This function blocks until the channel hangs up, or stasis_app_control_continue() is called on the channel's stasis_app_control struct.

Parameters
chanChannel to control with Stasis.
app_nameApplication controlling the channel.
argcNumber of arguments for the application.
argvArguments for the application.

Control a channel using stasis_app.

Definition at line 1369 of file res_stasis.c.

1371{
1372 RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
1373 RAII_VAR(struct stasis_app_control *, control, NULL, control_unlink);
1374 struct ast_bridge *bridge = NULL;
1375 int res = 0;
1376 int needs_depart;
1377
1378 ast_assert(chan != NULL);
1379
1380 /* Just in case there's a lingering indication that the channel has had a stasis
1381 * end published on it, remove that now.
1382 */
1384
1385 if (!apps_registry) {
1386 return -1;
1387 }
1388
1390 if (!app) {
1392 "Stasis app '%s' not registered\n", app_name);
1393 return -1;
1394 }
1395 if (!app_is_active(app)) {
1397 "Stasis app '%s' not active\n", app_name);
1398 return -1;
1399 }
1400
1401 control = control_create(chan, app);
1402 if (!control) {
1403 ast_log(LOG_ERROR, "Control allocation failed or Stasis app '%s' not registered\n", app_name);
1404 return -1;
1405 }
1406
1407 if (!control_app(control)) {
1408 ast_log(LOG_ERROR, "Stasis app '%s' not registered\n", app_name);
1409 return -1;
1410 }
1411
1412 if (!app_is_active(control_app(control))) {
1413 ast_log(LOG_ERROR, "Stasis app '%s' not active\n", app_name);
1414 return -1;
1415 }
1416 ao2_link(app_controls, control);
1417
1418 if (add_masquerade_store(chan)) {
1419 ast_log(LOG_ERROR, "Failed to attach masquerade detector\n");
1420 return -1;
1421 }
1422
1423 res = send_start_msg(control_app(control), chan, argc, argv);
1424 if (res != 0) {
1426 "Error sending start message to '%s'\n", app_name);
1428 return -1;
1429 }
1430
1431 /* Pull queued prestart commands and execute */
1432 control_prestart_dispatch_all(control, chan);
1433
1434 while (!control_is_done(control)) {
1435 RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
1436 int r;
1437 int command_count;
1438 RAII_VAR(struct ast_bridge *, last_bridge, NULL, ao2_cleanup);
1439
1440 /* Check to see if a bridge absorbed our hangup frame */
1441 if (ast_check_hangup_locked(chan)) {
1442 control_mark_done(control);
1443 break;
1444 }
1445
1446 /* control->next_app is only modified within the control thread, so this is safe */
1447 if (control_next_app(control)) {
1448 struct stasis_app *next_app = ao2_find(apps_registry, control_next_app(control), OBJ_SEARCH_KEY);
1449
1450 if (next_app && app_is_active(next_app)) {
1451 int idx;
1452 int next_argc;
1453 char **next_argv;
1454
1455 /* If something goes wrong in this conditional, res will need to be non-zero
1456 * so that the code below the exec loop knows something went wrong during a move.
1457 */
1459 res = has_masquerade_store(chan) && app_send_end_msg(control_app(control), chan);
1460 if (res != 0) {
1462 "Error sending end message to %s\n", stasis_app_name(control_app(control)));
1463 control_mark_done(control);
1464 ao2_ref(next_app, -1);
1465 break;
1466 }
1467 } else {
1469 }
1470
1471 /* This will ao2_bump next_app, and unref the previous app by 1 */
1472 control_set_app(control, next_app);
1473
1474 /* There's a chance that the previous application is ready for clean up, so go ahead
1475 * and do that now.
1476 */
1477 cleanup();
1478
1479 /* We need to add another masquerade store, otherwise the leave message will
1480 * not show up for the correct application.
1481 */
1482 if (add_masquerade_store(chan)) {
1483 ast_log(LOG_ERROR, "Failed to attach masquerade detector\n");
1484 res = -1;
1485 control_mark_done(control);
1486 ao2_ref(next_app, -1);
1487 break;
1488 }
1489
1490 /* We MUST get the size before the list, as control_next_app_args steals the elements
1491 * from the string vector.
1492 */
1493 next_argc = control_next_app_args_size(control);
1494 next_argv = control_next_app_args(control);
1495
1496 res = send_start_msg(control_app(control), chan, next_argc, next_argv);
1497
1498 /* Even if res != 0, we still need to free the memory we got from control_argv */
1499 if (next_argv) {
1500 for (idx = 0; idx < next_argc; idx++) {
1501 ast_free(next_argv[idx]);
1502 }
1503 ast_free(next_argv);
1504 }
1505
1506 if (res != 0) {
1508 "Error sending start message to '%s'\n", stasis_app_name(control_app(control)));
1510 control_mark_done(control);
1511 ao2_ref(next_app, -1);
1512 break;
1513 }
1514
1515 /* Done switching applications, free memory and clean up */
1516 control_move_cleanup(control);
1517 } else {
1518 /* If we can't switch applications, do nothing */
1519 struct ast_json *msg;
1520 RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
1521
1522 if (!next_app) {
1523 ast_log(LOG_ERROR, "Could not move to Stasis app '%s' - not registered\n",
1524 control_next_app(control));
1525 } else {
1526 ast_log(LOG_ERROR, "Could not move to Stasis app '%s' - not active\n",
1527 control_next_app(control));
1528 }
1529
1531 if (!snapshot) {
1532 ast_log(LOG_ERROR, "Could not get channel shapshot for '%s'\n",
1533 ast_channel_name(chan));
1534 } else {
1535 struct ast_json *json_args;
1536 int next_argc = control_next_app_args_size(control);
1537 char **next_argv = control_next_app_args(control);
1538
1539 msg = ast_json_pack("{s: s, s: o, s: o, s: s, s: []}",
1540 "type", "ApplicationMoveFailed",
1541 "timestamp", ast_json_timeval(ast_tvnow(), NULL),
1542 "channel", ast_channel_snapshot_to_json(snapshot, NULL),
1543 "destination", control_next_app(control),
1544 "args");
1545 if (!msg) {
1546 ast_log(LOG_ERROR, "Failed to pack JSON for ApplicationMoveFailed message\n");
1547 } else {
1548 json_args = ast_json_object_get(msg, "args");
1549 if (!json_args) {
1550 ast_log(LOG_ERROR, "Could not get args json array");
1551 } else {
1552 int r = 0;
1553 int idx;
1554 for (idx = 0; idx < next_argc; ++idx) {
1555 r = ast_json_array_append(json_args,
1556 ast_json_string_create(next_argv[idx]));
1557 if (r != 0) {
1558 ast_log(LOG_ERROR, "Error appending to ApplicationMoveFailed message\n");
1559 break;
1560 }
1561 }
1562 if (r == 0) {
1563 app_send(control_app(control), msg);
1564 }
1565 }
1566 ast_json_unref(msg);
1567 }
1568 }
1569 }
1570 control_move_cleanup(control);
1571 ao2_cleanup(next_app);
1572 }
1573
1574 last_bridge = bridge;
1575 bridge = ao2_bump(stasis_app_get_bridge(control));
1576
1577 if (bridge != last_bridge) {
1578 if (last_bridge) {
1579 app_unsubscribe_bridge(control_app(control), last_bridge);
1580 }
1581 if (bridge) {
1582 app_subscribe_bridge(control_app(control), bridge);
1583 }
1584 }
1585
1586 if (bridge) {
1587 /* Bridge/dial is handling channel frames */
1588 control_wait(control);
1589 control_dispatch_all(control, chan);
1590 continue;
1591 }
1592
1593 r = ast_waitfor(chan, MAX_WAIT_MS);
1594
1595 if (r < 0) {
1596 ast_debug(3, "%s: Poll error\n",
1597 ast_channel_uniqueid(chan));
1598 control_mark_done(control);
1599 break;
1600 }
1601
1602 command_count = control_dispatch_all(control, chan);
1603
1604 if (command_count > 0 && ast_channel_fdno(chan) == -1) {
1605 /* Command drained the channel; wait for next frame */
1606 continue;
1607 }
1608
1609 if (r == 0) {
1610 /* Timeout */
1611 continue;
1612 }
1613
1614 f = ast_read(chan);
1615 if (!f) {
1616 /* Continue on in the dialplan */
1617 ast_debug(3, "%s: Hangup (no more frames)\n",
1618 ast_channel_uniqueid(chan));
1619 control_mark_done(control);
1620 break;
1621 }
1622
1623 if (f->frametype == AST_FRAME_CONTROL) {
1624 if (f->subclass.integer == AST_CONTROL_HANGUP) {
1625 /* Continue on in the dialplan */
1626 ast_debug(3, "%s: Hangup\n",
1627 ast_channel_uniqueid(chan));
1628 control_mark_done(control);
1629 break;
1630 }
1631 }
1632 }
1633
1634 ast_channel_lock(chan);
1635 needs_depart = (ast_channel_internal_bridge_channel(chan) != NULL);
1636 ast_channel_unlock(chan);
1637 if (needs_depart) {
1638 ast_bridge_depart(chan);
1639 }
1640
1641 if (stasis_app_get_bridge(control)) {
1643 }
1644 ao2_cleanup(bridge);
1645
1646 /* Only publish a stasis_end event if it hasn't already been published */
1647 if (!res && !stasis_app_channel_is_stasis_end_published(chan)) {
1648 /* A masquerade has occurred and this message will be wrong so it
1649 * has already been sent elsewhere. */
1650 res = has_masquerade_store(chan) && app_send_end_msg(control_app(control), chan);
1651 if (res != 0) {
1653 "Error sending end message to %s\n", stasis_app_name(control_app(control)));
1654 return res;
1655 }
1656 } else {
1658 }
1659
1660 control_flush_queue(control);
1661
1662 /* Stop any lingering silence generator */
1663 control_silence_stop_now(control);
1664
1665 /* There's an off chance that app is ready for cleanup. Go ahead
1666 * and clean up, just in case
1667 */
1668 cleanup();
1669
1670 if (stasis_app_control_is_failed(control)) {
1671 res = -1;
1672 }
1673 /* The control needs to be removed from the controls container in
1674 * case a new PBX is started and ends up coming back into Stasis.
1675 */
1676 control_unlink(control);
1677 control = NULL;
1678
1679 if (!res && !ast_channel_pbx(chan)) {
1680 int chan_hungup;
1681
1682 /* The ASYNCGOTO softhangup flag may have broken the channel out of
1683 * its bridge to run dialplan, so if there's no pbx on the channel
1684 * let it run dialplan here. Otherwise, it will run when this
1685 * application exits. */
1686 ast_channel_lock(chan);
1688 chan_hungup = ast_check_hangup(chan);
1689 ast_channel_unlock(chan);
1690
1691 if (!chan_hungup) {
1692 struct ast_pbx_args pbx_args;
1693
1694 memset(&pbx_args, 0, sizeof(pbx_args));
1695 pbx_args.no_hangup_chan = 1;
1696
1697 res = ast_pbx_run_args(chan, &pbx_args);
1698 }
1699 }
1700
1701 return res;
1702}
static const char app[]
Definition: app_adsiprog.c:56
#define ast_free(a)
Definition: astmm.h:180
#define ast_log
Definition: astobj2.c:42
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
int ast_bridge_depart(struct ast_channel *chan)
Depart a channel from a bridge.
Definition: bridge.c:1975
const char * ast_channel_name(const struct ast_channel *chan)
void ast_channel_clear_softhangup(struct ast_channel *chan, int flag)
Clear a set of softhangup flags from a channel.
Definition: channel.c:2401
int ast_channel_fdno(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2972
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3130
const char * ast_channel_uniqueid(const struct ast_channel *chan)
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:458
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4214
struct ast_bridge_channel * ast_channel_internal_bridge_channel(const struct ast_channel *chan)
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:444
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2973
@ AST_SOFTHANGUP_ASYNCGOTO
Definition: channel.h:1146
struct stasis_app_control * control_create(struct ast_channel *channel, struct stasis_app *app)
Create a control object.
Definition: control.c:131
int control_prestart_dispatch_all(struct stasis_app_control *control, struct ast_channel *chan)
Dispatch all queued prestart commands.
Definition: control.c:1565
void control_wait(struct stasis_app_control *control)
Blocks until control's command queue has a command available.
Definition: control.c:1545
char ** control_next_app_args(struct stasis_app_control *control)
Returns the list of arguments to pass to the application we are moving to.
Definition: control.c:1740
int control_is_done(struct stasis_app_control *control)
Returns true if control_continue() has been called on this control.
Definition: control.c:363
void control_flush_queue(struct stasis_app_control *control)
Flush the control command queue.
Definition: control.c:1512
int control_dispatch_all(struct stasis_app_control *control, struct ast_channel *chan)
Dispatch all commands enqueued to this control.
Definition: control.c:1525
int control_next_app_args_size(struct stasis_app_control *control)
Returns the number of arguments to be passed to the application we are moving to.
Definition: control.c:1745
void control_set_app(struct stasis_app_control *control, struct stasis_app *app)
Set the application the control object belongs to.
Definition: control.c:1721
void control_silence_stop_now(struct stasis_app_control *control)
Stop playing silence to a channel right now.
Definition: control.c:863
char * control_next_app(struct stasis_app_control *control)
Returns the name of the application we are moving to.
Definition: control.c:1727
struct stasis_app * control_app(struct stasis_app_control *control)
Returns the pointer (non-reffed) to the app associated with this control.
Definition: control.c:1593
void control_move_cleanup(struct stasis_app_control *control)
Free any memory that was allocated for switching applications via /channels/{channelId}/move.
Definition: control.c:1732
void control_mark_done(struct stasis_app_control *control)
Definition: control.c:369
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...
void ast_frame_dtor(struct ast_frame *frame)
NULL-safe wrapper for ast_frfree, good for RAII_VAR.
Definition: main/frame.c:187
@ AST_FRAME_CONTROL
@ AST_CONTROL_HANGUP
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:278
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:378
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:670
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
enum ast_pbx_result ast_pbx_run_args(struct ast_channel *c, struct ast_pbx_args *args)
Execute the PBX in the current thread.
Definition: pbx.c:4750
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
int app_subscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge)
Add a bridge subscription to an existing channel subscription.
int app_unsubscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge)
Cancel the bridge subscription for an application.
int app_is_active(struct stasis_app *app)
Checks whether an app is active.
void app_send(struct stasis_app *app, struct ast_json *message)
Send a message to an application.
static int send_start_msg(struct stasis_app *app, struct ast_channel *chan, int argc, char *argv[])
Definition: res_stasis.c:1102
struct ao2_container * app_controls
Definition: res_stasis.c:102
static void remove_stasis_end_published(struct ast_channel *chan)
Definition: res_stasis.c:1355
static void cleanup(void)
Clean up any old apps that we don't need any more.
Definition: res_stasis.c:327
static int add_masquerade_store(struct ast_channel *chan)
Definition: res_stasis.c:1262
static int has_masquerade_store(struct ast_channel *chan)
Definition: res_stasis.c:1256
int app_send_end_msg(struct stasis_app *app, struct ast_channel *chan)
Send StasisEnd message to the listening app.
Definition: res_stasis.c:1128
#define MAX_WAIT_MS
Definition: res_stasis.c:77
static void remove_masquerade_store(struct ast_channel *chan)
Definition: res_stasis.c:1281
struct ao2_container * apps_registry
Stasis application container.
Definition: res_stasis.c:100
static void control_unlink(struct stasis_app_control *control)
In addition to running ao2_cleanup(), this function also removes the object from the app_controls con...
Definition: res_stasis.c:811
int stasis_app_channel_is_stasis_end_published(struct ast_channel *chan)
Has this channel had a StasisEnd published on it?
Definition: res_stasis.c:1344
#define NULL
Definition: resample.c:96
int stasis_app_control_is_failed(const struct stasis_app_control *control)
Check if a control object is marked as "failed".
Definition: control.c:382
struct ast_bridge * stasis_app_get_bridge(struct stasis_app_control *control)
Gets the bridge currently associated with a control object.
Definition: control.c:957
const char * stasis_app_name(const struct stasis_app *app)
Retrieve an application's name.
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
Structure that contains information about a bridge.
Definition: bridge.h:353
Structure representing a snapshot of channel state.
Data structure associated with a single frame of data.
Abstract JSON element (object, array, string, int, ...).
Options for ast_pbx_run()
Definition: pbx.h:408
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
#define ast_assert(a)
Definition: utils.h:739

References add_masquerade_store(), ao2_bump, ao2_cleanup, ao2_find, ao2_link, ao2_ref, app, app_controls, app_is_active(), app_name(), app_send(), app_send_end_msg(), app_subscribe_bridge(), app_unsubscribe_bridge(), apps_registry, ast_assert, ast_bridge_depart(), ast_channel_clear_softhangup(), ast_channel_fdno(), ast_channel_internal_bridge_channel(), ast_channel_lock, ast_channel_name(), ast_channel_pbx(), ast_channel_snapshot_get_latest(), ast_channel_snapshot_to_json(), ast_channel_uniqueid(), ast_channel_unlock, ast_check_hangup(), ast_check_hangup_locked(), AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CONTROL, ast_frame_dtor(), ast_free, ast_json_array_append(), ast_json_object_get(), ast_json_pack(), ast_json_string_create(), ast_json_timeval(), ast_json_unref(), ast_log, ast_pbx_run_args(), ast_read(), AST_SOFTHANGUP_ASYNCGOTO, ast_tvnow(), ast_waitfor(), cleanup(), control_app(), control_create(), control_dispatch_all(), control_flush_queue(), control_is_done(), control_mark_done(), control_move_cleanup(), control_next_app(), control_next_app_args(), control_next_app_args_size(), control_prestart_dispatch_all(), control_set_app(), control_silence_stop_now(), control_unlink(), control_wait(), has_masquerade_store(), LOG_ERROR, MAX_WAIT_MS, ast_pbx_args::no_hangup_chan, NULL, OBJ_SEARCH_KEY, RAII_VAR, remove_masquerade_store(), remove_stasis_end_published(), send_start_msg(), stasis_app_channel_is_stasis_end_published(), stasis_app_control_is_failed(), stasis_app_get_bridge(), and stasis_app_name().

Referenced by app_exec().

◆ stasis_app_send_command()

int stasis_app_send_command ( struct stasis_app_control control,
stasis_app_command_cb  command,
void *  data,
command_data_destructor_fn  data_destructor 
)

Invokes a command on a control's channel.

Since
12

This function dispatches the command to be executed in the context of stasis_app_exec(), so this command will block waiting for the results of the command.

Parameters
controlControl object for the channel to send the command to.
commandCommand function to execute.
dataOptional data to pass along with the control function.
data_destructorOptional function which will be called on the data in either the event of command completion or failure to schedule or complete the command
Returns
zero on success.
error code otherwise.

Definition at line 924 of file control.c.

926{
927 return app_send_command_on_condition(control, command_fn, data, data_destructor, NULL);
928}
static int app_send_command_on_condition(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor, app_command_can_exec_cb can_exec_fn)
Definition: control.c:892

References app_send_command_on_condition(), stasis_app_command::data, stasis_app_command::data_destructor, and NULL.

Referenced by ast_ari_bridges_set_video_source(), and stasis_app_control_answer().

◆ stasis_app_send_command_async()

int stasis_app_send_command_async ( struct stasis_app_control control,
stasis_app_command_cb  command,
void *  data,
command_data_destructor_fn  data_destructor 
)

Asynchronous version of stasis_app_send_command().

Since
12

This function enqueues a command for execution, but returns immediately without waiting for the response.

Parameters
controlControl object for the channel to send the command to.
commandCommand function to execute.
dataOptional data to pass along with the control function.
data_destructorOptional function which will be called on the data in either the event of command completion or failure to schedule or complete the command
Returns
0 on success.
Non-zero on error.

Definition at line 930 of file control.c.

933{
934 struct stasis_app_command *command;
935
936 if (control == NULL || control->is_done) {
937 /* If exec_command fails, it calls the data_destructor. In order to
938 * provide consistent behavior, we'll also call the data_destructor
939 * on this error path. This way, callers never have to call the
940 * data_destructor themselves.
941 */
942 if (data_destructor) {
944 }
945 return -1;
946 }
947
948 command = exec_command(control, command_fn, data, data_destructor);
949 if (!command) {
950 return -1;
951 }
952 ao2_ref(command, -1);
953
954 return 0;
955}
static struct stasis_app_command * exec_command(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor)
Definition: control.c:316
command_data_destructor_fn data_destructor
Definition: command.c:38
unsigned int is_done
Definition: control.c:105

References ao2_ref, stasis_app_command::data, stasis_app_command::data_destructor, exec_command(), stasis_app_control::is_done, and NULL.

Referenced by bridge_timeout(), dial_bridge_after_cb(), internal_bridge_after_cb(), stasis_app_control_add_role(), stasis_app_control_clear_roles(), stasis_app_control_continue(), stasis_app_control_dial(), stasis_app_control_dtmf(), stasis_app_control_hold(), stasis_app_control_moh_start(), stasis_app_control_moh_stop(), stasis_app_control_move(), stasis_app_control_mute(), stasis_app_control_play_uri(), stasis_app_control_record(), stasis_app_control_redirect(), stasis_app_control_ring(), stasis_app_control_ring_stop(), stasis_app_control_set_channel_var(), stasis_app_control_silence_start(), stasis_app_control_silence_stop(), stasis_app_control_unhold(), and stasis_app_control_unmute().