Ilie NEACSU
Ilie NEACSU

Reputation: 540

Modular gen_fsm behavior implementation

I have an gen_fsm implementation that has very much states and a lot of code (over 2000 lines of code). Any ideas how to make an gen_fsm modular, maybe something like a plugin system ? But i want that the fsm to be able to jump between states located in different plugins.

Upvotes: 0

Views: 102

Answers (1)

Akshat Jiwan Sharma
Akshat Jiwan Sharma

Reputation: 16000

Well you could create erlang modules. I am looking at this gen_fsm skeleton, you could swap out any of the functions to it's own module.

For instance suppose you have an event handler like

 handle_event(wakeup, StateName, State) -> 
                                  %% rest of the body

you could create a new module and move the definition of handle event there

  -module(wakeup_event).
   -export(wakeup/3).

    wakeup(_wakeup,Statename, State)-> %%do something here
                                       {nextstate, Statename,State}.

and call it from handle_event like so

   handle_event(wakeup,Statename,State)-> 
             wakeup_event:wakeup(wakeup,Statename,State);

Upvotes: 1

Related Questions