[asterisk-commits] dlee: branch dlee/stasis-core r382306 - in /team/dlee/stasis-core: include/as...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Feb 28 16:20:36 CST 2013
Author: dlee
Date: Thu Feb 28 16:20:32 2013
New Revision: 382306
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382306
Log:
Addressed more review feedback
Modified:
team/dlee/stasis-core/include/asterisk/channel.h
team/dlee/stasis-core/main/channel.c
team/dlee/stasis-core/main/manager.c
team/dlee/stasis-core/main/stasis.c
team/dlee/stasis-core/main/stasis_cache.c
Modified: team/dlee/stasis-core/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/include/asterisk/channel.h?view=diff&rev=382306&r1=382305&r2=382306
==============================================================================
--- team/dlee/stasis-core/include/asterisk/channel.h (original)
+++ team/dlee/stasis-core/include/asterisk/channel.h Thu Feb 28 16:20:32 2013
@@ -4152,19 +4152,6 @@
/*!
* \since 12
- * \brief Compare two channel state snapshots, in their entirety.
- *
- * \param obj The first snapshot to compare
- * \param args The second snapshot to compare
- * \param flags astobj2 comparison flags
- *
- * \retval CMP_MATCH | CMP_STOP if object match.
- * \retval 0 if objects don't match.
- */
-int ast_channel_snapshot_cmp(void *obj, void *arg, int flags);
-
-/*!
- * \since 12
* \brief Message type for \ref ast_channel_snapshot.
*
* \retval Message type for \ref ast_channel_snapshot.
@@ -4203,9 +4190,11 @@
* \brief Variable set event.
*/
struct ast_channel_varset_event {
- char *channel_name;
- char *uniqueid;
+ /*! Channel variable was set on (or NULL for global variable) */
+ struct ast_channel_snapshot *snapshot;
+ /*! Variable name */
char *variable;
+ /*! New value */
char *value;
};
Modified: team/dlee/stasis-core/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/channel.c?view=diff&rev=382306&r1=382305&r2=382306
==============================================================================
--- team/dlee/stasis-core/main/channel.c (original)
+++ team/dlee/stasis-core/main/channel.c Thu Feb 28 16:20:32 2013
@@ -223,7 +223,7 @@
{ AST_CAUSE_INTERWORKING, "INTERWORKING", "Interworking, unspecified" },
};
-static void stasis_publish_channel_state(struct ast_channel *chan)
+static void publish_channel_state(struct ast_channel *chan)
{
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
@@ -243,11 +243,10 @@
stasis_publish(ast_channel_events(chan), message);
}
-static void ast_channel_varset_event_dtor(void *obj)
+static void channel_varset_event_dtor(void *obj)
{
struct ast_channel_varset_event *event = obj;
- ast_free(event->channel_name);
- ast_free(event->uniqueid);
+ ao2_cleanup(event->snapshot);
ast_free(event->variable);
ast_free(event->value);
}
@@ -257,29 +256,25 @@
RAII_VAR(struct ast_channel_varset_event *, event, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
- event = ao2_alloc(sizeof(*event), ast_channel_varset_event_dtor);
+ event = ao2_alloc(sizeof(*event), channel_varset_event_dtor);
if (!event) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return;
}
if (chan) {
- event->channel_name = ast_strdup(ast_channel_name(chan));
- event->uniqueid = ast_strdup(ast_channel_name(chan));
- } else {
- event->channel_name = ast_strdup("none");
- event->uniqueid = ast_strdup("none");
+ event->snapshot = ast_channel_snapshot_create(chan);
+ if (event->snapshot == NULL) {
+ return;
+ }
}
event->variable = ast_strdup(name);
event->value = ast_strdup(value);
- if (event->channel_name == NULL || event->uniqueid == NULL || event->variable == NULL || event->value == NULL) {
- ast_log(LOG_ERROR, "Allocation failed\n");
+ if (event->variable == NULL || event->value == NULL) {
return;
}
msg = stasis_message_create(ast_channel_varset_event(), event);
if (!msg) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return;
}
@@ -291,7 +286,7 @@
}
-static void stasis_publish_cache_clear(struct ast_channel *chan)
+static void publish_cache_clear(struct ast_channel *chan)
{
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
@@ -1232,7 +1227,7 @@
* a lot of data into this func to do it here!
*/
if (ast_get_channel_tech(tech) || (tech2 && ast_get_channel_tech(tech2))) {
- stasis_publish_channel_state(tmp);
+ publish_channel_state(tmp);
}
ast_channel_internal_finalize(tmp);
@@ -2954,8 +2949,8 @@
ast_cc_offer(chan);
- stasis_publish_channel_state(chan);
- stasis_publish_cache_clear(chan);
+ publish_channel_state(chan);
+ publish_cache_clear(chan);
if (ast_channel_cdr(chan) && !ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_BRIDGED) &&
!ast_test_flag(ast_channel_cdr(chan), AST_CDR_FLAG_POST_DISABLED) &&
@@ -7465,7 +7460,7 @@
* we override what they are saying the state is and things go amuck. */
ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), name);
- stasis_publish_channel_state(chan);
+ publish_channel_state(chan);
return 0;
}
@@ -11254,6 +11249,79 @@
return 0;
}
+static void ast_channel_snapshot_dtor(void *obj)
+{
+ struct ast_channel_snapshot *snapshot = obj;
+ ast_string_field_free_memory(snapshot);
+}
+
+struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan)
+{
+ RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+
+ snapshot = ao2_alloc(sizeof(*snapshot), ast_channel_snapshot_dtor);
+ if (ast_string_field_init(snapshot, 1024)) {
+ return NULL;
+ }
+
+ ast_string_field_set(snapshot, name, ast_channel_name(chan));
+ ast_string_field_set(snapshot, accountcode, ast_channel_accountcode(chan));
+ ast_string_field_set(snapshot, peeraccount, ast_channel_peeraccount(chan));
+ ast_string_field_set(snapshot, userfield, ast_channel_userfield(chan));
+ ast_string_field_set(snapshot, uniqueid, ast_channel_uniqueid(chan));
+ ast_string_field_set(snapshot, linkedid, ast_channel_linkedid(chan));
+ ast_string_field_set(snapshot, parkinglot, ast_channel_parkinglot(chan));
+ ast_string_field_set(snapshot, hangupsource, ast_channel_hangupsource(chan));
+ if (ast_channel_appl(chan)) {
+ ast_string_field_set(snapshot, appl, ast_channel_appl(chan));
+ }
+ if (ast_channel_data(chan)) {
+ ast_string_field_set(snapshot, data, ast_channel_data(chan));
+ }
+ ast_string_field_set(snapshot, context, ast_channel_context(chan));
+ ast_string_field_set(snapshot, exten, ast_channel_exten(chan));
+
+ ast_string_field_set(snapshot, caller_name,
+ S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""));
+ ast_string_field_set(snapshot, caller_number,
+ S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""));
+
+ ast_string_field_set(snapshot, connected_name,
+ S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, ""));
+ ast_string_field_set(snapshot, connected_number,
+ S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, ""));
+
+ snapshot->creationtime = ast_channel_creationtime(chan);
+ snapshot->state = ast_channel_state(chan);
+ snapshot->priority = ast_channel_priority(chan);
+ snapshot->amaflags = ast_channel_amaflags(chan);
+ snapshot->hangupcause = ast_channel_hangupcause(chan);
+ snapshot->flags = *ast_channel_flags(chan);
+
+ ao2_ref(snapshot, +1);
+ return snapshot;
+}
+
+struct stasis_message_type *ast_channel_varset_event(void)
+{
+ return __ast_channel_varset_event;
+}
+
+struct stasis_message_type *ast_channel_snapshot(void)
+{
+ return __ast_channel_snapshot;
+}
+
+struct stasis_topic *ast_channel_events_all(void)
+{
+ return __ast_channel_events_all;
+}
+
+struct stasis_caching_topic *ast_channel_events_all_cached(void)
+{
+ return __ast_channel_events_all_cached;
+}
+
/* DO NOT PUT ADDITIONAL FUNCTIONS BELOW THIS BOUNDARY
*
* ONLY FUNCTIONS FOR PROVIDING BACKWARDS ABI COMPATIBILITY BELONG HERE
@@ -11292,99 +11360,3 @@
{
ao2_unlink(channels, chan);
}
-
-static void ast_channel_snapshot_dtor(void *obj)
-{
- struct ast_channel_snapshot *snapshot = obj;
- ast_string_field_free_memory(snapshot);
-}
-
-struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan)
-{
- RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
-
- snapshot = ao2_alloc(sizeof(*snapshot), ast_channel_snapshot_dtor);
- if (ast_string_field_init(snapshot, 1024)) {
- return NULL;
- }
-
- ast_string_field_set(snapshot, name, ast_channel_name(chan));
- ast_string_field_set(snapshot, accountcode, ast_channel_accountcode(chan));
- ast_string_field_set(snapshot, peeraccount, ast_channel_peeraccount(chan));
- ast_string_field_set(snapshot, userfield, ast_channel_userfield(chan));
- ast_string_field_set(snapshot, uniqueid, ast_channel_uniqueid(chan));
- ast_string_field_set(snapshot, linkedid, ast_channel_linkedid(chan));
- ast_string_field_set(snapshot, parkinglot, ast_channel_parkinglot(chan));
- ast_string_field_set(snapshot, hangupsource, ast_channel_hangupsource(chan));
- if (ast_channel_appl(chan)) {
- ast_string_field_set(snapshot, appl, ast_channel_appl(chan));
- }
- if (ast_channel_data(chan)) {
- ast_string_field_set(snapshot, data, ast_channel_data(chan));
- }
- ast_string_field_set(snapshot, context, ast_channel_context(chan));
- ast_string_field_set(snapshot, exten, ast_channel_exten(chan));
-
- ast_string_field_set(snapshot, caller_name,
- S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""));
- ast_string_field_set(snapshot, caller_number,
- S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""));
-
- ast_string_field_set(snapshot, connected_name,
- S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, ""));
- ast_string_field_set(snapshot, connected_number,
- S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, ""));
-
- snapshot->creationtime = ast_channel_creationtime(chan);
- snapshot->state = ast_channel_state(chan);
- snapshot->priority = ast_channel_priority(chan);
- snapshot->amaflags = ast_channel_amaflags(chan);
- snapshot->hangupcause = ast_channel_hangupcause(chan);
- snapshot->flags = *ast_channel_flags(chan);
-
- ao2_ref(snapshot, +1);
- return snapshot;
-}
-
-int ast_channel_snapshot_cmp(void *obj, void *arg, int flags)
-{
- /* Compare string fields */
- const struct ast_channel_snapshot *one = obj, *two = arg;
- int res;
- size_t non_str_len, offset;
-
- if (flags != 0) {
- /* No support for OBJ_KEY matching */
- return 0;
- }
-
- res = ast_string_fields_cmp(one, two);
- if (res) {
- return res;
- }
-
- /* Compare the rest of the structure */
- offset = (const void *)&one->creationtime - (const void *)one;
- non_str_len = sizeof(*one) - offset;
- return memcmp(one + offset, two + offset, non_str_len);
-}
-
-struct stasis_message_type *ast_channel_varset_event(void)
-{
- return __ast_channel_varset_event;
-}
-
-struct stasis_message_type *ast_channel_snapshot(void)
-{
- return __ast_channel_snapshot;
-}
-
-struct stasis_topic *ast_channel_events_all(void)
-{
- return __ast_channel_events_all;
-}
-
-struct stasis_caching_topic *ast_channel_events_all_cached(void)
-{
- return __ast_channel_events_all_cached;
-}
Modified: team/dlee/stasis-core/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/manager.c?view=diff&rev=382306&r1=382305&r2=382306
==============================================================================
--- team/dlee/stasis-core/main/manager.c (original)
+++ team/dlee/stasis-core/main/manager.c Thu Feb 28 16:20:32 2013
@@ -7510,7 +7510,7 @@
}
}
-static void channel_varset(char *channel_name, char *uniqueid, const char *name, const char *value)
+static void channel_varset(const char *channel_name, const char *uniqueid, const char *name, const char *value)
{
/*** DOCUMENTATION
<managerEventInstance>
@@ -7538,7 +7538,9 @@
}
} else if (stasis_message_type(message) == ast_channel_varset_event()) {
struct ast_channel_varset_event *event = stasis_message_data(message);
- channel_varset(event->channel_name, event->uniqueid, event->variable, event->value);
+ const char *name = event->snapshot ?event->snapshot->name : "none";
+ const char *uniqueid = event->snapshot ?event->snapshot->uniqueid : "none";
+ channel_varset(name, uniqueid, event->variable, event->value);
}
}
Modified: team/dlee/stasis-core/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/stasis.c?view=diff&rev=382306&r1=382305&r2=382306
==============================================================================
--- team/dlee/stasis-core/main/stasis.c (original)
+++ team/dlee/stasis-core/main/stasis.c Thu Feb 28 16:20:32 2013
@@ -78,20 +78,17 @@
topic = ao2_alloc(sizeof(*topic), topic_dtor);
if (!topic) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return NULL;
}
topic->name = ast_strdup(name);
if (!topic->name) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return NULL;
}
topic->num_subscribers_max = INITIAL_SUBSCRIBERS_MAX;
topic->subscribers = ast_calloc(topic->num_subscribers_max, sizeof(topic->subscribers));
if (!topic->subscribers) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return NULL;
}
@@ -133,7 +130,6 @@
sub = ao2_alloc(sizeof(*sub), subscription_dtor);
if (!sub) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return NULL;
}
@@ -210,7 +206,6 @@
if (topic->num_subscribers_current + 1 > topic->num_subscribers_max) {
subscribers = realloc(topic->subscribers, 2 * topic->num_subscribers_max * sizeof(*subscribers));
if (!subscribers) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return -1;
}
topic->subscribers = subscribers;
@@ -317,7 +312,7 @@
}
if (!subscribers) {
- ast_log(LOG_ERROR, "Allocation failure; dropping message\n");
+ ast_log(LOG_ERROR, "Dropping message\n");
return;
}
@@ -331,7 +326,7 @@
dispatch = dispatch_create(publisher_topic, message, sub);
if (!dispatch) {
- ast_log(LOG_DEBUG, "Allocation failure; dropping dispatch\n");
+ ast_log(LOG_DEBUG, "Dropping dispatch\n");
break;
}
Modified: team/dlee/stasis-core/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/stasis_cache.c?view=diff&rev=382306&r1=382305&r2=382306
==============================================================================
--- team/dlee/stasis-core/main/stasis_cache.c (original)
+++ team/dlee/stasis-core/main/stasis_cache.c Thu Feb 28 16:20:32 2013
@@ -87,13 +87,11 @@
entry = ao2_alloc(sizeof(*entry), cache_entry_dtor);
if (!entry) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return NULL;
}
entry->id = ast_strdup(id);
if (!entry->id) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return NULL;
}
@@ -233,13 +231,11 @@
ev = ao2_alloc(sizeof(*ev), cache_clear_data_dtor);
if (!ev) {
- ast_log(LOG_ERROR, "Allocation failure\n");
return NULL;
}
ev->id = ast_strdup(id);
if (!ev->id) {
- ast_log(LOG_ERROR, "Allocation failure\n");
return NULL;
}
ao2_ref(type, +1);
@@ -344,7 +340,6 @@
update = update_create(topic, old_snapshot, message);
if (update == NULL) {
- ast_log(LOG_ERROR, "Allocation error creating update\n");
return;
}
@@ -361,13 +356,11 @@
ret = asprintf(&new_name, "%s-cached", stasis_topic_name(original_topic));
if (ret < 0) {
- ast_log(LOG_ERROR, "Allocation failed\n");
return NULL;
}
caching_topic = ao2_alloc(sizeof(*caching_topic), stasis_caching_topic_dtor);
if (caching_topic == NULL) {
- ast_log(LOG_ERROR, "Allocation failure\n");
return NULL;
}
More information about the asterisk-commits
mailing list