Mapping ARI events to imperative call flows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ARI is inherently different to AGI in that it's event oriented rather 
than imperative oriented. I'm wondering, as an AGI developer, what the 
best way to handle this is. For example, consider the following 
pseudocode for a simple AGI voicemail application:

while ( ! hungup() ) {
   key = menu( 'main_menu' );
   if ( key == 1 ) {
     foreach message ( get_messages() ) {
       key2 = menu( message );
       if ( key2 == 3 ) {
         delete( message );
       }
     }
   } else if ( key == 2 ) {
     password = data( 'enter_new_password' );
     set_password( password );
   } else {
     menu( 'invalid_key' );
   }
}

If implementing this using ARI, we're going to get events such as 
PlaybackFinished, ChannelDtmfReceived, and Hangup. When this happens, 
how do we know where we are in the call flow and what to do next? 
Several options spring to mind:

1. Implement a pure state engine. Keep a data structure for each active 
call. When we receive relevant events we update the data structure, and 
figure where we are in the call flow using lots of if statements. This 
seems inelegant and hard to maintain for large call flows.

2. Implement a separate thread or forked subprocess for each call, that 
implements the imperative pseudocode above. Have the helper functions 
menu() and data() block when called. Have the master thread/process pass 
a message to the call thread/process when an event is received, and have 
the helper function return if appropriate. I'm leaning towards this 
model as it makes maintaining large complex flows easier, though I'm 
worried that it means losing some of the flexibility of event driven 
programming.

3. Something clever with closures. This is somewhat outside my personal 
experience, and I don't know how this would work.

-- 
Alistair Cunningham
+1 888 468 3111
+44 20 799 39 799
http://integrics.com/



[Index of Archives]     [Asterisk SS7]     [Asterisk Announcements]     [Asterisk Users]     [PJ SIP]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Linux API]

  Powered by Linux