[asterisk-commits] alecdavis: trunk r373188 - in /trunk: ./ apps/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 19 17:33:16 CDT 2012


Author: alecdavis
Date: Wed Sep 19 17:33:12 2012
New Revision: 373188

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=373188
Log:
app_queue: Support an 'agent available' hint

Sets INUSE when no free agents, NOT_INUSE when an agent is free.  

modifes handle_statechange() scan members loop to scan for a free agent
and updates the Queue:queuename_avial devstate.

Previously exited early if the member was found in the queue.

Now Exits later when both a member was found, and a free agent was found.


alecdavis (license 585)
Reported by: Alec Davis
Tested by: alecdavis

Review: https://reviewboard.asterisk.org/r/2121/


Modified:
    trunk/CHANGES
    trunk/apps/app_queue.c
    trunk/configs/extensions.conf.sample

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=373188&r1=373187&r2=373188
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Wed Sep 19 17:33:12 2012
@@ -22,6 +22,13 @@
  * When performing queue pause/unpause on an interface without specifying an
    individual queue, the PAUSEALL/UNPAUSEALL event will only be logged if at
    least one member of any queue exists for that interface.
+
+Queue
+-------------------
+ * Add queue available hint.  exten => 8501,hint,Queue:markq_avail
+   Note: the suffix '_avail' after the queuename.
+   Reports 'InUse' for no logged in agents or no free agents.
+   Reports 'Idle' when an agent is free.
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 10 to Asterisk 11 --------------------

Modified: trunk/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_queue.c?view=diff&rev=373188&r1=373187&r2=373188
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Wed Sep 19 17:33:12 2012
@@ -1660,29 +1660,53 @@
 	struct member *m;
 	struct call_queue *q;
 	char interface[80], *slash_pos;
-	int found = 0;
+	int found = 0;			/* Found this member in any queue */
+	int found_member;		/* Found this member in this queue */
+	int avail = 0;			/* Found an available member in this queue */
 
 	qiter = ao2_iterator_init(queues, 0);
 	while ((q = ao2_t_iterator_next(&qiter, "Iterate over queues"))) {
 		ao2_lock(q);
 
+		avail = 0;
+		found_member = 0;
 		miter = ao2_iterator_init(q->members, 0);
 		for (; (m = ao2_iterator_next(&miter)); ao2_ref(m, -1)) {
-			ast_copy_string(interface, m->state_interface, sizeof(interface));
-
-			if ((slash_pos = strchr(interface, '/'))) {
-				if (!strncasecmp(interface, "Local/", 6) && (slash_pos = strchr(slash_pos + 1, '/'))) {
-					*slash_pos = '\0';
+			if (!found_member) {
+				ast_copy_string(interface, m->state_interface, sizeof(interface));
+
+				if ((slash_pos = strchr(interface, '/'))) {
+					if (!strncasecmp(interface, "Local/", 6) && (slash_pos = strchr(slash_pos + 1, '/'))) {
+						*slash_pos = '\0';
+					}
 				}
-			}
-
-			if (!strcasecmp(interface, sc->dev)) {
-				found = 1;
-				update_status(q, m, sc->state);
+
+				if (!strcasecmp(interface, sc->dev)) {
+					found_member = 1;
+					update_status(q, m, sc->state);
+				}
+			}
+
+			/* check every member until we find one NOT_INUSE */
+			if (!avail && (m->status == AST_DEVICE_NOT_INUSE) && !m->paused) {
+				avail = 1;
+			}
+			if (avail && found_member) {
+				/* early exit as we've found an available member and the member of interest */
 				ao2_ref(m, -1);
 				break;
 			}
 		}
+
+		if (found_member) {
+			found = 1;
+			if (avail) {
+				ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Queue:%s_avail", q->name);
+			} else {
+				ast_devstate_changed(AST_DEVICE_INUSE, "Queue:%s_avail", q->name);
+			}
+		}
+
 		ao2_iterator_destroy(&miter);
 
 		ao2_unlock(q);
@@ -5852,7 +5876,11 @@
 			if (queue_persistent_members) {
 				dump_queue_members(q);
 			}
-			
+
+			if (!ao2_container_count(q->members)) {
+				ast_devstate_changed(AST_DEVICE_INUSE, "Queue:%s_avail", q->name);
+			}
+
 			res = RES_OKAY;
 		} else {
 			res = RES_EXISTS;
@@ -5931,6 +5959,10 @@
 
 			if (dump) {
 				dump_queue_members(q);
+			}
+
+			if (ao2_container_count(q->members) == 1) {
+				ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Queue:%s_avail", q->name);
 			}
 
 			res = RES_OKAY;

Modified: trunk/configs/extensions.conf.sample
URL: http://svnview.digium.com/svn/asterisk/trunk/configs/extensions.conf.sample?view=diff&rev=373188&r1=373187&r2=373188
==============================================================================
--- trunk/configs/extensions.conf.sample (original)
+++ trunk/configs/extensions.conf.sample Wed Sep 19 17:33:12 2012
@@ -708,6 +708,12 @@
 ;exten => 6600,hint,park:701 at parkedcalls
 ;exten => 6600,1,noop
 ;
+
+;To subscribe to the availability of a free member in the 'markq' queue.
+;Note: '_avail' is added to the QueueName
+;exten => 8501,hint,Queue:markq_avail
+;exten => 8501,1,Queue(markq)
+
 ; Some other handy things are an extension for checking voicemail via
 ; voicemailmain
 ;




More information about the asterisk-commits mailing list