Permalink
Browse files

Allow setting a name for the FSM in the settings file

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...
1 parent f738ba9 commit 5e20524f865a2720673b058f4f17714030c84ed1 @gdamjan committed Nov 4, 2011
Showing with 16 additions and 6 deletions.
  1. +16 −6 src/ircbot_fsm.erl
View
22 src/ircbot_fsm.erl
@@ -23,21 +23,31 @@
}).
-%% api to use in the shell
+%% PM api to use in the shell
new(Settings) ->
{ok, Ref} = start(Settings),
ircbot_api:new(Ref).
-start(Settings) ->
- gen_fsm:start(?MODULE, Settings, []).
-
-%% api for use in supervisors etc
new_link(Settings) ->
{ok, Ref} = start_link(Settings),
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) ->
- 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

0 comments on commit 5e20524

Please sign in to comment.