res/stasis/app.h File Reference

Internal API for the Stasis application controller. More...

#include "asterisk/channel.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_app.h"

Include dependency graph for res/stasis/app.h:

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

Go to the source code of this file.

Functions

struct stasis_appapp_create (const char *name, stasis_app_cb handler, void *data)
 Create a res_stasis application.
void app_deactivate (struct stasis_app *app)
 Deactivates an application.
char * app_get_replace_channel_app (struct ast_channel *chan)
 Get the app that the replacement channel will be controlled by.
int app_is_active (struct stasis_app *app)
 Checks whether an app is active.
int app_is_finished (struct stasis_app *app)
 Checks whether a deactivated app has no channels.
int app_is_subscribed_bridge_id (struct stasis_app *app, const char *bridge_id)
 Test if an app is subscribed to a bridge.
int app_is_subscribed_channel_id (struct stasis_app *app, const char *channel_id)
 Test if an app is subscribed to a channel.
int app_is_subscribed_endpoint_id (struct stasis_app *app, const char *endpoint_id)
 Test if an app is subscribed to a endpoint.
const char * app_name (const struct stasis_app *app)
 Return an application's name.
void app_send (struct stasis_app *app, struct ast_json *message)
 Send a message to an application.
int app_send_end_msg (struct stasis_app *app, struct ast_channel *chan)
 Send StasisEnd message to the listening app.
int app_set_replace_channel_app (struct ast_channel *chan, const char *replace_app)
 Set the app that the replacement channel will be controlled by.
int app_set_replace_channel_snapshot (struct ast_channel *chan, struct ast_channel_snapshot *replace_snapshot)
 Set the snapshot of the channel that this channel will replace.
void app_shutdown (struct stasis_app *app)
 Tears down an application.
int app_subscribe_bridge (struct stasis_app *app, struct ast_bridge *bridge)
 Add a bridge subscription to an existing channel subscription.
int app_subscribe_channel (struct stasis_app *app, struct ast_channel *chan)
 Subscribes an application to a channel.
int app_subscribe_endpoint (struct stasis_app *app, struct ast_endpoint *endpoint)
 Subscribes an application to a endpoint.
struct ast_jsonapp_to_json (const struct stasis_app *app)
int app_unsubscribe_bridge (struct stasis_app *app, struct ast_bridge *bridge)
 Cancel the bridge subscription for an application.
int app_unsubscribe_bridge_id (struct stasis_app *app, const char *bridge_id)
 Cancel the subscription an app has for a bridge.
int app_unsubscribe_channel (struct stasis_app *app, struct ast_channel *chan)
 Cancel the subscription an app has for a channel.
int app_unsubscribe_channel_id (struct stasis_app *app, const char *channel_id)
 Cancel the subscription an app has for a channel.
int app_unsubscribe_endpoint_id (struct stasis_app *app, const char *endpoint_id)
 Cancel the subscription an app has for a endpoint.
void app_update (struct stasis_app *app, stasis_app_cb handler, void *data)
 Update the handler and data for a res_stasis application.


Detailed Description

Internal API for the Stasis application controller.

Author:
David M. Lee, II <dlee@digium.com>
Since:
12

Definition in file res/stasis/app.h.


Function Documentation

struct stasis_app* app_create ( const char *  name,
stasis_app_cb  handler,
void *  data 
) [read]

Create a res_stasis application.

Parameters:
name Name of the application.
handler Callback for messages sent to the application.
data Data pointer provided to the callback.
Returns:
New res_stasis application.

NULL on error.

Definition at line 796 of file res/stasis/app.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_alloc_options, ao2_cleanup, AO2_CONTAINER_ALLOC_OPT_DUPS_OBJ_REJECT, ao2_container_alloc_rbtree, ao2_ref, app, app_dtor(), ast_assert, ast_attended_transfer_type(), ast_blind_transfer_type(), ast_bridge_merge_message_type(), ast_bridge_snapshot_type(), ast_bridge_topic_all(), ast_channel_snapshot_type(), ast_endpoint_snapshot_type(), ast_verb, bridge_attended_transfer_handler(), bridge_blind_transfer_handler(), bridge_default_handler(), bridge_merge_handler(), forwards_sort(), NULL, RAII_VAR, stasis_message_router_add(), stasis_message_router_add_cache_update(), stasis_message_router_create(), stasis_message_router_set_default(), stasis_topic_create(), sub_bridge_update_handler(), sub_channel_update_handler(), sub_default_handler(), and sub_endpoint_update_handler().

