--- orig_app_queue.c 2003-06-06 19:55:16.000000000 -0400 +++ app_queue.c 2003-06-15 05:09:57.000000000 -0400 @@ -83,10 +83,16 @@ struct queue_ent { struct ast_call_queue *parent; /* What queue is our parent */ char moh[80]; /* Name of musiconhold to be used */ + char adv[80]; /* Dir of advertisements */ char announce[80]; /* Announcement to play */ char context[80]; /* Context when user exits queue */ - int pos; /* Where we are in the queue */ + int announcetimeout; /* How often to announce their position */ + int advert_timeout; /* How often to play an advertisement */ + int pos; /* Where we are in the queue */ + int last_pos_said; /* Last position we told the caller they were */ time_t start; /* When we started holding */ + time_t last_pos; /* When we last played position */ + time_t last_adv; /* When we last played an advertisement */ struct ast_channel *chan; /* Our channel */ struct queue_ent *next; /* The next queue entry */ }; @@ -101,9 +107,11 @@ pthread_mutex_t lock; char name[80]; /* Name of the queue */ char moh[80]; /* Name of musiconhold to be used */ + char adv[80]; /* Dir of advertisements */ char announce[80]; /* Announcement to play */ char context[80]; /* Announcement to play */ int announcetimeout; /* How often to announce their position */ + int advert_timeout; /* How often to play an advertisement */ int count; /* How many entries are in the queue */ int maxlen; /* Max number of entries in queue */ @@ -151,7 +159,10 @@ qe->parent = q; qe->pos = ++pos; strncpy(qe->moh, q->moh, sizeof(qe->moh)); + strncpy(qe->adv, q->adv, sizeof(qe->adv)); strncpy(qe->announce, q->announce, sizeof(qe->announce)); + qe->announcetimeout = q->announcetimeout; + qe->advert_timeout = q->advert_timeout; strncpy(qe->context, q->context, sizeof(qe->context)); q->count++; res = 0; @@ -227,6 +238,26 @@ q->head = cur->next; } else { cur->pos = ++pos; + if ((cur->pos != cur->last_pos_said) && (cur->pos > 2)) { + ast_verbose(VERBOSE_PREFIX_3 "Position in queue changed %s\n", cur->chan->name); + ast_moh_stop(cur->chan); + // playback(cur->chan, "pos", "YouArePos"); + ast_stopstream(cur->chan); + int res2; + res2 = ast_streamfile(cur->chan, "YouArePos", cur->chan->language); + if (!res2) + res2 = ast_waitstream(cur->chan, ""); + else + res2 = 0; + if (res2) { + ast_log(LOG_WARNING, "ast_streamfile failed on %s \n", cur->chan->name); + res2 = 0; + } + ast_stopstream(cur->chan); + ast_say_number(cur->chan, pos, AST_DIGIT_ANY, cur->chan->language); + ast_moh_start(cur->chan, qe->moh); + cur->last_pos_said = pos; + } prev = cur; } cur = cur->next; @@ -292,6 +323,7 @@ *to = 0; return NULL; } + ast_verbose( VERBOSE_PREFIX_3 "waitfor_n %s, %s, %s\n", watchers[1], pos, to); winner = ast_waitfor_n(watchers, pos, to); o = outgoing; while(o) { @@ -391,11 +423,32 @@ { struct queue_ent *ch; int res = 0; + time_t now; for (;;) { /* Atomically read the parent head */ pthread_mutex_lock(&qe->parent->lock); ch = qe->parent->head; + time(&now); + if ( (qe->announcetimeout > 0) && ((now - qe->last_pos) >= qe->announcetimeout) ) { + qe->last_pos = now; + ast_moh_stop(qe->chan); + //playback(qe->chan, "pos", "QueueAnnouncement"); + ast_stopstream(qe->chan); + int res2; + res2 = ast_streamfile(qe->chan, "QueueAnnouncement", qe->chan->language); + if (!res2) + res2 = ast_waitstream(qe->chan, ""); + else + res2 = 0; + if (res2) { + ast_log(LOG_WARNING, "ast_streamfile failed on %s \n", qe->chan->name); + res2 = 0; + } + ast_stopstream(qe->chan); + ast_moh_start(qe->chan, qe->moh); + } pthread_mutex_unlock(&qe->parent->lock); + /* If we are now at the top of the head, break out */ if (qe->parent->head == qe) break; @@ -645,10 +698,11 @@ char *options = NULL; char *url = NULL; char *announceoverride = NULL; - + time_t now; /* Our queue entry */ struct queue_ent qe; + if (!data) { ast_log(LOG_WARNING, "Queue requires an argument (queuename|optional timeout|optional URL)\n"); return -1; @@ -682,11 +736,31 @@ memset(&qe, 0, sizeof(qe)); qe.chan = chan; qe.start = time(NULL); + qe.last_pos = qe.start; + qe.last_adv = qe.start; if (!join_queue(queuename, &qe)) { /* Start music on hold */ + //playback(chan, "pos", "YouArePos"); + ast_stopstream(chan); + int res2; + res2 = ast_streamfile(chan, "YouArePos", chan->language); + if (!res2) + res2 = ast_waitstream(chan, ""); + else + res2 = 0; + if (res2) { + ast_log(LOG_WARNING, "ast_streamfile failed on %s \n", chan->name); + res2 = 0; + } + ast_stopstream(chan); + qe.last_pos_said = qe.pos; + ast_say_number(chan, qe.pos, AST_DIGIT_ANY, chan->language); ast_moh_start(chan, qe.moh); for (;;) { res = wait_our_turn(&qe); + qe.start = time(NULL); + qe.last_pos = qe.start; + qe.last_adv = qe.start; /* If they hungup, return immediately */ if (res < 0) { if (option_verbose > 2) { @@ -705,6 +779,15 @@ res = try_calling(&qe, options, announceoverride, url); if (res) break; + time(&now); + if ( (qe.advert_timeout > 0) && ((now - qe.last_adv) >= qe.advert_timeout) ) { + qe.last_pos = now; + ast_log(LOG_WARNING, "timeout, play message?\n"); + //ast_moh_stop(chan); + //playback(chan, "adv", "YouArePos"); + //ast_say_number(chan, 1, AST_DIGIT_ANY, chan->language); + //ast_moh_start(chan, qe.moh); + } res = wait_a_bit(&qe); if (res < 0) { if (option_verbose > 2) { @@ -779,10 +862,14 @@ /* Re-initialize the queue */ q->dead = 0; q->retry = 0; + q->announcetimeout = 0; + q->advert_timeout = 0; + q->retry = 0; q->timeout = -1; q->maxlen = 0; free_members(q); strcpy(q->moh, ""); + strcpy(q->adv, ""); strcpy(q->announce, ""); strcpy(q->context, ""); prev = NULL; @@ -809,12 +896,18 @@ } } else if (!strcasecmp(var->name, "music")) { strncpy(q->moh, var->value, sizeof(q->moh) - 1); + } else if (!strcasecmp(var->name, "advert_dir")) { + strncpy(q->adv, var->value, sizeof(q->adv) - 1); } else if (!strcasecmp(var->name, "announce")) { strncpy(q->announce, var->value, sizeof(q->announce) - 1); } else if (!strcasecmp(var->name, "context")) { strncpy(q->context, var->value, sizeof(q->context) - 1); } else if (!strcasecmp(var->name, "timeout")) { q->timeout = atoi(var->value); + } else if (!strcasecmp(var->name, "announcetimeout")) { + q->announcetimeout = atoi(var->value); + } else if (!strcasecmp(var->name, "advert_timeout")) { + q->advert_timeout = atoi(var->value); } else if (!strcasecmp(var->name, "retry")) { q->retry = atoi(var->value); } else if (!strcasecmp(var->name, "maxlen")) { @@ -963,3 +1056,5 @@ { return ASTERISK_GPL_KEY; } + +