[asterisk-commits] mmichelson: branch group/CCSS_Monitor_Restructure r242975 - in /team/group/CC...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 25 15:58:38 CST 2010


Author: mmichelson
Date: Mon Jan 25 15:58:34 2010
New Revision: 242975

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=242975
Log:
A few changes to aid generic monitoring.

* Got rid of a circular reference in a generic_monitor_instance.

* Changed ast_cc_monitor_callee_available2 to ast_cc_monitor_callee_available
and changed its parameter from a monitor to a core_id. This helps the generic
monitor and other implementations have no need for a potential circular reference.

* Fixed some faulty logic regarding suspension and unsuspension of monitors. The
is_suspended flag is not actually used by the core, and so it makes more sense
for that to exist on the generic_monitor_instance structure instead. I also now
make sure to set it as appropriate and actually clear it when the monitor becomes
unsuspended.


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=242975&r1=242974&r2=242975
==============================================================================
--- team/group/CCSS_Monitor_Restructure/include/asterisk/ccss.h (original)
+++ team/group/CCSS_Monitor_Restructure/include/asterisk/ccss.h Mon Jan 25 15:58:34 2010
@@ -458,10 +458,6 @@
 	/* The instance of the CC core to which this monitor belongs
 	 */
 	int core_id;
-	/* An indicator that tells whether monitoring of the device
-	 * has been suspended.
-	 */
-	int is_suspended;
 	/* What service was offered by the endpoint. Note that
 	 * this field is completely irrelevant for cc_monitors
 	 * representing dialplan extensions.
@@ -1269,11 +1265,11 @@
  * The code in the core will take care of making sure that the information gets passed
  * up the ladder correctly.
  *
- * \param monitor The device monitor for the device
+ * \param core_id The core ID of the corresponding CC transaction
  * \retval 0 Request successfully queued
  * \retval -1 Request could not be queued
  */
-int ast_cc_monitor_callee_available2(struct ast_cc_monitor *monitor);
+int ast_cc_monitor_callee_available(const int core_id);
 
 /* 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=242975&r1=242974&r2=242975
==============================================================================
--- team/group/CCSS_Monitor_Restructure/main/ccss.c (original)
+++ team/group/CCSS_Monitor_Restructure/main/ccss.c Mon Jan 25 15:58:34 2010
@@ -839,7 +839,8 @@
 struct ao2_container *generic_monitors;
 
 struct generic_monitor_instance {
-	struct ast_cc_monitor *monitor;
+	int core_id;
+	int is_suspended;
 	AST_LIST_ENTRY(generic_monitor_instance) next;
 };
 
@@ -895,11 +896,6 @@
 	struct generic_monitor_instance *generic_instance;
 
 	while ((generic_instance = AST_LIST_REMOVE_HEAD(&generic_list->list, next))) {
-		/* Really, this shouldn't be necessary, since we'll only be calling
-		 * the destructor on the list when it is empty. Of course, it never hurts
-		 * to be safe.
-		 */
-		cc_unref(generic_instance->monitor, "Generic monitor instance list destructor");
 		ast_free(generic_instance);
 	}
 	ast_free((char *)generic_list->device_name);
@@ -972,8 +968,8 @@
 
 	if (new_state == AST_DEVICE_NOT_INUSE || new_state == AST_DEVICE_UNKNOWN) {
 		AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
-			if (!generic_instance->monitor->is_suspended) {
-				ast_cc_monitor_callee_available2(generic_instance->monitor);
+			if (!generic_instance->is_suspended) {
+				ast_cc_monitor_callee_available(generic_instance->core_id);
 				break;
 			}
 		}	
@@ -1052,6 +1048,7 @@
 		cc_unref(generic_list, "Generic monitor instance failed to allocate");
 		return -1;
 	}
+	generic_instance->core_id = monitor->core_id;
 	when = service == AST_CC_CCBS ? ast_get_ccbs_available_timer(monitor->interface->config_params) :
 		ast_get_ccnr_available_timer(monitor->interface->config_params);
 
