[Home]

Summary:ASTERISK-02857: app_while
Reporter:Anthony Minessale (anthm)Labels:
Date Opened:2004-11-18 19:10:52.000-0600Date Closed:2008-01-15 15:18:09.000-0600
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Applications/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) app_while.c
Description:This file implements while loops in the dialplan
and implements the ExecIf app

*CLI> show application While

 -= Info about application 'While' =-

[Synopsis]:
Start A While Loop

[Description]:
 While(<expr>)
Start a While Loop.  Execution will return to this point when
EndWhile is called until expr is no longer true.

*CLI> show application EndWhile

 -= Info about application 'EndWhile' =-

[Synopsis]:
End A While Loop

[Description]:
 EndWhile()
Return to the previous called While


*CLI> show application ExecIf

 -= Info about application 'ExecIf' =-

[Synopsis]:
ExecIF (<expr>|<app>|<data>)

[Description]:
 ExecIF (<expr>|<app>|<data>)
If <expr> is true, execute and return the result of <app>(<data>)



****** ADDITIONAL INFORMATION ******

Disclaimer on file
anthmct@yahoo.com
Comments:By: Mark Spencer (markster) 2004-11-19 00:40:18.000-0600

Probably worthwhile just to make pbx_builtin_goto (or something similar) an exposed function to avoid the findapp.  

Would be nice if we could avoid having so many ALL_DONE macro calls but just structured things to fall through and only have one return at the end...

Another interesting concept would be to make nested while loops easier supported by having the "label" component actually be a number.

e.g.

While app:

set WHILE_x to the place to return to where "x" is the lowest one which doesn't have a value yet.

end app:

find highest WHILE_x that is defined and return to there if the condition is true.  If one isn't, then print a warning about unmatched begin/end.  Also the variable must be deleted after exiting the loop.

By: Anthony Minessale (anthm) 2004-11-24 16:05:11.000-0600

Seamless Nesting now possible

exten => 00*,1,Verbose(0| )
exten => 00*,n,SetVar(Y=1)
exten => 00*,n,While($[ ${Y} < 5 ])
exten => 00*,n,SetVar(Z=1)
exten => 00*,n,While($[ ${Z} < 4 ])
exten => 00*,n,SetVar(X=1)
exten => 00*,n,While($[ ${X} < 2 ])
exten => 00*,n,verbose(0|${X} ${Y} ${Z})
exten => 00*,n,SetVar(X=$[ ${X} + 1 ])
exten => 00*,n,EndWhile()
exten => 00*,n,SetVar(Z=$[ ${Z} + 1 ])
exten => 00*,n,EndWhile
exten => 00*,n,SetVar(Y=$[ ${Y} + 1 ])
exten => 00*,n,EndWhile
exten => 00*,n,Hangup

produces

1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
1 4 1
1 4 2
1 4 3

By: Mark Spencer (markster) 2004-11-27 11:03:30.000-0600

Where does IfExec evaluate its expression?  Is it really necessary given the new GotoIf stuff where the implied target is the next entry?

I'm not following the waitfordigit thingy, can you explain its purpose?

By: Mark Spencer (markster) 2004-11-27 11:38:24.000-0600

Oh, and of course the documentation is totally inconsistant with other apps, maybe bkw_ can fix it up for you?

By: Anthony Minessale (anthm) 2004-11-27 13:36:17.000-0600

ExecIf uses ast_true() so the expr is evaluated by a $[ ] in the
dial plan or it can react to existance of a variable too

ExecIf($[ ${X} > 1 ]|SetVar(TEST=true)
ExecIf(${TEST}|SetCallerID(WooHoo <0001231234>))


I closed the WaitForDigit cos I don't care all that much though
it does do some stuff that may be useful

By: Mark Spencer (markster) 2004-12-01 00:43:12.000-0600

Am I missing where the call to ast_true is in ExecIf?

By: Anthony Minessale (anthm) 2004-12-01 09:26:41.000-0600

DoH !

I must have cut the code out by accident cos I had it working before.
Good Eye!

By: Mark Spencer (markster) 2004-12-22 22:29:11.000-0600

Okay so we're just waiting on the documentation fixes then?

By: Anthony Minessale (anthm) 2004-12-23 19:57:21.000-0600

uploaded new doc changes

By: Mark Spencer (markster) 2004-12-23 20:22:43.000-0600

Added to CVS, thanks!

By: Russell Bryant (russell) 2004-12-23 20:53:25.000-0600

not in 1.0

By: Digium Subversion (svnbot) 2008-01-15 15:18:09.000-0600

Repository: asterisk
Revision: 4551

U   trunk/apps/Makefile
A   trunk/apps/app_while.c

------------------------------------------------------------------------
r4551 | markster | 2008-01-15 15:18:09 -0600 (Tue, 15 Jan 2008) | 2 lines

Merge anthm's while loop code (thanks tony!) (bug ASTERISK-2857)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=4551