/
callflow_sup.erl
69 lines (57 loc) · 2.21 KB
/
callflow_sup.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
%%%-------------------------------------------------------------------
%%% @author Karl Anderson <karl@2600hz.org>
%%% @copyright (C) 2011, VoIP INC
%%% @doc
%%%
%%% @end
%%% Created : 27 June 2011 by Karl Anderson <karl@2600hz.org>
%%%-------------------------------------------------------------------
-module(callflow_sup).
-behaviour(supervisor).
-include_lib("whistle/include/wh_types.hrl").
%% API
-export([start_link/0]).
-export([listener_proc/0]).
%% Supervisor callbacks
-export([init/1]).
%% Helper macro for declaring children of supervisor
-define(CHILD(Name, Type), {Name, {Name, start_link, []}, permanent, 5000, Type, [Name]}).
-define(CHILDREN, [{cf_listener, worker}, {cf_exe_sup, supervisor}]).
%% ===================================================================
%% API functions
%% ===================================================================
%%--------------------------------------------------------------------
%% @public
%% @doc
%% Starts the supervisor
%% @end
%%--------------------------------------------------------------------
-spec start_link/0 :: () -> startlink_ret().
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-spec listener_proc/0 :: () -> {'ok', pid()}.
listener_proc() ->
[P] = [P || {Mod, P, _, _} <- supervisor:which_children(?MODULE),
Mod =:= cf_listener],
{ok, P}.
%% ===================================================================
%% Supervisor callbacks
%% ===================================================================
%%--------------------------------------------------------------------
%% @public
%% @doc
%% Whenever a supervisor is started using supervisor:start_link/[2,3],
%% this function is called by the new process to find out about
%% restart strategy, maximum restart frequency and child
%% specifications.
%% @end
%%--------------------------------------------------------------------
-spec init(Args) -> sup_init_ret() when
Args :: [].
init([]) ->
RestartStrategy = one_for_one,
MaxRestarts = 5,
MaxSecondsBetweenRestarts = 10,
SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},
Children = [?CHILD(Name, Type) || {Name, Type} <- ?CHILDREN],
{ok, {SupFlags, Children}}.