[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi AbstractAGIScript.java,1.7,1
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-03-12 09:57:01
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2210/src/java/net/sf/asterisk/fastagi Modified Files: AbstractAGIScript.java Log Message: Added some more convinience methods Index: AbstractAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AbstractAGIScript.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- AbstractAGIScript.java 11 Mar 2005 16:18:13 -0000 1.7 +++ AbstractAGIScript.java 12 Mar 2005 09:56:50 -0000 1.8 @@ -17,10 +17,20 @@ 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.GetVariableCommand; import net.sf.asterisk.fastagi.command.HangupCommand; +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; @@ -28,7 +38,8 @@ import net.sf.asterisk.fastagi.reply.AGI /** * The AbstractAGIScript provides some convinience methods to make it easier to - * write custom AGIScripts. + * write custom AGIScripts.<br> + * Just extend it by your own AGIScripts. * * @author srt * @version $Id$ @@ -51,18 +62,148 @@ public abstract class AbstractAGIScript channel.sendCommand(new HangupCommand()); } + /** + * 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. + */ + protected void setAutoHangup(AGIChannel channel, int time) + throws AGIException + { + channel.sendCommand(new SetAutoHangupCommand(time)); + } + + /** + * Sets the caller id on the current channel. + * + * @param callerId the raw caller id to set, for example "John Doe<1234>". + */ + protected void setCallerId(AGIChannel channel, String callerId) + throws AGIException + { + channel.sendCommand(new SetCallerIdCommand(callerId)); + } + + /** + * Plays music on hold from the default music on hold class. + */ + protected void playMusicOnHold(AGIChannel channel) throws AGIException + { + channel.sendCommand(new SetMusicOnCommand()); + } + + /** + * 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>. + */ + protected void playMusicOnHold(AGIChannel channel, String musicOnHoldClass) + throws AGIException + { + channel.sendCommand(new SetMusicOnCommand(musicOnHoldClass)); + } + + /** + * Stops playing music on hold. + */ + protected void stopMusicOnHold(AGIChannel channel) throws AGIException + { + channel.sendCommand(new SetMusicOffCommand()); + } + + /** + * 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. + */ + protected int getChannelStatus(AGIChannel channel) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new ChannelStatusCommand()); + return reply.getResultCode(); + } + + /** + * 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. + */ + protected int execCommand(AGIChannel channel, String application) + throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new ExecCommand(application)); + return reply.getResultCode(); + } + + /** + * 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. + */ + protected int execCommand(AGIChannel channel, String application, + String options) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new ExecCommand(application, options)); + return reply.getResultCode(); + } + + /** + * Sets the context for continuation upon exiting the application. + * + * @param context the context for continuation upon exiting the application. + */ protected void setContext(AGIChannel channel, String context) throws AGIException { channel.sendCommand(new SetContextCommand(context)); } + /** + * Sets the extension for continuation upon exiting the application. + * + * @param extension the extension for continuation upon exiting the + * application. + */ protected void setExtension(AGIChannel channel, String extension) throws AGIException { channel.sendCommand(new SetExtensionCommand(extension)); } + /** + * Sets the priority for continuation upon exiting the application. + * + * @param priority the priority for continuation upon exiting the + * application. + */ protected void setPriority(AGIChannel channel, int priority) throws AGIException { @@ -85,9 +226,9 @@ public abstract class AbstractAGIScript * given digit. * * @param file name of the file to play. - * @param escapeDigits a String containing the dtmf digits that allow the + * @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. + * @return the DTMF digit pressed or 0x0 if none was pressed. */ protected char streamFile(AGIChannel channel, String file, String escapeDigits) throws AGIException @@ -99,6 +240,122 @@ public abstract class AbstractAGIScript } /** + * Says the given digit string. + * + * @param digits the digit string to say. + */ + protected void sayDigits(AGIChannel channel, String digits) + throws AGIException + { + channel.sendCommand(new SayDigitsCommand(digits)); + } + + /** + * 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. + */ + protected char sayDigits(AGIChannel channel, String digits, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new SayDigitsCommand(digits)); + return reply.getResultCodeAsChar(); + } + + /** + * Says the given number. + * + * @param number the number to say. + */ + protected void sayNumber(AGIChannel channel, String number) + throws AGIException + { + channel.sendCommand(new SayNumberCommand(number)); + } + + /** + * 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. + */ + protected char sayNumber(AGIChannel channel, String number, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new SayNumberCommand(number)); + return reply.getResultCodeAsChar(); + } + + /** + * Says the given character string with phonetics. + * + * @param text the text to say. + */ + protected void sayPhonetic(AGIChannel channel, String text) + throws AGIException + { + channel.sendCommand(new SayPhoneticCommand(text)); + } + + /** + * 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. + */ + protected char sayPhonetic(AGIChannel channel, String text, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new SayPhoneticCommand(text)); + return reply.getResultCodeAsChar(); + } + + /** + * Says the given character string with phonetics. + * + * @param time the time to say in seconds since 00:00:00 on January 1, 1970. + */ + protected void sayTime(AGIChannel channel, long time) + throws AGIException + { + channel.sendCommand(new SayTimeCommand(time)); + } + + /** + * Says the given character string with phonetics, 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. + */ + protected char sayTime(AGIChannel channel, long time, + String escapeDigits) throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new SayTimeCommand(time)); + return reply.getResultCodeAsChar(); + } + + /** * Returns the value of the given channel variable. * * @param name the name of the variable to retrieve. |