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.

NOTE: This may fix a consistency issue with realtime ringinuse
because the ordering of things was backported from v13.  It is
similar to how set_member_paused() treats realtime for paused.

Change-Id: Iecc1f4119c63347341d7ea6b65f5fc4963706306
changes/04/1104/2
Richard Mudgett 10 years ago
parent a56da797d9
commit 6a364807f4

@ -6290,41 +6290,33 @@ static int add_to_queue(const char *queuename, const char *interface, const char
return res;
}
static int set_member_paused(const char *queuename, const char *interface, const char *reason, int paused)
/*!
* \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)
{
int found = 0;
struct call_queue *q;
struct member *mem;
struct ao2_iterator queue_iter;
int failed;
/* Special event for when all queues are paused - individual events still generated */
/* 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", "");
queue_iter = ao2_iterator_init(queues, 0);
while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues"))) {
ao2_lock(q);
if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) {
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);
ast_debug(1, "%spausing already-%spaused queue member %s:%s\n",
(paused ? "" : "un"), (paused ? "" : "un"), q->name, mem->interface);
}
failed = 0;
if (mem->realtime) {
failed = update_realtime_member_field(mem, q->name, "paused", paused ? "1" : "0");
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);
}
if (failed) {
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;
}
found++;
mem->paused = paused;
if (queue_persistent_members) {
@ -6332,12 +6324,15 @@ static int set_member_paused(const char *queuename, const char *interface, const
}
if (is_member_available(q, mem)) {
ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, "Queue:%s_avail", q->name);
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_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, ""));
ast_queue_log(q->name, "NONE", mem->membername, (paused ? "PAUSE" : "UNPAUSE"),
"%s", S_OR(reason, ""));
if (!ast_strlen_zero(reason)) {
/*** DOCUMENTATION
@ -6388,15 +6383,38 @@ static int set_member_paused(const char *queuename, const char *interface, const
"Paused: %d\r\n",
q->name, mem->interface, mem->membername, paused);
}
}
static int set_member_paused(const char *queuename, const char *interface, const char *reason, int paused)
{
int found = 0;
struct call_queue *q;
struct ao2_iterator queue_iter;
/* Special event for when all queues are paused - individual events still generated */
/* 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", "");
queue_iter = ao2_iterator_init(queues, 0);
while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues"))) {
ao2_lock(q);
if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) {
struct member *mem;
if ((mem = interface_exists(q, interface))) {
++found;
set_queue_member_pause(q, mem, reason, paused);
ao2_ref(mem, -1);
}
}
if (!ast_strlen_zero(queuename) && !strcasecmp(queuename, q->name)) {
if (!ast_strlen_zero(queuename)) {
ao2_unlock(q);
queue_t_unref(q, "Done with iterator");
break;
}
}
ao2_unlock(q);
queue_t_unref(q, "Done with iterator");
@ -6456,22 +6474,29 @@ static int set_member_penalty_help_members(struct call_queue *q, const char *int
return foundinterface;
}
static int set_member_ringinuse_help_members(struct call_queue *q, const char *interface, int ringinuse)
/*!
* \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)
{
struct member *mem;
int foundinterface = 0;
char rtringinuse[80];
if (mem->realtime) {
update_realtime_member_field(mem, q->name, realtime_ringinuse_field,
ringinuse ? "1" : "0");
}
ao2_lock(q);
if ((mem = interface_exists(q, interface))) {
foundinterface++;
if (!mem->realtime) {
mem->ringinuse = ringinuse;
} else {
sprintf(rtringinuse, "%i", ringinuse);
update_realtime_member_field(mem, q->name, realtime_ringinuse_field, rtringinuse);
}
ast_queue_log(q->name, "NONE", interface, "RINGINUSE", "%d", ringinuse);
ast_queue_log(q->name, "NONE", mem->interface, "RINGINUSE", "%d", ringinuse);
/*** DOCUMENTATION
<managerEventInstance>
<synopsis>Raised when a member's ringinuse setting is changed.</synopsis>
@ -6495,6 +6520,17 @@ static int set_member_ringinuse_help_members(struct call_queue *q, const char *i
"Location: %s\r\n"
"Ringinuse: %d\r\n",
q->name, mem->interface, ringinuse);
}
static int set_member_ringinuse_help_members(struct call_queue *q, const char *interface, int ringinuse)
{
struct member *mem;
int foundinterface = 0;
ao2_lock(q);
if ((mem = interface_exists(q, interface))) {
foundinterface++;
set_queue_member_ringinuse(q, mem, ringinuse);
ao2_ref(mem, -1);
}
ao2_unlock(q);

Loading…
Cancel
Save