From c8a91b5b013c568f3f99e8fb7abc662775c60520 Mon Sep 17 00:00:00 2001
From: Matthew Jordan <mjordan@digium.com>
Date: Thu, 1 Aug 2013 19:11:46 +0000
Subject: [PATCH] Add queue member paused hints

This patch adds the ability in Queue to raise a hint when a member's paused
state changes. The hint uses the form 'Queue:{queue_name}_pause_{member_name}',
where {queue_name} and {member_name} are the name of the queue and the name
of the member to subscribe to, respectively.

For example: exten => 8501,hint,Queue:sales_pause_mark.

Members will show as In Use when paused.

Note that the format of the queue pause hint was changed slightly from what
is on the issue to accomodate suggestion on the code review.

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

(closes issue ASTERISK-20842)
Reported by: Philippe Lindheimer
patches:
  qpause-10-378206.diff uploaded by Philippe Lindheimer (license 5519)
  qpause-11-378206.diff uploaded by Philippe Lindheimer (license 5519)
  qpause-trunk-378206.diff uploaded by Philippe Lindheimer (license 5519)



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396010 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 CHANGES          |  6 ++++++
 apps/app_queue.c | 17 +++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/CHANGES b/CHANGES
index 7e9cc98132..952ad3b55c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -98,6 +98,12 @@ Queue
    AgentConnect, AgentComplete, AgentDump, and AgentRingNoAnswer will always be
    sent.  The "Variable" fields will also no longer exist on the Agent* events.
 
+ * Queues now support a hint for member paused state. The hint uses the form
+   'Queue:{queue_name}_pause_{member_name}', where {queue_name} and {member_name}
+   are the name of the queue and the name of the member to subscribe to,
+   respectively. For example: exten => 8501,hint,Queue:sales_pause_mark.
+   Members will show as In Use when paused.
+
 ResetCDR
 ------------------
  * The 'e' option has been deprecated. Use the CDR_PROP function to re-enable
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 732a558657..737de9df8e 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -2781,6 +2781,11 @@ static void queue_set_param(struct call_queue *q, const char *param, const char
 	}
 }
 
+
+#define QUEUE_PAUSED_DEVSTATE AST_DEVICE_INUSE
+#define QUEUE_UNPAUSED_DEVSTATE AST_DEVICE_NOT_INUSE
+#define QUEUE_UNKNOWN_PAUSED_DEVSTATE AST_DEVICE_NOT_INUSE
+
 /*! \internal
  * \brief If adding a single new member to a queue, use this function instead of ao2_linking.
  *        This adds round robin queue position data for a fresh member as well as links it.
@@ -2792,6 +2797,8 @@ static void member_add_to_queue(struct call_queue *queue, struct member *mem)
 	ao2_lock(queue->members);
 	mem->queuepos = ao2_container_count(queue->members);
 	ao2_link(queue->members, mem);
+	ast_devstate_changed(mem->paused ? QUEUE_PAUSED_DEVSTATE : QUEUE_UNPAUSED_DEVSTATE,
+		AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", queue->name, mem->interface);
 	ao2_unlock(queue->members);
 }
 
@@ -2804,6 +2811,7 @@ static void member_add_to_queue(struct call_queue *queue, struct member *mem)
 static void member_remove_from_queue(struct call_queue *queue, struct member *mem)
 {
 	ao2_lock(queue->members);
+	ast_devstate_changed(QUEUE_UNKNOWN_PAUSED_DEVSTATE, AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", queue->name, mem->interface);
 	queue_member_follower_removal(queue, mem);
 	ao2_unlink(queue->members, mem);
 	ao2_unlock(queue->members);
@@ -2870,6 +2878,8 @@ static void rt_handle_member_record(struct call_queue *q, char *interface, struc
 			ast_copy_string(m->rt_uniqueid, rt_uniqueid, sizeof(m->rt_uniqueid));
 			if (paused_str) {
 				m->paused = paused;
+				ast_devstate_changed(m->paused ? QUEUE_PAUSED_DEVSTATE : QUEUE_UNPAUSED_DEVSTATE,
+					AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", q->name, m->interface);
 			}
 			if (strcasecmp(state_interface, m->state_interface)) {
 				ast_copy_string(m->state_interface, state_interface, sizeof(m->state_interface));
@@ -6286,7 +6296,8 @@ static int set_member_paused(const char *queuename, const char *interface, const
 				}
 
 				mem->paused = paused;
-
+				ast_devstate_changed(mem->paused ? QUEUE_PAUSED_DEVSTATE : QUEUE_UNPAUSED_DEVSTATE,
+					AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", q->name, mem->interface);
 				found++;
 
 				/* Before we do the PAUSE/UNPAUSE log, if this was a PAUSEALL/UNPAUSEALL, log that here, but only on the first found entry. */
@@ -7425,8 +7436,10 @@ static int queue_function_mem_write(struct ast_channel *chan, const char *cmd, c
 				if (m->realtime) {
 					update_realtime_member_field(m, q->name, args.option, rtvalue);
 				}
-
 				m->paused = (memvalue <= 0) ? 0 : 1;
+				ast_devstate_changed(m->paused ? QUEUE_PAUSED_DEVSTATE : QUEUE_UNPAUSED_DEVSTATE,
+					AST_DEVSTATE_CACHABLE, "Queue:%s_pause_%s", q->name, args.interface);
+
 			} else if ((!strcasecmp(args.option, "ignorebusy")) || (!strcasecmp(args.option, "ringinuse"))) {
 				if (m->realtime) {
 					update_realtime_member_field(m, q->name, args.option, rtvalue);
-- 
GitLab