[asterisk-commits] mmichelson: branch group/CCSS r222796 - /team/group/CCSS/main/ccss.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Oct 8 10:43:10 CDT 2009
Author: mmichelson
Date: Thu Oct 8 10:43:07 2009
New Revision: 222796
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=222796
Log:
Add logic to count the number of agents in use and
be sure not to exceed the cc_max_agents for a given
caller.
This is a bit difficult to test right now since only
generic agents are implemented. They only allow for
a single agent at a time, so I can't be sure that my
agent counting function is working correctly. Once native
agents begin being implemented I can go back to this.
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=222796&r1=222795&r2=222796
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Thu Oct 8 10:43:07 2009
@@ -1063,6 +1063,27 @@
return 0;
}
+static int count_agents_cb(void *obj, void *arg, void *data, int flags)
+{
+ struct cc_core_instance *core_instance = obj;
+ const char *name = arg;
+ long *count = data;
+
+ if (core_instance->monitor && !strcmp(core_instance->agent->interface, name)) {
+ (*count)++;
+ }
+ return 0;
+}
+
+static long count_agents(const char * const caller)
+{
+ long agent_count = 0;
+
+ ao2_t_callback_data(cc_core_instances, OBJ_NODATA, count_agents_cb, (char *)caller, &agent_count, "Counting agents");
+ ast_log(LOG_NOTICE, "Counted %ld agents\n", agent_count);
+ return agent_count;
+}
+
static void kill_duplicate_offers(char *caller) {
unsigned long match_flags = MATCH_NO_MONITOR;
ao2_t_callback_data(cc_core_instances, OBJ_UNLINK | OBJ_NODATA, match_agent, caller, &match_flags, "Killing duplicate offers");
@@ -1188,6 +1209,7 @@
char *dash = strrchr(caller, '-');
struct cc_core_instance *core_instance;
int core_id;
+ long agent_count;
if (dash) {
*dash = '\0';
@@ -1198,14 +1220,17 @@
*/
kill_duplicate_offers(caller);
+ agent_count = count_agents(caller);
+ if (agent_count >= ast_get_cc_max_agents(ast_channel_get_cc_config_params(caller_chan))) {
+ ast_log(LOG_NOTICE, "Caller %s already has the maximum number of agents configured\n", caller);
+ return -1;
+ }
+
/* Generic agents can only have a single outstanding CC request per caller. */
- if (ast_get_cc_agent_policy(ast_channel_get_cc_config_params(caller_chan)) == AST_CC_AGENT_GENERIC) {
- unsigned long match_flags = MATCH_MONITOR;
- if (ao2_t_callback_data(cc_core_instances, OBJ_NODATA, match_agent, caller, &match_flags, "Trying to find requests from this caller") != NULL) {
- ast_log(LOG_NOTICE, "Caller %s already has an outstanding CC request. "
- "Not creating a new core instance\n", caller);
- return -1;
- }
+ if (ast_get_cc_agent_policy(ast_channel_get_cc_config_params(caller_chan)) == AST_CC_AGENT_GENERIC &&
+ agent_count > 0) {
+ ast_log(LOG_NOTICE, "Generic agents can only have a single outstanding request\n");
+ return -1;
}
if ((core_id = ast_cc_get_current_core_id(caller_chan)) == -1) {
@@ -1464,7 +1489,7 @@
struct ast_cc_monitor *monitor = data;
ast_log(LOG_NOTICE, "Destructor called for monitor %s\n", monitor->interface->name);
monitor->callbacks->destructor(monitor);
- ao2_ref(monitor->interface, -1);
+ cc_unref(monitor->interface, "Remove monitor's reference to interface");
}
static struct ast_cc_monitor *cc_monitor_instance_init(struct ast_cc_interface *cc_interface,
More information about the asterisk-commits
mailing list