Index: apps/app_queue.c =================================================================== --- apps/app_queue.c (revision 86028) +++ apps/app_queue.c (working copy) @@ -100,7 +100,8 @@ QUEUE_STRATEGY_LEASTRECENT, QUEUE_STRATEGY_FEWESTCALLS, QUEUE_STRATEGY_RANDOM, - QUEUE_STRATEGY_RRMEMORY + QUEUE_STRATEGY_RRMEMORY, + QUEUE_STRATEGY_LINEAR }; static struct strategy { @@ -113,6 +114,7 @@ { QUEUE_STRATEGY_FEWESTCALLS, "fewestcalls" }, { QUEUE_STRATEGY_RANDOM, "random" }, { QUEUE_STRATEGY_RRMEMORY, "rrmemory" }, + { QUEUE_STRATEGY_LINEAR, "linear" } }; #define DEFAULT_RETRY 5 @@ -308,6 +310,8 @@ int opos; /*!< Where we started in the queue */ int handled; /*!< Whether our call was handled */ int max_penalty; /*!< Limit the members that can take this call to this penalty or lower */ + int linpos; /*!< If using linear strategy, position in queue */ + int linwrapped; /*!< Is the linpos wrapped? */ time_t start; /*!< When we started holding */ time_t expire; /*!< When this entry should expire (time out of queue) */ struct ast_channel *chan; /*!< Our channel */ @@ -774,8 +778,13 @@ q->context[0] = '\0'; q->monfmt[0] = '\0'; q->periodicannouncefrequency = 0; - if(!q->members) - q->members = ao2_container_alloc(37, member_hash_fn, member_cmp_fn); + if(!q->members) { + if(q->strategy == QUEUE_STRATEGY_LINEAR) + /*linear strategy depnds on order, so only use one hash bucket */ + q->members = ao2_container_alloc(1, member_hash_fn, member_cmp_fn); + else + q->members = ao2_container_alloc(37, member_hash_fn, member_cmp_fn); + } q->membercount = 0; q->found = 1; ast_copy_string(q->sound_next, "queue-youarenext", sizeof(q->sound_next)); @@ -1820,6 +1829,8 @@ qe->parent->rrpos++; ast_mutex_unlock(&qe->parent->lock); + qe->linpos++; + (*busies)++; return 0; } else if (status != tmp->oldstatus) @@ -1929,7 +1940,7 @@ return ret; } -static int store_next(struct queue_ent *qe, struct callattempt *outgoing) +static int store_next_rr(struct queue_ent *qe, struct callattempt *outgoing) { struct callattempt *best = find_best(outgoing); @@ -1953,6 +1964,30 @@ return 0; } +static int store_next_lin(struct queue_ent *qe, struct callattempt *outgoing) +{ + struct callattempt *best = find_best(outgoing); + + if (best) { + /* Ring just the best channel */ + if (option_debug) + ast_log(LOG_DEBUG, "Next is '%s' with metric %d\n", best->interface, best->metric); + qe->linpos = best->metric % 1000; + } else { + /* Just increment rrpos */ + if (qe->linwrapped) { + /* No more channels, start over */ + qe->linpos = 0; + } else { + /* Prioritize next entry */ + qe->linpos++; + } + } + qe->linwrapped = 0; + + return 0; +} + static int say_periodic_announcement(struct queue_ent *qe) { int res = 0; @@ -2439,6 +2474,17 @@ } tmp->metric += mem->penalty * 1000000; break; + case QUEUE_STRATEGY_LINEAR: + if (pos < qe->linpos) { + tmp->metric = 1000 + pos; + } else { + if (pos > qe->linpos) + /* Indicate there is another priority */ + qe->linwrapped = 1; + tmp->metric = pos; + } + tmp->metric += mem->penalty * 1000000; + break; case QUEUE_STRATEGY_RANDOM: tmp->metric = ast_random() % 1000; tmp->metric += mem->penalty * 1000000; @@ -2525,7 +2571,7 @@ ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT); break; case 'n': - if (qe->parent->strategy == QUEUE_STRATEGY_ROUNDROBIN || qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) + if (qe->parent->strategy == QUEUE_STRATEGY_ROUNDROBIN || qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY || qe->parent->strategy == QUEUE_STRATEGY_LINEAR) (*tries)++; else *tries = qe->parent->membercount; @@ -2592,8 +2638,11 @@ lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT), forwardsallowed); ast_mutex_lock(&qe->parent->lock); if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) { - store_next(qe, outgoing); + store_next_rr(qe, outgoing); } + if (qe->parent->strategy == QUEUE_STRATEGY_LINEAR) { + store_next_lin(qe, outgoing); + } ast_mutex_unlock(&qe->parent->lock); peer = lpeer ? lpeer->chan : NULL; if (!peer) {