@@ -1067,6 +1064,18 @@
 	struct generic_monitor_instance *generic_instance;
 	enum ast_device_state state = ast_device_state(monitor->interface->name);
 
+	if (!(generic_list = find_generic_monitor_instance_list(monitor->interface->name))) {
+		return -1;
+	}
+
+	/* First we need to mark this particular monitor as being suspended. */
+	AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
+		if (generic_instance->core_id == monitor->core_id) {
+			generic_instance->is_suspended = 1;
+			break;
+		}
+	}
+
 	/* If the device being suspended is currently in use, then we don't need to
 	 * take any further actions
 	 */
@@ -1078,13 +1087,10 @@
 	 * device's availability using a different monitor which is monitoring the
 	 * same device
 	 */
-	if (!(generic_list = find_generic_monitor_instance_list(monitor->interface->name))) {
-		return -1;
-	}
 
 	AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
-		if (!generic_instance->monitor->is_suspended) {
-			ast_cc_monitor_callee_available2(generic_instance->monitor);
+		if (!generic_instance->is_suspended) {
+			ast_cc_monitor_callee_available(generic_instance->core_id);
 			break;
 		}
 	}
@@ -1103,12 +1109,26 @@
 
 static int cc_generic_monitor_unsuspend(struct ast_cc_monitor *monitor)
 {
-	/* When a generic monitor becomes unsuspended, we should do a status request
-	 * to see if the device is available. That way, if it is, we can trigger an
-	 * immediate state change
-	 */
-	if (ast_device_state(monitor->interface->name) == AST_DEVICE_NOT_INUSE) {
-		ast_cc_monitor_callee_available2(monitor);
+	struct generic_monitor_instance *generic_instance;
+	struct generic_monitor_instance_list *generic_list = find_generic_monitor_instance_list(monitor->interface->name);
+	enum ast_device_state state = ast_device_state(monitor->interface->name);
+
+	if (!generic_list) {
+		return -1;
+	}
+	/* If the device is currently available, we can immediately announce
+	 * its availability
+	 */
+	if (state == AST_DEVICE_NOT_INUSE || state == AST_DEVICE_UNKNOWN) {
+		ast_cc_monitor_callee_available(monitor->core_id);
+	}
+
+	/* In addition, we need to mark this generic_monitor_instance as not being suspended anymore */
+	AST_LIST_TRAVERSE(&generic_list->list, generic_instance, next) {
+		if (generic_instance->core_id == monitor->core_id) {
+			generic_instance->is_suspended = 0;
+			break;
+		}
 	}
 	return 0;
 }
@@ -1151,7 +1171,7 @@
 	}
 
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&generic_list->list, generic_instance, next) {
-		if (generic_instance->monitor->core_id == gen_mon_pvt->core_id) {
+		if (generic_instance->core_id == gen_mon_pvt->core_id) {
 			AST_LIST_REMOVE_CURRENT(next);
 			ast_free(generic_instance);
 			break;
@@ -2406,8 +2426,6 @@
 				AST_DLLIST_REMOVE_CURRENT(next);
 				cc_unref(monitor_iter, "suspend failed. Unref list's reference to monitor");
 				cc_unref(monitor_iter, "suspend failed. Unref local reference to monitor");
-			} else {
-				monitor_iter->is_suspended = 1;
 			}
 		} else if (!has_children(monitor_iter)) {
 			AST_DLLIST_REMOVE_CURRENT(next);
@@ -2881,9 +2899,9 @@
 	return cc_request_state_change(CC_ACTIVE, core_id, debug);
 }
 
-int ast_cc_monitor_callee_available2(struct ast_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(const int core_id)
+{
+	return cc_request_state_change(CC_CALLEE_READY, core_id, "Device being monitored has become available");
 }
 
 int ast_cc_agent_caller_busy(int core_id, const char * debug)




More information about the asterisk-commits mailing list