blob: 8daa7b6e280e94781daf64b502ff2324548a1df2 [file] [log] [blame]
Harald Weltec6e466e2011-10-10 14:03:50 +02001% OTP Supervisor for Osmocom SCCP
2
3% (C) 2011 by Harald Welte <laforge@gnumonks.org>
4%
5% All Rights Reserved
6%
7% This program is free software; you can redistribute it and/or modify
8% it under the terms of the GNU Affero General Public License as
9% published by the Free Software Foundation; either version 3 of the
10% License, or (at your option) any later version.
11%
12% This program is distributed in the hope that it will be useful,
13% but WITHOUT ANY WARRANTY; without even the implied warranty of
14% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15% GNU General Public License for more details.
16%
17% You should have received a copy of the GNU Affero General Public License
18% along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20-module(osmo_ss7_sup).
21-behavior(supervisor).
22
23-export([start_link/0, add_mtp_link/1]).
24-export([init/1]).
25
26-include_lib("osmo_ss7/include/osmo_ss7.hrl").
27
28start_link() ->
29 supervisor:start_link({local, ?MODULE}, ?MODULE, [{debug, [trace]}]).
30
31init(Args) ->
32 LinksChild = {ss7_links, {ss7_links, start_link, []},
33 permanent, 2000, worker, [ss7_links]},
Harald Welteb8bfc4e2011-10-11 18:49:59 +020034 RouteChild = {ss7_routes, {ss7_routes, start_link, []},
35 permanent, 2000, worker, [ss7_routes]},
36 {ok,{{one_for_one,60,600}, [LinksChild, RouteChild]}}.
Harald Weltec6e466e2011-10-10 14:03:50 +020037
38% Add a m3ua link to this supervisor
39add_mtp_link(L=#sigtran_link{type = m3ua, name = Name,
40 local = Local, remote = Remote}) ->
41 ChildName = list_to_atom("ss7_link_m3ua_" ++ Name),
42 ChildSpec = {ChildName, {ss7_link_m3ua, start_link, [L]},
Harald Welte8fa297d2011-10-10 19:32:13 +020043 permanent, 2000, worker, [ss7_link_m3ua]},
Harald Weltec6e466e2011-10-10 14:03:50 +020044 supervisor:start_child(?MODULE, ChildSpec);
Harald Welte5cde7622012-01-23 23:18:28 +010045add_mtp_link(L=#sigtran_link{type = ipa_client, name = Name}) ->
46 ChildName = list_to_atom("ss7_link_ipa_client_" ++ Name),
47 ChildSpec = {ChildName, {ss7_link_ipa_client, start_link, [L]},
48 permanent, 2000, worker, [ss7_link_ipa_client]},
49 supervisor:start_child(?MODULE, ChildSpec);
Harald Weltec6e466e2011-10-10 14:03:50 +020050add_mtp_link([]) ->
51 ok;
52add_mtp_link([Head|Tail]) ->
53 add_mtp_link(Head, Tail).
54add_mtp_link(Head, Tail) ->
55 {ok, _Child} = add_mtp_link(Head),
56 add_mtp_link(Tail).