Skip to content

Commit

Permalink
Allow setting a name for the FSM in the settings file
Browse files Browse the repository at this point in the history
a `name` property in settings.cfg can be used to register the FSM.
it can be either {local, FsmName} or {global, FsmName}.
if no name is specified the FSM will not be registered.
  • Loading branch information
gdamjan committed Nov 4, 2011
1 parent f738ba9 commit 5e20524
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/ircbot_fsm.erl
Expand Up @@ -23,21 +23,31 @@
}). }).




%% api to use in the shell %% PM api to use in the shell
new(Settings) -> new(Settings) ->
{ok, Ref} = start(Settings), {ok, Ref} = start(Settings),
ircbot_api:new(Ref). ircbot_api:new(Ref).


start(Settings) ->
gen_fsm:start(?MODULE, Settings, []).

%% api for use in supervisors etc
new_link(Settings) -> new_link(Settings) ->
{ok, Ref} = start_link(Settings), {ok, Ref} = start_link(Settings),
ircbot_api:new(Ref). ircbot_api:new(Ref).


%% traditional OTP api
start(Settings) ->
case proplists:get_value(name, Settings) of
undefined ->
gen_fsm:start(?MODULE, Settings, []);
FsmName ->
gen_fsm:start(FsmName, ?MODULE, Settings, [])
end.

start_link(Settings) -> start_link(Settings) ->
gen_fsm:start_link(?MODULE, Settings, []). case proplists:get_value(name, Settings) of
undefined ->
gen_fsm:start_link(?MODULE, Settings, []);
FsmName ->
gen_fsm:start_link(FsmName, ?MODULE, Settings, [])
end.




%%% gen_fsm init/1 %%% gen_fsm init/1
Expand Down

0 comments on commit 5e20524

Please sign in to comment.