[Asterisk-Dev] Dev Meeting list

Andrew Kohlsmith akohlsmith-asterisk at benshaw.com
Fri Apr 29 04:18:48 MST 2005


On April 28, 2005 11:59 pm, Matthew Boehm wrote:
> What I think would work is having every app return different result codes
> for different "happenings" during the app. It is then up to the Asterisk
> manager to do the checking and jumping.

You mean the Dialplan, right?

> I'm going to relate this to the mysql C API cause I am familiar with that.
> Just about all of the functions return result codes. Those codes are
> clearly published. None of the functions jump internally to other functions
> upon error.

It's the same as any API, really.  0 for success, nonzero for some kind of 
error or condition that may need to be checked.

>  1 - Dialed Successfully
>  2 - Busy
>  3 - No Answer
>  4 - Unable to create channel
>  5 - Unknown error

I'd alter this a little.  result should be 0 for success, and copy 
${DIALSTATUS} to the generic app result (${RES}?  ${?}?  we need something 
short).

Dial's a bad example since it already has ${DIALSTATUS}, and also 
${HANGUPCAUSE} for that matter.  My current hangup macro looks something like 
this:

[macro-handle-hangup]
exten => s,1,NoOp(HANGUPCAUSE is ${HANGUPCAUSE} and DIALSTATUS is 
${DIALSTATUS})
exten => s,n,GotoIf($[${HANGUPCAUSE} = 0]?s,nohc)
exten => s,n,Goto(hc-${HANGUPCAUSE},1)
exten => s,n(nohc),GotoIf($[${DIALSTATUS} = ANSWER]?hc-16,1)
exten => s,n,GotoIf($[${DIALSTATUS} = BUSY]?hc-17,1)
exten => s,n,GotoIf($[${DIALSTATUS} = NOANSWER]?hc-19,1)
exten => s,n,GotoIf($[${DIALSTATUS} = CONGESTION]?hc-42,1)
exten => s,n,GotoIf($[${DIALSTATUS} = CHANUNAVAIL]?hc-44,1)
exten => s,n,GotoIf($[${DIALSTATUS} = CANCEL]?hc-0,1)
exten => s,n,Goto(hc-0,n)

So as you can see, if ${HANGUPCAUSE} is nonzero I use the more specific hangup 
cause to determine what to indicate.  Failing that, I look to ${DIALSTATUS} 
to give me some hint of what to indicate.

> It 'will' be the responsibility of the apps to modify the built-in channel
> var ${RESULTCODE} (or something similar). If the variable isn't defined,
> create it. That way ${RESULTCODE} always contains the result of the most
> recent app. Then Goto's and other jumps are easily handled. Perhaps even a
> Switch app could be created instead of many goto's?

Well I would also have pbx.c force ${RES} to the value of 0 before calling any 
application, but after variable substitution so that it's possible to do 
something like this:

exten => _NXXXXXX,n,MyFunkyApp(${RES})
exten => _NXXXXXX,n,NoOp(MyFunkyApp result was ${RES})

and have MyFunkyApp() process the result of the app above it, and similarly 
for NoOp(), process the result of the app above it.

> If the asterisk manager doesn't throw in a jump for a particular result
> code, there needs to be some sort of 'catch all'.

What do you mean?

-A.



More information about the asterisk-dev mailing list