[asterisk-commits] kmoore: branch kmoore/stasis-cel_bridging r388952 - /team/kmoore/stasis-cel_b...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri May 17 08:41:01 CDT 2013
Author: kmoore
Date: Fri May 17 08:41:00 2013
New Revision: 388952
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388952
Log:
Pull in rework from the channel refactor
Modified:
team/kmoore/stasis-cel_bridging/main/cel.c
Modified: team/kmoore/stasis-cel_bridging/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_bridging/main/cel.c?view=diff&rev=388952&r1=388951&r2=388952
==============================================================================
--- team/kmoore/stasis-cel_bridging/main/cel.c (original)
+++ team/kmoore/stasis-cel_bridging/main/cel.c Fri May 17 08:41:00 2013
@@ -60,11 +60,17 @@
#include "asterisk/stasis_bridging.h"
#include "asterisk/bridging.h"
-/*! Message router for channel state */
-static struct stasis_message_router *cel_channel_state_router;
-
-/*! Message router for bridge state */
-static struct stasis_message_router *cel_bridge_state_router;
+/*! Message router for state that CEL needs to know about */
+static struct stasis_message_router *cel_state_router;
+
+/*! Aggregation topic for all topics CEL needs to know about */
+static struct stasis_topic *cel_state_topic;
+
+/*! Subscription for forwarding the channel caching topic */
+static struct stasis_subscription *cel_channel_forwarder;
+
+/*! Subscription for forwarding the channel caching topic */
+static struct stasis_subscription *cel_bridge_forwarder;
/*! Container for primary channel listing for 2 party bridges */
static struct ao2_container *bridge_primaries;
@@ -406,6 +412,10 @@
peer_name = ast_strdupa(peer2_snapshot->name);
}
+ if (!cel_enabled) {
+ return 0;
+ }
+
/* Make sure a reload is not occurring while we're checking to see if this
* is an event that we care about. We could lose an important event in this
* process otherwise. */
@@ -413,14 +423,14 @@
/* Record the linkedid of new channels if we are tracking LINKEDID_END even if we aren't
* reporting on CHANNEL_START so we can track when to send LINKEDID_END */
- if (cel_enabled && ast_cel_track_event(AST_CEL_LINKEDID_END) && event_type == AST_CEL_CHANNEL_START && linkedid) {
+ if (ast_cel_track_event(AST_CEL_LINKEDID_END) && event_type == AST_CEL_CHANNEL_START && linkedid) {
if (ast_cel_linkedid_ref(linkedid)) {
ast_mutex_unlock(&reload_lock);
return -1;
}
}
- if (!cel_enabled || !ast_cel_track_event(event_type)) {
+ if (!ast_cel_track_event(event_type)) {
ast_mutex_unlock(&reload_lock);
return 0;
}
@@ -436,21 +446,13 @@
ast_mutex_unlock(&reload_lock);
- if (!userdefevname) {
- userdefevname = "";
- }
-
- if (!extra) {
- extra = "";
- }
-
eventtime = ast_tvnow();
ev = ast_event_new(AST_EVENT_CEL,
AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, event_type,
AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_sec,
AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_usec,
- AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, userdefevname,
+ AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, S_OR(userdefevname, ""),
AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_name,
AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_number,
AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_ani,
@@ -467,7 +469,7 @@
AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, snapshot->uniqueid,
AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_PLTYPE_STR, snapshot->linkedid,
AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_PLTYPE_STR, snapshot->userfield,
- AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, extra,
+ AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, S_OR(extra, ""),
AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, peer_name,
AST_EVENT_IE_END);
@@ -914,26 +916,52 @@
cel_channel_linkedid_change,
};
-static void cel_channel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
+static int snapshots_share_capability(
+ struct ast_bridge_snapshot *old_snapshot,
+ struct ast_bridge_snapshot *new_snapshot,
+ uint32_t capability)
+{
+ return ((old_snapshot->capabilities | capability)
+ && (new_snapshot->capabilities | capability));
+}
+
+static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
struct stasis_topic *topic,
struct stasis_message *message)
{
- struct stasis_cache_update *update;
- struct ast_channel_snapshot *old_snapshot;
- struct ast_channel_snapshot *new_snapshot;
- size_t i;
-
- update = stasis_message_data(message);
-
- if (ast_channel_snapshot_type() != update->type) {
- return;
- }
-
- old_snapshot = stasis_message_data(update->old_snapshot);
- new_snapshot = stasis_message_data(update->new_snapshot);
-
- for (i = 0; i < ARRAY_LEN(cel_channel_monitors); ++i) {
- cel_channel_monitors[i](old_snapshot, new_snapshot);
+ struct stasis_cache_update *update = stasis_message_data(message);
+ if (update->type == ast_channel_snapshot_type()) {
+ struct ast_channel_snapshot *old_snapshot;
+ struct ast_channel_snapshot *new_snapshot;
+ size_t i;
+
+ old_snapshot = stasis_message_data(update->old_snapshot);
+ new_snapshot = stasis_message_data(update->new_snapshot);
+
+ for (i = 0; i < ARRAY_LEN(cel_channel_monitors); ++i) {
+ cel_channel_monitors[i](old_snapshot, new_snapshot);
+ }
+ } else if (update->type == ast_bridge_snapshot_type()) {
+ struct ast_bridge_snapshot *old_snapshot;
+ struct ast_bridge_snapshot *new_snapshot;
+
+ update = stasis_message_data(message);
+
+ old_snapshot = stasis_message_data(update->old_snapshot);
+ new_snapshot = stasis_message_data(update->new_snapshot);
+
+ if (old_snapshot->capabilities == new_snapshot->capabilities) {
+ return;
+ }
+
+ if (snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_1TO1MIX)
+ || snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_NATIVE)
+ || snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_HOLDING)
+ || snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_MULTIMIX)) {
+ return;
+ }
+
+ /* Produce bridge capability change event */
}
}
@@ -1016,46 +1044,14 @@
}
}
-static int snapshots_share_capability(
- struct ast_bridge_snapshot *old_snapshot,
- struct ast_bridge_snapshot *new_snapshot,
- uint32_t capability)
-{
- return ((old_snapshot->capabilities | capability)
- && (new_snapshot->capabilities | capability));
-}
-
-static void cel_bridge_snapshot_update_cb(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic,
- struct stasis_message *message)
-{
- struct stasis_cache_update *update;
- struct ast_bridge_snapshot *old_snapshot;
- struct ast_bridge_snapshot *new_snapshot;
-
- update = stasis_message_data(message);
-
- old_snapshot = stasis_message_data(update->old_snapshot);
- new_snapshot = stasis_message_data(update->new_snapshot);
-
- if (old_snapshot->capabilities == new_snapshot->capabilities) {
- return;
- }
-
- if (snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_1TO1MIX)
- || snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_NATIVE)
- || snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_HOLDING)
- || snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_MULTIMIX)) {
- return;
- }
-
- /* Produce bridge capability change event */
-}
-
static void ast_cel_engine_term(void)
{
- stasis_message_router_unsubscribe(cel_channel_state_router);
- cel_channel_state_router = NULL;
+ stasis_message_router_unsubscribe(cel_state_router);
+ cel_state_router = NULL;
+ ao2_cleanup(cel_state_topic);
+ cel_state_topic = NULL;
+ cel_channel_forwarder = stasis_unsubscribe(cel_channel_forwarder);
+ cel_bridge_forwarder = stasis_unsubscribe(cel_bridge_forwarder);
if (appset) {
ao2_ref(appset, -1);
appset = NULL;
@@ -1065,10 +1061,8 @@
linkedids = NULL;
}
ast_cli_unregister(&cli_status);
- stasis_message_router_unsubscribe(cel_channel_state_router);
- cel_channel_state_router = NULL;
- stasis_message_router_unsubscribe(cel_bridge_state_router);
- cel_bridge_state_router = NULL;
+ stasis_message_router_unsubscribe(cel_state_router);
+ cel_state_router = NULL;
ao2_cleanup(bridge_primaries);
bridge_primaries = NULL;
}
@@ -1092,16 +1086,33 @@
return -1;
}
- cel_channel_state_router = stasis_message_router_create(
- stasis_caching_get_topic(ast_channel_topic_all_cached()));
-
- if (!cel_channel_state_router) {
- return -1;
- }
-
- ret |= stasis_message_router_add(cel_channel_state_router,
+ cel_state_topic = stasis_topic_create("cel_state_topic");
+ if (!cel_state_topic) {
+ return -1;
+ }
+
+ cel_channel_forwarder = stasis_forward_all(
+ stasis_caching_get_topic(ast_channel_topic_all_cached()),
+ cel_state_topic);
+ if (!cel_channel_forwarder) {
+ return -1;
+ }
+
+ cel_bridge_forwarder = stasis_forward_all(
+ stasis_caching_get_topic(ast_bridge_topic_all_cached()),
+ cel_state_topic);
+ if (!cel_bridge_forwarder) {
+ return -1;
+ }
+
+ cel_state_router = stasis_message_router_create(cel_state_topic);
+ if (!cel_state_router) {
+ return -1;
+ }
+
+ ret |= stasis_message_router_add(cel_state_router,
stasis_cache_update_type(),
- cel_channel_snapshot_update_cb,
+ cel_snapshot_update_cb,
NULL);
/* If somehow we failed to add any routes, just shut down the whole
@@ -1117,26 +1128,14 @@
return -1;
}
- cel_bridge_state_router = stasis_message_router_create(
- stasis_caching_get_topic(ast_bridge_topic_all_cached()));
-
- if (!cel_bridge_state_router) {
- return -1;
- }
-
- ret |= stasis_message_router_add(cel_bridge_state_router,
+ ret |= stasis_message_router_add(cel_state_router,
ast_channel_entered_bridge_type(),
cel_bridge_enter_cb,
NULL);
- ret |= stasis_message_router_add(cel_bridge_state_router,
+ ret |= stasis_message_router_add(cel_state_router,
ast_channel_left_bridge_type(),
cel_bridge_leave_cb,
- NULL);
-
- ret |= stasis_message_router_add(cel_bridge_state_router,
- stasis_cache_update_type(),
- cel_bridge_snapshot_update_cb,
NULL);
/* If somehow we failed to add any routes, just shut down the whole
More information about the asterisk-commits
mailing list