put all the QUEUE_STRATEGY values in an enum, and use them in all of the places

in the code where the strategy type is checked, to make the code more readable


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@25889 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant
2006-05-09 07:27:03 +00:00
parent a7c5ce76f6
commit 4120afc28e

View File

@@ -93,12 +93,14 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/devicestate.h" #include "asterisk/devicestate.h"
#include "asterisk/stringfields.h" #include "asterisk/stringfields.h"
#define QUEUE_STRATEGY_RINGALL 0 enum {
#define QUEUE_STRATEGY_ROUNDROBIN 1 QUEUE_STRATEGY_RINGALL = 0,
#define QUEUE_STRATEGY_LEASTRECENT 2 QUEUE_STRATEGY_ROUNDROBIN,
#define QUEUE_STRATEGY_FEWESTCALLS 3 QUEUE_STRATEGY_LEASTRECENT,
#define QUEUE_STRATEGY_RANDOM 4 QUEUE_STRATEGY_FEWESTCALLS,
#define QUEUE_STRATEGY_RRMEMORY 5 QUEUE_STRATEGY_RANDOM,
QUEUE_STRATEGY_RRMEMORY
};
static struct strategy { static struct strategy {
int strategy; int strategy;
@@ -732,7 +734,7 @@ static void queue_set_param(struct ast_call_queue *q, const char *param, const c
if (q->strategy < 0) { if (q->strategy < 0) {
ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n", ast_log(LOG_WARNING, "'%s' isn't a valid strategy for queue '%s', using ringall instead\n",
val, q->name); val, q->name);
q->strategy = 0; q->strategy = QUEUE_STRATEGY_RINGALL;
} }
} else if (!strcasecmp(param, "joinempty")) { } else if (!strcasecmp(param, "joinempty")) {
if (!strcasecmp(val, "strict")) if (!strcasecmp(val, "strict"))
@@ -1526,7 +1528,7 @@ static int ring_one(struct queue_ent *qe, struct callattempt *outgoing, int *bus
ast_log(LOG_DEBUG, "Nobody left to try ringing in queue\n"); ast_log(LOG_DEBUG, "Nobody left to try ringing in queue\n");
break; break;
} }
if (!qe->parent->strategy) { if (qe->parent->strategy == QUEUE_STRATEGY_RINGALL) {
struct callattempt *cur; struct callattempt *cur;
/* Ring everyone who shares this best metric (for ringall) */ /* Ring everyone who shares this best metric (for ringall) */
for (cur = outgoing; cur; cur = cur->q_next) { for (cur = outgoing; cur; cur = cur->q_next) {
@@ -1686,7 +1688,7 @@ static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callatte
numlines++; numlines++;
} }
if (pos > 1 /* found */ || !stillgoing /* nobody listening */ || if (pos > 1 /* found */ || !stillgoing /* nobody listening */ ||
qe->parent->strategy /* ring would not be delivered */) (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) /* ring would not be delivered */)
break; break;
/* On "ringall" strategy we only move to the next penalty level /* On "ringall" strategy we only move to the next penalty level
when *all* ringing phones are done in the current penalty level */ when *all* ringing phones are done in the current penalty level */
@@ -1784,7 +1786,7 @@ static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callatte
if (in->cdr) if (in->cdr)
ast_cdr_busy(in->cdr); ast_cdr_busy(in->cdr);
do_hang(o); do_hang(o);
if (qe->parent->strategy) { if (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) {
if (qe->parent->timeoutrestart) if (qe->parent->timeoutrestart)
*to = orig; *to = orig;
ring_one(qe, outgoing, &numbusies); ring_one(qe, outgoing, &numbusies);
@@ -1797,7 +1799,7 @@ static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callatte
if (in->cdr) if (in->cdr)
ast_cdr_busy(in->cdr); ast_cdr_busy(in->cdr);
do_hang(o); do_hang(o);
if (qe->parent->strategy) { if (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) {
if (qe->parent->timeoutrestart) if (qe->parent->timeoutrestart)
*to = orig; *to = orig;
ring_one(qe, outgoing, &numbusies); ring_one(qe, outgoing, &numbusies);
@@ -1824,7 +1826,7 @@ static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callatte
ast_frfree(f); ast_frfree(f);
} else { } else {
do_hang(o); do_hang(o);
if (qe->parent->strategy) { if (qe->parent->strategy != QUEUE_STRATEGY_RINGALL) {
if (qe->parent->timeoutrestart) if (qe->parent->timeoutrestart)
*to = orig; *to = orig;
ring_one(qe, outgoing, &numbusies); ring_one(qe, outgoing, &numbusies);
@@ -1925,7 +1927,7 @@ static int is_our_turn(struct queue_ent *qe)
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "There are %d available members.\n", avl); ast_log(LOG_DEBUG, "There are %d available members.\n", avl);
if (qe->parent->strategy == 0) { if (qe->parent->strategy == QUEUE_STRATEGY_RINGALL) {
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Even though there are %d available members, the strategy is ringall so only the head call is allowed in!\n", avl); ast_log(LOG_DEBUG, "Even though there are %d available members, the strategy is ringall so only the head call is allowed in!\n", avl);
avl = 1; avl = 1;