<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16481" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=062430418-08082007><FONT face=Arial
color=#0000ff size=2>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.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=062430418-08082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=062430418-08082007><FONT face=Arial
color=#0000ff size=2>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?</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=062430418-08082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=062430418-08082007><FONT face=Arial
color=#0000ff size=2>I`m much better at writing C code then actually integrating
that code in larger project...unfortunately.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=062430418-08082007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=062430418-08082007><FONT face=Arial
color=#0000ff size=2>Mike</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> asterisk-users-bounces@lists.digium.com
[mailto:asterisk-users-bounces@lists.digium.com] <B>On Behalf Of </B>James
FitzGibbon<BR><B>Sent:</B> Wednesday, August 08, 2007 14:03<BR><B>To:</B>
Asterisk Users Mailing List - Non-Commercial Discussion<BR><B>Subject:</B> Re:
[asterisk-users] How to write a function with a return value
inAsterisk<BR></FONT><BR></DIV>
<DIV></DIV>On 8/8/07, <B class=gmail_sendername>Mike</B> <<A
href="mailto:list@virtutel.ca">list@virtutel.ca</A>> wrote:
<DIV><SPAN class=gmail_quote></SPAN>
<DIV><BR></DIV>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV bgcolor="#ffffff" text="#000000">
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>So, I
wrote (well, plagarized directly from the Web) a simple Perl program that
prints "Hello World". I call it using this:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>exten
=> 12345,1,AGI(agi-helloworld.agi)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>Seems to
work (I'm not expecting anything, really, just no Asterisk
error).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>When I try
to use it as part Noop like this:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>exten
=> 12345,1,Noop(${AGI(agi-helloworld.agi)})</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN>In the hope of getting to see Noop(Hello World)
in my CLI, I get the following Asterisk error:</SPAN></DIV>
<DIV dir=ltr align=left><SPAN></SPAN> </DIV></FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2>Aug 8 13:40:48 ERROR[5771]:
pbx.c:1402 ast_func_read: Function AGI not registered</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN>AGI certainly seems
registered as it worked in the first case. Again, something obvious I
missed?</SPAN></FONT></DIV></DIV></BLOCKQUOTE>
<DIV><BR>This is calling the AGI application:<BR><BR>exten =>
something,priority,AGI(program|args)<BR><BR>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: <BR><BR>exten =>
something,priority,NoOp(${AGI(program|args)})<BR><BR>look at 'core show
applications' and 'core show functions' to see what you can call in each
case. Applications and functions aren't interchangeable. <BR><BR>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". <BR><BR>So if you have a very basic AGI script that just
does this:<BR><BR>echo "SET VARIABLE foo bar"<BR><BR>then your dialplan could
look something like this:<BR><BR>exten => foo,1,AGI(foo.agi)<BR>exten =>
foo,n,NoOp(${foo}) <BR><BR>And you'd expect to see "NoOp(bar)" on your console
when you called that extension.<BR><BR>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. <BR><BR></DIV></DIV>-- <BR>j.
</BODY></HTML>