[asterisk-users] Asterisk 1.6 AEL Macro vs GoSub

Jiří Pokorný J_Pok at seznam.cz
Mon Nov 14 03:47:36 CST 2011


Hi,
  
 I have recently run into the problem with macro implementation in AEL in Asterisk 1.6. I have some older AEL dialplan which runs on 1.4 but it does not on 1.6 and I'm not sure how to solve this correctly. Let me explain...
  
 For example, in Asterisk 1.4 I have a macro like this:
  
 macro read_digits(digits) {
     Set(playlist=${SHELL(${PYTHON} ${SCRIPTS}/read_digits.py ${digits})});
     if ("${playlist}"!="") {
         Background(${playlist});
     }
 }
  
 This macro calls a python script which generates a list of sound files which are then played back by Background application. So whenever in my Dialplan I need to read some digits, I simply do:
  
 &read_digits(20);
  
 In 1.4 macro is implemented as macro and this is quite nice because I can use it as follows:
  
 context test {
     s => {
         &read_digits(20);
     }
     h => {
         // do something
     }
 }
  
 Macro is executed in the original context and ordinary as well as special extensions are handled by this context. As AEL is not much of a real programming language and there aren't many possibilities how to make some parts of code abstract, this was at least something.
  
 But in 1.6 AEL macro has been reimplemented thru GoSub and it is translated into context. So when the "macro" is performing it's work there is a need to catch special extensions and so. The code above won't work because hangup in read_digits macro is not catched. New macro should look like this:
  
 macro read_digits(digits) {
     Set(playlist=${SHELL(${PYTHON} ${SCRIPTS}/read_digits.py ${digits})});
     if ("${playlist}"!="") {
         Background(${playlist});
     }
     catch h {
         // do something
     }
 }
  
 But catching the "h" extension in the macro doesn't solve my problem as I need to do different things in the "h" extension in different contexts. Only possible "workaround" that comes to my mind is a copy&paste of the code which practically ruins any advantage of using a macro.
  
 Any thoughts on how to do this in a nice way? Maybe I'm missing something...
  
 Thanks,
  
 Jiri Pokorny



More information about the asterisk-users mailing list