forked from erlang/signerl
add new tcap_user:start_sap() function
This can be used to instantiate the per-SAP tcap_sap_sup and tcap_tco_server callback module in a simple call like this: {ok, TcoPid} = tcap_user:start_sap(osmo_sccp_tcap, [7], []).
This commit is contained in:
parent
f23b46c414
commit
66514a113e
|
@ -49,7 +49,7 @@
|
|||
|
||||
-behaviour(supervisor).
|
||||
|
||||
-export([init/1]).
|
||||
-export([init/1, start_link/3]).
|
||||
|
||||
|
||||
%% @spec(StartArgs::term()) -> Result = {ok,{{RestartStrategy,MaxR,MaxT},[ChildSpec]}} | ignore
|
||||
|
@ -65,5 +65,8 @@ init([Module, Args, Options]) when is_list(Args), is_list(Options) ->
|
|||
StartArgs = [{local, Name}, tcap_tco_server, [self(), Module, Args], Options],
|
||||
StartFunc = {gen_server, start_link, StartArgs},
|
||||
ChildSpec = {tco, StartFunc, permanent, 4000, worker, [Module, tcap_tco_server]},
|
||||
{ok,{{one_for_one, 10, 60}, [ChildSpec]}}.
|
||||
{ok,{{one_for_one, 1, 1}, [ChildSpec]}}.
|
||||
|
||||
|
||||
start_link(Mod, Args, Opts) ->
|
||||
supervisor:start_link(?MODULE, [Mod, Args, Opts]).
|
||||
|
|
|
@ -60,9 +60,8 @@
|
|||
%%
|
||||
%% @equiv //stdlib/supervisor:init/1
|
||||
%%
|
||||
init(_StartArgs) ->
|
||||
StartMod = tcap_sap_sup,
|
||||
StartFunc = {supervisor, start_link, [StartMod,[osmo_sccp_tcap,[6],[]]]},
|
||||
init(_Args) ->
|
||||
StartFunc = {tcap_sap_sup, start_link, []},
|
||||
% {Id, StartFunc, Restart, Shutdown, Tpype, Modules}
|
||||
ChildSpec = {tcap_sap_sup, StartFunc, permanent, infinity, supervisor, [StartMod]},
|
||||
ChildSpec = {tcap_sap_sup, StartFunc, permanent, infinity, supervisor, [tcap_sap_sup]},
|
||||
{ok,{{simple_one_for_one, 10, 60}, [ChildSpec]}}.
|
||||
|
|
|
@ -1,7 +1,52 @@
|
|||
%%%
|
||||
%%%---------------------------------------------------------------------
|
||||
%%% @copyright 2011 Harald Welte
|
||||
%%% @author Harald Welte <laforge@gnumonks.org>
|
||||
%%% @end
|
||||
%%%
|
||||
%%% Copyright (c) 2011 Harald Welte
|
||||
%%%
|
||||
%%% All rights reserved.
|
||||
%%%
|
||||
%%% Redistribution and use in source and binary forms, with or without
|
||||
%%% modification, are permitted provided that the following conditions
|
||||
%%% are met:
|
||||
%%%
|
||||
%%% - Redistributions of source code must retain the above copyright
|
||||
%%% notice, this list of conditions and the following disclaimer.
|
||||
%%% - Redistributions in binary form must reproduce the above copyright
|
||||
%%% notice, this list of conditions and the following disclaimer in
|
||||
%%% the documentation and/or other materials provided with the
|
||||
%%% distribution.
|
||||
%%% - Neither the name of Motivity Telecom nor the names of its
|
||||
%%% contributors may be used to endorse or promote products derived
|
||||
%%% from this software without specific prior written permission.
|
||||
%%%
|
||||
%%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
%%% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
%%% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
%%% A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
%%% OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
%%% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
%%% LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
%%% DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
%%% THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
%%% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
%%% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
%%%
|
||||
%%%---------------------------------------------------------------------
|
||||
%%%
|
||||
%%% @doc TCAP application user SAP helper functions.
|
||||
%%%
|
||||
%%% @reference <a href="index.html">TCAP User's Guide</a>
|
||||
%%%
|
||||
%%% @private
|
||||
|
||||
-module(tcap_user).
|
||||
-copyright('Copyright (c) 2011 Harald Welte').
|
||||
-author('Harald Welte <laforge@gnumonks.org>').
|
||||
|
||||
-export([send_prim/2]).
|
||||
-export([send_prim/2, start_sap/3]).
|
||||
|
||||
-include("tcap.hrl").
|
||||
|
||||
|
@ -33,6 +78,18 @@ send_prim(TCO, P={'TC', 'BEGIN', request, Param}) when
|
|||
send_prim(_TCO, P) ->
|
||||
{errror, {unknown_prim, P}}.
|
||||
|
||||
% high-level user API to start the TCAP SAP supervisor + TCO server for a given SAP
|
||||
start_sap(SccpModule, Args, Opts) ->
|
||||
% tcap_sup os simple_one_for_one and thus will start a tcap_sap_sup
|
||||
% process that will in turn start the TCO "Module" as a child. The pid
|
||||
% we get is the tcap_sap_sup, not the TCO itself!
|
||||
case supervisor:start_child(tcap_sup, [SccpModule, Args, Opts]) of
|
||||
{ok, TcoSupPid} ->
|
||||
[{_, TCO, _, _}] = supervisor:which_children(TcoSupPid),
|
||||
{ok, TCO};
|
||||
Default ->
|
||||
Default
|
||||
end.
|
||||
|
||||
%% local functions
|
||||
|
||||
|
|
Loading…
Reference in New Issue