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

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


Author: mmichelson
Date: Tue Sep  8 18:19:35 2009
New Revision: 217328

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=217328
Log:
Get rid of the cc_pending_core_offers container and its contents.

Yay for early code reduction, and yay for making things a bit less
complicated.


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=217328&r1=217327&r2=217328
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Tue Sep  8 18:19:35 2009
@@ -566,6 +566,17 @@
 	 * agent's operation.
 	 */
 	struct ast_cc_config_params *cc_params;
+	/*!
+	 * \The "tree" of interfaces dialed by the caller
+	 *
+	 * In actuality, this is a linked list. Each element
+	 * contains an integer which tells who its parent is
+	 * in the tree. The tree is arranged in such a way that
+	 * all children of an interface will always appear later
+	 * in the list. We take advantage of this fact later when
+	 * creating the monitor structure.
+	 */
+	struct ast_cc_interface_tree *interface_tree;
 	/*! Data specific to agent implementation */
 	void *private_data;
 	/*! The name of the interface which this agent

Modified: team/group/CCSS/main/ccss.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=217328&r1=217327&r2=217328
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Tue Sep  8 18:19:35 2009
@@ -442,11 +442,9 @@
 
 static int core_id_counter;
 
-struct ao2_container *pending_cc_offers;
 struct ao2_container *cc_core_instances;
 struct ao2_container *cc_monitors;
 
-static const int CC_PENDING_OFFER_BUCKETS = 53;
 static const int CC_CORE_INSTANCES_BUCKETS = 17;
 
 static int cc_monitor_cmp_fn(void *obj, void *arg, int flags)
@@ -471,55 +469,10 @@
 	return ast_str_hash(monitor->monitor_type) + ast_str_hash(monitor->name);
 }
 
-/*!
- * \brief Struct for CC offers, before a monitor is created
- *
- * When we are going to offer CC to a caller, a lightweight
- * container of structures is used. Once the caller requests
- * CC, and the core creates the appropriate monitor structures,
- * then the core_pending_cc_offer can be destroyed.
- *
- * These structs are stored in an ao2_container which is hashed
- * based on the core_id of each element for easy lookup.
- *
- * Since an ao2_container is being used, core_pending_cc_offers
- * are ao2 objects themselves.
- */
-struct core_pending_cc_offer {
-	/*! 
-	 * A unique identifier for this CC offer. Essentially, this
-	 * is an identifier for the instance of the core for which
-	 * this offer belongs. So even after the offer matures into
-	 * an official request for CC, the same core_id will be used
-	 * when making state machine transactions and the like.
-	 */
-	int core_id;
-	/*!
-	 * The reference-counted "tree" of interfaces dialed by the
-	 * caller. In reality this is a linked list which has fields
-	 * which help to "point" to where a node's parent is in the
-	 * list.
-	 */
-	struct ast_cc_interface_tree *called_tree;
-	/*!
-	 * Text identifying the caller. Tentatively, this is just the
-	 * device name of the calling channel. However, this may need
-	 * to be modified to include CID information or something to
-	 * more uniquely identify the caller. For instance, an
-	 * inbound call over a trunk may be from one of several users,
-	 * so using just the device name as an identifier is not specific
-	 * enough.
-	 */
-	char caller[1];
-};
-
 struct cc_core_instance {
 	/*!
-	 * Unique identifier for this instance of the CC core. There will
-	 * be a corresponding core_pending_cc_offer structure with the
-	 * same core_id, up until this instance of the core creates
-	 * a monitor structure
-	 */
+	 * Unique identifier for this instance of the CC core.
+	 */ 
 	int core_id;
 	/*!
 	 * The current state for this instance of the CC core.
@@ -535,33 +488,11 @@
 	struct ast_cc_monitor *monitor;
 };
 
-static int pending_offer_hash_fn(const void *obj, const int flags)
-{
-	const struct core_pending_cc_offer *pending_offer = obj;
-	return pending_offer->core_id;
-}
-
-static int pending_offer_cmp_fn(void *obj, void *arg, int flags)
-{
-	struct core_pending_cc_offer *pending_offer1 = obj;
-	struct core_pending_cc_offer *pending_offer2 = arg;
-	return pending_offer1->core_id == pending_offer2->core_id ? CMP_MATCH | CMP_STOP : 0;
-}
-
-static int match_caller(void *obj, void *arg, int flags)
-{
-	struct core_pending_cc_offer *pending_offer = obj;
-	const char *caller = arg;
-	/* Because we always remove duplicate entries, there
-	 * should only ever be one entry for a given caller.
-	 * This is why we pass CMP_STOP in addition to CMP_MATCH.
-	 */
-	if (!strcmp(pending_offer->caller, caller)) {
-		return CMP_MATCH | CMP_STOP;
-	}
-	return 0;
-}
-
+/* XXX I need to modify this to be an ao2_callback_data
+ * callback instead. This way I'll know the context in which
+ * it is being used, because the circumstances strongly dictate
+ * what data should be ignored and what should not be.
+ */
 static int match_agent(void *obj, void *arg, int flags)
 {
 	struct cc_core_instance *core_instance1 = obj;
@@ -574,32 +505,7 @@
 }
 
 static void kill_duplicate_offers(char *caller) {
-	ao2_callback(pending_cc_offers, OBJ_UNLINK | OBJ_NODATA, match_caller, caller);
-}
-
-static void pending_offer_destructor(void *obj)
-{
-	struct core_pending_cc_offer *pending_offer = obj;
-	ao2_ref(pending_offer->called_tree, -1);
-	/*astobj2 code will free the pending offer */
-}
-
-static struct core_pending_cc_offer *pending_cc_offer_init(const char *caller, const size_t caller_len, 
-		struct ast_cc_interface_tree *called_tree)
-{
-	struct core_pending_cc_offer *pending_offer = ao2_alloc(sizeof(*pending_offer) + caller_len, 
-			pending_offer_destructor);
-
-	if (!pending_offer) {
-		return NULL;
-	}
-
-	strcpy(pending_offer->caller, caller);
-	pending_offer->core_id = ast_atomic_fetchadd_int(&core_id_counter, +1);
-	ao2_ref(called_tree, +1);
-	pending_offer->called_tree = called_tree;
-	ao2_link(pending_cc_offers, pending_offer);
-	return pending_offer;
+	ao2_callback(cc_core_instances, OBJ_UNLINK | OBJ_NODATA, match_agent, caller);
 }
 
 static void check_callback_sanity(const struct ast_cc_agent_callbacks *callbacks)
