[asterisk-commits] mmichelson: branch group/CCSS r219890 - /team/group/CCSS/main/ccss.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 22 18:37:06 CDT 2009


Author: mmichelson
Date: Tue Sep 22 18:37:02 2009
New Revision: 219890

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=219890
Log:
Add device state caching logic.

This makes CCNR work much much better than it had been
previously. Now, we actually wait for the device state
of the monitored device to change to AST_DEVICE_NOT_INUSE
from something different. Tests show it works.

As a side note, I actually did this plus quite a bit more
all at once earlier and it totally was awful. I ended up
having to revert it all and start from scratch. I decided
to break it into smaller manageable tasks, and that is
working out MUCH better. Just a tip for you kids out there!


Modified:
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=219890&r1=219889&r2=219890
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Tue Sep 22 18:37:02 2009
@@ -1508,6 +1508,10 @@
 	 * Handle for event subscription to device state
 	 */
 	struct ast_event_sub *sub;
+	/*!
+	 * Cached device state for this monitor
+	 */
+	enum ast_device_state current_state;
 };
 
 static int cc_generic_monitor_init(struct ast_cc_monitor *monitor, const int core_id)
@@ -1530,8 +1534,20 @@
 	 * no steenkin' locks!
 	 */
 	struct ast_cc_monitor *monitor = userdata;
-
-	ast_cc_monitor_announce_availability(monitor);
+	struct generic_monitor_pvt *gen_mon_pvt = monitor->private_data;
+	enum ast_device_state new_state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
+
+	/* XXX Move this to core taskprocessor thread.
+	 */
+	if (gen_mon_pvt->current_state == new_state) {
+		return;
+	}
+
+	gen_mon_pvt->current_state = new_state;
+
+	if (new_state == AST_DEVICE_NOT_INUSE) {
+		ast_cc_monitor_announce_availability(monitor);
+	}
 
 	return;
 }
@@ -1583,6 +1599,8 @@
 	struct generic_monitor_pvt *gen_mon_pvt = monitor->private_data;
 	enum ast_cc_service_type service = parent_link->service;
 	int when;
+
+	gen_mon_pvt->current_state = monitor->callbacks->status_request(monitor, core_id);
 
 	/* We can monitor a device for one of two services, CCBS or CCNR.
 	 *
@@ -1600,7 +1618,7 @@
 	 * the device state changes to "not in use" before we are able to subscribe to the device state event, then
 	 * will that mean a missed opportunity?
 	 */
-	if (service == AST_CC_CCBS && (monitor->callbacks->status_request(monitor, core_id) == AST_DEVICE_NOT_INUSE)) {
+	if (service == AST_CC_CCBS && gen_mon_pvt->current_state == AST_DEVICE_NOT_INUSE) {
 		ast_cc_request_state_change(CC_ACTIVE, core_id, "Formality. Device is already available but we have to go through the motions\n");
 		return ast_cc_monitor_announce_availability(monitor);
 	}




More information about the asterisk-commits mailing list