Referenced by stasis_app_register().

00797 {
00798    RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
00799    size_t size;
00800    int res = 0;
00801 
00802    ast_assert(name != NULL);
00803    ast_assert(handler != NULL);
00804 
00805    ast_verb(1, "Creating Stasis app '%s'\n", name);
00806 
00807    size = sizeof(*app) + strlen(name) + 1;
00808    app = ao2_alloc_options(size, app_dtor, AO2_ALLOC_OPT_LOCK_MUTEX);
00809 
00810    if (!app) {
00811       return NULL;
00812    }
00813 
00814    app->forwards = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_MUTEX,
00815       AO2_CONTAINER_ALLOC_OPT_DUPS_OBJ_REJECT,
00816       forwards_sort, NULL);
00817    if (!app->forwards) {
00818       return NULL;
00819    }
00820 
00821    app->topic = stasis_topic_create(name);
00822    if (!app->topic) {
00823       return NULL;
00824    }
00825 
00826    app->bridge_router = stasis_message_router_create(ast_bridge_topic_all());
00827    if (!app->bridge_router) {
00828       return NULL;
00829    }
00830 
00831    res |= stasis_message_router_add(app->bridge_router,
00832       ast_bridge_merge_message_type(), bridge_merge_handler, app);
00833 
00834    res |= stasis_message_router_add(app->bridge_router,
00835       ast_blind_transfer_type(), bridge_blind_transfer_handler, app);
00836 
00837    res |= stasis_message_router_add(app->bridge_router,
00838       ast_attended_transfer_type(), bridge_attended_transfer_handler, app);
00839 
00840    res |= stasis_message_router_set_default(app->bridge_router,
00841       bridge_default_handler, app);
00842 
00843    if (res != 0) {
00844       return NULL;
00845    }
00846    /* Bridge router holds a reference */
00847    ao2_ref(app, +1);
00848 
00849    app->router = stasis_message_router_create(app->topic);
00850    if (!app->router) {
00851       return NULL;
00852    }
00853 
00854    res |= stasis_message_router_add_cache_update(app->router,
00855       ast_bridge_snapshot_type(), sub_bridge_update_handler, app);
00856 
00857    res |= stasis_message_router_add_cache_update(app->router,
00858       ast_channel_snapshot_type(), sub_channel_update_handler, app);
00859 
00860    res |= stasis_message_router_add_cache_update(app->router,
00861       ast_endpoint_snapshot_type(), sub_endpoint_update_handler, app);
00862 
00863    res |= stasis_message_router_set_default(app->router,
00864       sub_default_handler, app);
00865 
00866    if (res != 0) {
00867       return NULL;
00868    }
00869    /* Router holds a reference */
00870    ao2_ref(app, +1);
00871 
00872    strncpy(app->name, name, size - sizeof(*app));
00873    app->handler = handler;
00874    ao2_ref(data, +1);
00875    app->data = data;
00876 
00877    ao2_ref(app, +1);
00878    return app;
00879 }

void app_deactivate ( struct stasis_app app  ) 

Deactivates an application.

Any channels currently in the application remain active (since the app might come back), but new channels are rejected.

Parameters:
app Application to deactivate.

Definition at line 915 of file res/stasis/app.c.

References ao2_cleanup, ast_verb, stasis_app::data, stasis_app::handler, lock, stasis_app::name, NULL, and SCOPED_AO2LOCK.

Referenced by stasis_app_unregister().

00916 {
00917    SCOPED_AO2LOCK(lock, app);
00918    ast_verb(1, "Deactivating Stasis app '%s'\n", app->name);
00919    app->handler = NULL;
00920    ao2_cleanup(app->data);
00921    app->data = NULL;
00922 }

char* app_get_replace_channel_app ( struct ast_channel chan  ) 

Get the app that the replacement channel will be controlled by.

Parameters:
channel The channel on which this will be set
Return values:
NULL on error
Returns:
the name of the controlling app (must be ast_free()d)

Definition at line 888 of file res_stasis.c.

References replace_channel_store::app, get_replace_channel_store(), NULL, and replace().

Referenced by bridge_stasis_run_cb().

