[asterisk-dev] [Code Review] 3362: func_periodic_hook: New function for periodic hooks.

Russell Bryant reviewboard at asterisk.org
Mon Mar 31 11:10:04 CDT 2014



> On March 30, 2014, 12:12 a.m., Corey Farrell wrote:
> > /trunk/funcs/func_periodic_hook.c, line 206
> > <https://reviewboard.asterisk.org/r/3362/diff/4/?file=56930#file56930line206>
> >
> >     state->last_hook is never pre-initialized to ast_tvnow(), so hooks would always trigger on first check after being created or re-enabled.  Unless this behaviour is documented I would expect the first run after create or resume to be delayed state->interval seconds.
> 
> Russell Bryant wrote:
>     Fair.  I had originally intended for it to run immediately, but I think it makes more sense to delay.
> 
> jamuel wrote:
>     So is the implication then if I were to set the interval to 30 seconds that the hook wouldn't run for 30 seconds and then run every 30 seconds?  That seems more counter intuitive.  I'd think that it should run and then repeat every interval seconds.

Yes, that's right.  I keep going back and forth but I think I agree with you that running immediately makes the most sense.


- Russell


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/3362/#review11441
-----------------------------------------------------------


On March 31, 2014, 1:14 p.m., Russell Bryant wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/3362/
> -----------------------------------------------------------
> 
> (Updated March 31, 2014, 1:14 p.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Repository: Asterisk
> 
> 
> Description
> -------
> 
>     This commit introduces a new dialplan function, PERIODIC_HOOK().
>     It allows you run to a dialplan hook on a channel periodically.  The
>     original use case that inspired this was the ability to play a beep
>     periodically into a call being recorded.  The implementation is much
>     more generic though and could be used for many other things.
>     
>     The implementation makes heavy use of existing Asterisk components.
>     It uses a combination of Local channels and ChanSpy() to run some
>     custom dialplan and inject any audio it generates into an active call.
>     
>     The other important bit of the implementation is how it figures out
>     when to trigger the beep playback.  This implementation uses the
>     audiohook API, even though it's not actually touching the audio in any
>     way.  It's a convenient way to get a callback and check if it's time
>     to kick off another beep.  It would be nice if this was timer event
>     based instead of polling based, but unfortunately I don't see a way to
>     do it that won't interfere with other things.
> 
> 
> Diffs
> -----
> 
>   /trunk/funcs/func_periodic_hook.c PRE-CREATION 
>   /trunk/CHANGES 411572 
> 
> Diff: https://reviewboard.asterisk.org/r/3362/diff/
> 
> 
> Testing
> -------
> 
> Called the following extension (100 at test), both letting it run all the way through, as well as hanging up at various points in the middle.
> 
> 
> [macro-beep]
> 
> exten => s,1,Answer()
>     same => n,Verbose(1,Channel name: ${ARG1})
>     same => n,Verbose(1,Hook ID: ${ARG2})
>     same => n,Playback(beep)
> 
> [test]
> 
> exten => 100,1,Answer()
>     same => n,Set(BEEP_ID=${PERIODIC_HOOK(beep,5)})
>     same => n,Wait(20)
>     same => n,Set(PERIODIC_HOOK(${BEEP_ID})=off)
>     same => n,Wait(20)
>     same => n,Set(PERIODIC_HOOK(${BEEP_ID})=on)
>     same => n,Wait(20)
>     same => n,Hangup()
> 
> 
> Thanks,
> 
> Russell Bryant
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20140331/25b0b061/attachment-0001.html>


More information about the asterisk-dev mailing list