Harald Welte | c6e466e | 2011-10-10 14:03:50 +0200 | [diff] [blame] | 1 | % 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/>. |
Harald Welte | f8bf032 | 2012-04-16 13:10:47 +0200 | [diff] [blame] | 19 | % |
| 20 | % Additional Permission under GNU AGPL version 3 section 7: |
| 21 | % |
| 22 | % If you modify this Program, or any covered work, by linking or |
| 23 | % combining it with runtime libraries of Erlang/OTP as released by |
| 24 | % Ericsson on http://www.erlang.org (or a modified version of these |
| 25 | % libraries), containing parts covered by the terms of the Erlang Public |
| 26 | % License (http://www.erlang.org/EPLICENSE), the licensors of this |
| 27 | % Program grant you additional permission to convey the resulting work |
| 28 | % without the need to license the runtime libraries of Erlang/OTP under |
| 29 | % the GNU Affero General Public License. Corresponding Source for a |
| 30 | % non-source form of such a combination shall include the source code |
| 31 | % for the parts of the runtime libraries of Erlang/OTP used as well as |
| 32 | % that of the covered work. |
Harald Welte | c6e466e | 2011-10-10 14:03:50 +0200 | [diff] [blame] | 33 | |
| 34 | -module(osmo_ss7_sup). |
| 35 | -behavior(supervisor). |
| 36 | |
| 37 | -export([start_link/0, add_mtp_link/1]). |
| 38 | -export([init/1]). |
| 39 | |
| 40 | -include_lib("osmo_ss7/include/osmo_ss7.hrl"). |
| 41 | |
| 42 | start_link() -> |
| 43 | supervisor:start_link({local, ?MODULE}, ?MODULE, [{debug, [trace]}]). |
| 44 | |
| 45 | init(Args) -> |
| 46 | LinksChild = {ss7_links, {ss7_links, start_link, []}, |
| 47 | permanent, 2000, worker, [ss7_links]}, |
Harald Welte | b8bfc4e | 2011-10-11 18:49:59 +0200 | [diff] [blame] | 48 | RouteChild = {ss7_routes, {ss7_routes, start_link, []}, |
| 49 | permanent, 2000, worker, [ss7_routes]}, |
| 50 | {ok,{{one_for_one,60,600}, [LinksChild, RouteChild]}}. |
Harald Welte | c6e466e | 2011-10-10 14:03:50 +0200 | [diff] [blame] | 51 | |
| 52 | % Add a m3ua link to this supervisor |
| 53 | add_mtp_link(L=#sigtran_link{type = m3ua, name = Name, |
| 54 | local = Local, remote = Remote}) -> |
| 55 | ChildName = list_to_atom("ss7_link_m3ua_" ++ Name), |
| 56 | ChildSpec = {ChildName, {ss7_link_m3ua, start_link, [L]}, |
Harald Welte | 8fa297d | 2011-10-10 19:32:13 +0200 | [diff] [blame] | 57 | permanent, 2000, worker, [ss7_link_m3ua]}, |
Harald Welte | c6e466e | 2011-10-10 14:03:50 +0200 | [diff] [blame] | 58 | supervisor:start_child(?MODULE, ChildSpec); |
Harald Welte | 5c9f3b5 | 2013-07-26 22:40:25 +0800 | [diff] [blame] | 59 | add_mtp_link(L=#sigtran_link{type = m2ua, name = Name, |
| 60 | local = Local, remote = Remote}) -> |
| 61 | ChildName = list_to_atom("ss7_link_m2ua_" ++ Name), |
| 62 | ChildSpec = {ChildName, {ss7_link_m2ua, start_link, [L]}, |
| 63 | permanent, 2000, worker, [ss7_link_m2ua]}, |
| 64 | supervisor:start_child(?MODULE, ChildSpec); |
Harald Welte | 5cde762 | 2012-01-23 23:18:28 +0100 | [diff] [blame] | 65 | add_mtp_link(L=#sigtran_link{type = ipa_client, name = Name}) -> |
| 66 | ChildName = list_to_atom("ss7_link_ipa_client_" ++ Name), |
| 67 | ChildSpec = {ChildName, {ss7_link_ipa_client, start_link, [L]}, |
| 68 | permanent, 2000, worker, [ss7_link_ipa_client]}, |
| 69 | supervisor:start_child(?MODULE, ChildSpec); |
Harald Welte | c6e466e | 2011-10-10 14:03:50 +0200 | [diff] [blame] | 70 | add_mtp_link([]) -> |
| 71 | ok; |
| 72 | add_mtp_link([Head|Tail]) -> |
| 73 | add_mtp_link(Head, Tail). |
| 74 | add_mtp_link(Head, Tail) -> |
| 75 | {ok, _Child} = add_mtp_link(Head), |
| 76 | add_mtp_link(Tail). |