_site/cover/mcd_status.COVER.html

1 %% Copyright (c) 2022 Peter Morgan <peter.james.morgan@gmail.com>
2 %%
3 %% Licensed under the Apache License, Version 2.0 (the "License");
4 %% you may not use this file except in compliance with the License.
5 %% You may obtain a copy of the License at
6 %%
7 %% http://www.apache.org/licenses/LICENSE-2.0
8 %%
9 %% Unless required by applicable law or agreed to in writing, software
10 %% distributed under the License is distributed on an "AS IS" BASIS,
11 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 %% See the License for the specific language governing permissions and
13 %% limitations under the License.
14
15
16 -module(mcd_status).
17
18
19 -export([callback_mode/0]).
20 -export([lookup/1]).
21 -export([init/1]).
22 -export([start_link/0]).
23 -include_lib("stdlib/include/ms_transform.hrl").
24
25
26 start_link() ->
27 13 gen_statem:start_link(?MODULE, [], []).
28
29
30 lookup(K) ->
31 48 case ets:lookup(?MODULE, K) of
32 [{K, V}] ->
33 48 V;
34
35 [] ->
36
:-(
error(badarg, [K])
37 end.
38
39
40 init([]) ->
41 13 process_flag(trap_exit, true),
42 13 ets:insert_new(
43 ets:new(?MODULE, [named_table]),
44 lists:flatmap(
45 fun dup_flip/1,
46 mcd:priv_consult("status.terms"))),
47 13 {ok, ready, #{}}.
48
49
50 dup_flip({K, V} = KV) ->
51 208 [KV, {V, K}].
52
53
54 callback_mode() ->
55 13 handle_event_function.
Line Hits Source