[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi BaseAGIScript.java,1.3,1.4 A
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-09-13 00:56:14
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3300/src/java/net/sf/asterisk/fastagi Modified Files: BaseAGIScript.java AbstractAGIScript.java AGIChannel.java Log Message: moved agi command methods to AGIChannel Index: BaseAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/BaseAGIScript.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- BaseAGIScript.java 27 Aug 2005 02:07:35 -0000 1.3 +++ BaseAGIScript.java 13 Sep 2005 00:56:05 -0000 1.4 @@ -18,27 +18,6 @@ package net.sf.asterisk.fastagi; import net.sf.asterisk.fastagi.command.AGICommand; import net.sf.asterisk.fastagi.command.AnswerCommand; -import net.sf.asterisk.fastagi.command.ChannelStatusCommand; -import net.sf.asterisk.fastagi.command.ExecCommand; -import net.sf.asterisk.fastagi.command.GetDataCommand; -import net.sf.asterisk.fastagi.command.GetOptionCommand; -import net.sf.asterisk.fastagi.command.GetVariableCommand; -import net.sf.asterisk.fastagi.command.HangupCommand; -import net.sf.asterisk.fastagi.command.SayAlphaCommand; -import net.sf.asterisk.fastagi.command.SayDigitsCommand; -import net.sf.asterisk.fastagi.command.SayNumberCommand; -import net.sf.asterisk.fastagi.command.SayPhoneticCommand; -import net.sf.asterisk.fastagi.command.SayTimeCommand; -import net.sf.asterisk.fastagi.command.SetAutoHangupCommand; -import net.sf.asterisk.fastagi.command.SetCallerIdCommand; -import net.sf.asterisk.fastagi.command.SetContextCommand; -import net.sf.asterisk.fastagi.command.SetExtensionCommand; -import net.sf.asterisk.fastagi.command.SetMusicOffCommand; -import net.sf.asterisk.fastagi.command.SetMusicOnCommand; -import net.sf.asterisk.fastagi.command.SetPriorityCommand; -import net.sf.asterisk.fastagi.command.SetVariableCommand; -import net.sf.asterisk.fastagi.command.StreamFileCommand; -import net.sf.asterisk.fastagi.command.WaitForDigitCommand; import net.sf.asterisk.fastagi.reply.AGIReply; /** @@ -65,7 +44,7 @@ public abstract class BaseAGIScript impl */ protected void hangup() throws AGIException { - sendCommand(new HangupCommand()); + getChannel().hangup(); } /** @@ -78,7 +57,7 @@ public abstract class BaseAGIScript impl */ protected void setAutoHangup(int time) throws AGIException { - sendCommand(new SetAutoHangupCommand(time)); + getChannel().setAutoHangup(time); } /** @@ -88,7 +67,7 @@ public abstract class BaseAGIScript impl */ protected void setCallerId(String callerId) throws AGIException { - sendCommand(new SetCallerIdCommand(callerId)); + getChannel().setCallerId(callerId); } /** @@ -96,7 +75,7 @@ public abstract class BaseAGIScript impl */ protected void playMusicOnHold() throws AGIException { - sendCommand(new SetMusicOnCommand()); + getChannel().playMusicOnHold(); } /** @@ -107,7 +86,7 @@ public abstract class BaseAGIScript impl */ protected void playMusicOnHold(String musicOnHoldClass) throws AGIException { - sendCommand(new SetMusicOnCommand(musicOnHoldClass)); + getChannel().playMusicOnHold(musicOnHoldClass); } /** @@ -115,7 +94,7 @@ public abstract class BaseAGIScript impl */ protected void stopMusicOnHold() throws AGIException { - sendCommand(new SetMusicOffCommand()); + getChannel().stopMusicOnHold(); } /** @@ -136,10 +115,7 @@ public abstract class BaseAGIScript impl */ protected int getChannelStatus() throws AGIException { - AGIReply reply; - - reply = sendCommand(new ChannelStatusCommand()); - return reply.getResultCode(); + return getChannel().getChannelStatus(); } /** @@ -152,10 +128,7 @@ public abstract class BaseAGIScript impl */ protected String getData(String file) throws AGIException { - AGIReply reply; - - reply = sendCommand(new GetDataCommand(file)); - return reply.getResult(); + return getChannel().getData(file); } /** @@ -171,10 +144,7 @@ public abstract class BaseAGIScript impl */ protected String getData(String file, int timeout) throws AGIException { - AGIReply reply; - - reply = sendCommand(new GetDataCommand(file, timeout)); - return reply.getResult(); + return getChannel().getData(file, timeout); } /** @@ -194,10 +164,7 @@ public abstract class BaseAGIScript impl protected String getData(String file, int timeout, int maxDigits) throws AGIException { - AGIReply reply; - - reply = sendCommand(new GetDataCommand(file, timeout, maxDigits)); - return reply.getResult(); + return getChannel().getData(file, timeout, maxDigits); } /** @@ -214,10 +181,7 @@ public abstract class BaseAGIScript impl protected char getOption(String file, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = sendCommand(new GetOptionCommand(file, escapeDigits)); - return reply.getResultCodeAsChar(); + return getChannel().getOption(file, escapeDigits); } /** @@ -236,10 +200,7 @@ public abstract class BaseAGIScript impl protected char getOption(String file, String escapeDigits, int timeout) throws AGIException { - AGIReply reply; - - reply = sendCommand(new GetOptionCommand(file, escapeDigits, timeout)); - return reply.getResultCodeAsChar(); + return getChannel().getOption(file, escapeDigits, timeout); } /** @@ -252,10 +213,7 @@ public abstract class BaseAGIScript impl */ protected int exec(String application) throws AGIException { - AGIReply reply; - - reply = sendCommand(new ExecCommand(application)); - return reply.getResultCode(); + return getChannel().exec(application); } /** @@ -270,10 +228,7 @@ public abstract class BaseAGIScript impl */ protected int exec(String application, String options) throws AGIException { - AGIReply reply; - - reply = sendCommand(new ExecCommand(application, options)); - return reply.getResultCode(); + return getChannel().exec(application, options); } /** @@ -283,7 +238,7 @@ public abstract class BaseAGIScript impl */ protected void setContext(String context) throws AGIException { - sendCommand(new SetContextCommand(context)); + getChannel().setContext(context); } /** @@ -294,7 +249,7 @@ public abstract class BaseAGIScript impl */ protected void setExtension(String extension) throws AGIException { - sendCommand(new SetExtensionCommand(extension)); + getChannel().setExtension(extension); } /** @@ -305,7 +260,7 @@ public abstract class BaseAGIScript impl */ protected void setPriority(int priority) throws AGIException { - sendCommand(new SetPriorityCommand(priority)); + getChannel().setPriority(priority); } /** @@ -315,7 +270,7 @@ public abstract class BaseAGIScript impl */ protected void streamFile(String file) throws AGIException { - sendCommand(new StreamFileCommand(file)); + getChannel().streamFile(file); } /** @@ -330,10 +285,7 @@ public abstract class BaseAGIScript impl protected char streamFile(String file, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = sendCommand(new StreamFileCommand(file, escapeDigits)); - return reply.getResultCodeAsChar(); + return getChannel().streamFile(file, escapeDigits); } /** @@ -343,7 +295,7 @@ public abstract class BaseAGIScript impl */ protected void sayDigits(String digits) throws AGIException { - sendCommand(new SayDigitsCommand(digits)); + getChannel().sayDigits(digits); } /** @@ -358,10 +310,7 @@ public abstract class BaseAGIScript impl protected char sayDigits(String digits, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = sendCommand(new SayDigitsCommand(digits, escapeDigits)); - return reply.getResultCodeAsChar(); + return getChannel().sayDigits(digits, escapeDigits); } /** @@ -371,7 +320,7 @@ public abstract class BaseAGIScript impl */ protected void sayNumber(String number) throws AGIException { - sendCommand(new SayNumberCommand(number)); + getChannel().sayNumber(number); } /** @@ -386,10 +335,7 @@ public abstract class BaseAGIScript impl protected char sayNumber(String number, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = sendCommand(new SayNumberCommand(number, escapeDigits)); - return reply.getResultCodeAsChar(); + return getChannel().sayNumber(number, escapeDigits); } /** @@ -399,7 +345,7 @@ public abstract class BaseAGIScript impl */ protected void sayPhonetic(String text) throws AGIException { - sendCommand(new SayPhoneticCommand(text)); + getChannel().sayPhonetic(text); } /** @@ -414,10 +360,7 @@ public abstract class BaseAGIScript impl protected char sayPhonetic(String text, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = sendCommand(new SayPhoneticCommand(text, escapeDigits)); - return reply.getResultCodeAsChar(); + return getChannel().sayPhonetic(text, escapeDigits); } /** @@ -427,7 +370,7 @@ public abstract class BaseAGIScript impl */ protected void sayAlpha(String text) throws AGIException { - sendCommand(new SayAlphaCommand(text)); + getChannel().sayAlpha(text); } /** @@ -442,10 +385,7 @@ public abstract class BaseAGIScript impl protected char sayAlpha(String text, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = sendCommand(new SayAlphaCommand(text, escapeDigits)); - return reply.getResultCodeAsChar(); + return getChannel().sayAlpha(text, escapeDigits); } /** @@ -455,7 +395,7 @@ public abstract class BaseAGIScript impl */ protected void sayTime(long time) throws AGIException { - sendCommand(new SayTimeCommand(time)); + getChannel().sayTime(time); } /** @@ -469,10 +409,7 @@ public abstract class BaseAGIScript impl */ protected char sayTime(long time, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = sendCommand(new SayTimeCommand(time, escapeDigits)); - return reply.getResultCodeAsChar(); + return getChannel().sayTime(time, escapeDigits); } /** @@ -484,14 +421,7 @@ public abstract class BaseAGIScript impl */ protected String getVariable(String name) throws AGIException { - AGIReply reply; - - reply = sendCommand(new GetVariableCommand(name)); - if (reply.getResultCode() != 1) - { - return null; - } - return reply.getExtra(); + return getChannel().getVariable(name); } /** @@ -502,7 +432,7 @@ public abstract class BaseAGIScript impl */ protected void setVariable(String name, String value) throws AGIException { - sendCommand(new SetVariableCommand(name, value)); + getChannel().setVariable(name, value); } /** @@ -514,10 +444,7 @@ public abstract class BaseAGIScript impl */ protected char waitForDigit(int timeout) throws AGIException { - AGIReply reply; - - reply = sendCommand(new WaitForDigitCommand(timeout)); - return reply.getResultCodeAsChar(); + return getChannel().waitForDigit(timeout); } /** @@ -529,6 +456,11 @@ public abstract class BaseAGIScript impl */ private AGIReply sendCommand(AGICommand command) throws AGIException { + return getChannel().sendCommand(command); + } + + private AGIChannel getChannel() + { AGIChannel channel; channel = AGIConnectionHandler.getChannel(); @@ -538,6 +470,6 @@ public abstract class BaseAGIScript impl "Trying to send command from an invalid thread"); } - return channel.sendCommand(command); + return channel; } } Index: AbstractAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AbstractAGIScript.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -p -r1.17 -r1.18 --- AbstractAGIScript.java 27 Aug 2005 02:07:35 -0000 1.17 +++ AbstractAGIScript.java 13 Sep 2005 00:56:05 -0000 1.18 @@ -17,28 +17,6 @@ package net.sf.asterisk.fastagi; import net.sf.asterisk.fastagi.command.AnswerCommand; -import net.sf.asterisk.fastagi.command.ChannelStatusCommand; -import net.sf.asterisk.fastagi.command.ExecCommand; -import net.sf.asterisk.fastagi.command.GetDataCommand; -import net.sf.asterisk.fastagi.command.GetOptionCommand; -import net.sf.asterisk.fastagi.command.GetVariableCommand; -import net.sf.asterisk.fastagi.command.HangupCommand; -import net.sf.asterisk.fastagi.command.SayAlphaCommand; -import net.sf.asterisk.fastagi.command.SayDigitsCommand; -import net.sf.asterisk.fastagi.command.SayNumberCommand; -import net.sf.asterisk.fastagi.command.SayPhoneticCommand; -import net.sf.asterisk.fastagi.command.SayTimeCommand; -import net.sf.asterisk.fastagi.command.SetAutoHangupCommand; -import net.sf.asterisk.fastagi.command.SetCallerIdCommand; -import net.sf.asterisk.fastagi.command.SetContextCommand; -import net.sf.asterisk.fastagi.command.SetExtensionCommand; -import net.sf.asterisk.fastagi.command.SetMusicOffCommand; -import net.sf.asterisk.fastagi.command.SetMusicOnCommand; -import net.sf.asterisk.fastagi.command.SetPriorityCommand; -import net.sf.asterisk.fastagi.command.SetVariableCommand; -import net.sf.asterisk.fastagi.command.StreamFileCommand; -import net.sf.asterisk.fastagi.command.WaitForDigitCommand; -import net.sf.asterisk.fastagi.reply.AGIReply; /** * The AbstractAGIScript provides some convinience methods to make it easier to @@ -64,7 +42,7 @@ public abstract class AbstractAGIScript */ protected void hangup(AGIChannel channel) throws AGIException { - channel.sendCommand(new HangupCommand()); + channel.hangup(); } /** @@ -78,7 +56,7 @@ public abstract class AbstractAGIScript protected void setAutoHangup(AGIChannel channel, int time) throws AGIException { - channel.sendCommand(new SetAutoHangupCommand(time)); + channel.setAutoHangup(time); } /** @@ -89,7 +67,7 @@ public abstract class AbstractAGIScript protected void setCallerId(AGIChannel channel, String callerId) throws AGIException { - channel.sendCommand(new SetCallerIdCommand(callerId)); + channel.setCallerId(callerId); } /** @@ -97,7 +75,7 @@ public abstract class AbstractAGIScript */ protected void playMusicOnHold(AGIChannel channel) throws AGIException { - channel.sendCommand(new SetMusicOnCommand()); + channel.playMusicOnHold(); } /** @@ -109,7 +87,7 @@ public abstract class AbstractAGIScript protected void playMusicOnHold(AGIChannel channel, String musicOnHoldClass) throws AGIException { - channel.sendCommand(new SetMusicOnCommand(musicOnHoldClass)); + channel.playMusicOnHold(musicOnHoldClass); } /** @@ -117,7 +95,7 @@ public abstract class AbstractAGIScript */ protected void stopMusicOnHold(AGIChannel channel) throws AGIException { - channel.sendCommand(new SetMusicOffCommand()); + channel.stopMusicOnHold(); } /** @@ -138,10 +116,7 @@ public abstract class AbstractAGIScript */ protected int getChannelStatus(AGIChannel channel) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new ChannelStatusCommand()); - return reply.getResultCode(); + return channel.getChannelStatus(); } /** @@ -156,10 +131,7 @@ public abstract class AbstractAGIScript protected String getData(AGIChannel channel, String file) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new GetDataCommand(file)); - return reply.getResult(); + return channel.getData(file); } /** @@ -177,10 +149,7 @@ public abstract class AbstractAGIScript protected String getData(AGIChannel channel, String file, int timeout) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new GetDataCommand(file, timeout)); - return reply.getResult(); + return channel.getData(file, timeout); } /** @@ -201,11 +170,7 @@ public abstract class AbstractAGIScript protected String getData(AGIChannel channel, String file, int timeout, int maxDigits) throws AGIException { - AGIReply reply; - - reply = channel - .sendCommand(new GetDataCommand(file, timeout, maxDigits)); - return reply.getResult(); + return channel.getData(file, timeout, maxDigits); } /** @@ -222,10 +187,7 @@ public abstract class AbstractAGIScript protected char getOption(AGIChannel channel, String file, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new GetOptionCommand(file, escapeDigits)); - return reply.getResultCodeAsChar(); + return channel.getOption(file, escapeDigits); } /** @@ -244,11 +206,7 @@ public abstract class AbstractAGIScript protected char getOption(AGIChannel channel, String file, String escapeDigits, int timeout) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new GetOptionCommand(file, escapeDigits, - timeout)); - return reply.getResultCodeAsChar(); + return channel.getOption(file, escapeDigits, timeout); } /** @@ -263,10 +221,7 @@ public abstract class AbstractAGIScript protected int exec(AGIChannel channel, String application) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new ExecCommand(application)); - return reply.getResultCode(); + return channel.exec(application); } /** @@ -283,10 +238,7 @@ public abstract class AbstractAGIScript protected int exec(AGIChannel channel, String application, String options) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new ExecCommand(application, options)); - return reply.getResultCode(); + return channel.exec(application, options); } /** @@ -301,10 +253,7 @@ public abstract class AbstractAGIScript protected int execCommand(AGIChannel channel, String application) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new ExecCommand(application)); - return reply.getResultCode(); + return channel.exec(application); } /** @@ -321,10 +270,7 @@ public abstract class AbstractAGIScript protected int execCommand(AGIChannel channel, String application, String options) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new ExecCommand(application, options)); - return reply.getResultCode(); + return channel.exec(application, options); } /** @@ -335,7 +281,7 @@ public abstract class AbstractAGIScript protected void setContext(AGIChannel channel, String context) throws AGIException { - channel.sendCommand(new SetContextCommand(context)); + channel.setContext(context); } /** @@ -347,7 +293,7 @@ public abstract class AbstractAGIScript protected void setExtension(AGIChannel channel, String extension) throws AGIException { - channel.sendCommand(new SetExtensionCommand(extension)); + channel.setExtension(extension); } /** @@ -359,7 +305,7 @@ public abstract class AbstractAGIScript protected void setPriority(AGIChannel channel, int priority) throws AGIException { - channel.sendCommand(new SetPriorityCommand(priority)); + channel.setPriority(priority); } /** @@ -370,7 +316,7 @@ public abstract class AbstractAGIScript protected void streamFile(AGIChannel channel, String file) throws AGIException { - channel.sendCommand(new StreamFileCommand(file)); + channel.streamFile(file); } /** @@ -385,10 +331,7 @@ public abstract class AbstractAGIScript protected char streamFile(AGIChannel channel, String file, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new StreamFileCommand(file, escapeDigits)); - return reply.getResultCodeAsChar(); + return channel.streamFile(file, escapeDigits); } /** @@ -399,7 +342,7 @@ public abstract class AbstractAGIScript protected void sayDigits(AGIChannel channel, String digits) throws AGIException { - channel.sendCommand(new SayDigitsCommand(digits)); + channel.sayDigits(digits); } /** @@ -414,10 +357,7 @@ public abstract class AbstractAGIScript protected char sayDigits(AGIChannel channel, String digits, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new SayDigitsCommand(digits, escapeDigits)); - return reply.getResultCodeAsChar(); + return channel.sayDigits(digits, escapeDigits); } /** @@ -428,7 +368,7 @@ public abstract class AbstractAGIScript protected void sayNumber(AGIChannel channel, String number) throws AGIException { - channel.sendCommand(new SayNumberCommand(number)); + channel.sayNumber(number); } /** @@ -443,10 +383,7 @@ public abstract class AbstractAGIScript protected char sayNumber(AGIChannel channel, String number, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new SayNumberCommand(number, escapeDigits)); - return reply.getResultCodeAsChar(); + return channel.sayNumber(number, escapeDigits); } /** @@ -457,7 +394,7 @@ public abstract class AbstractAGIScript protected void sayPhonetic(AGIChannel channel, String text) throws AGIException { - channel.sendCommand(new SayPhoneticCommand(text)); + channel.sayPhonetic(text); } /** @@ -472,10 +409,7 @@ public abstract class AbstractAGIScript protected char sayPhonetic(AGIChannel channel, String text, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new SayPhoneticCommand(text, escapeDigits)); - return reply.getResultCodeAsChar(); + return channel.sayPhonetic(text, escapeDigits); } /** @@ -486,7 +420,7 @@ public abstract class AbstractAGIScript protected void sayAlpha(AGIChannel channel, String text) throws AGIException { - channel.sendCommand(new SayAlphaCommand(text)); + channel.sayAlpha(text); } /** @@ -501,10 +435,7 @@ public abstract class AbstractAGIScript protected char sayAlpha(AGIChannel channel, String text, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new SayAlphaCommand(text, escapeDigits)); - return reply.getResultCodeAsChar(); + return channel.sayAlpha(text, escapeDigits); } /** @@ -514,7 +445,7 @@ public abstract class AbstractAGIScript */ protected void sayTime(AGIChannel channel, long time) throws AGIException { - channel.sendCommand(new SayTimeCommand(time)); + channel.sayTime(time); } /** @@ -529,10 +460,7 @@ public abstract class AbstractAGIScript protected char sayTime(AGIChannel channel, long time, String escapeDigits) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new SayTimeCommand(time, escapeDigits)); - return reply.getResultCodeAsChar(); + return channel.sayTime(time, escapeDigits); } /** @@ -545,14 +473,7 @@ public abstract class AbstractAGIScript protected String getVariable(AGIChannel channel, String name) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new GetVariableCommand(name)); - if (reply.getResultCode() != 1) - { - return null; - } - return reply.getExtra(); + return channel.getVariable(name); } /** @@ -564,7 +485,7 @@ public abstract class AbstractAGIScript protected void setVariable(AGIChannel channel, String name, String value) throws AGIException { - channel.sendCommand(new SetVariableCommand(name, value)); + channel.setVariable(name, value); } /** @@ -577,9 +498,6 @@ public abstract class AbstractAGIScript protected char waitForDigit(AGIChannel channel, int timeout) throws AGIException { - AGIReply reply; - - reply = channel.sendCommand(new WaitForDigitCommand(timeout)); - return reply.getResultCodeAsChar(); + return channel.waitForDigit(timeout); } } Index: AGIChannel.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIChannel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- AGIChannel.java 11 Mar 2005 09:37:39 -0000 1.3 +++ AGIChannel.java 13 Sep 2005 00:56:05 -0000 1.4 @@ -35,9 +35,355 @@ public interface AGIChannel * * @param command the command to send. * @return the reply of the asterisk server containing the return value. - * * @throws AGIException if the command can't be sent to Asterisk (for * example because the channel has been hung up) */ AGIReply sendCommand(AGICommand command) throws AGIException; + + /** + * Answers the channel. + * + * @since 0.2 + */ + void answer() throws AGIException; + + /** + * Hangs the channel up. + * + * @since 0.2 + */ + void hangup() throws AGIException; + + /** + * Cause the channel to automatically hangup at the given number of seconds + * in the future. + * + * @param time the number of seconds before this channel is automatically + * hung up.<br> + * 0 disables the autohangup feature. + * @since 0.2 + */ + void setAutoHangup(int time) throws AGIException; + + /** + * Sets the caller id on the current channel. + * + * @param callerId the raw caller id to set, for example "John Doe<1234>". + * @since 0.2 + */ + void setCallerId(String callerId) throws AGIException; + + /** + * Plays music on hold from the default music on hold class. + * + * @since 0.2 + */ + void playMusicOnHold() throws AGIException; + + /** + * Plays music on hold from the given music on hold class. + * + * @param musicOnHoldClass the music on hold class to play music from as + * configures in Asterisk's <code><musiconhold.conf/code>. + * @since 0.2 + */ + void playMusicOnHold(String musicOnHoldClass) throws AGIException; + + /** + * Stops playing music on hold. + * + * @since 0.2 + */ + void stopMusicOnHold() throws AGIException; + + /** + * Returns the status of the channel.<br> + * Return values: + * <ul> + * <li>0 Channel is down and available + * <li>1 Channel is down, but reserved + * <li>2 Channel is off hook + * <li>3 Digits (or equivalent) have been dialed + * <li>4 Line is ringing + * <li>5 Remote end is ringing + * <li>6 Line is up + * <li>7 Line is busy + * </ul> + * + * @return the status of the channel. + * @since 0.2 + */ + int getChannelStatus() throws AGIException; + + /** + * Plays the given file and waits for the user to enter DTMF digits until he + * presses '#'. The user may interrupt the streaming by starting to enter + * digits. + * + * @param file the name of the file to play + * @return a String containing the DTMF the user entered + * @since 0.2 + */ + String getData(String file) throws AGIException; + + /** + * Plays the given file and waits for the user to enter DTMF digits until he + * presses '#' or the timeout occurs. The user may interrupt the streaming + * by starting to enter digits. + * + * @param file the name of the file to play + * @param timeout the timeout to wait for user input.<br> + * 0 means standard timeout value, -1 means "ludicrous time" + * (essentially never times out). + * @return a String containing the DTMF the user entered + * @since 0.2 + */ + String getData(String file, int timeout) throws AGIException; + + /** + * Plays the given file and waits for the user to enter DTMF digits until he + * presses '#' or the timeout occurs or the maximum number of digits has + * been entered. The user may interrupt the streaming by starting to enter + * digits. + * + * @param file the name of the file to play + * @param timeout the timeout to wait for user input.<br> + * 0 means standard timeout value, -1 means "ludicrous time" + * (essentially never times out). + * @param maxDigits the maximum number of digits the user is allowed to + * enter + * @return a String containing the DTMF the user entered + * @since 0.2 + */ + String getData(String file, int timeout, int maxDigits) throws AGIException; + + /** + * Plays the given file, and waits for the user to press one of the given + * digits. If none of the esacpe digits is pressed while streaming the file + * it waits for the default timeout of 5 seconds still waiting for the user + * to press a digit. + * + * @param file the name of the file to stream, must not include extension. + * @param escapeDigits contains the digits that the user is expected to + * press. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char getOption(String file, String escapeDigits) throws AGIException; + + /** + * Plays the given file, and waits for the user to press one of the given + * digits. If none of the esacpe digits is pressed while streaming the file + * it waits for the specified timeout still waiting for the user to press a + * digit. + * + * @param file the name of the file to stream, must not include extension. + * @param escapeDigits contains the digits that the user is expected to + * press. + * @param timeout the timeout in seconds to wait if none of the defined + * esacpe digits was presses while streaming. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char getOption(String file, String escapeDigits, int timeout) + throws AGIException; + + /** + * Executes the given command. + * + * @param application the name of the application to execute, for example + * "Dial". + * @return the return code of the application of -2 if the application was + * not found. + * @since 0.2 + */ + int exec(String application) throws AGIException; + + /** + * Executes the given command. + * + * @param application the name of the application to execute, for example + * "Dial". + * @param options the parameters to pass to the application, for example + * "SIP/123". + * @return the return code of the application of -2 if the application was + * not found. + * @since 0.2 + */ + int exec(String application, String options) throws AGIException; + + /** + * Sets the context for continuation upon exiting the application. + * + * @param context the context for continuation upon exiting the application. + * @since 0.2 + */ + void setContext(String context) throws AGIException; + + /** + * Sets the extension for continuation upon exiting the application. + * + * @param extension the extension for continuation upon exiting the + * application. + * @since 0.2 + */ + void setExtension(String extension) throws AGIException; + + /** + * Sets the priority for continuation upon exiting the application. + * + * @param priority the priority for continuation upon exiting the + * application. + * @since 0.2 + */ + void setPriority(int priority) throws AGIException; + + /** + * Plays the given file. + * + * @param file name of the file to play. + * @since 0.2 + */ + void streamFile(String file) throws AGIException; + + /** + * Plays the given file and allows the user to escape by pressing one of the + * given digit. + * + * @param file name of the file to play. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char streamFile(String file, String escapeDigits) throws AGIException; + + /** + * Says the given digit string. + * + * @param digits the digit string to say. + * @since 0.2 + */ + void sayDigits(String digits) throws AGIException; + + /** + * Says the given number, returning early if any of the given DTMF number + * are received on the channel. + * + * @param digits the digit string to say. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char sayDigits(String digits, String escapeDigits) throws AGIException; + + /** + * Says the given number. + * + * @param number the number to say. + * @since 0.2 + */ + void sayNumber(String number) throws AGIException; + + /** + * Says the given number, returning early if any of the given DTMF number + * are received on the channel. + * + * @param number the number to say. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char sayNumber(String number, String escapeDigits) throws AGIException; + + /** + * Says the given character string with phonetics. + * + * @param text the text to say. + * @since 0.2 + */ + void sayPhonetic(String text) throws AGIException; + + /** + * Says the given character string with phonetics, returning early if any of + * the given DTMF number are received on the channel. + * + * @param text the text to say. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char sayPhonetic(String text, String escapeDigits) throws AGIException; + + /** + * Says the given character string. + * + * @param text the text to say. + * @since 0.2 + */ + void sayAlpha(String text) throws AGIException; + + /** + * Says the given character string, returning early if any of the given DTMF + * number are received on the channel. + * + * @param text the text to say. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char sayAlpha(String text, String escapeDigits) throws AGIException; + + /** + * Says the given time. + * + * @param time the time to say in seconds since 00:00:00 on January 1, 1970. + * @since 0.2 + */ + void sayTime(long time) throws AGIException; + + /** + * Says the given time, returning early if any of the given DTMF number are + * received on the channel. + * + * @param time the time to say in seconds since 00:00:00 on January 1, 1970. + * @param escapeDigits a String containing the DTMF digits that allow the + * user to escape. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char sayTime(long time, String escapeDigits) throws AGIException; + + /** + * Returns the value of the given channel variable. + * + * @param name the name of the variable to retrieve. + * @return the value of the given variable or <code>null</code> if not + * set. + * @since 0.2 + */ + String getVariable(String name) throws AGIException; + + /** + * Sets the value of the given channel variable to a new value. + * + * @param name the name of the variable to retrieve. + * @param value the new value to set. + * @since 0.2 + */ + void setVariable(String name, String value) throws AGIException; + + /** + * Waits up to 'timeout' milliseconds to receive a DTMF digit. + * + * @param timeout timeout the milliseconds to wait for the channel to + * receive a DTMF digit, -1 will wait forever. + * @return the DTMF digit pressed or 0x0 if none was pressed. + * @since 0.2 + */ + char waitForDigit(int timeout) throws AGIException; } |