00889 {
00890    struct replace_channel_store *replace = get_replace_channel_store(chan, 1);
00891    char *replace_channel_app;
00892 
00893    if (!replace) {
00894       return NULL;
00895    }
00896 
00897    replace_channel_app = replace->app;
00898    replace->app = NULL;
00899 
00900    return replace_channel_app;
00901 }

int app_is_active ( struct stasis_app app  ) 

Checks whether an app is active.

Parameters:
app Application to check.
Returns:
True (non-zero) if app is active.

False (zero) if app has been deactivated.

Definition at line 936 of file res/stasis/app.c.

References stasis_app::handler, lock, NULL, and SCOPED_AO2LOCK.

Referenced by stasis_app_exec().

00937 {
00938    SCOPED_AO2LOCK(lock, app);
00939    return app->handler != NULL;
00940 }

int app_is_finished ( struct stasis_app app  ) 

Checks whether a deactivated app has no channels.

Parameters:
app Application to check.
True (non-zero) if app is deactivated, and has no associated channels.
False (zero) otherwise.

Definition at line 942 of file res/stasis/app.c.

References ao2_container_count(), stasis_app::forwards, stasis_app::handler, lock, NULL, and SCOPED_AO2LOCK.

Referenced by app_shutdown(), and cleanup_cb().

00943 {
00944    SCOPED_AO2LOCK(lock, app);
00945 
00946    return app->handler == NULL && ao2_container_count(app->forwards) == 0;
00947 }

int app_is_subscribed_bridge_id ( struct stasis_app app,
const char *  bridge_id 
)

Test if an app is subscribed to a bridge.

Parameters:
app Subscribing application.
bridge_id Id of bridge to check.
Returns:
True (non-zero) if bridge is subscribed to app.

False (zero) if bridge is not subscribed.

Definition at line 1184 of file res/stasis/app.c.

References ao2_cleanup, ao2_find, stasis_app::forwards, NULL, OBJ_SEARCH_KEY, and RAII_VAR.

01185 {
01186    RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
01187    forwards = ao2_find(app->forwards, bridge_id, OBJ_SEARCH_KEY);
01188    return forwards != NULL;
01189 }

int app_is_subscribed_channel_id ( struct stasis_app app,
const char *  channel_id 
)

Test if an app is subscribed to a channel.

Parameters:
app Subscribing application.
channel_id Id of channel to check.
Returns:
True (non-zero) if channel is subscribed to app.

False (zero) if channel is not subscribed.

Definition at line 1115 of file res/stasis/app.c.

References ao2_cleanup, ao2_find, stasis_app::forwards, NULL, OBJ_SEARCH_KEY, and RAII_VAR.

01116 {
01117    RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
01118    forwards = ao2_find(app->forwards, channel_id, OBJ_SEARCH_KEY);
01119    return forwards != NULL;
01120 }

int app_is_subscribed_endpoint_id ( struct stasis_app app,
const char *  endpoint_id 
)

Test if an app is subscribed to a endpoint.

Parameters:
app Subscribing application.
endpoint_id Id of endpoint to check.
Returns:
True (non-zero) if endpoint is subscribed to app.

False (zero) if endpoint is not subscribed.

Definition at line 1247 of file res/stasis/app.c.

References ao2_cleanup, ao2_find, stasis_app::forwards, NULL, OBJ_SEARCH_KEY, and RAII_VAR.

01248 {
01249    RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
01250    forwards = ao2_find(app->forwards, endpoint_id, OBJ_SEARCH_KEY);
01251    return forwards != NULL;
01252 }

const char* app_name ( const struct stasis_app app  ) 

Return an application's name.

Parameters:
app Application.
Returns:
Name of the application.

NULL is app is NULL.

Definition at line 976 of file res/stasis/app.c.

References stasis_app::name.

Referenced by app_exec(), app_send_end_msg(), app_subscribe(), app_unsubscribe(), AST_TEST_DEFINE(), bridge_stasis_push_peek(), bridge_stasis_run_cb(), device_state_subscription_create(), device_to_json_cb(), lua_pbx_exec(), lua_pbx_findapp(), send_start_msg_snapshots(), and stasis_app_name().

00977 {
00978    return app->name;
00979 }

void app_send ( struct stasis_app app,
struct ast_json message 
)

Send a message to an application.

Parameters:
app Application.
message Message to send.
Send a message to an application.

Parameters:
app App to send the message to.
message Message to send.