@@ -615,7 +521,8 @@
 }
 
 static struct ast_cc_agent *cc_agent_init(struct ast_channel *caller_chan, 
-		const char * const caller_name, const int core_id) 
+		const char * const caller_name, const int core_id,
+		struct ast_cc_interface_tree *interface_tree) 
 {
 	struct ast_cc_agent *agent;
 
@@ -641,6 +548,8 @@
 		ast_free(agent);
 		return NULL;
 	}
+	ao2_ref(interface_tree, +1);
+	agent->interface_tree = interface_tree;
 	return agent;
 }
 
@@ -669,7 +578,6 @@
 {
 	char *caller = ast_strdupa(caller_chan->name);
 	char *dash = strrchr(caller, '-');
-	struct core_pending_cc_offer *pending_offer;
 	struct cc_core_instance *core_instance;
 
 	if (dash) {
@@ -681,27 +589,19 @@
 	 */
 	kill_duplicate_offers(caller);
 
-	/* Next, we need to allocate the structure we will use to store the tree. */
-	if (!(pending_offer = pending_cc_offer_init(caller, strlen(caller), called_tree))) {
-		return -1;
-	}
-
 	/* Next, we need to create the core instance for this call */
 	if (!(core_instance = ao2_alloc(sizeof(*core_instance), cc_core_instance_destructor))) {
-		ao2_ref(pending_offer, -1);
-		return -1;
-	}
-
-	core_instance->core_id = pending_offer->core_id;
-	if (!(core_instance->agent = cc_agent_init(caller_chan, caller, core_instance->core_id))) {
-		ao2_ref(pending_offer, -1);
+		return -1;
+	}
+
+	core_instance->core_id = ast_atomic_fetchadd_int(&core_id_counter, +1);
+	if (!(core_instance->agent = cc_agent_init(caller_chan, caller, core_instance->core_id, called_tree))) {
 		ao2_ref(core_instance, -1);
 		return -1;
 	}
 
 	ao2_link(cc_core_instances, core_instance);
 	ao2_ref(core_instance, -1); /* From ao2_alloc. */
-	ao2_ref(pending_offer, -1); /* From ao2_alloc within pending_cc_offer_init */
 
 	return core_instance->core_id;
 }
@@ -942,7 +842,7 @@
 	return new_monitor;
 }
 
