[asterisk-commits] mmichelson: branch 1.4 r76801 - /branches/1.4/apps/app_queue.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 24 11:26:59 CDT 2007


Author: mmichelson
Date: Tue Jul 24 11:26:58 2007
New Revision: 76801

URL: http://svn.digium.com/view/asterisk?view=rev&rev=76801
Log:
Added a membercount variable to call_queue struct which keeps track of the number of logged in members in a particular queue.
This makes it so that the 'n' option for Queue() can act properly depending on which strategy is used. If the strategy is
roundrobin, rrmemory, or ringall, we want to ring each phone once before moving on in the dialplan. However, if any other strategy is
used, we will only ring one phone since it cannot be guaranteed that a different phone will ring on subsequent attempts to ring a phone.

As a side effect of this, the QUEUE_MEMBER_COUNT dialplan function now just reads the membercount variable instead of traversing through
the member list to figure out how many members there are.

Special thanks to blitzrage for helping to test this out.

(closes issue #10127, reported by bcnit, patched by me, tested by blitzrage)


Modified:
    branches/1.4/apps/app_queue.c

Modified: branches/1.4/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_queue.c?view=diff&rev=76801&r1=76800&r2=76801
==============================================================================
--- branches/1.4/apps/app_queue.c (original)
+++ branches/1.4/apps/app_queue.c Tue Jul 24 11:26:58 2007
@@ -396,6 +396,7 @@
 	int autofill;                       /*!< Ignore the head call status and ring an available agent */
 	
 	struct member *members;             /*!< Head of the list of members */
+	int membercount;					/*!< Number of members in queue */
 	struct queue_ent *head;             /*!< Head of the list of callers */
 	AST_LIST_ENTRY(call_queue) list;    /*!< Next call queue */
 };
@@ -666,6 +667,7 @@
 	q->context[0] = '\0';
 	q->monfmt[0] = '\0';
 	q->periodicannouncefrequency = 0;
+	q->membercount = 0;
 	ast_copy_string(q->sound_next, "queue-youarenext", sizeof(q->sound_next));
 	ast_copy_string(q->sound_thereare, "queue-thereare", sizeof(q->sound_thereare));
 	ast_copy_string(q->sound_calls, "queue-callswaiting", sizeof(q->sound_calls));
@@ -958,6 +960,7 @@
 			} else {
 				q->members = m;
 			}
+			q->membercount++;
 		}
 	} else {
 		m->dead = 0;	/* Do not delete this one. */
@@ -980,6 +983,7 @@
 			else
 				q->members = next;
 			remove_from_interfaces(curm->interface);
+			q->membercount--;
 			free(curm);
 		} else
 			prev = curm;
@@ -1077,8 +1081,9 @@
 	if (q->strategy == QUEUE_STRATEGY_ROUNDROBIN)
 		rr_dep_warning();
 
-	/* Temporarily set non-dynamic members dead so we can detect deleted ones. */
-	for (m = q->members; m; m = m->next) {
+	/* Temporarily set non-dynamic members dead so we can detect deleted ones. 
+	 * Also set the membercount correctly for realtime*/
+	for (m = q->members; m; m = m->next, q->membercount++) {
 		if (!m->dynamic)
 			m->dead = 1;
 	}
@@ -1102,6 +1107,7 @@
 				q->members = next_m;
 			}
 			remove_from_interfaces(m->interface);
+			q->membercount--;
 			free(m);
 		} else {
 			prev_m = m;
@@ -2348,7 +2354,10 @@
 			ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT);
 			break;
 		case 'n':
-			*go_on = 1;
+			if (qe->parent->strategy == QUEUE_STRATEGY_ROUNDROBIN || qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY)
+				(*go_on)++;
+			else
+				*go_on = qe->parent->membercount;
 			break;
 		case 'i':
 			forwardsallowed = 0;
@@ -2778,10 +2787,12 @@
 		if ((last_member = interface_exists(q, interface))) {
 			if ((look = q->members) == last_member) {
 				q->members = last_member->next;
+				q->membercount--;
 			} else {
 				while (look != NULL) {
 					if (look->next == last_member) {
 						look->next = last_member->next;
+						q->membercount--;
 						break;
 					} else {
 						look = look->next;
@@ -2835,6 +2846,7 @@
 			new_member->dynamic = 1;
 			new_member->next = q->members;
 			q->members = new_member;
+			q->membercount++;
 			manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded",
 				"Queue: %s\r\n"
 				"Location: %s\r\n"
@@ -3436,7 +3448,7 @@
 			stat = get_member_status(qe.parent, qe.max_penalty);
 
 			/* exit after 'timeout' cycle if 'n' option enabled */
-			if (go_on) {
+			if (go_on >= qe.parent->membercount) {
 				if (option_verbose > 2)
 					ast_verbose(VERBOSE_PREFIX_3 "Exiting on time-out cycle\n");
 				ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
@@ -3535,7 +3547,6 @@
 	int count = 0;
 	struct call_queue *q;
 	struct ast_module_user *lu;
-	struct member *m;
 
 	buf[0] = '\0';
 	
@@ -3556,12 +3567,7 @@
 	AST_LIST_UNLOCK(&queues);
 
 	if (q) {
-		for (m = q->members; m; m = m->next) {
-			/* Count the agents who are logged in and presently answering calls */
-			if ((m->status != AST_DEVICE_UNAVAILABLE) && (m->status != AST_DEVICE_INVALID)) {
-				count++;
-			}
-		}
+		count = q->membercount;
 		ast_mutex_unlock(&q->lock);
 	} else
 		ast_log(LOG_WARNING, "queue %s was not found\n", data);
@@ -3814,6 +3820,7 @@
 							newm->next = q->members;
 							q->members = newm;
 						}
+						q->membercount++;
 					} else {
 						queue_set_param(q, var->name, var->value, var->lineno, 1);
 					}
@@ -3836,6 +3843,7 @@
 						q->members = next;
 
 					remove_from_interfaces(cur->interface);
+					q->membercount--;
 					free(cur);
 				}
 




More information about the asterisk-commits mailing list