[asterisk-commits] mmichelson: branch group/CCSS r216637 - in /team/group/CCSS: include/asterisk...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 4 15:54:36 CDT 2009


Author: mmichelson
Date: Fri Sep  4 15:54:35 2009
New Revision: 216637

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=216637
Log:
* Add comment explaining logic of generic device monitor operation
* Remove "state" parameter when passing status up. It will always be
  the same if we're passing it up...
* Change pass_state_up to pass_availability_up since that's what
  we're doing for real.
* Add API so that device monitors in channel drivers can notify the
  core of availability.
* Got it all to compile :)


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

Modified: team/group/CCSS/include/asterisk/ccss.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/include/asterisk/ccss.h?view=diff&rev=216637&r1=216636&r2=216637
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Fri Sep  4 15:54:35 2009
@@ -481,7 +481,9 @@
 	/* Which instance of the core state machine does this link correspond
 	 * to
 	 */
-	const unsigned int core_id;
+	int core_id;
+	/* Which service is being requested? */
+	enum ast_cc_service_type service;
 	/*!
 	 * Why are there two AST_LIST_ENTRY fields in this
 	 * struct? The reason is that each link is in a list
@@ -537,7 +539,7 @@
 	/* Allocate callback */
 	int (*init)(struct ast_cc_monitor *monitor, const int core_id);
 	/* Request CCSS callback */
-	int (*request_cc)(struct ast_cc_monitor *monitor, const int core_id);
+	int (*request_cc)(struct ast_cc_monitor *monitor, const int core_id, enum ast_cc_service_type service);
 	/* Suspend monitoring callback */
 	int (*suspend)(struct ast_cc_monitor *monitor, const int core_id);
 	/* Status request callback */
@@ -706,6 +708,19 @@
 int ast_cc_request_state_change(enum ast_cc_state state, const int core_id, const char *debug);
 
 /*!
+ * \sinxe 1.6.4
+ * \brief Alert the core that a device being monitored has become available.
+ *
+ * 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
+ * \retval 0 Request successfully queued
+ * \retval -1 Request could not be queued
+ */
+int ast_cc_monitor_announce_availability(struct ast_cc_monitor *monitor);
+
+/*!
  * \since 1.6.4
  * \brief Register a set of monitor callbacks with the core
  *

Modified: team/group/CCSS/main/ccss.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=216637&r1=216636&r2=216637
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Fri Sep  4 15:54:35 2009
@@ -880,6 +880,8 @@
 	new_link->parent = parent;
 	ao2_ref(new_link->child, +1);
 	ao2_ref(new_link->parent, +1);
+	new_link->core_id = core_id;
+	new_link->service = interface->service_offered;
 	AST_LIST_INSERT_TAIL(&parent->child_links, new_link, next_child);
 	AST_LIST_INSERT_TAIL(&new_monitor->parent_links, new_link, next_parent);
 	ast_log(LOG_NOTICE, "Created link with parent %s and child %s\n", new_link->parent->name, new_link->child->name);
@@ -958,11 +960,6 @@
 	char debug[1];
 };
 
-struct cc_devstate_args {
-	enum ast_device_state state;
-	struct ast_cc_monitor *monitor;
-};
-
 static void destroy_link(struct ast_cc_monitor_link *link)
 {
 	ao2_ref(link->child, -1);
@@ -1017,10 +1014,11 @@
  * upstream. There is no need to pass along the fact that a phone has
  * become busy.
  */
-static int pass_state_up(struct ast_cc_monitor *monitor, enum ast_device_state state, int core_id)
+static int pass_availability_up(struct ast_cc_monitor *monitor, int core_id)
 {
 	struct cc_core_instance *core_instance;
 	struct cc_core_instance finder = { .core_id = core_id };
+	struct ast_cc_monitor_link *link;
 	ast_assert(monitor->monitor_class == AST_CC_EXTENSION_MONITOR ||
 			monitor->monitor_class == AST_CC_ROOT_MONITOR);
 
@@ -1037,7 +1035,7 @@
 	 * Extension monitors may have multiple children with the same core_id,
 	 * but they SHOULD have only a single parent with that core_id.
 	 */
-	AST_LIST_TRAVERSE(monitor->parent_links, link, next_parent) {
+	AST_LIST_TRAVERSE(&monitor->parent_links, link, next_parent) {
 		if (link->core_id == core_id) {
 			break;
 		}
@@ -1049,7 +1047,7 @@
 		return -1;
 	}
 
-	pass_state_up(link->parent, state, core_id);
+	pass_availability_up(link->parent, core_id);
 
 	return 0;
 }
@@ -1081,15 +1079,11 @@
 	   link it has chosen. This will change if the link
 	   gets destroyed or becomes suspended.
 	 */
-	struct cc_devstate_args *args = datap;
-	enum ast_device_state state = args->state;
-	struct ast_cc_monitor *monitor = args->monitor;
+	struct ast_cc_monitor *monitor = datap;
 	struct ast_cc_monitor_link *link = monitor->saved_link;
 
-	monitor->state = state;
-
 	if (link && !link->is_suspended) {
-		return pass_state_up(link->parent, state, link->core_id);
+		return pass_availability_up(link->parent, link->core_id);
 	}
 
 	/* Dang, we need to find the lowest weighted unsuspended
@@ -1116,7 +1110,7 @@
 	}
 
 	/* We found a link to report on. Yay */
-	return pass_state_up(link->parent, state, link->core_id);
+	return pass_availability_up(link->parent, link->core_id);
 }
 
 static int cc_do_state_change(void *datap)
