[asterisk-commits] kmoore: branch kmoore/stasis-device_state r383099 - in /team/kmoore/stasis-de...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 14 13:27:27 CDT 2013


Author: kmoore
Date: Thu Mar 14 13:27:23 2013
New Revision: 383099

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383099
Log:
Address Matt's comments

Modified:
    team/kmoore/stasis-device_state/apps/app_queue.c
    team/kmoore/stasis-device_state/include/asterisk/devicestate.h
    team/kmoore/stasis-device_state/main/asterisk.c
    team/kmoore/stasis-device_state/main/ccss.c
    team/kmoore/stasis-device_state/main/devicestate.c
    team/kmoore/stasis-device_state/main/pbx.c
    team/kmoore/stasis-device_state/res/res_jabber.c
    team/kmoore/stasis-device_state/res/res_xmpp.c

Modified: team/kmoore/stasis-device_state/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/apps/app_queue.c?view=diff&rev=383099&r1=383098&r2=383099
==============================================================================
--- team/kmoore/stasis-device_state/apps/app_queue.c (original)
+++ team/kmoore/stasis-device_state/apps/app_queue.c Thu Mar 14 13:27:23 2013
@@ -1744,7 +1744,7 @@
 	int found_member;		/* Found this member in this queue */
 	int avail = 0;			/* Found an available member in this queue */
 
-	if (stasis_device_state() != stasis_message_type(msg)) {
+	if (stasis_device_state_message() != stasis_message_type(msg)) {
 		return;
 	}
 

Modified: team/kmoore/stasis-device_state/include/asterisk/devicestate.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/include/asterisk/devicestate.h?view=diff&rev=383099&r1=383098&r2=383099
==============================================================================
--- team/kmoore/stasis-device_state/include/asterisk/devicestate.h (original)
+++ team/kmoore/stasis-device_state/include/asterisk/devicestate.h Thu Mar 14 13:27:23 2013
@@ -276,7 +276,7 @@
  */
 struct stasis_device_state {
 	AST_DECLARE_STRING_FIELDS(
-		AST_STRING_FIELD(uniqueid);	/*!< A unique ID used for hashing */
+		AST_STRING_FIELD(cache_id);	/*!< A unique ID used for hashing */
 		AST_STRING_FIELD(device);	/*!< The name of the device */
 	);
 	enum ast_device_state state;		/*!< The state of the device */
@@ -315,7 +315,7 @@
  * \retval NULL if it has not been allocated
  * \since 12
  */
-struct stasis_message_type *stasis_device_state(void);
+struct stasis_message_type *stasis_device_state_message(void);
 
 /*!
  * \brief Initialize the device state core

Modified: team/kmoore/stasis-device_state/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/main/asterisk.c?view=diff&rev=383099&r1=383098&r2=383099
==============================================================================
--- team/kmoore/stasis-device_state/main/asterisk.c (original)
+++ team/kmoore/stasis-device_state/main/asterisk.c Thu Mar 14 13:27:23 2013
@@ -4126,11 +4126,6 @@
 		exit(1);
 	}
 
-	if (devstate_init()) {
-		printf("Device state core initialization failed.\n%s", term_quit());
-		exit(1);
-	}
-
 	ast_makesocket();
 	sigemptyset(&sigs);
 	sigaddset(&sigs, SIGHUP);
@@ -4183,6 +4178,11 @@
 
 	aco_init();
 
+	if (devstate_init()) {
+		printf("Device state core initialization failed.\n%s", term_quit());
+		exit(1);
+	}
+
 	if (astdb_init()) {
 		printf("%s", term_quit());
 		exit(1);

Modified: team/kmoore/stasis-device_state/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/main/ccss.c?view=diff&rev=383099&r1=383098&r2=383099
==============================================================================
--- team/kmoore/stasis-device_state/main/ccss.c (original)
+++ team/kmoore/stasis-device_state/main/ccss.c Thu Mar 14 13:27:23 2013
@@ -1274,6 +1274,7 @@
 	struct generic_monitor_instance_list *generic_list = ao2_t_alloc(sizeof(*generic_list),
 			generic_monitor_instance_list_destructor, "allocate generic monitor instance list");
 	char * device_name;
+	struct stasis_topic *device_specific_topic;
 
 	if (!generic_list) {
 		return NULL;
@@ -1286,7 +1287,12 @@
 	ast_tech_to_upper(device_name);
 	generic_list->device_name = device_name;
 
-	if (!(generic_list->sub = stasis_subscribe(stasis_device_state_topic(monitor->interface->device_name), generic_monitor_devstate_cb, NULL))) {
+	device_specific_topic = stasis_device_state_topic(device_name);
+	if (!device_specific_topic) {
+		return NULL;
+	}
+
+	if (!(generic_list->sub = stasis_subscribe(device_specific_topic, generic_monitor_devstate_cb, NULL))) {
 		cc_unref(generic_list, "Failed to subscribe to device state");
 		return NULL;
 	}
@@ -1297,7 +1303,7 @@
 
 static int generic_monitor_devstate_tp_cb(void *data)
 {
-	struct stasis_device_state *dev_state = data;
+	RAII_VAR(struct stasis_device_state *, dev_state, data, ao2_cleanup);
 	enum ast_device_state new_state = dev_state->state;
 	enum ast_device_state previous_state;
 	struct generic_monitor_instance_list *generic_list;
@@ -1308,14 +1314,12 @@
 		 * time between subscribing to its device state and the time this executes.
 		 * Not really a big deal.
 		 */
-		ao2_cleanup(dev_state);
 		return 0;
 	}
 
 	if (generic_list->current_state == new_state) {
 		/* The device state hasn't actually changed, so we don't really care */
 		cc_unref(generic_list, "Kill reference of generic list in devstate taskprocessor callback");
-		ao2_cleanup(dev_state);
 		return 0;
 	}
 
@@ -1335,7 +1339,6 @@
 		}
 	}
 	cc_unref(generic_list, "Kill reference of generic list in devstate taskprocessor callback");
