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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 25 14:21:20 CDT 2009


Author: mmichelson
Date: Tue Aug 25 14:21:16 2009
New Revision: 214067

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214067
Log:
Set up ao2 container for pending cc offers.


Modified:
    team/group/CCSS/include/asterisk/ccss.h
    team/group/CCSS/main/asterisk.c
    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=214067&r1=214066&r2=214067
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Tue Aug 25 14:21:16 2009
@@ -605,18 +605,17 @@
  */
 int ast_cc_request_state_change(enum ast_cc_state state, const unsigned int core_id, const char *debug);
 
-#if 0
-Commented out for now, but will be necessary when taskprocessor is added later
 /*!
  * \since 1.6.4
  * \brief Initialize CCSS
  *
- * Registers applications, custom functions, and manager actions.
- * Creates core task processor
+ * XXX This needs to be updated as more functionality is added.
+ *
+ * Creates ao2 container for pending CC offers.
+ *
  * \retval 0 Success
  * \retval nonzero Failure
  */
 int ast_cc_init(void);
-#endif
 
 #endif /* _ASTERISK_CCSS_H */

Modified: team/group/CCSS/main/asterisk.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/main/asterisk.c?view=diff&rev=214067&r1=214066&r2=214067
==============================================================================
--- team/group/CCSS/main/asterisk.c (original)
+++ team/group/CCSS/main/asterisk.c Tue Aug 25 14:21:16 2009
@@ -138,6 +138,7 @@
 #include "asterisk/buildinfo.h"
 #include "asterisk/xmldoc.h"
 #include "asterisk/poll-compat.h"
+#include "asterisk/ccss.h"
 
 #include "../defaults.h"
 
@@ -3655,6 +3656,11 @@
 		exit(1);
 	}
 
+	if (ast_cc_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
 	if (load_modules(0)) {
 		printf("%s", term_quit());
 		exit(1);

Modified: team/group/CCSS/main/ccss.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=214067&r1=214066&r2=214067
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Tue Aug 25 14:21:16 2009
@@ -363,6 +363,12 @@
 	}
 }
 
+static int core_id_counter;
+
+struct ao2_container *pending_cc_offers;
+
+static const int CC_PENDING_OFFER_BUCKETS = 37;
+
 /*!
  * \brief Struct for CC offers, before a monitor is created
  *
@@ -373,6 +379,9 @@
  *
  * 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 {
 	/*! 
@@ -382,14 +391,14 @@
 	 * an official request for CC, the same core_id will be used
 	 * when making state machine transactions and the like.
 	 */
-	unsigned int core_id;
+	int core_id;
 	/*!
 	 * 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, if an
+	 * 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 good
+	 * so using just the device name as an identifier is not specific
 	 * enough.
 	 */
 	const char *caller;
@@ -406,13 +415,55 @@
 	struct ast_cc_agent *agent;
 };
 
-int ast_cc_core_init_instance(struct ast_channel *caller, struct ast_cc_interface_tree *called_tree)
-{
-
+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 % CC_PENDING_OFFER_BUCKETS);
+}
+
+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;
+	if (pending_offer1->core_id == pending_offer2->core_id) {
+		return CMP_MATCH | CMP_STOP;
+	}
+	return 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)) {
+		ast_log(LOG_NOTICE, "Killing duplicate pending offer for caller '%s'\n", caller);
+		return CMP_MATCH | CMP_STOP;
+	}
+	return 0;
+}
+
+static void kill_duplicate_offers(char *caller) {
+	ao2_callback(pending_cc_offers, OBJ_UNLINK | OBJ_NODATA, match_caller, caller);
+}
+
+int ast_cc_core_init_instance(struct ast_channel *caller_chan, struct ast_cc_interface_tree *called_tree)
+{
+	char *caller = ast_strdupa(caller_chan->name);
+	char *dash = strrchr(caller, '-');
+	
+	if (dash) {
+		*dash = '\0';
+	}
 	/* First, we need to kill off other pending CC offers to caller. If the caller is going
 	 * to request a CC service, it may only be for the latest call he made.
 	 */
 
+	kill_duplicate_offers(caller);
+
 	/* Next, we need to allocate the structure we will use to store the tree. */
 
 	/* Next, we need to store this new tree in a container */
@@ -424,3 +475,12 @@
 	/*ao2_ref(called_tree, +1);*/
 	return 0;
 }
+
+int ast_cc_init(void)
+{
+	if (!(pending_cc_offers = ao2_container_alloc(CC_PENDING_OFFER_BUCKETS,
+					pending_offer_hash_fn, pending_offer_cmp_fn))) {
+		return -1;
+	}
+	return 0;
+}




More information about the svn-commits mailing list