[Asterisk-cvs] asterisk/apps app_queue.c,1.60,1.61

markster at lists.digium.com markster at lists.digium.com
Tue May 18 01:29:50 CDT 2004


Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv14317/apps

Modified Files:
	app_queue.c 
Log Message:
Add Round-Robin w/ Memory queueing strategy (rrmemory)


Index: app_queue.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_queue.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- app_queue.c	9 May 2004 19:13:43 -0000	1.60
+++ app_queue.c	18 May 2004 05:41:53 -0000	1.61
@@ -62,6 +62,7 @@
 #define QUEUE_STRATEGY_LEASTRECENT	2
 #define QUEUE_STRATEGY_FEWESTCALLS	3
 #define QUEUE_STRATEGY_RANDOM		4
+#define QUEUE_STRATEGY_RRMEMORY		5
 
 static struct strategy {
 	int strategy;
@@ -72,6 +73,7 @@
 	{ QUEUE_STRATEGY_LEASTRECENT, "leastrecent" },
 	{ QUEUE_STRATEGY_FEWESTCALLS, "fewestcalls" },
 	{ QUEUE_STRATEGY_RANDOM, "random" },
+	{ QUEUE_STRATEGY_RRMEMORY, "rrmemory" },
 };
 
 #define DEFAULT_RETRY		5
@@ -575,6 +577,33 @@
 	return 1;
 }
 
+static int store_next(struct queue_ent *qe, struct localuser *outgoing)
+{
+	struct localuser *cur;
+	struct localuser *best;
+	int bestmetric=0;
+	best = NULL;
+	cur = outgoing;
+	while(cur) {
+		if (cur->stillgoing &&							/* Not already done */
+			!cur->chan &&								/* Isn't already going */
+			(!best || (cur->metric < bestmetric))) {	/* We haven't found one yet, or it's better */
+				bestmetric = cur->metric;
+				best = cur;
+		}
+		cur = cur->next;
+	}
+	if (best) {
+		/* Ring just the best channel */
+		ast_log(LOG_DEBUG, "Next is '%s/%s' with metric %d\n", best->tech, best->numsubst, best->metric);
+		qe->parent->rrpos = best->metric % 1000;
+	} else {
+		/* Just increment rrpos */
+		qe->parent->rrpos++;
+	}
+	return 0;
+}
+
 static int valid_exit(struct queue_ent *qe, char digit)
 {
 	char tmp[2];
@@ -821,6 +850,8 @@
 			}
 			q->wrapped = 0;
 		}
+		/* Fall through */
+	case QUEUE_STRATEGY_RRMEMORY:
 		if (pos < q->rrpos) {
 			tmp->metric = 1000 + pos;
 		} else {
@@ -948,6 +979,11 @@
 	ring_one(qe, outgoing);
 	ast_mutex_unlock(&qe->parent->lock);
 	lpeer = wait_for_answer(qe, outgoing, &to, &allowredir_in, &allowredir_out, &allowdisconnect, &digit);
+	ast_mutex_lock(&qe->parent->lock);
+	if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) {
+		store_next(qe, outgoing);
+	}
+	ast_mutex_unlock(&qe->parent->lock);
 	if (lpeer)
 		peer = lpeer->chan;
 	else




More information about the svn-commits mailing list