On Sun, Nov 27, 2016 at 8:07 AM, Jonathan H <lardconce...@gmail.com> wrote:

> Thanks, Max.
>
> Yes, of course, you are right, and I am an idiot because I was tired
> and putting underscores before the variable name when I read it back!
> Then I forgot to post the followup email to say I had figured it out.
>
> Now, this SHARED was not something I was aware of, but looked like an
> ideal solution to passing variables BACK from to the parent channel.
>
> However, it does not seem to be very reliable.
>
> Code:
>
> [svtest1]
> exten => s,1,Answer()
>     same => n,Verbose(1,Answered channel:${CHANNEL})
>     same => n,Dial(Local/s@svtest2,,g)
>     same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:
> ${SHARED(sharedVar,Local/s@svtest2)} )
>     same => n,Hangup()
>
> [svtest2]
> exten => s,1,NoOp()
>     same => n,Set(SHARED(sharedVar,Local/s@svtest2)="I have been set
> in svtest2")
>     same => n,Verbose(1,***In channel:${CHANNEL} sharedVar:
> ${SHARED(sharedVar,Local/s@svtest2)})
>     same => n,Answer()
>     same => n,Hangup()
>

There are a few problems with the way you are trying to use SHARED
here.
1)  Dial with the g option continues in the dialplan when the called channel
hangs up and you are accessing a SHARED variable on the called channel
while it is being destroyed.  Thus it may or may not still exist when you
attempt to access it.
2) You are using local channels.  Remember local channels always come
in pairs.  The local channel name you are using to reference the SHARED
variable is ambiguous.  Not only do you not know which half of a local
channel pair you will get, you may not even get one of the local channels
the Dial created for this call if you have more than one of these calls
happening in parallel.

Executing this CLI command:
CLI> originate local/s@svtest1 application echo

Your dialplan creates this channel chain when Local/s@svtest2 executes
the Answer:

Echo() -- Local/s@svtest1-00000000;1 -- Local/s@svtest1-00000000;2 --
    Local/s@svtest2-00000001;1 -- Local/s@svtest2-00000001;2 -- Answer()

These problems can be avoided if we make a couple of changes.
1) Change which channel maintains the SHARED variables to the calling
channel.
2) Pass the calling channel name to the called channel using variable
inheritance.

[svtest1]
exten = s,1,NoOp()
same = n,Answer()
same = n,Set(__MY_CALLER=${CHANNEL(name)})
same = n,Dial(Local/s@svtest2,,g)
same = n,NoOp(Returned SHARED(sharedVar) = '${SHARED(sharedVar)'}
same = n,Hangup()

[svtest2]
exten = s,1,NoOp()
exten = n,Set(SHARED(sharedVar,MY_CALLER)="I have been set in svtest2 by
${CHANNEL(name)}")
exten = n,Answer()
exten = n,Hangup()

Richard
-- 
_____________________________________________________________________
-- 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

Reply via email to