[svn-commits] mmichelson: branch group/CCSS r217634 - /team/group/CCSS/main/ccss.c
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Sep 10 10:52:24 CDT 2009
Author: mmichelson
Date: Thu Sep 10 10:52:23 2009
New Revision: 217634
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=217634
Log:
Rewrite the interface tree to monitor graph function.
Look at this. Really, just look at it for a second.
It's beautiful. Why the heck didn't I write it this way
the first time?
Modified:
team/group/CCSS/main/ccss.c
Modified: team/group/CCSS/main/ccss.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=217634&r1=217633&r2=217634
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Thu Sep 10 10:52:23 2009
@@ -948,47 +948,37 @@
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);
- ao2_ref(new_monitor, -1);
return new_monitor;
}
+static void recursive_builder(struct ast_cc_interface *current_place, struct ast_cc_monitor *parent, const int core_id)
+{
+ struct ast_cc_interface *cc_interface = current_place;
+ struct ast_cc_monitor *monitor = find_or_create_monitor(parent, current_place, core_id);
+
+ if (!monitor) {
+ /* Um, that's messed up */
+ return;
+ }
+
+ /* Device monitors won't have children, so don't bother looking.
+ */
+ if (current_place->monitor_class == AST_CC_DEVICE_MONITOR) {
+ ao2_ref(monitor, -1);
+ return;
+ }
+
+ while ((cc_interface = AST_LIST_NEXT(cc_interface, next))) {
+ if (cc_interface->parent_id == current_place->id) {
+ recursive_builder(cc_interface, monitor, core_id);
+ }
+ }
+ ao2_ref(monitor, -1);
+}
+
static void interface_tree_to_monitor(struct ast_cc_interface_tree *called_tree, struct cc_core_instance *core_instance)
{
- struct ast_cc_interface *parent_interface_iterator;
-
- /* The way that the interface tree is set up, and the way this loop works, the
- * type of interface that we pull off the front of the list should ALWAYS be
- * an extension interface
- */
- while ((parent_interface_iterator = AST_LIST_REMOVE_HEAD(called_tree, next))) {
- struct ast_cc_monitor *parent = root_monitor;
- struct ast_cc_monitor *target = NULL;
- struct ast_cc_interface *child_interface_iterator;
-
- ast_assert(strcmp(parent_interface_iterator->monitor_type, "extension") == 0);
- target = find_or_create_monitor(parent, parent_interface_iterator, core_instance->core_id);
- /* XXX Do something here in case target is NULL */
- parent = target;
- AST_LIST_TRAVERSE_SAFE_BEGIN(called_tree, child_interface_iterator, next) {
- struct ast_cc_monitor *child;
- if (child_interface_iterator->parent_id != parent_interface_iterator->id) {
- continue;
- }
- child = find_or_create_monitor(parent, child_interface_iterator, core_instance->core_id);
- if (child_interface_iterator->monitor_class != AST_CC_EXTENSION_MONITOR) {
- /* If we aren't dealing with an extension interface, then we
- * can remove it from the list since we know it will have no
- * children and we know that a corresponding monitor exists in
- * the graph.
- */
- AST_LIST_REMOVE_CURRENT(next);
- }
- ao2_ref(child, -1);
- }
- AST_LIST_TRAVERSE_SAFE_END;
- ao2_ref(parent, -1);
- }
-
+ recursive_builder(AST_LIST_FIRST(called_tree), root_monitor, core_instance->core_id);
}
static int cc_monitor_tree_init(const int core_id)
More information about the svn-commits
mailing list