Definition at line 890 of file res/stasis/app.c.

References ao2_cleanup, ao2_ref, ast_verb, stasis_app::data, stasis_app::handler, handler(), lock, stasis_app::name, NULL, RAII_VAR, and SCOPED_AO2LOCK.

Referenced by app_update(), message_received_handler(), stasis_app_send(), sub_bridge_update_handler(), sub_channel_update_handler(), sub_default_handler(), and sub_endpoint_update_handler().

00891 {
00892    stasis_app_cb handler;
00893    RAII_VAR(void *, data, NULL, ao2_cleanup);
00894 
00895    /* Copy off mutable state with lock held */
00896    {
00897       SCOPED_AO2LOCK(lock, app);
00898       handler = app->handler;
00899       if (app->data) {
00900          ao2_ref(app->data, +1);
00901          data = app->data;
00902       }
00903       /* Name is immutable; no need to copy */
00904    }
00905 
00906    if (!handler) {
00907       ast_verb(3,
00908          "Inactive Stasis app '%s' missed message\n", app->name);
00909       return;
00910    }
00911 
00912    handler(data, app->name, message);
00913 }

int app_send_end_msg ( struct stasis_app app,
struct ast_channel chan 
)

Send StasisEnd message to the listening app.

Parameters:
app The app that owns the channel
chan The channel for which the message is being sent
Return values:
zero on success
Returns:
non-zero on failure

Definition at line 997 of file res_stasis.c.

References ao2_cleanup, app_name(), app_unsubscribe_channel(), ast_app_get_topic(), ast_channel_blob_create(), ast_json_pack(), ast_json_unref(), ast_log, stasis_message_sanitizer::channel, LOG_ERROR, remove_masquerade_store(), stasis_app_get_sanitizer(), and stasis_publish().

Referenced by bridge_stasis_moving(), channel_replaced_cb(), channel_stolen_cb(), and stasis_app_exec().

00998 {
00999    struct stasis_message_sanitizer *sanitize = stasis_app_get_sanitizer();
01000    struct ast_json *blob;
01001    struct stasis_message *msg;
01002 
01003    if (sanitize && sanitize->channel
01004       && sanitize->channel(chan)) {
01005       return 0;
01006    }
01007 
01008    blob = ast_json_pack("{s: s}", "app", app_name(app));
01009    if (!blob) {
01010       ast_log(LOG_ERROR, "Error packing JSON for StasisEnd message\n");
01011       return -1;
01012    }
01013 
01014    remove_masquerade_store(chan);
01015    app_unsubscribe_channel(app, chan);
01016    msg = ast_channel_blob_create(chan, end_message_type(), blob);
01017    if (msg) {
01018       stasis_publish(ast_app_get_topic(app), msg);
01019    }
01020    ao2_cleanup(msg);
01021    ast_json_unref(blob);
01022 
01023    return 0;
01024 }

int app_set_replace_channel_app ( struct ast_channel chan,
const char *  replace_app 
)

Set the app that the replacement channel will be controlled by.

Parameters:
channel The channel on which this will be set
replace_app The app that will be controlling this channel
Return values:
zero success
non-zero failure

Definition at line 852 of file res_stasis.c.

References replace_channel_store::app, ast_free, ast_strdup, get_replace_channel_store(), NULL, and replace().

Referenced by bridge_stasis_push_peek().

00853 {
00854    struct replace_channel_store *replace = get_replace_channel_store(chan, 0);
00855 
00856    if (!replace) {
00857       return -1;
00858    }
00859 
00860    ast_free(replace->app);
00861    replace->app = NULL;
00862 
00863    if (replace_app) {
00864       replace->app = ast_strdup(replace_app);
00865       if (!replace->app) {
00866          return -1;
00867       }
00868    }
00869 
00870    return 0;
00871 }

int app_set_replace_channel_snapshot ( struct ast_channel chan,
struct ast_channel_snapshot replace_snapshot 
)

Set the snapshot of the channel that this channel will replace.

Parameters:
channel The channel on which this will be set
replace_snapshot The snapshot of the channel that is being replaced
Return values:
zero success
non-zero failure

Definition at line 840 of file res_stasis.c.

References ao2_replace, get_replace_channel_store(), replace(), and replace_channel_store::snapshot.

Referenced by bridge_stasis_push_peek().

