--- asterisk/apps/app_queue.c 2004-10-04 23:46:11.000000000 -0700 +++ app_queue.c 2004-10-08 20:11:37.000000000 -0700 @@ -168,6 +168,8 @@ int prio; /* Our priority */ int last_pos_said; /* Last position we told the user */ time_t last_pos; /* Last time we told the user their position */ + time_t last_msg1; /* Last time we played the user message 1 */ + time_t last_msg2; /* Last time we played the user message 2 */ int opos; /* Where we started in the queue */ int handled; /* Whether our call was handled */ time_t start; /* When we started holding */ @@ -201,6 +203,8 @@ int callsabandoned; /* Number of queue calls abandoned */ int servicelevel; /* seconds setting for servicelevel*/ int callscompletedinsl; /* Number of queue calls answererd with servicelevel*/ + int announcemsg1; /* Frequency to announce message 1 */ + int announcemsg2; /* Frequency to announce message 2 */ char monfmt[8]; /* Format to use when recording calls */ int monjoin; /* Should we join the two files when we are done with the call */ char sound_next[80]; /* Sound file: "Your call is now first in line" (def. queue-youarenext) */ @@ -212,6 +216,8 @@ char sound_seconds[80]; /* Sound file: "seconds." (def. queue-seconds) */ char sound_thanks[80]; /* Sound file: "Thank you for your patience." (def. queue-thankyou) */ char sound_reporthold[80]; /* Sound file: "Hold time" (def. queue-reporthold) */ + char sound_message1[80]; /* Sound file: Message played every announcemsg1 frequency */ + char sound_message2[80]; /* Sound file: Message played every announcemsg2 frequency */ int count; /* How many entries are in the queue */ int maxlen; /* Max number of entries in queue */ @@ -399,6 +405,81 @@ return res; } +static int say_message1(struct queue_ent *qe) +{ + int res=0; + time_t now; + + time(&now); + + /* If the caller has just entered the queue, and message 1 delay hasnt completed, return */ + if ( (now - qe->start) < qe->parent->announcemsg1 ) + return -1; + + /* If message 2 is set, but hasn't been played and message 1 has been played, return */ + if ( qe->parent->announcemsg2 && (qe->last_msg2 == 0) && qe->last_msg1 ) + return -1; + + /* If message 2 is not set and message 1 delay has not been reached since last message 1, return */ + if ( (qe->parent->announcemsg2 == 0) && ( (now - qe->last_msg1) < qe->parent->announcemsg1) ) + return -1; + + /* If message 2 has been played, and delay has not passed for message 1, return */ + if ( qe->last_msg2 && ( (now - qe->last_msg2) < qe->parent->announcemsg1) ) + return -1; + + /* if message 2 is set and message 1 is more recent than message 2, return */ + if ( qe->last_msg2 && qe->last_msg2 < qe->last_msg1 ) + return -1; + + /* if the position announcement is about to happen, don't play until after it does. */ + if ( qe->parent->announcefrequency && ( qe->parent->announcefrequency - ( now - qe->last_pos )) < 10 ) + return -1; + + ast_moh_stop(qe->chan); + res += play_file(qe->chan, qe->parent->sound_message1); + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Told %s in %s message 1\n", qe->chan->name, qe->parent->name); + qe->last_msg1 = now; + ast_moh_start(qe->chan, qe->moh); + + return (res>0); +} + +static int say_message2(struct queue_ent *qe) +{ + int res=0; + time_t now; + + time(&now); + + /* If message 1 hasn't played, then we don't play. */ + if (qe->last_msg1 == 0) + return -1; + + /* If message 2 delay hasn't passed since message 1, then return */ + if ( (now - qe->last_msg1) < qe->parent->announcemsg2 ) + return -1; + + /* If message 2 has been played more recently than message 1, return */ + if ( qe->last_msg1 < qe->last_msg2 ) + return -1; + + /* if the position announcement is about to happen, don't play until after it does. */ + if ( qe->parent->announcefrequency && ( qe->parent->announcefrequency - ( now - qe->last_pos) ) < 10 ) + return -1; + + ast_moh_stop(qe->chan); + res += play_file(qe->chan, qe->parent->sound_message2); + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Told %s in %s message 2\n", qe->chan->name, qe->parent->name); + qe->last_msg2 = now; + ast_moh_start(qe->chan, qe->moh); + + return (res>0); +} + + static int say_position(struct queue_ent *qe) { int res = 0, avgholdmins, avgholdsecs; @@ -413,6 +494,13 @@ if ( (qe->last_pos_said == qe->pos) && ((now - qe->last_pos) < qe->parent->announcefrequency) ) return -1; + /* If we are first and there is an agent active, override announce */ + if ( (qe->last_pos_said == 0) && (qe->pos == 1) && qe->parent->members ) { + qe->last_pos = now; + qe->last_pos_said = qe->pos; + return -1; + } + ast_moh_stop(qe->chan); /* Say we're next, if we are */ if (qe->pos == 1) { @@ -1006,6 +1094,13 @@ if (qe->parent->announcefrequency && !ringing) say_position(qe); + /* Make alternate message announcements if enabled */ + if (qe->parent->announcemsg1 && !ringing) + say_message1(qe); + + if (qe->parent->announcemsg2 && !ringing) + say_message2(qe); + /* Wait a second before checking again */ res = ast_waitfordigit(qe->chan, RECHECK * 1000); if (res) @@ -1696,6 +1791,8 @@ qe.prio = (int)prio; qe.last_pos_said = 0; qe.last_pos = 0; + qe.last_msg1 = 0; + qe.last_msg2 = 0; if (!join_queue(queuename, &qe)) { ast_queue_log(queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s", url ? url : "", chan->cid.cid_num ? chan->cid.cid_num : ""); /* Start music on hold */ @@ -1749,6 +1846,14 @@ /* Make a position announcement, if enabled */ if (qe.parent->announcefrequency && !ringing) say_position(&qe); + + /* Make alternate message announcements if enabled */ + if (qe.parent->announcemsg1 && !ringing) + say_message1(&qe); + + if (qe.parent->announcemsg2 && !ringing) + say_message2(&qe); + /* Try calling all queue members for 'timeout' seconds */ res = try_calling(&qe, options, announceoverride, url, &go_on); @@ -1874,6 +1979,8 @@ q->maxlen = 0; q->announcefrequency = 0; q->announceholdtime = 0; + q->announcemsg1 = 0; + q->announcemsg2 = 0; q->roundingseconds = 0; /* Default - don't announce seconds */ q->holdtime = 0; q->callscompleted = 0; @@ -1895,6 +2002,8 @@ strncpy(q->sound_thanks, "queue-thankyou", sizeof(q->sound_thanks) - 1); strncpy(q->sound_lessthan, "queue-less-than", sizeof(q->sound_lessthan) - 1); strncpy(q->sound_reporthold, "queue-reporthold", sizeof(q->sound_reporthold) - 1); + strncpy(q->sound_message1, "queue-message-1", sizeof(q->sound_message1) - 1 ); + strncpy(q->sound_message2, "queue-message-2", sizeof(q->sound_message2) - 1); prev = q->members; if (prev) { /* find the end of any dynamic members */ @@ -1961,8 +2070,16 @@ strncpy(q->sound_thanks, var->value, sizeof(q->sound_thanks) - 1); } else if (!strcasecmp(var->name, "queue-reporthold")) { strncpy(q->sound_reporthold, var->value, sizeof(q->sound_reporthold) - 1); + } else if (!strcasecmp(var->name, "queue-message-1")) { + strncpy(q->sound_message1, var->value, sizeof(q->sound_message1) - 1); + } else if (!strcasecmp(var->name, "queue-message-2")) { + strncpy(q->sound_message2, var->value, sizeof(q->sound_message2) - 1); } else if (!strcasecmp(var->name, "announce-frequency")) { q->announcefrequency = atoi(var->value); + } else if (!strcasecmp(var->name, "announce-message-1")) { + q->announcemsg1 = atoi(var->value); + } else if (!strcasecmp(var->name, "announce-message-2")) { + q->announcemsg2 = atoi(var->value); } else if (!strcasecmp(var->name, "announce-round-seconds")) { q->roundingseconds = atoi(var->value); if(q->roundingseconds>60 || q->roundingseconds<0) {