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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 21 16:13:11 CDT 2009


Author: mmichelson
Date: Mon Sep 21 16:13:08 2009
New Revision: 219792

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=219792
Log:
Now monitors use an ast_cc_interface, too.


I have undoubtedly introduced some new bugs with
the latest commits :)


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

Modified: team/group/CCSS/include/asterisk/ccss.h
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/include/asterisk/ccss.h?view=diff&rev=219792&r1=219791&r2=219792
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Mon Sep 21 16:13:08 2009
@@ -515,9 +515,6 @@
  * type can be retrieved through the monitor_data union.
  */
 struct ast_cc_monitor {
-	/*! One of CCBS or CCNR. */
-	enum ast_cc_monitor_class monitor_class;
-	const char *monitor_type;
 	/*! The list of links to upstream extension monitors */
 	AST_LIST_HEAD(,ast_cc_monitor_link) parent_links;
 	AST_LIST_HEAD(,ast_cc_monitor_link) child_links;
@@ -536,13 +533,7 @@
 	 * become unsuspended.
 	 */
 	struct ast_cc_monitor_link *saved_link;
-	/*!
-	 * CC configuration parameters to use for this monitored
-	 * device.
-	 */
-	struct ast_cc_config_params *config_params;
-	/*! The name of the device/extension being monitored */
-	char name[1];
+	struct ast_cc_interface *interface;
 };
 
 struct ast_cc_monitor_callbacks {

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=219792&r1=219791&r2=219792
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Mon Sep 21 16:13:08 2009
@@ -139,7 +139,7 @@
 static int print_debug(void *obj, void *args, int flags)
 {
 	struct ast_cc_monitor *monitor = obj;
-	ast_log(LOG_NOTICE, "%s is in the container\n", monitor->name);
+	ast_log(LOG_NOTICE, "%s is in the container\n", monitor->interface->name);
 	return 0;
 }
 
@@ -475,8 +475,8 @@
 	struct ast_cc_monitor *monitor1 = obj;
 	struct ast_cc_monitor *monitor2 = arg;
 
-	if (!strcmp(monitor1->name, monitor2->name) &&
-			!strcmp(monitor1->monitor_type, monitor2->monitor_type)) {
+	if (!strcmp(monitor1->interface->name, monitor2->interface->name) &&
+			!strcmp(monitor1->interface->monitor_type, monitor2->interface->monitor_type)) {
 		return CMP_MATCH | CMP_STOP;
 	}
 	return 0;
@@ -485,7 +485,7 @@
 static int cc_monitor_hash_fn(const void *obj, int flags)
 {
 	const struct ast_cc_monitor *monitor = obj;
-	return ast_str_hash_add(monitor->monitor_type, ast_str_hash(monitor->name));
+	return ast_str_hash_add(monitor->interface->monitor_type, ast_str_hash(monitor->interface->name));
 }
 
 struct cc_core_instance {
@@ -866,35 +866,24 @@
 	return callbacks;
 }
 
-static struct ast_cc_monitor *cc_monitor_instance_init(enum ast_cc_monitor_class monitor_class, 
-		const char * const callback_type, const char * const monitor_name, const int core_id,
-		const struct ast_cc_config_params *config_params)
+static struct ast_cc_monitor *cc_monitor_instance_init(struct ast_cc_interface *cc_interface,
+		const int core_id)
 {
 	struct ast_cc_monitor *monitor;
-	const struct ast_cc_monitor_callbacks *callbacks = find_monitor_callbacks(callback_type);
+	const struct ast_cc_monitor_callbacks *callbacks = find_monitor_callbacks(cc_interface->monitor_type);
 
 	ast_assert(callbacks != NULL);
 
-	if (!(monitor = ao2_t_alloc(sizeof(*monitor) + strlen(monitor_name), callbacks->destructor, "Allocating new monitor structure"))) {
+	if (!(monitor = ao2_t_alloc(sizeof(*monitor), callbacks->destructor, "Allocating new monitor structure"))) {
 		return NULL;
 	}
 
-	if (config_params) {
-		if (!(monitor->config_params = ast_cc_config_params_init())) {
-			ao2_ref(monitor, -1);
-			return NULL;
-		}
-
-		ast_cc_copy_config_params(monitor->config_params, config_params);
-	}
-	monitor->monitor_class = monitor_class;
-	strcpy(monitor->name, monitor_name);
+	monitor->interface = cc_interface;
 	monitor->callbacks = callbacks;
 	monitor->callbacks->init(monitor, core_id);
-	monitor->monitor_type = callback_type;
 	AST_LIST_HEAD_INIT(&monitor->child_links);
 	AST_LIST_HEAD_INIT(&monitor->parent_links);
-	ast_log(LOG_NOTICE, "Created new monitor named %s of type %s\n", monitor->name, monitor->monitor_type);
+	ast_log(LOG_NOTICE, "Created new monitor named %s of type %s\n", monitor->interface->name, monitor->interface->monitor_type);
 	ao2_t_link(cc_monitors, monitor, "Link monitor into container");
 	ao2_callback(cc_monitors, OBJ_NODATA, print_debug, NULL);
 	return monitor;
@@ -905,15 +894,16 @@
 	struct ast_cc_monitor *new_monitor;
 	struct ast_cc_monitor_link *new_link;
 	struct ast_cc_interface *interface = tree_item->interface;
-	struct ast_cc_monitor *finder = alloca(sizeof(*finder) + strlen(interface->name));
-
-	strcpy(finder->name, interface->name);
-	finder->monitor_type = interface->monitor_type;
+	struct ast_cc_interface *finder_interface = alloca(sizeof(*finder_interface) + strlen(interface->name));
+	struct ast_cc_monitor *finder = alloca(sizeof(*finder));
+
+	strcpy(finder_interface->name, interface->name);
+	finder_interface->monitor_type = interface->monitor_type;
+	finder->interface = finder_interface;
 
 	if ((new_monitor = ao2_t_find(cc_monitors, finder, OBJ_POINTER, "Trying to find a specific monitor"))) {
-		ast_log(LOG_NOTICE, "Found monitor %s in tree. Re-using\n", new_monitor->name);
-	} else if (!(new_monitor = cc_monitor_instance_init(interface->monitor_class, 
-					interface->monitor_type, interface->name, core_id, interface->config_params))) {
+		ast_log(LOG_NOTICE, "Found monitor %s in tree. Re-using\n", new_monitor->interface->name);
+	} else if (!(new_monitor = cc_monitor_instance_init(interface, core_id))) {
 		return NULL;
 	}
 
@@ -933,7 +923,7 @@
 	new_link->service = tree_item->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 core_id %d, parent %s and child %s\n", new_link->core_id, new_link->parent->name, new_link->child->name);
+	ast_log(LOG_NOTICE, "Created link with core_id %d, parent %s and child %s\n", new_link->core_id, new_link->parent->interface->name, new_link->child->interface->name);
 	return new_monitor;
 }
 
@@ -990,7 +980,7 @@
 static void destroy_link(struct ast_cc_monitor_link *link)
 {
 	ast_log(LOG_NOTICE, "Destroying link with parent %s and child %s\n",
-			link->parent->name, link->child->name);
+			link->parent->interface->name, link->child->interface->name);
 	ao2_t_ref(link->child, -1, "Unref link's child");
 	ao2_t_ref(link->parent, -1, "Unref link's parent");
 	ast_free(link);
@@ -1000,7 +990,7 @@
 static void prune_links(struct ast_cc_monitor *monitor, const int core_id, struct ast_cc_monitor_link *link_parent)
 {
 	struct ast_cc_monitor_link *link_iter;
-	ast_log(LOG_NOTICE, "Prune links called for monitor %s\n", monitor->name);
+	ast_log(LOG_NOTICE, "Prune links called for monitor %s\n", monitor->interface->name);
 	ao2_callback(cc_monitors, OBJ_NODATA, print_debug, NULL);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&monitor->child_links, link_iter, next_child) {
 		if (link_iter->core_id == core_id) {
@@ -1010,32 +1000,32 @@
 		}
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
-	ast_log(LOG_NOTICE, "Finished traversing children of monitor %s\n", monitor->name);
+	ast_log(LOG_NOTICE, "Finished traversing children of monitor %s\n", monitor->interface->name);
 
 	if (link_parent) {
-		ast_log(LOG_NOTICE, "Removing parent link from monitor %s\n", monitor->name);
+		ast_log(LOG_NOTICE, "Removing parent link from monitor %s\n", monitor->interface->name);
 		AST_LIST_REMOVE(&monitor->parent_links, link_parent, next_parent);
 	}
-	if (monitor->monitor_class == AST_CC_ROOT_MONITOR) {
+	if (monitor->interface->monitor_class == AST_CC_ROOT_MONITOR) {
 		/* Never ever under any circumstances unlink
 		 * the root monitor
 		 */
-		ast_log(LOG_NOTICE, "Not unlinking monitor %s because it is the root\n", monitor->name);
+		ast_log(LOG_NOTICE, "Not unlinking monitor %s because it is the root\n", monitor->interface->name);
 		return;
 	}
-	ast_log(LOG_NOTICE, "Just a checkpoint. In prune_links for monitor %s\n", monitor->name);
+	ast_log(LOG_NOTICE, "Just a checkpoint. In prune_links for monitor %s\n", monitor->interface->name);
 	if (AST_LIST_EMPTY(&monitor->parent_links) &&
 			AST_LIST_EMPTY(&monitor->child_links)) {
 		/* This should cause the monitor's destructor
 		 * callback to be called
 		 */
-		ast_log(LOG_NOTICE, "Unlinking monitor %s\n", monitor->name);
+		ast_log(LOG_NOTICE, "Unlinking monitor %s\n", monitor->interface->name);
 		ao2_t_unlink(cc_monitors, monitor, "Unlink monitor since nothing refers to it anymore");
 	} else {
 		if (!AST_LIST_EMPTY(&monitor->parent_links)) {
-			ast_log(LOG_NOTICE, "Not unlinking %s because it has parent links, still\n", monitor->name);
+			ast_log(LOG_NOTICE, "Not unlinking %s because it has parent links, still\n", monitor->interface->name);
 		} else {
-			ast_log(LOG_NOTICE, "Not unlinking %s because it has child links, stil\n", monitor->name);
+			ast_log(LOG_NOTICE, "Not unlinking %s because it has child links, stil\n", monitor->interface->name);
 		}
 	}
 }
@@ -1067,14 +1057,14 @@
 	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);
+	ast_assert(monitor->interface->monitor_class == AST_CC_EXTENSION_MONITOR ||
+			monitor->interface->monitor_class == AST_CC_ROOT_MONITOR);
 
 	if (!(core_instance = ao2_t_find(cc_core_instances, &finder, OBJ_POINTER, "Find core instance for passing up availability"))) {
 		return -1;
 	}
 
-	if (monitor->monitor_class == AST_CC_ROOT_MONITOR) {
+	if (monitor->interface->monitor_class == AST_CC_ROOT_MONITOR) {
 		ao2_t_ref(core_instance, -1, "Unref core_instance from earlier ao2_find");
 		ast_cc_request_state_change(CC_CALLEE_READY, core_id, "Device being monitored has become available");
 		return 0;
@@ -1093,7 +1083,7 @@
 
 	if (!link) {
 		ast_log(LOG_WARNING, "Monitor %s has no parent link with core_id %d but it had a child. That should be impossible\n",
-				monitor->name, core_id);
+				monitor->interface->name, core_id);
 		return -1;
 	}
 
@@ -1468,7 +1458,7 @@
 static void cc_extension_monitor_destructor(void *monitor)
 {
 	struct ast_cc_monitor *mon = monitor;
-	ast_log(LOG_NOTICE, "Calling destructor for monitor %s\n", mon->name);
+	ast_log(LOG_NOTICE, "Calling destructor for monitor %s\n", mon->interface->name);
 	/* STUB */
 	return;
 }
@@ -1507,7 +1497,7 @@
 	if (!gen_mon_pvt) {
 		return -1;
 	}
-	ast_log(LOG_NOTICE, "Allocated a generic monitor pvt for device %s\n", monitor->name);
+	ast_log(LOG_NOTICE, "Allocated a generic monitor pvt for device %s\n", monitor->interface->name);
 	monitor->private_data = gen_mon_pvt;
 	return 0;
 }
@@ -1557,7 +1547,7 @@
 
 	if (!(gen_mon_pvt->sub = ast_event_subscribe(
 			AST_EVENT_DEVICE_STATE, generic_monitor_devstate_cb, "Requesting CC", monitor, 
-			AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, monitor->name,
+			AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, monitor->interface->name,
 			AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, AST_DEVICE_NOT_INUSE,
 			AST_EVENT_IE_END))) {
 		return -1;
@@ -1584,7 +1574,7 @@
 
 static enum ast_device_state cc_generic_monitor_status_request(struct ast_cc_monitor *monitor, const int core_id)
 {
-	return ast_device_state(monitor->name);
+	return ast_device_state(monitor->interface->name);
 }
 
 static int cc_generic_monitor_unsuspend(struct ast_cc_monitor *monitor, const int core_id)
@@ -1728,9 +1718,24 @@
 	return 0;
 }
 
+static struct ast_cc_interface *root_interface_init(void)
+{
+	struct ast_cc_interface *cc_interface = ast_calloc(1, sizeof(*cc_interface) + strlen("root"));
+
+	strcpy(cc_interface->name, "root");
+	cc_interface->monitor_class = AST_CC_ROOT_MONITOR;
+	cc_interface->monitor_type = "extension";
+	return cc_interface;
+}
+
 int ast_cc_init(void)
 {
 	int res;
+	struct ast_cc_interface *root_interface = root_interface_init();
+
+	if (!root_interface) {
+		return -1;
+	}
 
 	ast_log(LOG_NOTICE, "Successfully created pending offers container\n");
 	if (!(cc_core_instances = ao2_t_container_alloc(CC_CORE_INSTANCES_BUCKETS,
@@ -1762,7 +1767,7 @@
 	 * extension monitor callbacks since the gist of those will be to traverse
 	 * their child links and call each of their children's callbacks
 	 */
-	if (!(root_monitor = cc_monitor_instance_init(AST_CC_ROOT_MONITOR, "extension", "root", -1, NULL))) {
+	if (!(root_monitor = cc_monitor_instance_init(root_interface, -1))) {
 		return -1;
 	}
 	ast_log(LOG_NOTICE, "Successfully created the root CC monitor\n");




More information about the asterisk-commits mailing list