[asterisk-users] How to write a function with a return value inAsterisk

Mike list at virtutel.ca
Wed Aug 8 13:13:41 CDT 2007


AH! Thanks, I've been thinking that apps and functions were interchangeable,
hoping that I could return values with functions.  Now that this is very
clear in my mind (at least I think it is) I'll go and write a function.
 
Might as well ask this before I go out, not find my answer and come back to
ask the question: What are the best practice when it comes to building these
functions, and making them useable from Asterisk, without needing to build
Asterisk every single time...?  Can I compile/build them separately, and
somehow register them into Asterisk?
 
I`m much better at writing C code then actually integrating that code in
larger project...unfortunately.
 
Mike

  _____  

From: asterisk-users-bounces at lists.digium.com
[mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of James
FitzGibbon
Sent: Wednesday, August 08, 2007 14:03
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] How to write a function with a return value
inAsterisk


On 8/8/07, Mike <list at virtutel.ca> wrote: 


So, I wrote (well, plagarized directly from the Web) a simple Perl program
that prints "Hello World".  I call it using this:
 
exten => 12345,1,AGI(agi-helloworld.agi)
 
Seems to work (I'm not expecting anything, really, just no Asterisk error).
 
When I try to use it as part Noop like this:

exten => 12345,1,Noop(${AGI(agi-helloworld.agi)})
 
In the hope of getting to see Noop(Hello World) in my CLI, I get the
following Asterisk error:
 
Aug  8 13:40:48 ERROR[5771]: pbx.c:1402 ast_func_read: Function AGI not
registered
 
AGI certainly seems registered as it worked in the first case.  Again,
something obvious I missed?


This is calling the AGI application:

exten => something,priority,AGI(program|args)

This is an attempt to call a function called AGI (which doesn't exist) and
pass the results of said non-existent function to the NoOp application: 

exten => something,priority,NoOp(${AGI(program|args)})

look at 'core show applications' and 'core show functions' to see what you
can call in each case.  Applications and functions aren't interchangeable. 

If you want to use an AGI script to set a variable you can later use as an
arg to Dial(), then you want to call the AGI application from your dialplan,
then from inside the AGI script do your calculations and issue the AGI
command "SET VARIABLE name value". 

So if you have a very basic AGI script that just does this:

echo "SET VARIABLE foo bar"

then your dialplan could look something like this:

exten => foo,1,AGI(foo.agi)
exten => foo,n,NoOp(${foo}) 

And you'd expect to see "NoOp(bar)" on your console when you called that
extension.

Of course, you'd want to use one of the available AGI frameworks to do the
heavy lifting of parsing the input that Asterisk gives an AGI script and
take care of the error handing when you issue a command back to Asterisk
from the AGI script. 


-- 
j. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20070808/195a8048/attachment-0001.htm 


More information about the asterisk-users mailing list