[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi AbstractAGIScript.java,1.3,1
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-03-11 13:40:53
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26067/src/java/net/sf/asterisk/fastagi Modified Files: AbstractAGIScript.java Log Message: Added getVariable() and setVariable() Index: AbstractAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AbstractAGIScript.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- AbstractAGIScript.java 11 Mar 2005 09:37:39 -0000 1.3 +++ AbstractAGIScript.java 11 Mar 2005 13:40:39 -0000 1.4 @@ -17,7 +17,10 @@ package net.sf.asterisk.fastagi; import net.sf.asterisk.fastagi.command.AnswerCommand; +import net.sf.asterisk.fastagi.command.GetVariableCommand; import net.sf.asterisk.fastagi.command.HangupCommand; +import net.sf.asterisk.fastagi.command.SetVariableCommand; +import net.sf.asterisk.fastagi.reply.AGIReply; /** * The AbstractAGIScript provides some convinience methods to make it easier to @@ -30,10 +33,6 @@ public abstract class AbstractAGIScript { /** * Answers the channel. - * - * @param channel the channel as received by the service method. - * - * @throws AGIException if the command can't be sent to Asterisk. */ protected void answer(AGIChannel channel) throws AGIException { @@ -42,13 +41,41 @@ public abstract class AbstractAGIScript /** * Hangs the channel up. - * - * @param channel the channel as received by the service method. - * - * @throws AGIException if the command can't be sent to Asterisk. */ protected void hangup(AGIChannel channel) throws AGIException { channel.sendCommand(new HangupCommand()); } + + /** + * 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. + */ + protected String getVariable(AGIChannel channel, String name) + throws AGIException + { + AGIReply reply; + + reply = channel.sendCommand(new GetVariableCommand(name)); + if (reply.getResultCode() != 0) + { + return null; + } + return reply.getExtra(); + } + + /** + * 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. + */ + protected void setVariable(AGIChannel channel, String name, String value) + throws AGIException + { + channel.sendCommand(new SetVariableCommand(name, value)); + } } |