Function SHARED And Function IMPORT : 2 Questions

Home » Asterisk Users » Function SHARED And Function IMPORT : 2 Questions
Asterisk Users No Comments

Hello

I am trying to use the functions SHARED and IMPORT to share variables across SIP-channels.

During my use I encounter 2 problems/questions.

Question 1. only 1 shared variable per channel ??

When I set 2 shared variables on a channel, and I read them a bit futher in the dialplan, there is only 1 variable that has its value :

Dialplan :
exten => s,n,Set(SHARED(TheINPUT)=1)
exten => s,n,Set(SHARED(MyVar)”2)
… exten => s,n,Set(Import=${IMPORT(${CHANNEL},TheINPUT)})
exten => s,n,Set(ImportAdv=${IMPORT(${CHANNEL},MyVar)})

Execution :

[Mar 2 14:19:20] — Executing [s@routing:56]
Set(“SIP/980419-00000016”, “SHARED(TheINPUT)=1”) in new stack
[Mar 2 14:19:20] — Executing [s@routing:57]
Set(“SIP/980419-00000016”, “SHARED(MyVar)”2”) in new stack

[Mar 2 14:19:26] — Executing [s@routing:80]
Set(“SIP/980419-00000016”, “Import=1”) in new stack
[Mar 2 14:19:26] — Executing [s@routing:81]
Set(“SIP/980419-00000016”, “ImportAdv=”) in new stack

As you can see, only variable “TheINPUT” has its value ( 1 ). Variable
‘MyVar’ is empty.

How come ??

Question 2 : how to set a variable on another channel ??

I try to set a Shared Variable on 1 channel :

exten => s,n,Set(SHARED(TheINPUT,${BRIDGECH})=1)

And read the variable on another channel :

exten => s,n,Set(Import=${IMPORT(${BRIDGECH},TheINPUT)})
exten => s,n,Set(Hell=${IMPORT(TheINPUT)})

Execution :

(here the shared var is set)
[Mar 2 14:58:44] — Executing [s@routing:58]
NoOp(“SIP/980419-00000025”, “bridgech = SIP/SipT01-00000021”) in new stack
[Mar 2 14:58:44] — Executing [s@routing:59]
Set(“SIP/980419-00000025”, “SHARED(TheINPUT,SIP/SipT01-00000021)=1”) in new stack

(here the hared var is read)
[Mar 2 14:58:54] — Executing [s@routing:42]
Set(“SIP/SipT01-00000021”, “Import=”) in new stack
[Mar 2 14:58:54] — Executing [s@routing:43]
Set(“SIP/SipT01-00000021”, “Hell=”) in new stack

So why is the shared variable “TheINPUT” empty on the channel SIP/SipT01-00000021 ?? It clealry has been set by the channel SIP/980419-00000025.

Thank you for answering these 2 questions of mine.

Kind regards,

Jonas.