mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
stasis: Use an implementation specific channel snapshot cache.
Channels no longer use the Stasis cache for channel snapshots. Instead they are stored in a hash table in stasis_channels which reduces the number of Stasis messages created and allows better storage. As a result the following APIs are no longer available since the stasis cache is no longer used: ast_channel_topic_cached() ast_channel_topic_all_cached() The ast_channel_cache_all() and ast_channel_cache_by_name() functions now return an ao2_container of ast_channel_snapshots rather than a container of stasis_messages therefore you can't (and don't need to) call stasis_cache functions on it. The ast_channel_topic_all() function now returns a normal topic not a cached one so you can't use stasis cache functions on it either. The ast_channel_snapshot_type() stasis message now has the ast_channel_snapshot_update structure as it's data. It contains the last snapshot and the new one. ast_channel_snapshot_get_latest() still returns the latest snapshot. The latest snapshot is now stored on the channel itself to eliminate cache hits when Stasis messages that have the snapshot as a payload are created. ASTERISK-28102 Change-Id: I9334febff60a82d7c39703e49059fa3a68825786
This commit is contained in:
@@ -144,17 +144,11 @@ static struct app_forwards *forwards_create_channel(struct stasis_app *app,
|
||||
}
|
||||
|
||||
forwards->forward_type = FORWARD_CHANNEL;
|
||||
if (chan) {
|
||||
forwards->topic_forward = stasis_forward_all(ast_channel_topic(chan),
|
||||
app->topic);
|
||||
}
|
||||
forwards->topic_cached_forward = stasis_forward_all(
|
||||
chan ? ast_channel_topic_cached(chan) : ast_channel_topic_all_cached(),
|
||||
forwards->topic_forward = stasis_forward_all(
|
||||
chan ? ast_channel_topic(chan) : ast_channel_topic_all(),
|
||||
app->topic);
|
||||
|
||||
if ((!forwards->topic_forward && chan) || !forwards->topic_cached_forward) {
|
||||
/* Half-subscribed is a bad thing */
|
||||
forwards_unsubscribe(forwards);
|
||||
if (!forwards->topic_forward) {
|
||||
ao2_ref(forwards, -1);
|
||||
return NULL;
|
||||
}
|
||||
@@ -420,7 +414,7 @@ static struct ast_json *channel_state(
|
||||
|
||||
if (!old_snapshot) {
|
||||
return channel_created_event(snapshot, tv);
|
||||
} else if (!new_snapshot) {
|
||||
} else if (ast_test_flag(&new_snapshot->flags, AST_FLAG_DEAD)) {
|
||||
return channel_destroyed_event(snapshot, tv);
|
||||
} else if (old_snapshot->state != new_snapshot->state) {
|
||||
return channel_state_change_event(snapshot, tv);
|
||||
@@ -436,8 +430,8 @@ static struct ast_json *channel_dialplan(
|
||||
{
|
||||
struct ast_json *json_channel;
|
||||
|
||||
/* No Newexten event on cache clear or first event */
|
||||
if (!old_snapshot || !new_snapshot) {
|
||||
/* No Newexten event on first channel snapshot */
|
||||
if (!old_snapshot) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -470,8 +464,8 @@ static struct ast_json *channel_callerid(
|
||||
{
|
||||
struct ast_json *json_channel;
|
||||
|
||||
/* No NewCallerid event on cache clear or first event */
|
||||
if (!old_snapshot || !new_snapshot) {
|
||||
/* No NewCallerid event on first channel snapshot */
|
||||
if (!old_snapshot) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -500,8 +494,8 @@ static struct ast_json *channel_connected_line(
|
||||
{
|
||||
struct ast_json *json_channel;
|
||||
|
||||
/* No ChannelConnectedLine event on cache clear or first event */
|
||||
if (!old_snapshot || !new_snapshot) {
|
||||
/* No ChannelConnectedLine event on first channel snapshot */
|
||||
if (!old_snapshot) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -532,39 +526,22 @@ static void sub_channel_update_handler(void *data,
|
||||
struct stasis_message *message)
|
||||
{
|
||||
struct stasis_app *app = data;
|
||||
struct stasis_cache_update *update;
|
||||
struct ast_channel_snapshot *new_snapshot;
|
||||
struct ast_channel_snapshot *old_snapshot;
|
||||
const struct timeval *tv;
|
||||
struct ast_channel_snapshot_update *update = stasis_message_data(message);
|
||||
int i;
|
||||
|
||||
ast_assert(stasis_message_type(message) == stasis_cache_update_type());
|
||||
|
||||
update = stasis_message_data(message);
|
||||
|
||||
ast_assert(update->type == ast_channel_snapshot_type());
|
||||
|
||||
new_snapshot = stasis_message_data(update->new_snapshot);
|
||||
old_snapshot = stasis_message_data(update->old_snapshot);
|
||||
|
||||
/* Pull timestamp from the new snapshot, or from the update message
|
||||
* when there isn't one. */
|
||||
tv = update->new_snapshot ?
|
||||
stasis_message_timestamp(update->new_snapshot) :
|
||||
stasis_message_timestamp(message);
|
||||
|
||||
for (i = 0; i < ARRAY_LEN(channel_monitors); ++i) {
|
||||
struct ast_json *msg;
|
||||
|
||||
msg = channel_monitors[i](old_snapshot, new_snapshot, tv);
|
||||
msg = channel_monitors[i](update->old_snapshot, update->new_snapshot,
|
||||
stasis_message_timestamp(message));
|
||||
if (msg) {
|
||||
app_send(app, msg);
|
||||
ast_json_unref(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!new_snapshot && old_snapshot) {
|
||||
unsubscribe(app, "channel", old_snapshot->uniqueid, 1);
|
||||
if (ast_test_flag(&update->new_snapshot->flags, AST_FLAG_DEAD)) {
|
||||
unsubscribe(app, "channel", update->new_snapshot->uniqueid, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -987,7 +964,7 @@ struct stasis_app *app_create(const char *name, stasis_app_cb handler, void *dat
|
||||
res |= stasis_message_router_add_cache_update(app->router,
|
||||
ast_bridge_snapshot_type(), sub_bridge_update_handler, app);
|
||||
|
||||
res |= stasis_message_router_add_cache_update(app->router,
|
||||
res |= stasis_message_router_add(app->router,
|
||||
ast_channel_snapshot_type(), sub_channel_update_handler, app);
|
||||
|
||||
res |= stasis_message_router_add_cache_update(app->router,
|
||||
|
@@ -773,22 +773,7 @@ void stasis_app_control_silence_stop(struct stasis_app_control *control)
|
||||
struct ast_channel_snapshot *stasis_app_control_get_snapshot(
|
||||
const struct stasis_app_control *control)
|
||||
{
|
||||
struct stasis_message *msg;
|
||||
struct ast_channel_snapshot *snapshot;
|
||||
|
||||
msg = stasis_cache_get(ast_channel_cache(), ast_channel_snapshot_type(),
|
||||
stasis_app_control_get_channel_id(control));
|
||||
if (!msg) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
snapshot = stasis_message_data(msg);
|
||||
ast_assert(snapshot != NULL);
|
||||
|
||||
ao2_ref(snapshot, +1);
|
||||
ao2_ref(msg, -1);
|
||||
|
||||
return snapshot;
|
||||
return ast_channel_snapshot_get_latest(stasis_app_control_get_channel_id(control));
|
||||
}
|
||||
|
||||
static int app_send_command_on_condition(struct stasis_app_control *control,
|
||||
|
Reference in New Issue
Block a user