Re: [asterisk-users] While loop inside recursive calls

2017-03-21 Thread Jonathan H
Well, I've never seen dialplan like that - is this a very old version
of Asterisk, or psuedocode?

Anyway..

A subroutine MUST be balanced, and if a subroutine is aborted before
it reaches return, you'll be in all sorts of hell.

An example:

You make a subroutine of some sound files you want to loop through to
make an IVR menu.

You call it using Gosub. Someone presses two while the third of 5
tracks is playing.

The stack will then be unbalanced and you'll then be in a potential
world of stack overflow and unknown hell.

So keep the gosubs for things where they cannot be interrupted.
Playback is fine. Background and ControlPlayback is not. See?

Here's a solution to this problem which caused me HUGE amounts of
headaches early on (and I mean days and nights on end!)

Hope it helps...
https://github.com/lardconcepts/asterisk-pbx-tips-and-snips/blob/master/gotchas-and-warnings.md

On 21 March 2017 at 17:31, Ethy H. Brito  wrote:
>
> Hi All
>
> What happens if I, inside of a while/endwhile loop, call recursively a
> macro that itself has another while/endwhile loop and calls exitwhile() 
> inside the
> recursive call?
>
> [macro-recursive]
> instance=$ARG1
> if instance>3
> macroexit
> X=1
> _var1=""
> ; recursive loop
> while(Dcondition)
> _var1=value_${X}
> recursive(instance+1)
> if var1==""
> ExitWhile()
> X=X+1
> some_Dcondition_changing
> bla...
> bla...
> EndWhile
> macroexit
>
> [some_running_context]
> ; Main loop
> while(Zcondition)
> recursive(1)
> if (var1=="")
> ExitWhile
> some_Zcondition_changing
> bla...
> bla...
> endwhile
> more_intructions
> MacroExit
>
> The problem I see is if I reentry "macro-recursive" a the second time,
> Macroexit returns to "more_instructions" at "some_running_context" (just after
> the Main Loop endWhile). It should return to 'if (var1=="")' at the previous
> "macro-recursive" call.
>
> It is like the second call to "macro-recursive" overwrites the first
> "macro-recursive" while/endwhile loop return point, and the second ExitWhile
> exits from the while/endwhile at "some_running_context" and not from first
> "macro-recursive" instance.
>
> In short: second (and subsequent??) call to macro-recursive is ExitWhile()ing
> from "some_running_context" while loop. First call exits ok.
>
> Any directions to share?
>
> Is this explanation too complicated to understand?
>
> Regards
>
> Ethy
>
> --
> _
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Check out the new Asterisk community forum at: https://community.asterisk.org/
>
> New to Asterisk? Start here:
>   https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>http://lists.digium.com/mailman/listinfo/asterisk-users

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


[asterisk-users] While loop inside recursive calls

2017-03-21 Thread Ethy H. Brito

Hi All

What happens if I, inside of a while/endwhile loop, call recursively a
macro that itself has another while/endwhile loop and calls exitwhile() inside 
the
recursive call?

[macro-recursive]
instance=$ARG1
if instance>3
macroexit
X=1
_var1=""
; recursive loop
while(Dcondition)
_var1=value_${X}
recursive(instance+1)
if var1==""
ExitWhile()
X=X+1
some_Dcondition_changing
bla...
bla...
EndWhile
macroexit

[some_running_context]
; Main loop
while(Zcondition) 
recursive(1)
if (var1=="")
ExitWhile
some_Zcondition_changing
bla...
bla...
endwhile
more_intructions
MacroExit

The problem I see is if I reentry "macro-recursive" a the second time,
Macroexit returns to "more_instructions" at "some_running_context" (just after
the Main Loop endWhile). It should return to 'if (var1=="")' at the previous
"macro-recursive" call.

It is like the second call to "macro-recursive" overwrites the first
"macro-recursive" while/endwhile loop return point, and the second ExitWhile
exits from the while/endwhile at "some_running_context" and not from first
"macro-recursive" instance.

In short: second (and subsequent??) call to macro-recursive is ExitWhile()ing
from "some_running_context" while loop. First call exits ok.

Any directions to share?

Is this explanation too complicated to understand?

Regards

Ethy

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users