Harald Welte | 789c8b1 | 2011-01-22 20:53:50 +0000 | [diff] [blame] | 1 | % Wrapper code, wrapping sctp_handler.erl into OTP gen_server |
| 2 | |
| 3 | % (C) 2011 by Harald Welte <laforge@gnumonks.org> |
| 4 | % (C) 2011 OnWaves |
| 5 | % |
| 6 | % All Rights Reserved |
| 7 | % |
| 8 | % This program is free software; you can redistribute it and/or modify |
| 9 | % it under the terms of the GNU Affero General Public License as |
| 10 | % published by the Free Software Foundation; either version 3 of the |
| 11 | % License, or (at your option) any later version. |
| 12 | % |
| 13 | % This program is distributed in the hope that it will be useful, |
| 14 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | % GNU General Public License for more details. |
| 17 | % |
| 18 | % You should have received a copy of the GNU Affero General Public License |
| 19 | % along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | |
| 21 | -module(mgw_nat_usr). |
| 22 | -author("Harald Welte <laforge@gnumonks.org>"). |
| 23 | |
| 24 | -behavior(gen_server). |
| 25 | |
Harald Welte | a6b0da7 | 2011-02-04 18:08:52 +0100 | [diff] [blame] | 26 | -export([start_link/1, stop/0, sccp_masq_reset/0]). |
Harald Welte | 789c8b1 | 2011-01-22 20:53:50 +0000 | [diff] [blame] | 27 | -export([init/1, handle_cast/2, handle_info/2, terminate/2]). |
| 28 | |
| 29 | |
| 30 | start_link(Params) -> |
| 31 | gen_server:start_link({local, ?MODULE}, ?MODULE, Params, []). |
| 32 | |
| 33 | stop() -> |
| 34 | gen_server:cast(?MODULE, stop). |
| 35 | |
Harald Welte | a6b0da7 | 2011-02-04 18:08:52 +0100 | [diff] [blame] | 36 | sccp_masq_reset() -> |
| 37 | gen_server:cast(?MODULE, sccp_masq_reset). |
| 38 | |
Harald Welte | 789c8b1 | 2011-01-22 20:53:50 +0000 | [diff] [blame] | 39 | |
| 40 | %% Callback functions of the OTP behavior |
| 41 | |
| 42 | init(Params) -> |
Harald Welte | 99f21c6 | 2011-02-03 19:05:33 +0100 | [diff] [blame] | 43 | sccp_masq:init(), |
Harald Welte | 789c8b1 | 2011-01-22 20:53:50 +0000 | [diff] [blame] | 44 | apply(sctp_handler, init, Params). |
| 45 | |
| 46 | handle_cast(stop, LoopData) -> |
Harald Welte | a6b0da7 | 2011-02-04 18:08:52 +0100 | [diff] [blame] | 47 | {stop, normal, LoopData}; |
| 48 | |
| 49 | handle_cast(sccp_masq_reset, LoopData) -> |
| 50 | sccp_masq:reset(), |
| 51 | {noreply, LoopData}. |
Harald Welte | 789c8b1 | 2011-01-22 20:53:50 +0000 | [diff] [blame] | 52 | |
| 53 | terminate(_Reason, _LoopData) -> |
| 54 | ok. |
| 55 | |
| 56 | % callback for other events like incoming SCTP message |
| 57 | handle_info({sctp, Sock, Ip, Port, Data}, LoopData) -> |
| 58 | NewL = sctp_handler:handle_sctp(LoopData, {sctp, Sock, Ip, Port, Data}), |
| 59 | {noreply, NewL}. |