Macro()

Ruft ein zuvor definiertes Makro auf.

Macro(macroname[,Arg1[,Arg2[,...]]])

Führt ein im Context macro-macroname definiertes Makro aus, indem es zur s-Extension dieses Contextes springt und nach der Ausführung des Makros zurückkehrt.

Die angerufene Extension, Context und Priorität sind innerhalb des Makros in ${MACRO_EXTEN}, ${MACRO_CONTEXT} und ${MACRO_PRIORITY} verfügbar. Die Parameter Arg1, Arg2 ... werden im MakroContext zu ${ARG1}, ${ARG2} usw.

Macro() liefert -1 zurück, falls irgendein Schritt des Makros -1 zurückliefert, sonst 0. Falls bei Beendigung des Ablaufs ${MACRO_OFFSET} gesetzt ist, versucht die Anwendung bei Priorität n+1+MACRO_OFFSET fortzufahren, falls ein solcher Schritt existiert, sonst bei n+1.

Falls die Goto()-Anwendung aus dem Makro heraus aufgerufen wird, wird das Makro enden und die Kontrolle an das Ziel von Goto() gehen.

; ein Makro definieren, das vom übergebenen Wert runterzählt:
[macro-countdown]
exten => s,1,Set(COUNT=${ARG1})
exten => s,n,While($[ ${COUNT} > 0])
exten => s,n,SayNumber(${COUNT})
exten => s,n,Set(COUNT=$[ ${COUNT} - 1 ])
exten => s,n,EndWhile()

[default]
exten => 123,1,Macro(countdown,3)   ; das Makro "countdown" mit ARG1=3 aufrufen
exten => 124,1,Macro(countdown,5)   ; das Makro "countdown" mit ARG1=5 aufrufen
[Anmerkung]Anmerkung

Interner Hilfetext zu dieser Applikation in Asterisk 1.4: 

  -= Info about application 'Macro' =- 

[Synopsis]
Macro Implementation

[Description]
  Macro(macroname|arg1|arg2...): Executes a macro using the context
'macro-<macroname>', jumping to the 's' extension of that context and
executing each step, then returning when the steps end. 
The calling extension, context, and priority are stored in ${MACRO_EXTEN}, 
${MACRO_CONTEXT} and ${MACRO_PRIORITY} respectively.  Arguments become
${ARG1}, ${ARG2}, etc in the macro context.
If you Goto out of the Macro context, the Macro will terminate and control
will be returned at the location of the Goto.
If ${MACRO_OFFSET} is set at termination, Macro will attempt to continue
at priority MACRO_OFFSET + N + 1 if such a step exists, and N + 1 otherwise.
WARNING: Because of the way Macro is implemented (it executes the priorities
         contained within it via sub-engine), and a fixed per-thread
         memory stack allowance, macros are limited to 7 levels
         of nesting (macro calling macro calling macro, etc.); It
         may be possible that stack-intensive applications in deeply nested macros
         could cause asterisk to crash earlier than this limit.

Differenz zum internen Hilfetext in Asterisk 1.2: 

22,23c22,23
<          may be possible that stack-intensive applications in deeply nested macros
<          could cause asterisk to crash earlier than this limit.
---
>          may be possible that stack-intensive applications in deeply nested
>          macros could cause asterisk to crash earlier than this limit.

Siehe auch. Goto(), Gosub()


Version 1.2, November 2002

Neue Version verfügbar

Sie betrachten gerade die alte Version des Buches (Version 1.0). Wir empfehlen Ihnen für Asterisk 1.4 und 1.6 die neue Version des Buches.

Asterisk-Tag 2008

Lernen Sie Mark Spencer (den Erfinder von Asterisk) kennen! Viele Vorträge, Case-Studies und Workshops rund um das Thema VoIP. Asterisk-Tag.org

Das gedruckte Buch