[asterisk-users] Howto create variable from the name of another one and get content of it

Satish Barot satish4asterisk at gmail.com
Fri Mar 22 00:08:19 CDT 2013


>
>
> > I found the problem, it's (I think) a bug with queue command. My
> > dialplan:
> >
> > [context]
> > ...
> > exten => 33123,n,macro(unpauseQueueMembers,q820,104,105,136,,)
> > exten => 33123,n(back2Queue),Queue(${myQueue},nit,,,14400)
> > exten => 33123,n,NoOp(Queue ${myQueue} call status is ${QUEUESTATUS}
> > -
> > Dial status is ${DIALSTATUS} - Our status is ${${myQueue}STATUS})  ;
> > value is empty
> > exten => 33123,n,GotoIf($["${${myQueue}STATUS}" =
> > "myTIMEOUT"]?back2Queue)
> >
> > [to-q820]
> >
> > exten => 104,1,Dial(SIP/${EXTEN},,Tt)
> > exten => 105,1,Dial(SIP/${EXTEN},,Tt)
> > exten => 136,1,Dial(SIP/${EXTEN},,Tt)
> > exten => _XXX,2,macro(queueCallStatus,${EXTEN})
> >
> > [macro-queueCallStatus]
> >
> > exten => s,1,Set(__myExten=${ARG1})
> >     same => n,NoOp(Call status to ${myExten}@${myQueue} is
> >     ${DIALSTATUS})
> >     same => n,GotoIf($["${DIALSTATUS}" = "ANSWER"]?exitMacro)
> >     same => n,GotoIf($["${DIALSTATUS}" != "NOANSWER"]?Pause)
> >     same => n(exitMacro),MacroExit
> > ...
> >     same =>
> > n(Pause),NoOp(PauseQueueMember(,Local/${myExten}@to-${myQueue}))
> >     same => n,Set(__${myQueue}STATUS=myTIMEOUT)
> >     same => n,NoOp(Value of my variable is ${${myQueue}STATUS})
> >                           ; here I get correct value
> > ...
> > [macro-unpauseQueueMembers]
> >
> > exten => s,1,Set(__myQueue=${ARG1})
> >     same => n,Set(__${myQueue}STATUS=)
> >     same => n,UnpauseQueueMember(,Local/${ARG2}@to-${myQueue})
> >     same => n,UnpauseQueueMember(,Local/${ARG3}@to-${myQueue})
> >     same => n,UnpauseQueueMember(,Local/${ARG4}@to-${myQueue})
> >
> > If I 33123  the NoOp(Value of my variable is ${${myQueue}STATUS}) in
> > macro-queueCallStatus shows the right value which is text myTIMEOUT.
> > But
> > this value isn't anymore present in
> > NoOp(Queue ${myQueue} call status is ${QUEUESTATUS} - Dial status is
> > ${DIALSTATUS} - Our status is ${${myQueue}STATUS}) from [context]
> > which
> > is *after* the queue cmd exit.
>
> The the parent channel (the incoming channel on exten 33123) sets the
> variable to empty.  A child channel (Dialed by app Queue) running a
> local channel in the context [to-q820] sets the variable to the status
> you are wanting.  The child cannot send that variable value back to the
> parent channel.  Channel variable inheritance only goes one way: from
> parent to child.
>
> Richard
>
>
SHARED function is your best pal here.

Here is the updated (but not tested) dialplan for you

[context]
...
;Store CHANNEL in a variable
exten => 33123,n,Set(__PARENTCHANNEL=${CHANNEL})
exten => 33123,n,macro(unpauseQueueMembers,q820,104,105,136,,)
exten => 33123,n(back2Queue),Queue(${myQueue},nit,,,14400)
exten => 33123,n,NoOp(Queue ${myQueue} call status is ${QUEUESTATUS} - Dial
status is ${DIALSTATUS} - Our status is ${${myQueue}STATUS}) ; value is
empty
;;exten => 33123,n,GotoIf($["${${myQueue}STATUS}" = "myTIMEOUT"]?back2Queue)
; See the SHARED FUNCTION
exten => 33123,n,GotoIf($["${SHARED(${myQueue}STATUS,${PARENTCHANNEL})}" =
"myTIMEOUT"]?back2Queue)

[to-q820]

exten => 104,1,Dial(SIP/${EXTEN},,Tt)
exten => 105,1,Dial(SIP/${EXTEN},,Tt)
exten => 136,1,Dial(SIP/${EXTEN},,Tt)
exten => _XXX,2,macro(queueCallStatus,${EXTEN})

[macro-queueCallStatus]

exten => s,1,Set(__myExten=${ARG1})
   same => n,NoOp(Call status to ${myExten}@${myQueue} is ${DIALSTATUS})
   same => n,GotoIf($["${DIALSTATUS}" = "ANSWER"]?exitMacro)
   same => n,GotoIf($["${DIALSTATUS}" != "NOANSWER"]?Pause)
   same => n(exitMacro),MacroExit
...
same => n(Pause),NoOp(PauseQueueMember(,Local/${myExten}@to-${myQueue}))
;;same => n,Set(__${myQueue}STATUS=myTIMEOUT)
same => n,Set(SHARED(${myQueue}STATUS,${PARENTCHANNEL})=myTIMEOUT)
;;same => n,NoOp(Value of my variable is ${${myQueue}STATUS}) ; here I get
correct value
; ${myQueue}STATUS is set here through SHARED FUNCTION
same => n,NoOp(Value of my variable is
${SHARED(${myQueue}STATUS,${PARENTCHANNEL})})
...
[macro-unpauseQueueMembers]

exten => s,1,Set(__myQueue=${ARG1})
   same => n,Set(__${myQueue}STATUS=)
   same => n,UnpauseQueueMember(,Local/${ARG2}@to-${myQueue})
   same => n,UnpauseQueueMember(,Local/${ARG3}@to-${myQueue})
   same => n,UnpauseQueueMember(,Local/${ARG4}@to-${myQueue})

Hope this helps.

--Satish Barot
Ahmedabad, India
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20130322/5f20b9e3/attachment.htm>


More information about the asterisk-users mailing list