_site/cover/resp_sup.COVER.html

1 %% Copyright (c) 2023 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(resp_sup).
17
18
19 -behaviour(supervisor).
20 -export([init/1]).
21 -export([start_link/0]).
22 -export([supervisor/1]).
23 -export([worker/1]).
24
25
26 start_link() ->
27
:-(
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
28
29
30 init([]) ->
31
:-(
{ok, configuration()}.
32
33
34 configuration() ->
35
:-(
{#{}, children()}.
36
37
38 children() ->
39
:-(
Callback = resp_config:protocol(callback),
40
41
:-(
[worker(resp_telemetry),
42 worker(#{m => resp_listener, args => [#{callback => Callback}]}),
43 supervisor(resp_connection_sup)].
44
45
46 worker(Arg) ->
47
:-(
child(Arg).
48
49
50 supervisor(Arg) ->
51
:-(
maps:merge(child(Arg), #{type => supervisor}).
52
53
54 child(#{m := M} = Arg) ->
55
:-(
maps:merge(
56 #{id => M, start => mfargs(Arg)},
57 maps:with(keys(), Arg));
58
59 child(Arg) when is_atom(Arg) ->
60
:-(
?FUNCTION_NAME(#{m => Arg}).
61
62
63 mfargs(#{m := M} = Arg) ->
64
:-(
{M, maps:get(f, Arg, start_link), maps:get(args, Arg, [])}.
65
66
67 keys() ->
68
:-(
[id, start, restart, significant, shutdown, type, modules].
Line Hits Source