[asterisk-commits] kmoore: branch kmoore/stasis-cel_refactoring r388956 - in /team/kmoore/stasis...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri May 17 10:39:41 CDT 2013
Author: kmoore
Date: Fri May 17 10:39:39 2013
New Revision: 388956
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388956
Log:
Rework dialstatus to be pulled from the dial end event
Modified:
team/kmoore/stasis-cel_refactoring/include/asterisk/stasis_channels.h
team/kmoore/stasis-cel_refactoring/main/cel.c
team/kmoore/stasis-cel_refactoring/main/stasis_channels.c
Modified: team/kmoore/stasis-cel_refactoring/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_refactoring/include/asterisk/stasis_channels.h?view=diff&rev=388956&r1=388955&r2=388956
==============================================================================
--- team/kmoore/stasis-cel_refactoring/include/asterisk/stasis_channels.h (original)
+++ team/kmoore/stasis-cel_refactoring/include/asterisk/stasis_channels.h Fri May 17 10:39:39 2013
@@ -59,11 +59,6 @@
AST_STRING_FIELD(caller_dnid); /*!< Caller ID DNID Number */
AST_STRING_FIELD(connected_name); /*!< Connected Line Name */
AST_STRING_FIELD(connected_number); /*!< Connected Line Number */
- /*!
- * The value of the DIALSTATUS channel variable.
- * This is necessary to keep separately from manager_vars for CEL purposes.
- */
- AST_STRING_FIELD(dialstatus);
);
struct timeval creationtime; /*!< The time of channel creation */
Modified: team/kmoore/stasis-cel_refactoring/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_refactoring/main/cel.c?view=diff&rev=388956&r1=388955&r2=388956
==============================================================================
--- team/kmoore/stasis-cel_refactoring/main/cel.c (original)
+++ team/kmoore/stasis-cel_refactoring/main/cel.c Fri May 17 10:39:39 2013
@@ -67,6 +67,9 @@
/*! Subscription for forwarding the channel caching topic */
static struct stasis_subscription *cel_channel_forwarder;
+/*! Container for dial end multichannel blobs for holding on to dial statuses */
+static struct ao2_container *cel_dialstatus_store;
+
/*! Is the CEL subsystem enabled ? */
static unsigned char cel_enabled;
@@ -95,6 +98,11 @@
* \brief Number of buckets for the appset container
*/
#define NUM_APP_BUCKETS 97
+
+/*!
+ * \brief Number of buckets for the dialstatus container
+ */
+#define NUM_DIALSTATUS_BUCKETS 251
/*!
* \brief Container of Asterisk application names
@@ -143,6 +151,40 @@
[AST_CEL_LINKEDID_END] = "LINKEDID_END",
};
+static const char *get_caller_uniqueid(struct ast_multi_channel_blob *blob)
+{
+ struct ast_channel_snapshot *caller = ast_multi_channel_blob_get_channel(blob, "caller");
+ if (!caller) {
+ return NULL;
+ }
+
+ return caller->uniqueid;
+}
+
+/*! \brief Hashing function for dialstatus container */
+static int dialstatus_hash(const void *obj, int flags)
+{
+ struct ast_multi_channel_blob *blob = (void *) obj;
+ const char *uniqueid = obj;
+ if (flags & OBJ_KEY) {
+ uniqueid = get_caller_uniqueid(blob);
+ }
+
+ return ast_str_hash(uniqueid);
+}
+
+/*! \brief Comparator function for dialstatus container */
+static int dialstatus_cmp(void *obj, void *arg, int flags)
+{
+ struct ast_multi_channel_blob *blob1 = obj, *blob2 = arg;
+ const char *blob2_id = arg, *blob1_id = get_caller_uniqueid(blob1);
+ if (flags & OBJ_KEY) {
+ blob2_id = get_caller_uniqueid(blob2);
+ }
+
+ return !strcmp(blob1_id, blob2_id) ? CMP_MATCH | CMP_STOP : 0;
+}
+
/*!
* \brief Map of ast_cel_ama_flags to strings
*/
@@ -291,21 +333,12 @@
}
while ((cur_app = strsep(&apps, ","))) {
- char *app;
-
cur_app = ast_strip(cur_app);
if (ast_strlen_zero(cur_app)) {
continue;
}
- if (!(app = ao2_alloc(strlen(cur_app) + 1, NULL))) {
- continue;
- }
- strcpy(app, cur_app);
-
- ao2_link(appset, app);
- ao2_ref(app, -1);
- app = NULL;
+ ast_str_container_add(appset, cur_app);
}
}
@@ -480,7 +513,7 @@
/* We have a ref for each channel with this linkedid, the link and the above find, so if
* before unreffing the channel we have a refcount of 3, we're done. Unlink and report. */
if (ao2_ref(lid, -1) == 3) {
- ao2_unlink(linkedids, lid);
+ ast_str_container_remove(linkedids, lid);
report_event_snapshot(snapshot, AST_CEL_LINKEDID_END, NULL, NULL);
}
ao2_ref(lid, -1);
@@ -791,26 +824,31 @@
return 0;
}
-static int app_hash(const void *obj, const int flags)
-{
- return ast_str_case_hash((const char *) obj);
-}
-
-static int app_cmp(void *obj, void *arg, int flags)
-{
- const char *app1 = obj, *app2 = arg;
-
- return !strcasecmp(app1, app2) ? CMP_MATCH | CMP_STOP : 0;
-}
-
-#define lid_hash app_hash
-#define lid_cmp app_cmp
-
/*! \brief Typedef for callbacks that get called on channel snapshot updates */
typedef void (*cel_channel_snapshot_monitor)(
struct ast_channel_snapshot *old_snapshot,
struct ast_channel_snapshot *new_snapshot);
+static struct ast_multi_channel_blob *get_dialstatus_blob(const char *uniqueid)
+{
+ return ao2_find(cel_dialstatus_store, uniqueid, OBJ_KEY | OBJ_UNLINK);
+}
+
+static const char *get_caller_dialstatus(struct ast_multi_channel_blob *blob)
+{
+ struct ast_json *json = ast_multi_channel_blob_get_json(blob);
+ if (!json) {
+ return NULL;
+ }
+
+ json = ast_json_object_get(json, "dialstatus");
+ if (!json) {
+ return NULL;
+ }
+
+ return ast_json_string_get(json);
+}
+
/*! \brief Handle channel state changes */
static void cel_channel_state_change(
struct ast_channel_snapshot *old_snapshot,
@@ -834,7 +872,15 @@
if (!was_hungup && is_hungup) {
RAII_VAR(struct ast_str *, extra_str, ast_str_create(128), ast_free);
- ast_str_set(&extra_str, 0, "%d,%s,%s", new_snapshot->hangupcause, new_snapshot->hangupsource, new_snapshot->dialstatus);
+ RAII_VAR(struct ast_multi_channel_blob *, blob, get_dialstatus_blob(new_snapshot->uniqueid), ao2_cleanup);
+ const char *dialstatus = "";
+ if (blob && get_caller_dialstatus(blob)) {
+ dialstatus = get_caller_dialstatus(blob);
+ }
+ ast_str_set(&extra_str, 0, "%d,%s,%s",
+ new_snapshot->hangupcause,
+ new_snapshot->hangupsource,
+ dialstatus);
report_event_snapshot(new_snapshot, AST_CEL_HANGUP, NULL, ast_str_buffer(extra_str));
return;
}
@@ -885,8 +931,8 @@
};
static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic,
- struct stasis_message *message)
+ struct stasis_topic *topic,
+ struct stasis_message *message)
{
struct stasis_cache_update *update = stasis_message_data(message);
if (ast_channel_snapshot_type() == update->type) {
@@ -903,6 +949,28 @@
}
}
+static void save_dialstatus(struct ast_multi_channel_blob *blob)
+{
+ ao2_link(cel_dialstatus_store, blob);
+}
+
+static void cel_dial_cb(void *data, struct stasis_subscription *sub,
+ struct stasis_topic *topic,
+ struct stasis_message *message)
+{
+ struct ast_multi_channel_blob *blob = stasis_message_data(message);
+
+ if (!get_caller_uniqueid(blob)) {
+ return;
+ }
+
+ if (!get_caller_dialstatus(blob)) {
+ return;
+ }
+
+ save_dialstatus(blob);
+}
+
static void ast_cel_engine_term(void)
{
stasis_message_router_unsubscribe(cel_state_router);
@@ -910,33 +978,28 @@
ao2_cleanup(cel_state_topic);
cel_state_topic = NULL;
cel_channel_forwarder = stasis_unsubscribe(cel_channel_forwarder);
- if (appset) {
- ao2_ref(appset, -1);
- appset = NULL;
- }
- if (linkedids) {
- ao2_ref(linkedids, -1);
- linkedids = NULL;
- }
+ ao2_cleanup(appset);
+ appset = NULL;
+ ao2_cleanup(linkedids);
+ linkedids = NULL;
ast_cli_unregister(&cli_status);
}
int ast_cel_engine_init(void)
{
int ret = 0;
- if (!(appset = ao2_container_alloc(NUM_APP_BUCKETS, app_hash, app_cmp))) {
- return -1;
- }
- if (!(linkedids = ao2_container_alloc(NUM_APP_BUCKETS, lid_hash, lid_cmp))) {
- ao2_ref(appset, -1);
+ if (!(appset = ast_str_container_alloc(NUM_APP_BUCKETS))) {
+ return -1;
+ }
+ if (!(linkedids = ast_str_container_alloc(NUM_APP_BUCKETS))) {
+ return -1;
+ }
+
+ if (!(cel_dialstatus_store = ao2_container_alloc(NUM_DIALSTATUS_BUCKETS, dialstatus_hash, dialstatus_cmp))) {
return -1;
}
if (do_reload() || ast_cli_register(&cli_status)) {
- ao2_ref(appset, -1);
- appset = NULL;
- ao2_ref(linkedids, -1);
- linkedids = NULL;
return -1;
}
@@ -958,6 +1021,11 @@
ret |= stasis_message_router_add(cel_state_router,
stasis_cache_update_type(),
cel_snapshot_update_cb,
+ NULL);
+
+ ret |= stasis_message_router_add(cel_state_router,
+ ast_channel_dial_type(),
+ cel_dial_cb,
NULL);
/* If somehow we failed to add any routes, just shut down the whole
Modified: team/kmoore/stasis-cel_refactoring/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_refactoring/main/stasis_channels.c?view=diff&rev=388956&r1=388955&r2=388956
==============================================================================
--- team/kmoore/stasis-cel_refactoring/main/stasis_channels.c (original)
+++ team/kmoore/stasis-cel_refactoring/main/stasis_channels.c Fri May 17 10:39:39 2013
@@ -163,8 +163,6 @@
snapshot->flags = *ast_channel_flags(chan);
snapshot->caller_pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
- ast_string_field_set(snapshot, dialstatus,
- S_OR(pbx_builtin_getvar_helper(chan, "DIALSTATUS"), ""));
snapshot->manager_vars = ast_channel_get_manager_vars(chan);
ao2_ref(snapshot, +1);
More information about the asterisk-commits
mailing list