[svn-commits] mmichelson: branch group/CCSS_Monitor_Restructure r241711 - in /team/group/CC...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jan 20 15:08:53 CST 2010


Author: mmichelson
Date: Wed Jan 20 15:08:49 2010
New Revision: 241711

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=241711
Log:
Got the necessary stuff in place for dealing with a callee becoming available.


Modified:
    team/group/CCSS_Monitor_Restructure/include/asterisk/ccss.h
    team/group/CCSS_Monitor_Restructure/main/ccss.c

Modified: team/group/CCSS_Monitor_Restructure/include/asterisk/ccss.h
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS_Monitor_Restructure/include/asterisk/ccss.h?view=diff&rev=241711&r1=241710&r2=241711
==============================================================================
--- team/group/CCSS_Monitor_Restructure/include/asterisk/ccss.h (original)
+++ team/group/CCSS_Monitor_Restructure/include/asterisk/ccss.h Wed Jan 20 15:08:49 2010
@@ -1356,6 +1356,7 @@
  * \retval -1 Request could not be queued
  */
 int ast_cc_monitor_callee_available(struct ast_cc_monitor *monitor);
+int ast_cc_monitor_callee_available2(struct cc_monitor *monitor);
 
 /* END API FOR USE WITH/BY MONITORS */
 

Modified: team/group/CCSS_Monitor_Restructure/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS_Monitor_Restructure/main/ccss.c?view=diff&rev=241711&r1=241710&r2=241711
==============================================================================
--- team/group/CCSS_Monitor_Restructure/main/ccss.c (original)
+++ team/group/CCSS_Monitor_Restructure/main/ccss.c Wed Jan 20 15:08:49 2010
@@ -1124,8 +1124,14 @@
 static struct generic_monitor_instance_list *create_new_generic_list(struct cc_monitor *monitor)
 {
 	struct generic_monitor_instance_list *generic_list = ao2_alloc(sizeof(*generic_list), generic_monitor_instance_list_destructor);
+	char *monitor_name_copy = ast_strdup(monitor->interface->name);
 
 	if (!generic_list) {
+		return NULL;
+	}
+	
+	if (!monitor_name_copy) {
+		cc_unref(generic_list, "Failed to make monitor name copy in create_new_generic_list");
 		return NULL;
 	}
 
@@ -1135,7 +1141,7 @@
 	}
 
 	if (!(generic_list->sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, generic_monitor_devstate_cb,
-				"Requesting CC", monitor, AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, 
+				"Requesting CC", monitor_name_copy, AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, 
 				monitor->interface->name, AST_EVENT_IE_END))) {
 		cc_unref(generic_list, "Failed to subscribe to device state");
 		return NULL;
@@ -1158,29 +1164,48 @@
 }
 
 struct generic_tp_cb_data {
-	struct ast_cc_monitor *monitor;
+	char *monitor_name;
 	enum ast_device_state new_state;
 };
 
 static int generic_monitor_devstate_tp_cb(void *data)
 {
 	struct generic_tp_cb_data *gtcd = data;
-	struct ast_cc_monitor *monitor = gtcd->monitor;
+	char *monitor_name = gtcd->monitor_name;
 	enum ast_device_state new_state = gtcd->new_state;
-	struct generic_monitor_pvt *gen_mon_pvt = monitor->private_data;
-
-	if (gen_mon_pvt->current_state == new_state) {
+	struct generic_monitor_instance_list *generic_list;
+	struct generic_monitor_instance *generic_instance;
+
+	if (!(generic_list = find_generic_monitor_instance_list(monitor_name))) {
+		/* The most likely cause for this is that we destroyed the monitor in the
+		 * time between subscribing to its device state and the time this executes.
+		 * Not really a big deal.
+		 */
+		ast_free(monitor_name);
 		ast_free(gtcd);
-		cc_unref(monitor, "Kill reference from generic_monitor_devstate_cb");
 		return 0;
 	}
 
-	gen_mon_pvt->current_state = new_state;
+	if (generic_list->current_state == new_state) {
+		/* The device state hasn't actually changed, so we don't really care */
+		ast_free(monitor_name);
+		ast_free(gtcd);
+		cc_unref(generic_list, "Kill reference of generic list in devstate taskprocessor callback");
+		return 0;
+	}
+
+	generic_list->current_state = new_state;
 
 	if (new_state == AST_DEVICE_NOT_INUSE || new_state == AST_DEVICE_UNKNOWN) {
-		ast_cc_monitor_callee_available(monitor);
-	}
-	cc_unref(monitor, "Kill reference from generic_monitor_devstate_cb");
+		AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
+			if (!generic_instance->monitor->is_suspended) {
+				ast_cc_monitor_callee_available2(generic_instance->monitor);
+				break;
+			}
+		}	
+	}
+	cc_unref(generic_list, "Kill reference of generic list in devstate taskprocessor callback");
+	ast_free(monitor_name);
 	ast_free(gtcd);
 	return 0;
 }
@@ -1192,18 +1217,19 @@
 	 * so that all monitor operations can be serialized. Locks?! We don't need
 	 * no steenkin' locks!
 	 */
-	struct ast_cc_monitor *monitor = userdata;
+	char *monitor_name = userdata;
 	struct generic_tp_cb_data *gtcd = ast_calloc(1, sizeof(*gtcd));
 
 	if (!gtcd) {
+		ast_free(monitor_name);
 		return;
 	}
 
-	gtcd->monitor = cc_ref(monitor, "Keep reference until taskprocessor callback executes");
+	gtcd->monitor_name = monitor_name;
 	gtcd->new_state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
 
 	if (ast_taskprocessor_push(cc_core_taskprocessor, generic_monitor_devstate_tp_cb, gtcd)) {
-		cc_unref(gtcd->monitor, "Kill reference from generic_monitor_devstate_cb");
+		ast_free(gtcd->monitor_name);
 		ast_free(gtcd);
 	}
 }
@@ -3166,6 +3192,11 @@
 	return cc_request_state_change(CC_ACTIVE, core_id, debug);
 }
 
+int ast_cc_monitor_callee_available2(struct cc_monitor *monitor)
+{
+	return cc_request_state_change(CC_CALLEE_READY, monitor->core_id, "Device being monitored has become available");
+}
+
 int ast_cc_monitor_callee_available(struct ast_cc_monitor *monitor)
 {
 	int res;




More information about the svn-commits mailing list