-static void interface_tree_to_monitor(struct core_pending_cc_offer *pending_offer, struct cc_core_instance *core_instance)
+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;
 
@@ -950,7 +850,7 @@
 	 * 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(pending_offer->called_tree, next))) {
+	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;
@@ -959,7 +859,7 @@
 		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(pending_offer->called_tree, child_interface_iterator, next) {
+		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;
@@ -979,32 +879,23 @@
 		ao2_ref(parent, -1);
 	}
 
-	ao2_unlink(pending_cc_offers, pending_offer);
 }
 
 static int cc_monitor_tree_init(const int core_id)
 {
 	struct cc_core_instance *core_instance;
-	struct core_pending_cc_offer *pending_offer;
 	struct cc_core_instance instance_finder = { .core_id = core_id };
-	struct core_pending_cc_offer offer_finder = { .core_id = core_id };
 
 	if (!(core_instance = ao2_find(cc_core_instances, &instance_finder, OBJ_POINTER))) {
 		return -1;
 	}
 
-	if (!(pending_offer = ao2_find(pending_cc_offers, &offer_finder, OBJ_POINTER))) {
-		ao2_ref(core_instance, -1);
-		return -1;
-	}
-
 	ast_assert(core_instance->monitor == NULL);
 
-	interface_tree_to_monitor(pending_offer, core_instance);
+	interface_tree_to_monitor(core_instance->agent->interface_tree, core_instance);
 	core_instance->monitor = root_monitor;
 
 	ao2_ref(core_instance, -1);
-	ao2_ref(pending_offer, -1);
 	return 0;
 }
 
@@ -1304,9 +1195,7 @@
 
 static int ccreq_exec(struct ast_channel *chan, const char *data)
 {
-	struct core_pending_cc_offer *pending_offer;
 	struct cc_core_instance *core_instance;
-	struct cc_core_instance finder;
 	char interface[AST_CHANNEL_NAME];
 	struct cc_generic_agent_pvt *generic_pvt;
 	char *dash;
@@ -1316,15 +1205,8 @@
 		*dash = '\0';
 	}
 
-	if (!(pending_offer = ao2_callback(pending_cc_offers, 0, match_caller, interface))) {
-		ast_log(LOG_NOTICE, "Couldn't find a pending offer for interface %s\n", interface);
-		return -1;
-	}
-
-	finder.core_id = pending_offer->core_id;
-
-	if (!(core_instance = ao2_find(cc_core_instances, &finder, OBJ_POINTER))) {
-		ast_log(LOG_NOTICE, "Couldn't find a core instance with core_id %d\n", pending_offer->core_id);
+	if (!(core_instance = ao2_callback(cc_core_instances, 0, match_agent, interface))) {
+		ast_log(LOG_NOTICE, "Couldn't find a core instance for caller %s\n", interface);
 		return -1;
 	}
 
@@ -1613,10 +1495,6 @@
 {
 	int res;
 
-	if (!(pending_cc_offers = ao2_container_alloc(CC_PENDING_OFFER_BUCKETS,
-					pending_offer_hash_fn, pending_offer_cmp_fn))) {
-		return -1;
-	}
 	ast_log(LOG_NOTICE, "Successfully created pending offers container\n");
 	if (!(cc_core_instances = ao2_container_alloc(CC_CORE_INSTANCES_BUCKETS,
 					cc_core_instance_hash_fn, cc_core_instance_cmp_fn))) {




More information about the asterisk-commits mailing list