[asterisk-dev] Variable Inheritance, Setting Channel Variables outside of current context

Peter Beckman beckman at purplecow.com
Thu May 18 07:41:39 MST 2006


On Wed, 17 May 2006, Tilghman Lesher wrote:

> On Wednesday 17 May 2006 15:58, Peter Beckman wrote:
>> On Wed, 17 May 2006, Kevin P. Fleming wrote:
>>   In this situation, the 'parent context' would be 'foo', and the
>> 'child context' would be 'macro-bar' or just 'bar' for variable
>> inheritance discussions?  Channel variables set in foo such as _FOO
>> and __FOO would be inherited by the macro called by the Dial() in
>> 'foo' context, right?
>
> In that case, what you said was incorrect.  There is no "child" or
> "parent" context, when it comes to setting variables.

  I understand inheritance better now; there are child and parent CHANNELS,
  and variables set in Channel A (parent) with a leading one or two
  underscores will be inherited by Channel B (child) when Channel A creates
  Channel B.

> Variables which you set in Macro (other than the special ARG variables
> used for passing parameters) will still be set when Macro returns.

  IFF the macro is called within the same channel.  If the macro is called
  as part of Dial() using the M(x) option, variables set in the Macro will
  NOT be available to the channel that called the Dial(); correct?

>>> Macros can return values back to their callers via MACRO_RESULT,
>>> but the rest of what you said appears to be true and expected
>>> behavior.
>>
>>   It seems that the only way to communicate between channels is via
>> Global variables.  In order to prevent overwriting them while
>> multiple calls are in progress, a unique name for the Global variable
>> is required.
>
> If you wanted to do this directly, yes.  A much better approach would
> be to write a value into a database, for retrieval at the appropriate
> time by another channel.

  My issue right now is that I'm running 90% of my workload through a
  FastAGI application, which has DB access, and my Asterisk install, where
  my Dial() macro lives, which does not.  The fewer connections to the DB
  per call the better.  I was hoping to use/find a non-database solution.
  Global variables did the trick.

>>   Once a Global variable is set, how do you "unset" that Global
>> variable, in order to avoid overwriting and variable messyness?
>
> Setting it to an empty string effectively resets the value.

  Excellent!  I'll document that.  Does that "destroy" the variable within
  asterisk?  IE if I do an AGI GET VARIABLE VARNAME after setting it to ""
  does the AGI return that the variable is unset or does it return that the
  variable is "" (an empty string)?

> There's no need.  A database does this just fine already, in a
> completely predictable way.  Setting another channel's variables
> asynchronously is not a smart idea.  For example, if one channel
> is using ${i} to iterate through a loop and you asynchronously change
> the value of ${i} halfway through the loop, the dialplan is going to do
> something unpredictable and completely unreproduceable.

  I see your point.

Beckman
---------------------------------------------------------------------------
Peter Beckman                                                  Internet Guy
beckman at purplecow.com                             http://www.purplecow.com/
---------------------------------------------------------------------------



More information about the asterisk-dev mailing list