summaryrefslogtreecommitdiff
path: root/apps/app_queue.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2015-08-17 16:41:19 -0500
committerRichard Mudgett <rmudgett@digium.com>2015-08-17 19:15:42 -0500
commit87b22969a431c73b5ec49af842fa3098c8cba88a (patch)
tree3725b7dfe5691379afdd14a9e95c1f3edc30a0d7 /apps/app_queue.c
parent178e1adffbcfe02d70e9def261e8c95f6e3bc8fe (diff)
app_queue.c: Extract some functions for simpler code.
* Extract set_queue_member_pause() from set_member_paused() for simpler and more consistent code. * Extract set_queue_member_ringinuse() from set_member_ringinuse_help_members() for simpler code. Change-Id: Iecc1f4119c63347341d7ea6b65f5fc4963706306
Diffstat (limited to 'apps/app_queue.c')
-rw-r--r--apps/app_queue.c149
1 files changed, 94 insertions, 55 deletions
diff --git a/apps/app_queue.c b/apps/app_queue.c
index d04080c27..9cc6efa4b 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -6983,6 +6983,55 @@ static int publish_queue_member_pause(struct call_queue *q, struct member *membe
return 0;
}
+/*!
+ * \internal
+ * \brief Set the pause status of the specific queue member.
+ *
+ * \param q Which queue the member belongs.
+ * \param mem Queue member being paused/unpaused.
+ * \param reason Why is this happening (Can be NULL/empty for no reason given.)
+ * \param paused Set to 1 if the member is being paused or 0 to unpause.
+ *
+ * \pre The q is locked on entry.
+ *
+ * \return Nothing
+ */
+static void set_queue_member_pause(struct call_queue *q, struct member *mem, const char *reason, int paused)
+{
+ if (mem->paused == paused) {
+ ast_debug(1, "%spausing already-%spaused queue member %s:%s\n",
+ (paused ? "" : "un"), (paused ? "" : "un"), q->name, mem->interface);
+ }
+
+ if (mem->realtime) {
+ if (update_realtime_member_field(mem, q->name, "paused", paused ? "1" : "0")) {
+ ast_log(LOG_WARNING, "Failed %spause update of realtime queue member %s:%s\n",
+ (paused ? "" : "un"), q->name, mem->interface);
+ }
+ }
+
+ 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);
+
+ if (queue_persistent_members) {
+ dump_queue_members(q);
+ }
+
+ if (is_member_available(q, mem)) {
+ ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE,
+ "Queue:%s_avail", q->name);
+ } else if (!num_available_members(q)) {
+ ast_devstate_changed(AST_DEVICE_INUSE, AST_DEVSTATE_CACHABLE,
+ "Queue:%s_avail", q->name);
+ }
+
+ ast_queue_log(q->name, "NONE", mem->membername, (paused ? "PAUSE" : "UNPAUSE"),
+ "%s", S_OR(reason, ""));
+
+ publish_queue_member_pause(q, mem, reason);
+}
+
static int set_member_paused(const char *queuename, const char *interface, const char *reason, int paused)
{
int found = 0;
@@ -6996,55 +7045,30 @@ static int set_member_paused(const char *queuename, const char *interface, const
struct member *mem;
if ((mem = interface_exists(q, interface))) {
- if (mem->paused == paused) {
- ast_debug(1, "%spausing already-%spaused queue member %s:%s\n", (paused ? "" : "un"), (paused ? "" : "un"), q->name, interface);
- }
-
- if (mem->realtime) {
- if (update_realtime_member_field(mem, q->name, "paused", paused ? "1" : "0")) {
- ast_log(LOG_WARNING, "Failed %spausing realtime queue member %s:%s\n", (paused ? "" : "un"), q->name, interface);
- ao2_ref(mem, -1);
- ao2_unlock(q);
- queue_t_unref(q, "Done with iterator");
- continue;
- }
- }
-
- 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. */
- if (found == 1) {
-
- /* XXX In all other cases, we use the membername, but since this affects all queues, we cannot */
- if (ast_strlen_zero(queuename)) {
- ast_queue_log("NONE", "NONE", interface, (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", "");
- }
+ /*
+ * Before we do the PAUSE/UNPAUSE, log if this was a
+ * PAUSEALL/UNPAUSEALL but only on the first found entry.
+ */
+ ++found;
+ if (found == 1
+ && ast_strlen_zero(queuename)) {
+ /*
+ * XXX In all other cases, we use the queue name,
+ * but since this affects all queues, we cannot.
+ */
+ ast_queue_log("NONE", "NONE", mem->membername,
+ (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", "");
}
- if (queue_persistent_members) {
- dump_queue_members(q);
- }
-
- if (is_member_available(q, mem)) {
- ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, "Queue:%s_avail", q->name);
- } else if (!num_available_members(q)) {
- ast_devstate_changed(AST_DEVICE_INUSE, AST_DEVSTATE_CACHABLE, "Queue:%s_avail", q->name);
- }
-
- ast_queue_log(q->name, "NONE", mem->membername, (paused ? "PAUSE" : "UNPAUSE"), "%s", S_OR(reason, ""));
-
- publish_queue_member_pause(q, mem, reason);
+ set_queue_member_pause(q, mem, reason, paused);
ao2_ref(mem, -1);
}
- }
- if (!ast_strlen_zero(queuename) && !strcasecmp(queuename, q->name)) {
- ao2_unlock(q);
- queue_t_unref(q, "Done with iterator");
- break;
+ if (!ast_strlen_zero(queuename)) {
+ ao2_unlock(q);
+ queue_t_unref(q, "Done with iterator");
+ break;
+ }
}
ao2_unlock(q);
@@ -7090,6 +7114,31 @@ static int set_member_penalty_help_members(struct call_queue *q, const char *int
return foundinterface;
}
+/*!
+ * \internal
+ * \brief Set the ringinuse value of the specific queue member.
+ *
+ * \param q Which queue the member belongs.
+ * \param mem Queue member being set.
+ * \param ringinuse Set to 1 if the member is called when inuse.
+ *
+ * \pre The q is locked on entry.
+ *
+ * \return Nothing
+ */
+static void set_queue_member_ringinuse(struct call_queue *q, struct member *mem, int ringinuse)
+{
+ if (mem->realtime) {
+ update_realtime_member_field(mem, q->name, realtime_ringinuse_field,
+ ringinuse ? "1" : "0");
+ }
+
+ mem->ringinuse = ringinuse;
+
+ ast_queue_log(q->name, "NONE", mem->interface, "RINGINUSE", "%d", ringinuse);
+ queue_publish_member_blob(queue_member_ringinuse_type(), queue_member_blob_create(q, mem));
+}
+
static int set_member_ringinuse_help_members(struct call_queue *q, const char *interface, int ringinuse)
{
struct member *mem;
@@ -7098,17 +7147,7 @@ static int set_member_ringinuse_help_members(struct call_queue *q, const char *i
ao2_lock(q);
if ((mem = interface_exists(q, interface))) {
foundinterface++;
- if (mem->realtime) {
- char rtringinuse[80];
-
- sprintf(rtringinuse, "%i", ringinuse);
- update_realtime_member_field(mem, q->name, realtime_ringinuse_field, rtringinuse);
- }
-
- mem->ringinuse = ringinuse;
-
- ast_queue_log(q->name, "NONE", interface, "RINGINUSE", "%d", ringinuse);
- queue_publish_member_blob(queue_member_ringinuse_type(), queue_member_blob_create(q, mem));
+ set_queue_member_ringinuse(q, mem, ringinuse);
ao2_ref(mem, -1);
}
ao2_unlock(q);