00841 {
00842    struct replace_channel_store *replace = get_replace_channel_store(chan, 0);
00843 
00844    if (!replace) {
00845       return -1;
00846    }
00847 
00848    ao2_replace(replace->snapshot, replace_snapshot);
00849    return 0;
00850 }

void app_shutdown ( struct stasis_app app  ) 

Tears down an application.

It should be finished before calling this.

Parameters:
app Application to unsubscribe.

Definition at line 924 of file res/stasis/app.c.

References app_is_finished(), ast_assert, stasis_app::bridge_router, lock, NULL, stasis_app::router, SCOPED_AO2LOCK, and stasis_message_router_unsubscribe().

Referenced by cleanup_cb().

00925 {
00926    SCOPED_AO2LOCK(lock, app);
00927 
00928    ast_assert(app_is_finished(app));
00929 
00930    stasis_message_router_unsubscribe(app->router);
00931    app->router = NULL;
00932    stasis_message_router_unsubscribe(app->bridge_router);
00933    app->bridge_router = NULL;
00934 }

int app_subscribe_bridge ( struct stasis_app app,
struct ast_bridge bridge 
)

Add a bridge subscription to an existing channel subscription.

Parameters:
app Application.
bridge Bridge to subscribe to.
Returns:
0 on success.

Non-zero on error.

Definition at line 1135 of file res/stasis/app.c.

References ao2_cleanup, ao2_find, ao2_link_flags, ast_debug, stasis_app::forwards, forwards_create_bridge(), lock, stasis_app::name, NULL, OBJ_NOLOCK, OBJ_SEARCH_KEY, RAII_VAR, SCOPED_AO2LOCK, and ast_bridge::uniqueid.

Referenced by control_add_channel_to_bridge(), stasis_app_exec(), and subscribe_bridge().

01136 {
01137    if (!app || !bridge) {
01138       return -1;
01139    } else {
01140       RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
01141       SCOPED_AO2LOCK(lock, app->forwards);
01142 
01143       forwards = ao2_find(app->forwards, bridge->uniqueid,
01144          OBJ_SEARCH_KEY | OBJ_NOLOCK);
01145 
01146       if (!forwards) {
01147          /* Forwards not found, create one */
01148          forwards = forwards_create_bridge(app, bridge);
01149          if (!forwards) {
01150             return -1;
01151          }
01152          ao2_link_flags(app->forwards, forwards, OBJ_NOLOCK);
01153       }
01154 
01155       ++forwards->interested;
01156       ast_debug(3, "Bridge '%s' is %d interested in %s\n", bridge->uniqueid, forwards->interested, app->name);
01157       return 0;
01158    }
01159 }

int app_subscribe_channel ( struct stasis_app app,
struct ast_channel chan 
)

Subscribes an application to a channel.

Parameters:
app Application.
chan Channel to subscribe to.
Returns:
0 on success.

Non-zero on error.

Definition at line 1031 of file res/stasis/app.c.

References ao2_cleanup, ao2_find, ao2_link_flags, ast_channel_uniqueid(), ast_debug, stasis_app::forwards, forwards_create_channel(), lock, stasis_app::name, NULL, OBJ_NOLOCK, OBJ_SEARCH_KEY, RAII_VAR, and SCOPED_AO2LOCK.

Referenced by call_forwarded_handler(), send_start_msg_snapshots(), stasis_app_subscribe_channel(), and subscribe_channel().

01032 {
01033    int res;
01034 
01035    if (!app || !chan) {
01036       return -1;
01037    } else {
01038       RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
01039       SCOPED_AO2LOCK(lock, app->forwards);
01040 
01041       forwards = ao2_find(app->forwards, ast_channel_uniqueid(chan),
01042          OBJ_SEARCH_KEY | OBJ_NOLOCK);
01043       if (!forwards) {
01044          /* Forwards not found, create one */
01045          forwards = forwards_create_channel(app, chan);
01046          if (!forwards) {
01047             return -1;
01048          }
01049 
01050          res = ao2_link_flags(app->forwards, forwards,
01051             OBJ_NOLOCK);
01052          if (!res) {
01053             return -1;
01054          }
01055       }
01056 
01057       ++forwards->interested;
01058       ast_debug(3, "Channel '%s' is %d interested in %s\n", ast_channel_uniqueid(chan), forwards->interested, app->name);
01059       return 0;
01060    }
01061 }

