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/



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@373188 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Alec L Davis
2012-09-19 22:33:12 +00:00
parent 9d4f8abdc6
commit 67ca3b9126
3 changed files with 54 additions and 9 deletions

View File

@@ -23,6 +23,13 @@ Logging
individual queue, the PAUSEALL/UNPAUSEALL event will only be logged if at individual queue, the PAUSEALL/UNPAUSEALL event will only be logged if at
least one member of any queue exists for that interface. 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 -------------------- --- Functionality changes from Asterisk 10 to Asterisk 11 --------------------
------------------------------------------------------------------------------ ------------------------------------------------------------------------------

View File

@@ -1660,29 +1660,53 @@ static int handle_statechange(void *datap)
struct member *m; struct member *m;
struct call_queue *q; struct call_queue *q;
char interface[80], *slash_pos; 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); qiter = ao2_iterator_init(queues, 0);
while ((q = ao2_t_iterator_next(&qiter, "Iterate over queues"))) { while ((q = ao2_t_iterator_next(&qiter, "Iterate over queues"))) {
ao2_lock(q); ao2_lock(q);
avail = 0;
found_member = 0;
miter = ao2_iterator_init(q->members, 0); miter = ao2_iterator_init(q->members, 0);
for (; (m = ao2_iterator_next(&miter)); ao2_ref(m, -1)) { for (; (m = ao2_iterator_next(&miter)); ao2_ref(m, -1)) {
ast_copy_string(interface, m->state_interface, sizeof(interface)); if (!found_member) {
ast_copy_string(interface, m->state_interface, sizeof(interface));
if ((slash_pos = strchr(interface, '/'))) { if ((slash_pos = strchr(interface, '/'))) {
if (!strncasecmp(interface, "Local/", 6) && (slash_pos = strchr(slash_pos + 1, '/'))) { if (!strncasecmp(interface, "Local/", 6) && (slash_pos = strchr(slash_pos + 1, '/'))) {
*slash_pos = '\0'; *slash_pos = '\0';
}
}
if (!strcasecmp(interface, sc->dev)) {
found_member = 1;
update_status(q, m, sc->state);
} }
} }
if (!strcasecmp(interface, sc->dev)) { /* check every member until we find one NOT_INUSE */
found = 1; if (!avail && (m->status == AST_DEVICE_NOT_INUSE) && !m->paused) {
update_status(q, m, sc->state); avail = 1;
}
if (avail && found_member) {
/* early exit as we've found an available member and the member of interest */
ao2_ref(m, -1); ao2_ref(m, -1);
break; 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_iterator_destroy(&miter);
ao2_unlock(q); ao2_unlock(q);
@@ -5852,7 +5876,11 @@ static int remove_from_queue(const char *queuename, const char *interface)
if (queue_persistent_members) { if (queue_persistent_members) {
dump_queue_members(q); dump_queue_members(q);
} }
if (!ao2_container_count(q->members)) {
ast_devstate_changed(AST_DEVICE_INUSE, "Queue:%s_avail", q->name);
}
res = RES_OKAY; res = RES_OKAY;
} else { } else {
res = RES_EXISTS; res = RES_EXISTS;
@@ -5933,6 +5961,10 @@ static int add_to_queue(const char *queuename, const char *interface, const char
dump_queue_members(q); 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; res = RES_OKAY;
} else { } else {
res = RES_OUTOFMEMORY; res = RES_OUTOFMEMORY;

View File

@@ -708,6 +708,12 @@ include => demo
;exten => 6600,hint,park:701@parkedcalls ;exten => 6600,hint,park:701@parkedcalls
;exten => 6600,1,noop ;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 ; Some other handy things are an extension for checking voicemail via
; voicemailmain ; voicemailmain
; ;