[erlang-questions] how to handle a complex timer process ?

Kaiduan Xie kaiduanx@REDACTED
Tue Jun 15 01:20:25 CEST 2010


John,

Please see attached file from an Erlang SIP proxy. The state machine
itself is described in the comments.

Kaiduan

On Mon, Jun 14, 2010 at 5:23 PM, info <info@REDACTED> wrote:
> Could you show us a skeleton with gen_fsm ?
> Rgds,
> John
>
> I'd use a gen_fsm for this, then you can handle the timeout message in each state and transition appropriately.
>
> Chad DePue
> skype: cdepue
> inakanetworks.com - Erlang consulting
> rubyrescue.com - Ruby on Rails consulting
>
>
>
>
> On Mon, Jun 14, 2010 at 2:10 PM, info <info@REDACTED> wrote:
>
> Hi all,
> I want to manage a timer with several actions.
> - creation: creation of the timer process with "Period" as parameter. The timer shall be in suspend state.
> - start: the timer is started.
> - restart: the timer restarts with the Period.
> - stop: the timer is stopped. The timer shall be in wait state. A start starts the timer.
> - kill: the timer process is killed.
> - after the timeout, a message is sent to another process. The timer shall be in suspend state.
>
> For the creation, I do:
> Pid = spawn (fun,?MODULE,the_timer,[Period]),
> and after I manage like this:
> Pid ! {start}
> Pid ! {stop}
> Pid ! {restart}
> Pid ! {kill}
>
> The structure of the timer is like this:
>
> the_timer(Period)->
>   receive
>       {start}-> ???
>       {restart}->
>           the_timer(Period);
>       {stop}-> ???
>       {kill}-> ???
>   after Period ->
>       Pid0 -> {one_message},
>       ???
>   end.
>
> How to handle the state ? how to keep the time after a stop and to start again with this time ? how to kill the process ?
> How to start the timer only if a start message is received ?
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: erlsip_inv_client_tran.erl
Type: text/x-erlang
Size: 10968 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20100614/2cfedb08/attachment.bin>


More information about the erlang-questions mailing list