app_queue: 'agent available' hint, cleanup restart, and initial state
authorAlec L Davis <sivad.a@paradise.net.nz>
Wed, 26 Sep 2012 08:31:46 +0000 (08:31 +0000)
committerAlec L Davis <sivad.a@paradise.net.nz>
Wed, 26 Sep 2012 08:31:46 +0000 (08:31 +0000)
Fix previously untested senarios;

1). On queue initialisation set queue_avail devstate to INUSE.
    Previously was unavailable, which indicated an agent was available.

2). When removing members, if there are no other members available, set queue_avail to INUSE.
    Previously, if a member interface had become 'unavailable', they were never going to be removed, particularly when persistant queues is enabled.

3). When adding a member, check that they are available, if they are set queue_avail to NOT_INUSE.
 Previously on reloaded, members may have been 'unavailable'.

4). When pausing or unpausing a member, set appropriate queue availability.

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

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

Merged revisions 373804 from http://svn.asterisk.org/svn/asterisk/branches/11

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@373805 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_queue.c

index 2b29e67..13577cc 100644 (file)
@@ -2018,6 +2018,15 @@ static void init_queue(struct call_queue *q)
        while ((pr_iter = AST_LIST_REMOVE_HEAD(&q->rules,list))) {
                ast_free(pr_iter);
        }
+
+       /* On restart assume no members are available.
+        * The queue_avail hint is a boolean state to indicate whether a member is available or not.
+        *
+        * This seems counter intuitive, but is required to light a BLF
+        * AST_DEVICE_INUSE indicates no members are available.
+        * AST_DEVICE_NOT_INUSE indicates a member is available.
+        */
+       ast_devstate_changed(AST_DEVICE_INUSE, "Queue:%s_avail", q->name);
 }
 
 static void clear_queue(struct call_queue *q)
@@ -5900,7 +5909,7 @@ static int remove_from_queue(const char *queuename, const char *interface)
                                dump_queue_members(q);
                        }
 
-                       if (!ao2_container_count(q->members)) {
+                       if (!num_available_members(q)) {
                                ast_devstate_changed(AST_DEVICE_INUSE, "Queue:%s_avail", q->name);
                        }
 
@@ -5977,6 +5986,10 @@ static int add_to_queue(const char *queuename, const char *interface, const char
                                new_member->penalty, new_member->calls, (int) new_member->lastcall,
                                new_member->status, new_member->paused);
 
+                       if (is_member_available(new_member)) {
+                               ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Queue:%s_avail", q->name);
+                       }
+
                        ao2_ref(new_member, -1);
                        new_member = NULL;
 
@@ -5984,10 +5997,6 @@ static int add_to_queue(const char *queuename, const char *interface, const char
                                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;
                } else {
                        res = RES_OUTOFMEMORY;
@@ -6048,6 +6057,12 @@ static int set_member_paused(const char *queuename, const char *interface, const
                                        dump_queue_members(q);
                                }
 
+                               if (is_member_available(mem)) {
+                                       ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Queue:%s_avail", q->name);
+                               } else if (!num_available_members(q)) {
+                                       ast_devstate_changed(AST_DEVICE_INUSE, "Queue:%s_avail", q->name);
+                               }
+
                                ast_queue_log(q->name, "NONE", mem->membername, (paused ? "PAUSE" : "UNPAUSE"), "%s", S_OR(reason, ""));
 
                                /*** DOCUMENTATION