Index: asterisk/apps/app_queue.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_queue.c,v retrieving revision 1.6 diff -u -r1.6 app_queue.c --- asterisk/apps/app_queue.c 14 Jun 2003 16:01:32 -0000 1.6 +++ asterisk/apps/app_queue.c 26 Jun 2003 19:00:43 -0000 @@ -92,11 +92,18 @@ }; struct member { + time_t last_used; char tech[80]; /* Technology */ char loc[256]; /* Location */ struct member *next; /* Next member */ }; +struct myagent { + char *loc; + time_t *last_used; + char *tech; +}; + struct ast_call_queue { pthread_mutex_t lock; char name[80]; /* Name of the queue */ @@ -406,6 +413,15 @@ } return res; } + +int compare_last_used (const struct myagent *c1, const struct myagent *c2) +{ + char str1[15]; + char str2[15]; + sprintf(str1, "%d", c1->last_used); + sprintf(str2, "%d", c2->last_used); + return strncmp (str1, str2,15); +} static int try_calling(struct queue_ent *qe, char *options, char *announceoverride, char *url) { @@ -420,14 +436,41 @@ struct ast_channel *peer; int res = 0, bridge = 0; char *announce = NULL; + time_t now; + int n = 0; + int i = 0; /* Hold the lock while we setup the outgoing calls */ ast_pthread_mutex_lock(&qe->parent->lock); cur = qe->parent->members; + while(cur) { + cur = cur->next; + n++; + } + + struct myagent myagents[n]; + + cur = qe->parent->members; + while(cur) { + myagents[i].loc = cur->loc; + myagents[i].last_used = cur->last_used; + myagents[i].tech = cur->tech; +// ast_verbose( VERBOSE_PREFIX_3 "loading agent array: %s last_used: %d tech: %s\n", myagents[i].loc, myagents[i].last_used, myagents[i].tech); + cur = cur->next; + i++; + } + + qsort (myagents, n, sizeof (struct myagent), compare_last_used); + +// for(i = 0; i < n; i++) { +// ast_verbose( VERBOSE_PREFIX_3 "sorted agent array: %s last_used: %d\n", myagents[i].loc, myagents[i].last_used ); +// } + if (strlen(qe->announce)) announce = qe->announce; if (announceoverride && strlen(announceoverride)) announce = announceoverride; - while(cur) { +// while(cur) { + for(i=0; i < n; i++) { /* Get a technology/[device:]number pair */ tmp = malloc(sizeof(struct localuser)); if (!tmp) { @@ -451,8 +494,8 @@ ast_log(LOG_DEBUG, "Queue with URL=%s_\n", url); } else ast_log(LOG_DEBUG, "Simple queue (no URL)\n"); - - strncpy(numsubst, cur->loc, sizeof(numsubst)-1); + strncpy(numsubst, myagents[i].loc, sizeof(numsubst)-1); +// strncpy(numsubst, cur->loc, sizeof(numsubst)-1); /* If we're dialing by extension, look at the extension to know what to dial */ if ((newnum = strstr(numsubst, "BYEXTENSION"))) { strncpy(restofit, newnum + strlen("BYEXTENSION"), sizeof(restofit)-1); @@ -461,7 +504,9 @@ ast_log(LOG_DEBUG, "Dialing by extension %s\n", numsubst); } /* Request the peer */ - tmp->chan = ast_request(cur->tech, qe->chan->nativeformats, numsubst); +// tmp->chan = ast_request(cur->tech, qe->chan->nativeformats, numsubst); + tmp->chan = ast_request(myagents[i].tech, qe->chan->nativeformats, numsubst); + if (!tmp->chan) { /* If we can't, just go on to the next call */ #if 0 @@ -489,6 +534,15 @@ break; } #endif + cur = qe->parent->members; + while(cur) { + if (cur->loc == myagents[i].loc) { + cur->last_used = time(&now); + break; + } + cur = cur->next; + } + tmp->chan->appl = "AppQueue"; tmp->chan->data = "(Outgoing Line)"; tmp->chan->whentohangup = 0; @@ -531,7 +585,7 @@ if (outgoing->chan->_state == AST_STATE_UP) break; - cur = cur->next; +// cur = cur->next; } if (qe->parent->timeout) to = qe->parent->timeout * 1000;