[asterisk-commits] mmichelson: branch group/CCSS r222534 - /team/group/CCSS/main/ccss.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 7 10:42:28 CDT 2009


Author: mmichelson
Date: Wed Oct  7 10:42:24 2009
New Revision: 222534

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=222534
Log:
Insert infrastructure for counting total
number of CC requests.

This will be used soon as a way of limiting the
number of CC requests in the system.


Modified:
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=222534&r1=222533&r2=222534
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Wed Oct  7 10:42:24 2009
@@ -96,6 +96,7 @@
 static const unsigned int CCBS_AVAILABLE_TIMER_DEFAULT = 4800u;
 static const unsigned int CC_MAX_AGENTS_DEFAULT = 5u;
 static const unsigned int CC_MAX_MONITORS_DEFAULT = 5u;
+static const unsigned int GLOBAL_CC_MAX_REQUESTS_DEFAULT = 20u;
 
 /* Generic agent callbacks */
 static int cc_generic_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan);
@@ -122,6 +123,10 @@
 };
 
 static struct ast_cc_monitor *root_monitor;
+/* The parsed configuration value */
+static unsigned int global_cc_max_requests;
+/* The actual number of CC requests in the system */
+static int cc_request_count;
 
 struct cc_generic_agent_pvt {
 	/*!
@@ -1535,6 +1540,7 @@
 	interface_tree_to_monitor(AST_LIST_FIRST(core_instance->agent->interface_tree),
 			root_monitor, core_instance->core_id);
 	core_instance->monitor = root_monitor;
+	ast_atomic_fetchadd_int(&cc_request_count, +1);
 
 	cc_unref(core_instance, "Unref the core instance we just found");
 	return 0;
@@ -1585,8 +1591,12 @@
 
 	if (monitor->interface->monitor_class == AST_CC_ROOT_MONITOR) {
 		/* Never ever under any circumstances unlink
-		 * the root monitor
+		 * the root monitor. Of course, since the root monitor
+		 * is being acted on here, it means that a CC transaction
+		 * failed or has completed. So decrease the number of 
+		 * CC requests in the system.
 		 */
+		ast_atomic_fetchadd_int(&cc_request_count, -1);
 		ast_log(LOG_NOTICE, "Not unlinking monitor %s because it is the root\n", monitor->interface->name);
 		return;
 	}
@@ -2498,6 +2508,38 @@
 	return cc_interface;
 }
 
+static void initialize_cc_max_requests(void)
+{
+	struct ast_config *cc_config;
+	const char *cc_max_requests_str;
+	struct ast_flags config_flags = {0,};
+	char *endptr;
+	
+	cc_config = ast_config_load2("ccss.conf", "ccss", config_flags);
+	if (!cc_config || cc_config == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_WARNING, "Could not find valid ccss.conf file. Using cc_max_requests default\n");
+		global_cc_max_requests = GLOBAL_CC_MAX_REQUESTS_DEFAULT;
+		return;
+	}
+
+	if (!(cc_max_requests_str = ast_variable_retrieve(cc_config, "general", "cc_max_requests"))) {
+		ast_config_destroy(cc_config);
+		ast_log(LOG_WARNING, "No cc_max_requests defined. Using default\n");
+		global_cc_max_requests = GLOBAL_CC_MAX_REQUESTS_DEFAULT;
+		return;
+	}
+
+	global_cc_max_requests = strtol(cc_max_requests_str, &endptr, 10);
+
+	if (!ast_strlen_zero(endptr)) {
+		ast_log(LOG_WARNING, "Invalid input given for cc_max_requests. Using default\n");
+		global_cc_max_requests = GLOBAL_CC_MAX_REQUESTS_DEFAULT;
+	}
+
+	ast_config_destroy(cc_config);
+	return;
+}
+
 int ast_cc_init(void)
 {
 	int res;
@@ -2544,5 +2586,6 @@
 	/* FOR THE LOVE OF GOD DO NOT SET root_monitor TO NULL HERE */
 	cc_unref(root_monitor, "Unref root monitor from allocation");
 	dialed_cc_interface_counter = 1;
+	initialize_cc_max_requests();
 	return res;
 }




More information about the asterisk-commits mailing list