1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.asterisk.fastagi;
18
19 import net.sf.asterisk.fastagi.command.AnswerCommand;
20
21 /***
22 * The AbstractAGIScript provides some convinience methods to make it easier to
23 * write custom AGIScripts.<br>
24 * Just extend it by your own AGIScripts.<br>
25 *
26 * @deprecated use {@see net.sf.asterisk.fastagi.BaseAGIScript} instead
27 * @author srt
28 * @version $Id: AbstractAGIScript.java,v 1.19 2005/11/27 15:22:40 srt Exp $
29 */
30 public abstract class AbstractAGIScript implements AGIScript
31 {
32 /***
33 * Answers the channel.
34 */
35 protected void answer(AGIChannel channel) throws AGIException
36 {
37 channel.sendCommand(new AnswerCommand());
38 }
39
40 /***
41 * Hangs the channel up.
42 */
43 protected void hangup(AGIChannel channel) throws AGIException
44 {
45 channel.hangup();
46 }
47
48 /***
49 * Cause the channel to automatically hangup at the given number of seconds
50 * in the future.
51 *
52 * @param time the number of seconds before this channel is automatically
53 * hung up.<br>
54 * 0 disables the autohangup feature.
55 */
56 protected void setAutoHangup(AGIChannel channel, int time)
57 throws AGIException
58 {
59 channel.setAutoHangup(time);
60 }
61
62 /***
63 * Sets the caller id on the current channel.
64 *
65 * @param callerId the raw caller id to set, for example "John Doe<1234>".
66 */
67 protected void setCallerId(AGIChannel channel, String callerId)
68 throws AGIException
69 {
70 channel.setCallerId(callerId);
71 }
72
73 /***
74 * Plays music on hold from the default music on hold class.
75 */
76 protected void playMusicOnHold(AGIChannel channel) throws AGIException
77 {
78 channel.playMusicOnHold();
79 }
80
81 /***
82 * Plays music on hold from the given music on hold class.
83 *
84 * @param musicOnHoldClass the music on hold class to play music from as
85 * configures in Asterisk's <code><musiconhold.conf/code>.
86 */
87 protected void playMusicOnHold(AGIChannel channel, String musicOnHoldClass)
88 throws AGIException
89 {
90 channel.playMusicOnHold(musicOnHoldClass);
91 }
92
93 /***
94 * Stops playing music on hold.
95 */
96 protected void stopMusicOnHold(AGIChannel channel) throws AGIException
97 {
98 channel.stopMusicOnHold();
99 }
100
101 /***
102 * Returns the status of the channel.<br>
103 * Return values:
104 * <ul>
105 * <li>0 Channel is down and available
106 * <li>1 Channel is down, but reserved
107 * <li>2 Channel is off hook
108 * <li>3 Digits (or equivalent) have been dialed
109 * <li>4 Line is ringing
110 * <li>5 Remote end is ringing
111 * <li>6 Line is up
112 * <li>7 Line is busy
113 * </ul>
114 *
115 * @return the status of the channel.
116 */
117 protected int getChannelStatus(AGIChannel channel) throws AGIException
118 {
119 return channel.getChannelStatus();
120 }
121
122 /***
123 * Plays the given file and waits for the user to enter DTMF digits until he
124 * presses '#'. The user may interrupt the streaming by starting to enter
125 * digits.
126 *
127 * @param file the name of the file to play
128 * @return a String containing the DTMF the user entered
129 * @since 0.2
130 */
131 protected String getData(AGIChannel channel, String file)
132 throws AGIException
133 {
134 return channel.getData(file);
135 }
136
137 /***
138 * Plays the given file and waits for the user to enter DTMF digits until he
139 * presses '#' or the timeout occurs. The user may interrupt the streaming
140 * by starting to enter digits.
141 *
142 * @param file the name of the file to play
143 * @param timeout the timeout to wait for user input.<br>
144 * 0 means standard timeout value, -1 means "ludicrous time"
145 * (essentially never times out).
146 * @return a String containing the DTMF the user entered
147 * @since 0.2
148 */
149 protected String getData(AGIChannel channel, String file, int timeout)
150 throws AGIException
151 {
152 return channel.getData(file, timeout);
153 }
154
155 /***
156 * Plays the given file and waits for the user to enter DTMF digits until he
157 * presses '#' or the timeout occurs or the maximum number of digits has
158 * been entered. The user may interrupt the streaming by starting to enter
159 * digits.
160 *
161 * @param file the name of the file to play
162 * @param timeout the timeout to wait for user input.<br>
163 * 0 means standard timeout value, -1 means "ludicrous time"
164 * (essentially never times out).
165 * @param maxDigits the maximum number of digits the user is allowed to
166 * enter
167 * @return a String containing the DTMF the user entered
168 * @since 0.2
169 */
170 protected String getData(AGIChannel channel, String file, int timeout,
171 int maxDigits) throws AGIException
172 {
173 return channel.getData(file, timeout, maxDigits);
174 }
175
176 /***
177 * Plays the given file, and waits for the user to press one of the given
178 * digits. If none of the esacpe digits is pressed while streaming the file
179 * it waits for the default timeout of 5 seconds still waiting for the user
180 * to press a digit.
181 *
182 * @param file the name of the file to stream, must not include extension.
183 * @param escapeDigits contains the digits that the user is expected to
184 * press.
185 * @return the DTMF digit pressed or 0x0 if none was pressed.
186 */
187 protected char getOption(AGIChannel channel, String file,
188 String escapeDigits) throws AGIException
189 {
190 return channel.getOption(file, escapeDigits);
191 }
192
193 /***
194 * Plays the given file, and waits for the user to press one of the given
195 * digits. If none of the esacpe digits is pressed while streaming the file
196 * it waits for the specified timeout still waiting for the user to press a
197 * digit.
198 *
199 * @param file the name of the file to stream, must not include extension.
200 * @param escapeDigits contains the digits that the user is expected to
201 * press.
202 * @param timeout the timeout in seconds to wait if none of the defined
203 * esacpe digits was presses while streaming.
204 * @return the DTMF digit pressed or 0x0 if none was pressed.
205 */
206 protected char getOption(AGIChannel channel, String file,
207 String escapeDigits, int timeout) throws AGIException
208 {
209 return channel.getOption(file, escapeDigits, timeout);
210 }
211
212 /***
213 * Executes the given command.
214 *
215 * @param application the name of the application to execute, for example
216 * "Dial".
217 * @return the return code of the application of -2 if the application was
218 * not found.
219 * @since 0.2
220 */
221 protected int exec(AGIChannel channel, String application)
222 throws AGIException
223 {
224 return channel.exec(application);
225 }
226
227 /***
228 * Executes the given command.
229 *
230 * @param application the name of the application to execute, for example
231 * "Dial".
232 * @param options the parameters to pass to the application, for example
233 * "SIP/123".
234 * @return the return code of the application of -2 if the application was
235 * not found.
236 * @since 0.2
237 */
238 protected int exec(AGIChannel channel, String application, String options)
239 throws AGIException
240 {
241 return channel.exec(application, options);
242 }
243
244 /***
245 * Executes the given command.
246 *
247 * @param application the name of the application to execute, for example
248 * "Dial".
249 * @return the return code of the application of -2 if the application was
250 * not found.
251 * @deprecated use {@see #exec(AGIChannel, String)} instead
252 */
253 protected int execCommand(AGIChannel channel, String application)
254 throws AGIException
255 {
256 return channel.exec(application);
257 }
258
259 /***
260 * Executes the given command.
261 *
262 * @param application the name of the application to execute, for example
263 * "Dial".
264 * @param options the parameters to pass to the application, for example
265 * "SIP/123".
266 * @return the return code of the application of -2 if the application was
267 * not found.
268 * @deprecated use {@see #exec(AGIChannel, String, String)} instead
269 */
270 protected int execCommand(AGIChannel channel, String application,
271 String options) throws AGIException
272 {
273 return channel.exec(application, options);
274 }
275
276 /***
277 * Sets the context for continuation upon exiting the application.
278 *
279 * @param context the context for continuation upon exiting the application.
280 */
281 protected void setContext(AGIChannel channel, String context)
282 throws AGIException
283 {
284 channel.setContext(context);
285 }
286
287 /***
288 * Sets the extension for continuation upon exiting the application.
289 *
290 * @param extension the extension for continuation upon exiting the
291 * application.
292 */
293 protected void setExtension(AGIChannel channel, String extension)
294 throws AGIException
295 {
296 channel.setExtension(extension);
297 }
298
299 /***
300 * Sets the priority or label for continuation upon exiting the application.
301 *
302 * @param priority the priority or label for continuation upon exiting the
303 * application.
304 */
305 protected void setPriority(AGIChannel channel, String priority)
306 throws AGIException
307 {
308 channel.setPriority(priority);
309 }
310
311 /***
312 * Plays the given file.
313 *
314 * @param file name of the file to play.
315 */
316 protected void streamFile(AGIChannel channel, String file)
317 throws AGIException
318 {
319 channel.streamFile(file);
320 }
321
322 /***
323 * Plays the given file and allows the user to escape by pressing one of the
324 * given digit.
325 *
326 * @param file name of the file to play.
327 * @param escapeDigits a String containing the DTMF digits that allow the
328 * user to escape.
329 * @return the DTMF digit pressed or 0x0 if none was pressed.
330 */
331 protected char streamFile(AGIChannel channel, String file,
332 String escapeDigits) throws AGIException
333 {
334 return channel.streamFile(file, escapeDigits);
335 }
336
337 /***
338 * Says the given digit string.
339 *
340 * @param digits the digit string to say.
341 */
342 protected void sayDigits(AGIChannel channel, String digits)
343 throws AGIException
344 {
345 channel.sayDigits(digits);
346 }
347
348 /***
349 * Says the given number, returning early if any of the given DTMF number
350 * are received on the channel.
351 *
352 * @param digits the digit string to say.
353 * @param escapeDigits a String containing the DTMF digits that allow the
354 * user to escape.
355 * @return the DTMF digit pressed or 0x0 if none was pressed.
356 */
357 protected char sayDigits(AGIChannel channel, String digits,
358 String escapeDigits) throws AGIException
359 {
360 return channel.sayDigits(digits, escapeDigits);
361 }
362
363 /***
364 * Says the given number.
365 *
366 * @param number the number to say.
367 */
368 protected void sayNumber(AGIChannel channel, String number)
369 throws AGIException
370 {
371 channel.sayNumber(number);
372 }
373
374 /***
375 * Says the given number, returning early if any of the given DTMF number
376 * are received on the channel.
377 *
378 * @param number the number to say.
379 * @param escapeDigits a String containing the DTMF digits that allow the
380 * user to escape.
381 * @return the DTMF digit pressed or 0x0 if none was pressed.
382 */
383 protected char sayNumber(AGIChannel channel, String number,
384 String escapeDigits) throws AGIException
385 {
386 return channel.sayNumber(number, escapeDigits);
387 }
388
389 /***
390 * Says the given character string with phonetics.
391 *
392 * @param text the text to say.
393 */
394 protected void sayPhonetic(AGIChannel channel, String text)
395 throws AGIException
396 {
397 channel.sayPhonetic(text);
398 }
399
400 /***
401 * Says the given character string with phonetics, returning early if any of
402 * the given DTMF number are received on the channel.
403 *
404 * @param text the text to say.
405 * @param escapeDigits a String containing the DTMF digits that allow the
406 * user to escape.
407 * @return the DTMF digit pressed or 0x0 if none was pressed.
408 */
409 protected char sayPhonetic(AGIChannel channel, String text,
410 String escapeDigits) throws AGIException
411 {
412 return channel.sayPhonetic(text, escapeDigits);
413 }
414
415 /***
416 * Says the given character string.
417 *
418 * @param text the text to say.
419 */
420 protected void sayAlpha(AGIChannel channel, String text)
421 throws AGIException
422 {
423 channel.sayAlpha(text);
424 }
425
426 /***
427 * Says the given character string, returning early if any of the given DTMF
428 * number are received on the channel.
429 *
430 * @param text the text to say.
431 * @param escapeDigits a String containing the DTMF digits that allow the
432 * user to escape.
433 * @return the DTMF digit pressed or 0x0 if none was pressed.
434 */
435 protected char sayAlpha(AGIChannel channel, String text, String escapeDigits)
436 throws AGIException
437 {
438 return channel.sayAlpha(text, escapeDigits);
439 }
440
441 /***
442 * Says the given time.
443 *
444 * @param time the time to say in seconds since 00:00:00 on January 1, 1970.
445 */
446 protected void sayTime(AGIChannel channel, long time) throws AGIException
447 {
448 channel.sayTime(time);
449 }
450
451 /***
452 * Says the given time, returning early if any of the given DTMF number are
453 * received on the channel.
454 *
455 * @param time the time to say in seconds since 00:00:00 on January 1, 1970.
456 * @param escapeDigits a String containing the DTMF digits that allow the
457 * user to escape.
458 * @return the DTMF digit pressed or 0x0 if none was pressed.
459 */
460 protected char sayTime(AGIChannel channel, long time, String escapeDigits)
461 throws AGIException
462 {
463 return channel.sayTime(time, escapeDigits);
464 }
465
466 /***
467 * Returns the value of the given channel variable.
468 *
469 * @param name the name of the variable to retrieve.
470 * @return the value of the given variable or <code>null</code> if not
471 * set.
472 */
473 protected String getVariable(AGIChannel channel, String name)
474 throws AGIException
475 {
476 return channel.getVariable(name);
477 }
478
479 /***
480 * Sets the value of the given channel variable to a new value.
481 *
482 * @param name the name of the variable to retrieve.
483 * @param value the new value to set.
484 */
485 protected void setVariable(AGIChannel channel, String name, String value)
486 throws AGIException
487 {
488 channel.setVariable(name, value);
489 }
490
491 /***
492 * Waits up to 'timeout' milliseconds to receive a DTMF digit.
493 *
494 * @param timeout timeout the milliseconds to wait for the channel to
495 * receive a DTMF digit, -1 will wait forever.
496 * @return the DTMF digit pressed or 0x0 if none was pressed.
497 */
498 protected char waitForDigit(AGIChannel channel, int timeout)
499 throws AGIException
500 {
501 return channel.waitForDigit(timeout);
502 }
503 }