forked from erlang/signerl
TCAP: resolve DHA / CCO dependencies on TC-U initiated BEGIN
Prior to this patch, DHA needs to know the CCO pid, and CCO needed to know the DHA pid at startup. The idea was to start CCO from within the init() callback in DHA. However, this caused a deadlock in the supervisor. We now use the locally registred process names (tcap_cco_DLGID) to resolve the process. However, it might be cleaner to use an ets table at some later point. For now it is nice to see the name of each process in pman for debugging...
This commit is contained in:
parent
5c1cd340eb
commit
d828cfabba
|
@ -68,11 +68,16 @@
|
|||
%%----------------------------------------------------------------------
|
||||
|
||||
%% initialize the server
|
||||
init([Supervisor, USAP, DialogueID, DHA]) ->
|
||||
init([Supervisor, USAP, DialogueID]) ->
|
||||
process_flag(trap_exit, true),
|
||||
DHA = list_to_atom("tcap_dha_" ++ integer_to_list(DialogueID)),
|
||||
{ok, #state{supervisor = Supervisor, usap = USAP, dha = DHA,
|
||||
dialogueID = DialogueID, components = []}}.
|
||||
|
||||
%% set the DHA pid
|
||||
handle_call(set_dha, From, State) ->
|
||||
{noreply, State#state{dha = From}};
|
||||
|
||||
%% shutdown the server
|
||||
handle_call(stop, _From, State) ->
|
||||
{stop, shutdown, ok, State};
|
||||
|
|
|
@ -84,14 +84,8 @@
|
|||
init({USAP, DialogueID, TCO, Supervisor}) ->
|
||||
init({USAP, DialogueID, TCO, undefined, Supervisor});
|
||||
init({USAP, DialogueID, TCO, SupId, Supervisor}) ->
|
||||
%% Start a Component Coordinator (CCO) process
|
||||
ChildName = list_to_atom("cco_sup_" ++ integer_to_list(DialogueID)),
|
||||
ChildArgs = [USAP, DialogueID, self()],
|
||||
StartFunc = {supervisor, start_link, [tcap_components_sup, ChildArgs]},
|
||||
ChildSpec = {ChildName, StartFunc, permanent, infinity,
|
||||
supervisor, [tcap_components_sup]},
|
||||
{ok, CCO} = supervisor:start_child(Supervisor, ChildSpec),
|
||||
ets:insert(tcap_dha, {DialogueID, self()}),
|
||||
CCO = list_to_atom("tcap_cco_" ++ integer_to_list(DialogueID)),
|
||||
process_flag(trap_exit, true),
|
||||
{ok, idle, #state{usap = USAP, did = DialogueID,
|
||||
tco = TCO, supid = SupId, cco = CCO}}.
|
||||
|
@ -839,5 +833,5 @@ code_change(_OldVsn, StateName, State, _Extra) ->
|
|||
|
||||
|
||||
% front-end function called by tcap_user to get CCO for given DHA
|
||||
get_cco_pid(DHA) when is_pid(DHA) ->
|
||||
get_cco_pid(DHA) ->
|
||||
gen_fsm:sync_send_all_state_event(DHA, get_cco_pid).
|
||||
|
|
|
@ -46,11 +46,10 @@
|
|||
%% call backs needed for supervisor behaviour
|
||||
-export([init/1]).
|
||||
|
||||
init([USAP, ID, DHA]) ->
|
||||
init([USAP, ID]) ->
|
||||
Name = list_to_atom("tcap_cco_" ++ integer_to_list(ID)),
|
||||
StartArgs = [tcap_cco_server, [self(), USAP, ID, DHA], [{debug, [trace]}]],
|
||||
StartArgs = [{local, Name}, tcap_cco_server, [self(), USAP, ID], [{debug, [trace]}]],
|
||||
StartFunc = {gen_server, start_link, StartArgs},
|
||||
ChildSpec = {Name, StartFunc, temporary, 4000, worker,
|
||||
[tcap_cco_server]},
|
||||
ChildSpec = {cco, StartFunc, temporary, 4000, worker, [tcap_cco_server]},
|
||||
{ok,{{one_for_all, 0, 1}, [ChildSpec]}}.
|
||||
|
||||
|
|
|
@ -46,18 +46,33 @@
|
|||
%% call backs needed for supervisor behaviour
|
||||
-export([init/1]).
|
||||
|
||||
|
||||
%% Gen child specification for Component Coordinator (CCO) supervisor process
|
||||
gen_comp_sup_spec(USAP, DialogueID) ->
|
||||
ChildName = list_to_atom("tcap_components_sup_" ++ integer_to_list(DialogueID)),
|
||||
ChildArgs = [USAP, DialogueID],
|
||||
StartArgs = [{local, ChildName}, tcap_components_sup, ChildArgs],
|
||||
StartFunc = {supervisor, start_link, StartArgs},
|
||||
ChildSpec = {cco_sup, StartFunc, permanent, infinity,
|
||||
supervisor, [tcap_components_sup]},
|
||||
ChildSpec.
|
||||
|
||||
%% when started from TCO
|
||||
init({USAP, LocalTID, TCO, SupId}) ->
|
||||
StartArgs = [tcap_dha_fsm, [{USAP, LocalTID, TCO, SupId, self()}], []],
|
||||
StartName = list_to_atom("tcap_dha_" ++ integer_to_list(LocalTID)),
|
||||
StartArgs = [{local, StartName}, tcap_dha_fsm, [{USAP, LocalTID, TCO, SupId, self()}], []],
|
||||
StartFunc = {gen_fsm, start_link, StartArgs},
|
||||
ChildSpecComp = gen_comp_sup_spec(USAP, LocalTID),
|
||||
ChildSpec = {dha, StartFunc, permanent, 4000, worker,
|
||||
[tcap_dha_fsm]},
|
||||
{ok,{{one_for_all, 0, 1}, [ChildSpec]}};
|
||||
{ok,{{one_for_all, 0, 1}, [ChildSpecComp, ChildSpec]}};
|
||||
|
||||
%% when started from TSM
|
||||
init({USAP, LocalTID, TCO}) ->
|
||||
StartArgs = [tcap_dha_fsm, {USAP, LocalTID, TCO, self()}, []],
|
||||
StartName = list_to_atom("tcap_dha_" ++ integer_to_list(LocalTID)),
|
||||
StartArgs = [{local, StartName}, tcap_dha_fsm, {USAP, LocalTID, TCO, self()}, []],
|
||||
StartFunc = {gen_fsm, start_link, StartArgs},
|
||||
ChildSpecComp = gen_comp_sup_spec(USAP, LocalTID),
|
||||
ChildSpec = {dha, StartFunc, permanent, 4000, worker,
|
||||
[tcap_dha_fsm]},
|
||||
{ok,{{one_for_all, 0, 1}, [ChildSpec]}}.
|
||||
{ok,{{one_for_all, 0, 1}, [ChildSpecComp, ChildSpec]}}.
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
|
||||
init([USAP, InvokeID]) ->
|
||||
Name = list_to_atom("tcap_ism_" ++ integer_to_list(InvokeID)),
|
||||
StartArgs = [tcap_ism_fsm, [USAP, InvokeID], []],
|
||||
StartArgs = [{local, Name}, tcap_ism_fsm, [USAP, InvokeID], []],
|
||||
StartFunc = {gen_fsm, start_link, StartArgs},
|
||||
ChildSpec = {Name, StartFunc, temporary, 4000, worker,
|
||||
[tcap_ism_sup]},
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
|
||||
init({NSAP, USAP, TID, SupRef}) ->
|
||||
Name = list_to_atom("tcap_tsm_" ++ integer_to_list(TID)),
|
||||
StartArgs = [tcap_tsm_fsm, [NSAP, USAP, TID, self(), SupRef], []],
|
||||
StartArgs = [{local, Name}, tcap_tsm_fsm, [NSAP, USAP, TID, self(), SupRef], []],
|
||||
StartFunc = {gen_fsm, start_link, StartArgs},
|
||||
ChildSpec = {Name, StartFunc, permanent, 1000, worker, [tcap_tsm_fsm]},
|
||||
{ok,{{one_for_all, 0, 1}, [ChildSpec]}}.
|
||||
|
|
|
@ -95,6 +95,7 @@ start_sap(SccpModule, Args, Opts) ->
|
|||
|
||||
start_new_dha(TCO, LocalTID) ->
|
||||
Args = {self(), LocalTID, TCO},
|
||||
% this returns the _supervisor_ pid, not DHA
|
||||
{ok, Pid} = supervisor:start_link(tcap_dialogue_sup, Args),
|
||||
Pid.
|
||||
list_to_atom("tcap_dha_" ++ integer_to_list(LocalTID)).
|
||||
|
||||
|
|
Loading…
Reference in New Issue