Index: apps/app_queue.c =================================================================== --- apps/app_queue.c (revision 85278) +++ 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 { @@ -112,6 +113,7 @@ { QUEUE_STRATEGY_FEWESTCALLS, "fewestcalls" }, { QUEUE_STRATEGY_RANDOM, "random" }, { QUEUE_STRATEGY_RRMEMORY, "rrmemory" }, + { QUEUE_STRATEGY_LINEAR, "linear" }, }; #define DEFAULT_RETRY 5 @@ -319,6 +321,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, what position are we at? */ + 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 */ @@ -819,8 +823,13 @@ q->monfmt[0] = '\0'; q->periodicannouncefrequency = 0; q->sound_callerannounce[0] = '\0'; /* Default, don't announce the caller that he has been answered */ - 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 depends on order, so we have to place all members in a single 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)); @@ -1896,6 +1905,8 @@ qe->parent->rrpos++; ao2_unlock(qe->parent); + qe->linpos++; + (*busies)++; return 0; } else if (status != tmp->oldstatus) @@ -2001,7 +2012,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); @@ -2024,6 +2035,29 @@ 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 */ + ast_debug(1, "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 ringing) { int res = 0; @@ -2499,6 +2533,17 @@ /* Everyone equal, except for penalty */ 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_RRMEMORY: if (pos < q->rrpos) { tmp->metric = 1000 + pos; @@ -2647,7 +2692,7 @@ ast_set_flag(&(bridge_config.features_caller), AST_FEATURE_PARKCALL); break; case 'n': - if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) + if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY || qe->parent->strategy == QUEUE_STRATEGY_LINEAR) (*tries)++; else *tries = qe->parent->membercount; @@ -2714,8 +2759,11 @@ lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT), forwardsallowed); ao2_lock(qe->parent); 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); + } ao2_unlock(qe->parent); peer = lpeer ? lpeer->chan : NULL; if (!peer) {