[asterisk-commits] mmichelson: trunk r103658 - in /trunk: UPGRADE.txt res/res_musiconhold.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 13 09:47:25 CST 2008


Author: mmichelson
Date: Wed Feb 13 09:47:25 2008
New Revision: 103658

URL: http://svn.digium.com/view/asterisk?view=rev&rev=103658
Log:
1. Deprecate SetMusicOnHold and WaitMusicOnHold.
2. Add a duration parameter to MusicOnHold

(closes issue #11904)
Reported by: dimas
Patches:
      v2-moh.patch uploaded by dimas (license 88)
	  Tested by: dimas


Modified:
    trunk/UPGRADE.txt
    trunk/res/res_musiconhold.c

Modified: trunk/UPGRADE.txt
URL: http://svn.digium.com/view/asterisk/trunk/UPGRADE.txt?view=diff&rev=103658&r1=103657&r2=103658
==============================================================================
--- trunk/UPGRADE.txt (original)
+++ trunk/UPGRADE.txt Wed Feb 13 09:47:25 2008
@@ -92,6 +92,11 @@
   you need to do so explicitly in your dialplan.
 * Privacy() no longer uses privacy.conf, so any options must be specified
   directly in the application arguments.
+* MusicOnHold application now has duration parameter which allows specifying
+  timeout in seconds.
+* WaitMusicOnHold application is now deprecated in favor of extended MusicOnHold.
+* SetMusicOnHold is now deprecated. You should use Set(CHANNEL(musicclass)=...)
+  instead.
 
 Dialplan Functions:
 

Modified: trunk/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_musiconhold.c?view=diff&rev=103658&r1=103657&r2=103658
==============================================================================
--- trunk/res/res_musiconhold.c (original)
+++ trunk/res/res_musiconhold.c Wed Feb 13 09:47:25 2008
@@ -52,6 +52,7 @@
 #include "asterisk/file.h"
 #include "asterisk/channel.h"
 #include "asterisk/pbx.h"
+#include "asterisk/app.h"
 #include "asterisk/module.h"
 #include "asterisk/translate.h"
 #include "asterisk/say.h"
@@ -76,22 +77,33 @@
 static char *start_moh_syn = "Play Music On Hold";
 static char *stop_moh_syn = "Stop Playing Music On Hold";
 
-static char *play_moh_desc = "  MusicOnHold(class):\n"
+static char *play_moh_desc = "  MusicOnHold(class[,duration]):\n"
 "Plays hold music specified by class.  If omitted, the default\n"
-"music source for the channel will be used. Set the default \n"
-"class with the SetMusicOnHold() application.\n"
-"Returns -1 on hangup.\n"
-"Never returns otherwise.\n";
+"music source for the channel will be used. Change the default \n"
+"class with Set(CHANNEL(musicclass)=...).\n"
+"If duration is given, hold music will be played specified number\n"
+"of seconds. If duration is ommited, music plays indefinitely.\n"
+"Returns 0 when done, -1 on hangup.\n";
 
 static char *wait_moh_desc = "  WaitMusicOnHold(delay):\n"
+"\n"
+"  !!! DEPRECATED. Use MusicOnHold instead !!!\n"
+"\n"
 "Plays hold music specified number of seconds.  Returns 0 when\n"
 "done, or -1 on hangup.  If no hold music is available, the delay will\n"
-"still occur with no sound.\n";
+"still occur with no sound.\n"
+"\n"
+"  !!! DEPRECATED. Use MusicOnHold instead !!!\n";
 
 static char *set_moh_desc = "  SetMusicOnHold(class):\n"
+"\n"
+"  !!! DEPRECATED. USe Set(CHANNEL(musicclass)=...) instead !!!\n"
+"\n"
 "Sets the default class for music on hold for a given channel.  When\n"
 "music on hold is activated, this class will be used to select which\n"
-"music is played.\n";
+"music is played.\n"
+"\n"
+"  !!! DEPRECATED. USe Set(CHANNEL(musicclass)=...) instead !!!\n";
 
 static char *start_moh_desc = "  StartMusicOnHold(class):\n"
 "Starts playing music on hold, uses default music class for channel.\n"
@@ -610,18 +622,54 @@
 
 static int play_moh_exec(struct ast_channel *chan, void *data)
 {
-	if (ast_moh_start(chan, data, NULL)) {
-		ast_log(LOG_WARNING, "Unable to start music on hold (class '%s') on channel %s\n", (char *)data, chan->name);
+	char *parse;
+	char *class;
+	int timeout = -1;
+	int res;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(class);
+		AST_APP_ARG(duration);
+	);
+
+	parse = ast_strdupa(data);
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (!ast_strlen_zero(args.duration)) {
+		if (sscanf(args.duration, "%d", &timeout) == 1) {
+			timeout *= 1000;
+		} else {
+			ast_log(LOG_WARNING, "Invalid MusicOnHold duration '%s'. Will wait indefinitely.\n", args.duration);
+		}
+	}
+
+	class = S_OR(args.class, NULL);
+	if (ast_moh_start(chan, class, NULL)) {
+		ast_log(LOG_WARNING, "Unable to start music on hold class '%s' on channel %s\n", class, chan->name);
 		return 0;
 	}
-	while (!ast_safe_sleep(chan, 10000));
+
+	if (timeout > 0)
+		res = ast_safe_sleep(chan, timeout);
+	else {
+		while (!(res = ast_safe_sleep(chan, 10000)));
+	}
+
 	ast_moh_stop(chan);
-	return -1;
+
+	return res;
 }
 
 static int wait_moh_exec(struct ast_channel *chan, void *data)
 {
+	static int deprecation_warning = 0;
 	int res;
+
+	if (!deprecation_warning) {
+		deprecation_warning = 1;
+		ast_log(LOG_WARNING, "WaitMusicOnHold application is deprecated and will be removed. Use MusicOnHold with duration parameter instead\n");
+	}
+
 	if (!data || !atoi(data)) {
 		ast_log(LOG_WARNING, "WaitMusicOnHold requires an argument (number of seconds to wait)\n");
 		return -1;
@@ -637,6 +685,13 @@
 
 static int set_moh_exec(struct ast_channel *chan, void *data)
 {
+	static int deprecation_warning = 0;
+
+	if (!deprecation_warning) {
+		deprecation_warning = 1;
+		ast_log(LOG_WARNING, "SetMusicOnHold application is deprecated and will be removed. Use Set(CHANNEL(musicclass)=...) instead\n");
+	}
+
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "SetMusicOnHold requires an argument (class)\n");
 		return -1;
@@ -647,11 +702,19 @@
 
 static int start_moh_exec(struct ast_channel *chan, void *data)
 {
-	char *class = NULL;
-	if (data && strlen(data))
-		class = data;
+	char *parse;
+	char *class;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(class);
+	);
+
+	parse = ast_strdupa(data);
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	class = S_OR(args.class, NULL);
 	if (ast_moh_start(chan, class, NULL)) 
-		ast_log(LOG_NOTICE, "Unable to start music on hold class '%s' on channel %s\n", class ? class : "default", chan->name);
+		ast_log(LOG_WARNING, "Unable to start music on hold class '%s' on channel %s\n", class, chan->name);
 
 	return 0;
 }




More information about the asterisk-commits mailing list