-	ao2_cleanup(dev_state);
 	return 0;
 }
 
@@ -1347,7 +1350,7 @@
 	 * no steenkin' locks!
 	 */
 	struct stasis_device_state *dev_state;
-	if (stasis_device_state() != stasis_message_type(msg)) {
+	if (stasis_device_state_message() != stasis_message_type(msg)) {
 		return;
 	}
 
@@ -1360,7 +1363,7 @@
 	if (ast_taskprocessor_push(cc_core_taskprocessor, generic_monitor_devstate_tp_cb, dev_state)) {
 		return;
 	}
-	ao2_ref(dev_state, +1);
+	ao2_t_ref(dev_state, +1, "Bumping dev_state ref for cc_core_taskprocessor");
 }
 
 int ast_cc_available_timer_expire(const void *data)
@@ -2632,7 +2635,7 @@
 	if (stasis_subscription_final_message(sub, msg)) {
 		cc_unref(agent, "Done holding ref for subscription");
 		return;
-	} else if (stasis_device_state() != stasis_message_type(msg)) {
+	} else if (stasis_device_state_message() != stasis_message_type(msg)) {
 		return;
 	}
 
@@ -2657,12 +2660,18 @@
 {
 	struct cc_generic_agent_pvt *generic_pvt = agent->private_data;
 	struct ast_str *str = ast_str_alloca(128);
+	struct stasis_topic *device_specific_topic;
 
 	ast_assert(generic_pvt->sub == NULL);
 	ast_str_set(&str, 0, "Agent monitoring %s device state since it is busy\n",
 		agent->device_name);
 
-	if (!(generic_pvt->sub = stasis_subscribe(stasis_device_state_topic(agent->device_name), generic_agent_devstate_cb, agent))) {
+	device_specific_topic = stasis_device_state_topic(agent->device_name);
+	if (!device_specific_topic) {
+		return -1;
+	}
+
+	if (!(generic_pvt->sub = stasis_subscribe(device_specific_topic, generic_agent_devstate_cb, agent))) {
 		return -1;
 	}
 	cc_ref(agent, "Ref agent for subscription");

Modified: team/kmoore/stasis-device_state/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/main/devicestate.c?view=diff&rev=383099&r1=383098&r2=383099
==============================================================================
--- team/kmoore/stasis-device_state/main/devicestate.c (original)
+++ team/kmoore/stasis-device_state/main/devicestate.c Thu Mar 14 13:27:23 2013
@@ -133,6 +133,8 @@
 #include "asterisk/stasis.h"
 #include "asterisk/event.h"
 #include "asterisk/devicestate.h"
+
+#define DEVSTATE_TOPIC_BUCKETS 57
 
 /*! \brief Device state strings for printing */
 static const char * const devstatestring[][2] = {
@@ -193,13 +195,14 @@
 
 struct stasis_subscription *devstate_message_sub;
 
-static struct stasis_topic *__device_state_topic_all;
-static struct stasis_caching_topic *__device_state_topic_cached;
-static struct stasis_message_type *__device_state_message_type;
-static struct ao2_container *__device_state_topics;
-
+static struct stasis_topic *device_state_topic_all;
+static struct stasis_caching_topic *device_state_topic_cached;
+static struct stasis_message_type *device_state_message_type;
+static struct ao2_container *device_state_topics;
+
+/* container for dynamically generated device-specific topics */
 struct device_state_topic {
-	char *uniqueid;
+	char *device;
 	struct stasis_subscription *forward;
 	struct stasis_topic *topic;
 };
@@ -207,8 +210,8 @@
 static void device_state_topic_dtor(void *obj)
 {
 	struct device_state_topic *topic = obj;
-	ast_free(topic->uniqueid);
-	topic->uniqueid = NULL;
+	ast_free(topic->device);
+	topic->device = NULL;
 	stasis_unsubscribe(topic->forward);
 	topic->forward = NULL;
 	ao2_cleanup(topic->topic);
@@ -302,15 +305,15 @@
 static enum ast_device_state devstate_cached(const char *device)
 {
 	RAII_VAR(struct stasis_message *, cached_msg, NULL, ao2_cleanup);
-	struct stasis_device_state *dev_state;
-
-	cached_msg = stasis_cache_get(stasis_device_state_topic_cached(), stasis_device_state(), device);
+	struct stasis_device_state *device_state;
+
+	cached_msg = stasis_cache_get(stasis_device_state_topic_cached(), stasis_device_state_message(), device);
 	if (!cached_msg) {
 		return AST_DEVICE_UNKNOWN;
 	}
-	dev_state = stasis_message_data(cached_msg);
-
-	return dev_state->state;
+	device_state = stasis_message_data(cached_msg);
+
+	return device_state->state;
 }
 
 /*! \brief Check device state through channel specific function or generic function */
@@ -543,17 +546,17 @@
 static int devstate_change_aggregator_cb(void *obj, void *arg, void *data, int flags)
 {
 	struct stasis_message *msg = obj;
-	struct ast_devstate_aggregate *agg = arg;
+	struct ast_devstate_aggregate *aggregate = arg;
 	char *device = data;
-	struct stasis_device_state *dev_state = stasis_message_data(msg);
-
-	if (!dev_state->eid || strcmp(device, dev_state->device)) {
+	struct stasis_device_state *device_state = stasis_message_data(msg);
+
+	if (!device_state->eid || strcmp(device, device_state->device)) {
 		/* ignore aggregate states and devices that don't match */
 		return 0;
 	}
 	ast_debug(1, "Adding per-server state of '%s' for '%s'\n",
-		ast_devstate2str(dev_state->state), device);
-	ast_devstate_aggregate_add(agg, dev_state->state);
+		ast_devstate2str(device_state->state), device);
+	ast_devstate_aggregate_add(aggregate, device_state->state);
 	return 0;
 }
 
@@ -566,101 +569,112 @@
 
 static struct stasis_device_state *device_state_alloc(const char *device, enum ast_device_state state, enum ast_devstate_cache cached, const struct ast_eid *eid)
 {
-	RAII_VAR(struct stasis_device_state *, new_dev_state, NULL, ao2_cleanup);
-	new_dev_state = ao2_alloc(sizeof(*new_dev_state), device_state_dtor);
-
-	if (!new_dev_state || ast_string_field_init(new_dev_state, 256)) {
+	RAII_VAR(struct stasis_device_state *, new_device_state, ao2_alloc(sizeof(*new_device_state), device_state_dtor), ao2_cleanup);
+
+	if (!new_device_state || ast_string_field_init(new_device_state, 256)) {
 		return NULL;
 	}
 
-	ast_string_field_set(new_dev_state, device, device);
-	new_dev_state->state = state;
+	ast_string_field_set(new_device_state, device, device);
+	new_device_state->state = state;
 
 	if (eid) {
 		char eid_str[20];
-		struct ast_str *uniqueid = ast_str_alloca(256);
-
-		new_dev_state->eid = ast_malloc(sizeof(*eid));
-		if (!new_dev_state->eid) {
+		struct ast_str *cache_id = ast_str_alloca(256);
+
+		new_device_state->eid = ast_malloc(sizeof(*eid));
+		if (!new_device_state->eid) {
 			return NULL;
 		}
 
-		*new_dev_state->eid = *eid;
-		ast_eid_to_str(eid_str, sizeof(eid_str), new_dev_state->eid);
-		ast_str_set(&uniqueid, 0, "%s%s", eid_str, device);
-		ast_string_field_set(new_dev_state, uniqueid, ast_str_buffer(uniqueid));
+		*new_device_state->eid = *eid;
+		ast_eid_to_str(eid_str, sizeof(eid_str), new_device_state->eid);
+		ast_str_set(&cache_id, 0, "%s%s", eid_str, device);
+		ast_string_field_set(new_device_state, cache_id, ast_str_buffer(cache_id));
 	} else {
 		/* no EID makes this an aggregate state */
-		ast_string_field_set(new_dev_state, uniqueid, device);
-	}
-
-	ao2_ref(new_dev_state, +1);
-	return new_dev_state;
-}
-
-static enum ast_device_state get_agg_state(char *device)
+		ast_string_field_set(new_device_state, cache_id, device);
+	}
+
+	ao2_ref(new_device_state, +1);
+	return new_device_state;
+}
+
+static enum ast_device_state get_aggregate_state(char *device)
 {
 	RAII_VAR(struct ao2_container *, cached, NULL, ao2_cleanup);
-	struct ast_devstate_aggregate agg;
-
-	ast_devstate_aggregate_init(&agg);
+	struct ast_devstate_aggregate aggregate;
+
+	ast_devstate_aggregate_init(&aggregate);
 
 	cached = stasis_cache_dump(stasis_device_state_topic_cached(), NULL);
 
-	ao2_callback_data(cached, OBJ_NODATA, devstate_change_aggregator_cb, &agg, device);
-
-	return ast_devstate_aggregate_result(&agg);
+	ao2_callback_data(cached, OBJ_NODATA, devstate_change_aggregator_cb, &aggregate, device);
+
+	return ast_devstate_aggregate_result(&aggregate);
+}
+
+static int aggregate_state_changed(char *device, enum ast_device_state new_aggregate_state)
+{
+	RAII_VAR(struct stasis_message *, cached_aggregate_msg, NULL, ao2_cleanup);
+	struct stasis_device_state *cached_aggregate_device_state;
+
+	cached_aggregate_msg = stasis_cache_get(stasis_device_state_topic_cached(), stasis_device_state_message(), device);
+	if (!cached_aggregate_msg) {
+		return 1;
+	}
+
+	cached_aggregate_device_state = stasis_message_data(cached_aggregate_msg);
+	if (cached_aggregate_device_state->state == new_aggregate_state) {
+		return 0;
+	}
+	return 1;
 }
 
 static void devstate_change_collector_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
 {
-	enum ast_device_state agg_state;
+	enum ast_device_state aggregate_state;
 	char *device;
-	struct stasis_device_state *dev_state;
-	RAII_VAR(struct stasis_message *, new_agg_msg, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_device_state *, new_agg_state, NULL, ao2_cleanup);
-
-	if (stasis_device_state() != stasis_message_type(msg)) {
+	struct stasis_device_state *device_state;
+	RAII_VAR(struct stasis_message *, new_aggregate_msg, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_device_state *, new_aggregate_state, NULL, ao2_cleanup);
+
+	if (stasis_device_state_message() != stasis_message_type(msg)) {
 		return;
 	}
 
-	dev_state = stasis_message_data(msg);
-
-	if (!dev_state->eid) {
+	device_state = stasis_message_data(msg);
+
+	if (!device_state->eid) {
 		/* ignore aggregate messages */
 		return;
 	}
 
-	device = (char *)dev_state->device;
+	device = ast_strdupa(device_state->device);
 	ast_debug(1, "Processing device state change for '%s'\n", device);
 
-	if (dev_state->cachable == AST_DEVSTATE_NOT_CACHABLE) {
+	if (device_state->cachable == AST_DEVSTATE_NOT_CACHABLE) {
 		/* if it's not cachable, there will be no aggregate state to get
 		 * and this should be passed through */
-		agg_state = dev_state->state;
+		aggregate_state = device_state->state;
 	} else {
-		RAII_VAR(struct stasis_message *, cached_agg_msg, NULL, ao2_cleanup);
-
-		agg_state = get_agg_state(device);
+
+		aggregate_state = get_aggregate_state(device);
 		ast_debug(1, "Aggregate devstate result is '%s' for '%s'\n",
-			ast_devstate2str(agg_state), device);
-
-		cached_agg_msg = stasis_cache_get(stasis_device_state_topic_cached(), stasis_device_state(), device);
-		if (cached_agg_msg) {
-			struct stasis_device_state *cached_agg_dev_state = stasis_message_data(cached_agg_msg);
-			if (cached_agg_dev_state->state == agg_state) {
-				/* No change since last reported device state */
-				ast_debug(1, "Aggregate state for device '%s' has not changed from '%s'\n",
-					device, ast_devstate2str(agg_state));
-				return;
-			}
+			ast_devstate2str(aggregate_state), device);
+
+		if (!aggregate_state_changed(device, aggregate_state)) {
+			/* No change since last reported device state */
+			ast_debug(1, "Aggregate state for device '%s' has not changed from '%s'\n",
+				device, ast_devstate2str(aggregate_state));
+			return;
 		}
 	}
 
 	ast_debug(1, "Aggregate state for device '%s' has changed to '%s'\n",
-		device, ast_devstate2str(agg_state));
-
-	stasis_publish_device_state_full(device, agg_state, dev_state->cachable, NULL);
+		device, ast_devstate2str(aggregate_state));
+
+	stasis_publish_device_state_full(device, aggregate_state, device_state->cachable, NULL);
 }
 
 /*! \brief Initialize the device state engine in separate thread */
@@ -715,22 +729,22 @@
 
 struct stasis_topic *stasis_device_state_topic_all(void)
 {
-	return __device_state_topic_all;
+	return device_state_topic_all;
 }
 
 struct stasis_caching_topic *stasis_device_state_topic_cached(void)
 {
-	return __device_state_topic_cached;
-}
-
-struct stasis_message_type *stasis_device_state(void)
-{
-	return __device_state_message_type;
+	return device_state_topic_cached;
+}
+
+struct stasis_message_type *stasis_device_state_message(void)
+{
+	return device_state_message_type;
 }
 
 struct stasis_topic *stasis_device_state_topic(const char *device)
 {
-	RAII_VAR(struct device_state_topic *, device_state_topic, ao2_find(__device_state_topics, device, OBJ_KEY), ao2_cleanup);
+	RAII_VAR(struct device_state_topic *, device_state_topic, ao2_find(device_state_topics, device, OBJ_KEY), ao2_cleanup);
 
 	if (device_state_topic) {
 		return device_state_topic->topic;
@@ -752,12 +766,12 @@
 		return NULL;
 	}
 
-	device_state_topic->uniqueid = ast_strdup(device);
-	if (!device_state_topic->uniqueid) {
+	device_state_topic->device = ast_strdup(device);
+	if (!device_state_topic->device) {
 		return NULL;
 	}
 
-	ao2_link(__device_state_topics, device_state_topic);
+	ao2_link(device_state_topics, device_state_topic);
 
 	return device_state_topic->topic;
 }
@@ -770,6 +784,7 @@
 {
 	RAII_VAR(struct stasis_device_state *, device_state, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+	struct stasis_topic *device_specific_topic;
 
 	ast_assert(!ast_strlen_zero(device));
 
@@ -778,17 +793,21 @@
 		return -1;
 	}
 
-	message = stasis_message_create(stasis_device_state(), device_state);
-
-	ast_assert(stasis_device_state_topic(device) != NULL);
-	stasis_publish(stasis_device_state_topic(device), message);
+	message = stasis_message_create(stasis_device_state_message(), device_state);
+
+	device_specific_topic = stasis_device_state_topic(device);
+	if (!device_specific_topic) {
+		return -1;
+	}
+
+	stasis_publish(device_specific_topic, message);
 	return 0;
 }
 
 static const char *device_state_get_id(struct stasis_message *message)
 {
 	struct stasis_device_state *device_state;
-	if (stasis_device_state() != stasis_message_type(message)) {
+	if (stasis_device_state_message() != stasis_message_type(message)) {
 		return NULL;
 	}
 
@@ -797,53 +816,50 @@
 		return NULL;
 	}
 
-	return device_state->uniqueid;
+	return device_state->cache_id;
 }
 
 static int device_state_topic_hash(const void *obj, const int flags)
 {
-	const char *uniqueid = (flags & OBJ_KEY) ? obj : ((struct device_state_topic*) obj)->uniqueid;
-	return ast_str_case_hash(uniqueid);
+	const char *device = (flags & OBJ_KEY) ? obj : ((struct device_state_topic*) obj)->device;
+	return ast_str_case_hash(device);
 }
 
 static int device_state_topic_cmp(void *obj, void *arg, int flags)
 {
 	struct device_state_topic *opt1 = obj, *opt2 = arg;
-	const char *uniqueid = (flags & OBJ_KEY) ? arg : opt2->uniqueid;
-	return strcasecmp(opt1->uniqueid, uniqueid) ? 0 : CMP_MATCH | CMP_STOP;
+	const char *device = (flags & OBJ_KEY) ? arg : opt2->device;
+	return strcasecmp(opt1->device, device) ? 0 : CMP_MATCH | CMP_STOP;
 }
 
 static void devstate_exit(void)
 {
-	ao2_cleanup(__device_state_topic_all);
-	__device_state_topic_all = NULL;
-	stasis_caching_unsubscribe(__device_state_topic_cached);
-	__device_state_topic_cached = NULL;
-	ao2_cleanup(__device_state_message_type);
-	__device_state_message_type = NULL;
-	ao2_cleanup(__device_state_topics);
-	__device_state_topics = NULL;
-}
-
-#define DEVSTATE_TOPIC_BUCKETS 57
+	ao2_cleanup(device_state_topic_all);
+	device_state_topic_all = NULL;
+	stasis_caching_unsubscribe(device_state_topic_cached);
+	device_state_topic_cached = NULL;
+	ao2_cleanup(device_state_message_type);
+	device_state_message_type = NULL;
+	ao2_cleanup(device_state_topics);
+	device_state_topics = NULL;
+}
 
 int devstate_init(void)
 {
-	ast_register_atexit(devstate_exit);
-	__device_state_topic_all = stasis_topic_create("stasis_device_state_topic");
-	if (!__device_state_topic_all) {
+	device_state_topic_all = stasis_topic_create("stasis_device_state_topic");
+	if (!device_state_topic_all) {
 		return -1;
 	}
-	__device_state_topic_cached = stasis_caching_topic_create(__device_state_topic_all, device_state_get_id);
-	if (!__device_state_topic_cached) {
+	device_state_topic_cached = stasis_caching_topic_create(device_state_topic_all, device_state_get_id);
+	if (!device_state_topic_cached) {
 		return -1;
 	}
-	__device_state_message_type = stasis_message_type_create("stasis_device_state");
-	if (!__device_state_message_type) {
+	device_state_message_type = stasis_message_type_create("stasis_device_state");
+	if (!device_state_message_type) {
 		return -1;
 	}
-	__device_state_topics = ao2_container_alloc(DEVSTATE_TOPIC_BUCKETS, device_state_topic_hash, device_state_topic_cmp);
-	if (!__device_state_topics) {
+	device_state_topics = ao2_container_alloc(DEVSTATE_TOPIC_BUCKETS, device_state_topic_hash, device_state_topic_cmp);
+	if (!device_state_topics) {
 		return -1;
 	}
 
@@ -854,5 +870,6 @@
 		return -1;
 	}
 
+	ast_register_atexit(devstate_exit);
 	return 0;
 }

Modified: team/kmoore/stasis-device_state/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/main/pbx.c?view=diff&rev=383099&r1=383098&r2=383099
==============================================================================
--- team/kmoore/stasis-device_state/main/pbx.c (original)
+++ team/kmoore/stasis-device_state/main/pbx.c Thu Mar 14 13:27:23 2013
@@ -5262,7 +5262,7 @@
 	char context_name[AST_MAX_CONTEXT];
 	char exten_name[AST_MAX_EXTENSION];
 
-	if (stasis_device_state() != stasis_message_type(msg)) {
+	if (stasis_device_state_message() != stasis_message_type(msg)) {
 		return;
 	}
 

Modified: team/kmoore/stasis-device_state/res/res_jabber.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/res/res_jabber.c?view=diff&rev=383099&r1=383098&r2=383099
==============================================================================
--- team/kmoore/stasis-device_state/res/res_jabber.c (original)
+++ team/kmoore/stasis-device_state/res/res_jabber.c Thu Mar 14 13:27:23 2013
@@ -3276,10 +3276,7 @@
 	struct aji_client *client = data;
 	struct stasis_device_state *dev_state;
 
-	if (stasis_subscription_final_message(sub, msg)) {
-		ASTOBJ_UNREF(client, ast_aji_client_destroy);
-		return;
-	} else if (stasis_device_state() != stasis_message_type(msg)) {
+	if (!stasis_subscription_is_subscribed(sub) || stasis_device_state_message() != stasis_message_type(msg)) {
 		return;
 	}
 
@@ -3313,7 +3310,6 @@
 	}
 	if (!device_state_sub) {
 		RAII_VAR(struct ao2_container *, cached, NULL, ao2_cleanup);
-		client = ASTOBJ_REF(client);
 		device_state_sub = stasis_subscribe(stasis_device_state_topic_all(),
 			aji_devstate_cb, client);
 		cached = stasis_cache_dump(stasis_device_state_topic_cached(), NULL);

Modified: team/kmoore/stasis-device_state/res/res_xmpp.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-device_state/res/res_xmpp.c?view=diff&rev=383099&r1=383098&r2=383099
==============================================================================
--- team/kmoore/stasis-device_state/res/res_xmpp.c (original)
+++ team/kmoore/stasis-device_state/res/res_xmpp.c Thu Mar 14 13:27:23 2013
@@ -1351,10 +1351,7 @@
 	struct ast_xmpp_client *client = data;
 	struct stasis_device_state *dev_state;
 
-	if (stasis_subscription_final_message(sub, msg)) {
-		ao2_cleanup(client);
-		return;
-	} else if (stasis_device_state() != stasis_message_type(msg)) {
+	if (!stasis_subscription_is_subscribed(sub) || stasis_device_state_message() != stasis_message_type(msg)) {
 		return;
 	}
 
@@ -1608,7 +1605,6 @@
 		return;
 	}
 
-	ao2_ref(client, +1);
 	cached = stasis_cache_dump(stasis_device_state_topic_cached(), NULL);
 	ao2_callback(cached, OBJ_NODATA, cached_devstate_cb, client);
 




More information about the asterisk-commits mailing list