From 2977fbc6b658b0d664f7d3b36ecf8ca9e897aaa3 Mon Sep 17 00:00:00 2001
From: Raimo Niskanen
-export([locked/3,open/3]).
start_link(Code) ->
- gen_statem:start_link({local,code_lock}, ?MODULE, Code, []).
+ gen_statem:start_link({local,?NAME}, ?MODULE, Code, []).
button(Digit) ->
- gen_statem:cast(code_lock, {button,Digit}).
+ gen_statem:cast(?NAME, {button,Digit}).
init(Code) ->
@@ -278,7 +279,7 @@ code_change(_Vsn, State, Data, _Extra) ->
- gen_statem:start_link({local,code_lock}, ?MODULE, Code, []).
+ gen_statem:start_link({local,?NAME}, ?MODULE, Code, []).
]]>
- The first argument,
If the name is omitted, the
-
@@ -495,7 +497,7 @@ open(timeout, _, Data) ->
...
code_length() ->
- gen_statem:call(code_lock, code_length).
+ gen_statem:call(?NAME, code_length).
...
locked(...) -> ... ;
@@ -627,7 +629,7 @@ terminate(_Reason, State, _Data) ->
...
stop() ->
- gen_statem:stop(code_lock).
+ gen_statem:stop(?NAME).
]]>
This makes the
- gen_statem:cast(code_lock, {button,Digit}).
+ gen_statem:cast(?NAME, {button,Digit}).
]]>
spawn(
fun () ->
- true = register(code_lock, self()),
+ true = register(?NAME, self()),
do_lock(),
locked(Code, Code)
end).
button(Digit) ->
- code_lock ! {button,Digit}.
+ ?NAME ! {button,Digit}.
locked(Code, [Digit|Remaining]) ->
receive
@@ -1049,6 +1052,7 @@ enter(Tag, State, Data) ->
-export([locked/3,open/3]).
start_link(Code) ->
- gen_statem:start_link({local,code_lock}, ?MODULE, Code, []).
+ gen_statem:start_link({local,?NAME}, ?MODULE, Code, []).
stop() ->
- gen_statem:stop(code_lock).
+ gen_statem:stop(?NAME).
button(Digit) ->
- gen_statem:cast(code_lock, {button,Digit}).
+ gen_statem:cast(?NAME, {button,Digit}).
code_length() ->
- gen_statem:call(code_lock, code_length).
+ gen_statem:call(?NAME, code_length).
init(Code) ->
Data = #{code => Code},
--
cgit v1.2.3