@@ -1299,7 +1293,7 @@
 }
 
 static int cc_extension_monitor_init(struct ast_cc_monitor *monitor, const int core_id);
-static int cc_extension_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id);
+static int cc_extension_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id, enum ast_cc_service_type service);
 static int cc_extension_monitor_suspend(struct ast_cc_monitor *monitor, const int core_id);
 static enum ast_device_state cc_extension_monitor_status_request(struct ast_cc_monitor *monitor, const int core_id);
 static int cc_extension_monitor_unsuspend(struct ast_cc_monitor *monitor, const int core_id);
@@ -1324,7 +1318,7 @@
 	return 0;
 }
 
-static int cc_extension_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id)
+static int cc_extension_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id, enum ast_cc_service_type service)
 {
 	struct ast_cc_monitor_link *link_iter;
 	AST_LIST_TRAVERSE(&monitor->child_links, link_iter, next_child) {
@@ -1333,7 +1327,7 @@
 		}
 		ast_assert(link_iter->child != NULL);
 		ast_assert(link_iter->child->callbacks != NULL);
-		link_iter->child->callbacks->request_cc(link_iter->child, core_id);
+		link_iter->child->callbacks->request_cc(link_iter->child, core_id, service);
 		/* XXX Should check the return value and potentially prune
 		 * out monitors that return unsuccessfully since they were
 		 * not able to properly request CC
@@ -1386,7 +1380,7 @@
 }
 
 static int cc_generic_monitor_init(struct ast_cc_monitor *monitor, const int core_id);
-static int cc_generic_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id);
+static int cc_generic_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id, enum ast_cc_service_type service);
 static int cc_generic_monitor_suspend(struct ast_cc_monitor *monitor, const int core_id);
 static enum ast_device_state cc_generic_monitor_status_request(struct ast_cc_monitor *monitor, const int core_id);
 static int cc_generic_monitor_unsuspend(struct ast_cc_monitor *monitor, const int core_id);
@@ -1429,19 +1423,14 @@
 	 * so that all monitor operations can be serialized. Locks?! We don't need
 	 * no steenkin' locks!
 	 */
-	struct cc_devstate_args *args = ast_calloc(1, sizeof(*args));
-
-	if (!args) {
-		return;
-	}
-
-	args->state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
-	args->monitor = userdata;
-	ast_taskprocessor_push(cc_core_taskprocessor, cc_devstate_change, args);
+	struct ast_cc_monitor *monitor = userdata;
+
+	ast_cc_monitor_announce_availability(monitor);
+
 	return;
 }
 
-static int cc_generic_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id)
+static int cc_generic_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id, enum ast_cc_service_type service)
 {
 	struct generic_monitor_pvt *gen_mon_pvt = monitor->private_data;
 
@@ -1449,9 +1438,25 @@
 		return 0;
 	}
 	
+	/* We can monitor a device for one of two services, CCBS or CCNR.
+	 *
+	 * In the case of CCBS, When the state of the device changes to "not in use" then
+	 * this means that it is ready to be called back. Also, with CCBS, it is important that
+	 * we check the current device state in case it changed to "not in use" between when
+	 * the initial call failed and now.
+	 *
+	 * In the case of CCNR, the state of the device will likely already be "not in use." However,
+	 * the next time that the device state *changes* to "not in use" that will be indication that
+	 * the phone has been used and that we may try ringing the phone again.
+	 */
+	if (service == AST_CC_CCBS && (monitor->callbacks->status_request(monitor, core_id) == AST_DEVICE_NOT_INUSE)) {
+		return ast_cc_monitor_announce_availability(monitor);
+	}
+
 	if (!(gen_mon_pvt->sub = ast_event_subscribe(
 			AST_EVENT_DEVICE_STATE, generic_monitor_devstate_cb, NULL, monitor, 
-			AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, monitor->name))) {
+			AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, monitor->name,
+			AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, AST_DEVICE_NOT_INUSE))) {
 		return -1;
 	}
 	return 0;
@@ -1505,6 +1510,10 @@
 	AST_RWLIST_INSERT_TAIL(&cc_monitor_backends, backend, next);
 	AST_RWLIST_UNLOCK(&cc_monitor_backends);
 	return 0;
+}
+
+int ast_cc_monitor_announce_availability(struct ast_cc_monitor *monitor) {
+	return ast_taskprocessor_push(cc_core_taskprocessor, cc_devstate_change, monitor);
 }
 
 int ast_cc_init(void)




More information about the asterisk-commits mailing list