[svn-commits] mmichelson: branch mmichelson/queue-position r102802 - /team/mmichelson/queue...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Feb 6 16:56:23 CST 2008


Author: mmichelson
Date: Wed Feb  6 16:56:23 2008
New Revision: 102802

URL: http://svn.digium.com/view/asterisk?view=rev&rev=102802
Log:
Adding ability to specify a position to insert a caller in the queue, as well as
adding a channel variable called QUEUEPOSITION which is set when a caller exits the
queue.

I have tested the setting of QUEUEPOSITION but I have not yet tried inserting callers.


Modified:
    team/mmichelson/queue-position/apps/app_queue.c

Modified: team/mmichelson/queue-position/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/queue-position/apps/app_queue.c?view=diff&rev=102802&r1=102801&r2=102802
==============================================================================
--- team/mmichelson/queue-position/apps/app_queue.c (original)
+++ team/mmichelson/queue-position/apps/app_queue.c Wed Feb  6 16:56:23 2008
@@ -1612,7 +1612,7 @@
 	ast_config_destroy(member_config);
 }
 
-static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason)
+static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason, int position)
 {
 	struct call_queue *q;
 	struct queue_ent *cur, *prev = NULL;
@@ -1652,6 +1652,16 @@
 				insert_entry(q, prev, qe, &pos);
 				inserted = 1;
 			}
+			/* <= is necessary for the position comparison because it may not be possible to enter
+			 * at our desired position since higher-priority callers may have taken the position we want
+			 */
+			if ((!inserted) && (qe->prio <= cur->prio) && (position) && (position <= pos + 1)) {
+				insert_entry(q, prev, qe, &pos);
+				/*pos is incremented inside insert_entry, so don't need to add 1 here*/
+				if (position < pos)
+					ast_log(LOG_NOTICE, "Asked to be inserted at position %d but forced into position %d due to higher priority callers\n", position, pos);
+				inserted = 1;
+			}
 			cur->pos = ++pos;
 			prev = cur;
 			cur = cur->next;
@@ -1872,12 +1882,13 @@
 	prev = NULL;
 	for (cur = q->head; cur; cur = cur->next) {
 		if (cur == qe) {
+			char posstr[20] = {0,};
 			q->count--;
 
 			/* Take us out of the queue */
 			manager_event(EVENT_FLAG_CALL, "Leave",
-				"Channel: %s\r\nQueue: %s\r\nCount: %d\r\nUniqueid: %s\r\n",
-				qe->chan->name, q->name,  q->count, qe->chan->uniqueid);
+				"Channel: %s\r\nQueue: %s\r\nCount: %d\r\nPosition: %d\r\nUniqueid: %s\r\n",
+				qe->chan->name, q->name,  q->count, qe->pos, qe->chan->uniqueid);
 			ast_debug(1, "Queue '%s' Leave, Channel '%s'\n", q->name, qe->chan->name );
 			/* Take us out of the queue */
 			if (prev)
@@ -1887,6 +1898,8 @@
 			/* Free penalty rules */
 			while ((pr_iter = AST_LIST_REMOVE_HEAD(&qe->qe_rules, list)))
 				ast_free(pr_iter);
+			snprintf(posstr, sizeof(posstr), "%d", qe->pos);
+			pbx_builtin_setvar_helper(qe->chan, "QUEUEPOSITION", posstr);
 		} else {
 			/* Renumber the people after us in the queue based on a new count */
 			cur->pos = ++pos;
@@ -4277,6 +4290,7 @@
 	int noption = 0;
 	char *parse;
 	int makeannouncement = 0;
+	int position = 0;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(queuename);
 		AST_APP_ARG(options);
@@ -4287,6 +4301,7 @@
 		AST_APP_ARG(macro);
 		AST_APP_ARG(gosub);
 		AST_APP_ARG(rule);
+		AST_APP_ARG(position);
 	);
 	/* Our queue entry */
 	struct queue_ent qe;
@@ -4356,6 +4371,12 @@
 	if (args.options && (strchr(args.options, 'c')))
 		qcontinue = 1;
 
+	if (args.position) {
+		position = atoi(args.position);
+		if (position < 0)
+			position = 0;
+	}
+
 	ast_debug(1, "queue: %s, options: %s, url: %s, announce: %s, expires: %ld, priority: %d\n",
 		args.queuename, args.options, args.url, args.announceoverride, (long)qe.expire, prio);
 
@@ -4368,7 +4389,7 @@
 	qe.last_periodic_announce_time = time(NULL);
 	qe.last_periodic_announce_sound = 0;
 	qe.valid_digits = 0;
-	if (join_queue(args.queuename, &qe, &reason)) {
+	if (join_queue(args.queuename, &qe, &reason, position)) {
 		ast_log(LOG_WARNING, "Unable to join queue '%s'\n", args.queuename);
 		set_queue_result(chan, reason);
 		return 0;




More information about the svn-commits mailing list