int app_subscribe_endpoint ( struct stasis_app app,
struct ast_endpoint endpoint 
)

Subscribes an application to a endpoint.

Parameters:
app Application.
chan Endpoint to subscribe to.
Returns:
0 on success.

Non-zero on error.

Definition at line 1204 of file res/stasis/app.c.

References ao2_cleanup, ao2_find, ao2_link_flags, ast_debug, ast_endpoint_get_id(), stasis_app::forwards, forwards_create_endpoint(), lock, message_received_handler(), messaging_app_subscribe_endpoint(), stasis_app::name, NULL, OBJ_NOLOCK, OBJ_SEARCH_KEY, RAII_VAR, and SCOPED_AO2LOCK.

Referenced by subscribe_endpoint().

01205 {
01206    if (!app || !endpoint) {
01207       return -1;
01208    } else {
01209       RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
01210       SCOPED_AO2LOCK(lock, app->forwards);
01211 
01212       forwards = ao2_find(app->forwards, ast_endpoint_get_id(endpoint),
01213          OBJ_SEARCH_KEY | OBJ_NOLOCK);
01214 
01215       if (!forwards) {
01216          /* Forwards not found, create one */
01217          forwards = forwards_create_endpoint(app, endpoint);
01218          if (!forwards) {
01219             return -1;
01220          }
01221          ao2_link_flags(app->forwards, forwards, OBJ_NOLOCK);
01222 
01223          /* Subscribe for messages */
01224          messaging_app_subscribe_endpoint(app->name, endpoint, &message_received_handler, app);
01225       }
01226 
01227       ++forwards->interested;
01228       ast_debug(3, "Endpoint '%s' is %d interested in %s\n", ast_endpoint_get_id(endpoint), forwards->interested, app->name);
01229       return 0;
01230    }
01231 }

struct ast_json* app_to_json ( const struct stasis_app app  )  [read]

Definition at line 981 of file res/stasis/app.c.

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ast_json_array_append(), ast_json_object_get(), ast_json_pack(), ast_json_ref(), ast_json_string_create(), ast_json_unref(), ast_log, bridges, channels, endpoints, FORWARD_BRIDGE, FORWARD_CHANNEL, FORWARD_ENDPOINT, stasis_app::forwards, LOG_ERROR, stasis_app::name, NULL, and RAII_VAR.

Referenced by stasis_app_object_to_json().

00982 {
00983    RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
00984    struct ast_json *channels;
00985    struct ast_json *bridges;
00986    struct ast_json *endpoints;
00987    struct ao2_iterator i;
00988    void *obj;
00989 
00990    json = ast_json_pack("{s: s, s: [], s: [], s: []}",
00991       "name", app->name,
00992       "channel_ids", "bridge_ids", "endpoint_ids");
00993    channels = ast_json_object_get(json, "channel_ids");
00994    bridges = ast_json_object_get(json, "bridge_ids");
00995    endpoints = ast_json_object_get(json, "endpoint_ids");
00996 
00997    i = ao2_iterator_init(app->forwards, 0);
00998    while ((obj = ao2_iterator_next(&i))) {
00999       RAII_VAR(struct app_forwards *, forwards, obj, ao2_cleanup);
01000       RAII_VAR(struct ast_json *, id, NULL, ast_json_unref);
01001       int append_res = -1;
01002 
01003       id = ast_json_string_create(forwards->id);
01004 
01005       switch (forwards->forward_type) {
01006       case FORWARD_CHANNEL:
01007          append_res = ast_json_array_append(channels,
01008             ast_json_ref(id));
01009          break;
01010       case FORWARD_BRIDGE:
01011          append_res = ast_json_array_append(bridges,
01012             ast_json_ref(id));
01013          break;
01014       case FORWARD_ENDPOINT:
01015          append_res = ast_json_array_append(endpoints,
01016             ast_json_ref(id));
01017          break;
01018       }
01019 
01020       if (append_res != 0) {
01021          ast_log(LOG_ERROR, "Error building response\n");
01022          ao2_iterator_destroy(&i);
01023          return NULL;
01024       }
01025    }
01026    ao2_iterator_destroy(&i);
01027 
01028    return ast_json_ref(json);
01029 }

int app_unsubscribe_bridge ( struct stasis_app app,
struct ast_bridge bridge 
)

Cancel the bridge subscription for an application.

