_site/cover/pgmp_message_tags.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(pgmp_message_tags).
17
18
19 -export([callback_mode/0]).
20 -export([init/1]).
21 -export([name/2]).
22 -export([start/0]).
23 -export([start_link/0]).
24 -include_lib("stdlib/include/ms_transform.hrl").
25
26
27 start_link() ->
28 10 gen_statem:start_link(?MODULE, [], envy_gen:options(?MODULE)).
29
30
31 start() ->
32 1 gen_statem:start(?MODULE, [], []).
33
34 name(Role, Tag) ->
35 71425 case ets:lookup(?MODULE, {Role, Tag}) of
36 [{_, Name}] ->
37 71425 Name;
38
39 [] ->
40
:-(
error(badarg, [Role, Tag])
41 end.
42
43
44 init([]) ->
45 11 process_flag(trap_exit, true),
46 11 ets:insert_new(
47 ets:new(?MODULE, [named_table]),
48 lists:flatmap(
49 fun
50 ({Name, {both, Tag}}) ->
51 22 [{{frontend, Tag}, Name},
52 {{backend, Tag}, Name}];
53
54 ({Name, {_Role, _Tag} = RoleTag}) ->
55 396 [{RoleTag, Name}]
56 end,
57 pgmp:priv_consult("message-tags.terms"))),
58 11 {ok, ready, #{}}.
59
60
61 callback_mode() ->
62 11 handle_event_function.
Line Hits Source