From b283a02a7df767a62d7b9db57be2c6eba99f70d1 Mon Sep 17 00:00:00 2001
From: Mark Spencer <markster@digium.com>
Date: Mon, 28 Jun 2004 20:17:20 +0000
Subject: [PATCH] Merge seconds announcement for queue hold time (bug #1941)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3332 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 apps/app_queue.c           |  41 ++++++++++++++++++++++++++++++-------
 configs/queues.conf.sample |   7 +++++++
 sounds.txt                 |   2 ++
 sounds/queue-seconds.gsm   | Bin 0 -> 1386 bytes
 4 files changed, 43 insertions(+), 7 deletions(-)
 create mode 100755 sounds/queue-seconds.gsm

diff --git a/apps/app_queue.c b/apps/app_queue.c
index 102baa7e2b..29efabb5e5 100755
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -187,6 +187,7 @@ struct ast_call_queue {
 	char context[80];		/* Context for this queue */
 	int strategy;			/* Queueing strategy */
 	int announcefrequency;          /* How often to announce their position */
+	int roundingseconds;            /* How many seconds do we round to? */
 	int announceholdtime;           /* When to announce holdtime: 0 = never, -1 = every announcement, 1 = only once */
 	int holdtime;                   /* Current avg holdtime for this queue, based on recursive boxcar filter */
 	int callscompleted;             /* Number of queue calls completed */
@@ -200,6 +201,7 @@ struct ast_call_queue {
 	char sound_calls[80];           /* Sound file: "calls waiting to speak to a representative." (def. queue-callswaiting)*/
 	char sound_holdtime[80];        /* Sound file: "The current estimated total holdtime is" (def. queue-holdtime) */
 	char sound_minutes[80];         /* Sound file: "minutes." (def. queue-minutes) */
+	char sound_seconds[80];         /* Sound file: "seconds." (def. queue-seconds) */
 	char sound_thanks[80];          /* Sound file: "Thank you for your patience." (def. queue-thankyou) */
 
 	int count;			/* How many entries are in the queue */
@@ -386,7 +388,7 @@ static int play_file(struct ast_channel *chan, char *filename)
 
 static int say_position(struct queue_ent *qe)
 {
-	int res = 0, avgholdmins;
+	int res = 0, avgholdmins, avgholdsecs;
 	time_t now;
 
 	/* Check to see if this is ludicrous -- if we just announced position, don't do it again*/
@@ -408,18 +410,33 @@ static int say_position(struct queue_ent *qe)
 		res += ast_say_number(qe->chan, qe->pos, AST_DIGIT_ANY, qe->chan->language, (char *) NULL); /* Needs gender */
 		res += play_file(qe->chan, qe->parent->sound_calls);
 	}
-
 	/* Round hold time to nearest minute */
-	avgholdmins = ( (qe->parent->holdtime + 30) - (now - qe->start) ) / 60;
+	avgholdmins = abs(( (qe->parent->holdtime + 30) - (now - qe->start) ) / 60);
+
+	/* If they have specified a rounding then round the seconds as well */
+	if(qe->parent->roundingseconds) {
+		avgholdsecs = (abs(( (qe->parent->holdtime + 30) - (now - qe->start) )) - 60 * avgholdmins) / qe->parent->roundingseconds;
+		avgholdsecs*= qe->parent->roundingseconds;
+	} else {
+		avgholdsecs=0;
+	}
+
 	if (option_verbose > 2)
-		ast_verbose(VERBOSE_PREFIX_3 "Hold time for %s is %d minutes\n", qe->parent->name, avgholdmins);
+		ast_verbose(VERBOSE_PREFIX_3 "Hold time for %s is %d minutes %d seconds\n", qe->parent->name, avgholdmins, avgholdsecs);
 
 	/* If the hold time is >1 min, if it's enabled, and if it's not
 	   supposed to be only once and we have already said it, say it */
-	if (avgholdmins > 1 && (qe->parent->announceholdtime) && (!(qe->parent->announceholdtime==1 && qe->last_pos)) ) {
+	if ((avgholdmins+avgholdsecs) > 0 && (qe->parent->announceholdtime) && (!(qe->parent->announceholdtime==1 && qe->last_pos)) ) {
 		res += play_file(qe->chan, qe->parent->sound_holdtime);
-		res += ast_say_number(qe->chan, avgholdmins, AST_DIGIT_ANY, qe->chan->language, (char*) NULL);
-		res += play_file(qe->chan, qe->parent->sound_minutes);
+		if(avgholdmins>0) {
+			res += ast_say_number(qe->chan, avgholdmins, AST_DIGIT_ANY, qe->chan->language, (char*) NULL);
+			res += play_file(qe->chan, qe->parent->sound_minutes);
+		}
+		if(avgholdsecs>0) {
+			res += ast_say_number(qe->chan, avgholdsecs, AST_DIGIT_ANY, qe->chan->language, (char*) NULL);
+			res += play_file(qe->chan, qe->parent->sound_seconds);
+		}
+
 	}
 
 	posout:
@@ -1708,6 +1725,7 @@ static void reload_queues(void)
 				q->maxlen = 0;
 				q->announcefrequency = 0;
 				q->announceholdtime = 0;
+				q->roundingseconds = 0; /* Default - don't announce seconds */
 				q->holdtime = 0;
 				q->callscompleted = 0;
 				q->callsabandoned = 0;
@@ -1724,6 +1742,7 @@ static void reload_queues(void)
 				strcpy(q->sound_calls, "queue-callswaiting");
 				strcpy(q->sound_holdtime, "queue-holdtime");
 				strcpy(q->sound_minutes, "queue-minutes");
+				strcpy(q->sound_seconds, "queue-seconds");
 				strcpy(q->sound_thanks, "queue-thankyou");
 				prev = q->members;
 				if (prev) {
@@ -1783,10 +1802,18 @@ static void reload_queues(void)
 						strncpy(q->sound_holdtime, var->value, sizeof(q->sound_holdtime) - 1);
 					} else if (!strcasecmp(var->name, "queue-minutes")) {
 						strncpy(q->sound_minutes, var->value, sizeof(q->sound_minutes) - 1);
+					} else if (!strcasecmp(var->name, "queue-seconds")) {
+						strncpy(q->sound_seconds, var->value, sizeof(q->sound_seconds) - 1);
 					} else if (!strcasecmp(var->name, "queue-thankyou")) {
 						strncpy(q->sound_thanks, var->value, sizeof(q->sound_thanks) - 1);
 					} else if (!strcasecmp(var->name, "announce-frequency")) {
 						q->announcefrequency = atoi(var->value);
+					} else if (!strcasecmp(var->name, "announce-round-seconds")) {
+						q->roundingseconds = atoi(var->value);
+						if(q->roundingseconds>60 || q->roundingseconds<0) {
+							ast_log(LOG_WARNING, "'%s' isn't a valid value for queue-rounding-seconds using 0 instead at line %d of queue.conf\n", var->value, var->lineno);
+							q->roundingseconds=0;
+						}
 					} else if (!strcasecmp(var->name, "announce-holdtime")) {
 						q->announceholdtime = (!strcasecmp(var->value,"once")) ? 1 : ast_true(var->value);
 					} else if (!strcasecmp(var->name, "retry")) {
diff --git a/configs/queues.conf.sample b/configs/queues.conf.sample
index 4d483393c4..66ed932420 100755
--- a/configs/queues.conf.sample
+++ b/configs/queues.conf.sample
@@ -73,6 +73,12 @@
 ; Either yes, no, or only once; hold time will not be announced if <1 minute
 ;
 ;announce-holdtime = yes|no|once
+
+;
+; What's the rounding time for the seconds?
+; If this is non zero then we announce the seconds as well as the minutes rounded to this value
+;
+; announce-round-seconds = 10
 ;
 ; Use these sound files in making position/holdtime announcements.  The
 ; defaults are as listed below -- change only if you need to.
@@ -82,6 +88,7 @@
 ;queue-callswaiting = queue-callswaiting	;	("calls waiting.")
 ;queue-holdtime = queue-holdtime		;	("The current est. holdtime is")
 ;queue-minutes = queue-minutes			;	("minutes.")
+;queue-seconds = queue-seconds			;	("seconds.")
 ;queue-thankyou = queue-thankyou		;	("Thank you for your patience.")
 ;
 ; Calls may be recorded using Asterisk's monitor resource
diff --git a/sounds.txt b/sounds.txt
index ce7e5a4a87..4a6276d47d 100755
--- a/sounds.txt
+++ b/sounds.txt
@@ -82,6 +82,8 @@
 
 %queue-minutes.gsm%Minutes
 
+%queue-seconds.gsm%Seconds
+
 %queue-thankyou.gsm%Thank you for your patience
 
 %queue-thereare.gsm%You are currently caller number
diff --git a/sounds/queue-seconds.gsm b/sounds/queue-seconds.gsm
new file mode 100755
index 0000000000000000000000000000000000000000..a2d55d5bc66bdf93a9ab7e2c9df7f23d2f0d44be
GIT binary patch
literal 1386
zcmcbf=*cl7fI;JS;dbc&2Y0F79e1J}%$`iLls?knsa&LS`{t@SUXDo#>e7WP($*`e
zTrRUoNjPAi5~sZ=Tj6wV=#D!#-pmP_)V1K!tzMBks}8KVw9D<@ONHgasf!lhR5)^E
z>9&}gdUL`Yk26Z$Dcq_w?ZA;cSv%xjEtrwyD#Ntc(PZ@uvvoH&9=Y~(&4RAWE~#w0
z4!PXUoUan7)bjeQ#*(B%)^}EA3f|Cap4Bzo$uIexS60&^cTv$Jx6dr`xYhe@QAqNw
zCDXPzURmn%j<r+Ev!tipEaT}l*GW5*S8{Tv<X+kR*lWjQ>#4J^ysXP;DSol>)mAgz
z)hq7DWH|3BUKw_C;jK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