Parameters:
forwards Return from app_subscribe_channel().
bridge Bridge to subscribe to.
Returns:
0 on success.

Non-zero on error.

Definition at line 1166 of file res/stasis/app.c.

References app_unsubscribe_bridge_id(), and ast_bridge::uniqueid.

Referenced by bridge_after_cb(), and stasis_app_exec().

01167 {
01168    if (!app || !bridge) {
01169       return -1;
01170    }
01171 
01172    return app_unsubscribe_bridge_id(app, bridge->uniqueid);
01173 }

int app_unsubscribe_bridge_id ( struct stasis_app app,
const char *  bridge_id 
)

Cancel the subscription an app has for a bridge.

Parameters:
app Subscribing application.
bridge_id Id of bridge to unsubscribe from.
Returns:
0 on success.

Non-zero on error.

Definition at line 1175 of file res/stasis/app.c.

References unsubscribe().

Referenced by app_unsubscribe_bridge().

01176 {
01177    if (!app || !bridge_id) {
01178       return -1;
01179    }
01180 
01181    return unsubscribe(app, "bridge", bridge_id, 0);
01182 }

int app_unsubscribe_channel ( struct stasis_app app,
struct ast_channel chan 
)

Cancel the subscription an app has for a channel.

Parameters:
app Subscribing application.
chan Channel to unsubscribe from.
Returns:
0 on success.

Non-zero on error.

Definition at line 1097 of file res/stasis/app.c.

References app_unsubscribe_channel_id(), and ast_channel_uniqueid().

Referenced by app_send_end_msg().

01098 {
01099    if (!app || !chan) {
01100       return -1;
01101    }
01102 
01103    return app_unsubscribe_channel_id(app, ast_channel_uniqueid(chan));
01104 }

int app_unsubscribe_channel_id ( struct stasis_app app,
const char *  channel_id 
)

Cancel the subscription an app has for a channel.

Parameters:
app Subscribing application.
channel_id Id of channel to unsubscribe from.
Returns:
0 on success.

Non-zero on error.

Definition at line 1106 of file res/stasis/app.c.

References unsubscribe().

Referenced by app_unsubscribe_channel(), and send_start_msg_snapshots().

01107 {
01108    if (!app || !channel_id) {
01109       return -1;
01110    }
01111 
01112    return unsubscribe(app, "channel", channel_id, 0);
01113 }

int app_unsubscribe_endpoint_id ( struct stasis_app app,
const char *  endpoint_id 
)

Cancel the subscription an app has for a endpoint.

Parameters:
app Subscribing application.
endpoint_id Id of endpoint to unsubscribe from.
Returns:
0 on success.

Non-zero on error.

Definition at line 1238 of file res/stasis/app.c.

References unsubscribe().

01239 {
01240    if (!app || !endpoint_id) {
01241       return -1;
01242    }
01243 
01244    return unsubscribe(app, "endpoint", endpoint_id, 0);
01245 }

void app_update ( struct stasis_app app,
stasis_app_cb  handler,
void *  data 
)

Update the handler and data for a res_stasis application.

If app has been deactivated, this will reactivate it.

Parameters:
app Application to update.
handler New application callback.
data New data pointer for the callback.

Definition at line 949 of file res/stasis/app.c.

References ao2_cleanup, ao2_ref, app_send(), ast_json_pack(), ast_json_unref(), ast_verb, stasis_app::data, stasis_app::handler, lock, stasis_app::name, NULL, RAII_VAR, and SCOPED_AO2LOCK.

Referenced by stasis_app_register().

00950 {
00951    SCOPED_AO2LOCK(lock, app);
00952 
00953    if (app->handler) {
00954       RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
00955 
00956       ast_verb(1, "Replacing Stasis app '%s'\n", app->name);
00957 
00958       msg = ast_json_pack("{s: s, s: s}",
00959          "type", "ApplicationReplaced",
00960          "application", app->name);
00961       if (msg) {
00962          app_send(app, msg);
00963       }
00964    } else {
00965       ast_verb(1, "Activating Stasis app '%s'\n", app->name);
00966    }
00967 
00968    app->handler = handler;
00969    ao2_cleanup(app->data);
00970    if (data) {
00971       ao2_ref(data, +1);
00972    }
00973    app->data = data;
00974 }


Generated on Thu Apr 16 06:28:16 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6