[Asterisk-Users] after hours - is this logic ok ?
Tilghman Lesher
tilghman at mail.jeffandtilghman.com
Thu Jan 1 12:16:57 MST 2004
On Thursday 01 January 2004 12:45, Lance Arbuckle wrote:
> Tilghman Lesher wrote:
> > I'm curious as to why you're going the extra step to put a value
> > into the database. Why not just set a channel variable and check
> > that value?
> >
> > [day]
> > exten => s,2,SetVar(daytime=1)
> >
> > [night]
> > exten => s,2,SetVar(daytime=0)
> >
> > [macro-stdexten]
> > exten => s,10,GotoIf($[${daytime}]?11:111)
> >
> > Using a variable is nice, because all channels get their own
> > variable space, so there's no chance of collisions between
> > different calls, and the variable is automatically trashed when the
> > channel is hungup.
> >
> > -Tilghman
>
> Hi Tilghman
> thanks for your response.
> I stuck the value in the database because I haven't a clue as to what
> I'm doing :-) In all my reading I didn't see anything that talked
> about variables having their own private per channel sandbox in which
> to play. I just figured since * had a DB, I'd use it :) It's
> exactly this type of thing that I'm finding frustrating while trying
> to learn Asterisk. I'll spend hours reading about something ( in
> this case I read a bunch about setvar and the DB commands ) but at
> the end of all that reading all I could show for it was two methods
> of accomplishing a task, but I din't know which way (if any) was the
> best or most appropriate way. I feel like I'm handicapped in
> learning Asterisk by my lack of not knowing a programming language.
> I have a sneaky feeling that a lot of the answers to my questions
> would be obvious to someone with C/C++ experience.
>
> So, here's another question... How does someone with no programming
> experience, effectively learn the proper way to do things in Asterisk
> ?
Trial and error is especially effective. This is how I learned. In
addition, I read the source regularly, which is not nearly as daunting
as it may seem, when taken in small doses. Don't try to understand
everything at once, but take a look at a small application, for example,
SayUnixTime and trace back its function calls elsewhere into the code,
into say.c and into stdtime/localtime.c, if you want to go that far.
"grep -r some_function_name /usr/src/asterisk" will help you do the
trace through code. When somebody asks me about some functionality,
if I don't know, the first thing I do is to go look in the source and
see if I can figure it out.
For the variables, see the README.variables in the root directory of the
Asterisk source. The example I quoted above uses both variable
interpolation ${} as well as expression evaluation $[], although the
expression is the most simple. You can also do comparisons in there:
$[${var} > 3] or $[${var} = "oink"].
-Tilghman
More information about the asterisk-users
mailing list