add new tcap_user module

This is what a user process will call in order to initiate TCAP
transactions.
This commit is contained in:
Harald Welte 2011-12-15 16:43:37 +01:00
parent efd9ab0344
commit 6f1e72c678
2 changed files with 46 additions and 2 deletions

View File

@ -5,7 +5,7 @@ EBIN = ../ebin
ERL = erl
ERLC = erlc
EMULATOR = beam
ERLCFLAGS = -b $(EMULATOR) -o $(EBIN) -W -v +warn_unused_vars
ERLCFLAGS = -b $(EMULATOR) -o $(EBIN) -W -v +warn_unused_vars -I../include
$(EBIN)/%.$(EMULATOR):%.erl
$(ERLC) $(ERLCFLAGS) $<
@ -16,7 +16,8 @@ BEAMS = $(EBIN)/tcap.$(EMULATOR) $(EBIN)/tcap_app.$(EMULATOR) \
$(EBIN)/tcap_transaction_sup.$(EMULATOR) \
$(EBIN)/tcap_dialogue_sup.$(EMULATOR) \
$(EBIN)/tcap_components_sup.$(EMULATOR) \
$(EBIN)/tcap_invocation_sup.$(EMULATOR)
$(EBIN)/tcap_invocation_sup.$(EMULATOR) \
$(EBIN)/tcap_user.$(EMULATOR)
.PHONY: default
default: all

43
TCAP/src/tcap_user.erl Normal file
View File

@ -0,0 +1,43 @@
-module(tcap_user).
-export([send_prim/2]).
-include("tcap.hrl").
% the user (TCU) sends us a primitive. We decide where to route it
send_prim(TCO, P={'TC', 'INVOKE', request, Param}) when
is_record(Param, 'TC-INVOKE') ->
DialgId = Param#'TC-INVOKE'.dialogueID,
case ets:lookup(tcap_dha, DialgId) of
[] ->
% start new DHA FSM for this dialogue; it will start CCO
DHA = start_new_dha(TCO, DialgId);
[DHA] ->
ok
end,
% resolve CCO from DHA
CCO = tcap_dha_fsm:get_cco_pid(DHA),
gen_server:cast(CCO, P);
send_prim(TCO, P={'TC', 'BEGIN', request, Param}) when
is_record(Param, 'TC-BEGIN') ->
DialgId = Param#'TC-BEGIN'.dialogueID,
case ets:lookup(tcap_dha, DialgId) of
[] ->
% start new DHA FSM for this dialogue; it will start CCO
DHA = start_new_dha(TCO, DialgId);
[DHA] ->
ok
end,
gen_fsm:send_event(DHA, P);
send_prim(_TCO, P) ->
{errror, {unknown_prim, P}}.
%% local functions
start_new_dha(TCO, LocalTID) ->
Args = [self(), LocalTID, TCO],
{ok, Pid} = supervisor:start_link(tcap_dialogue_sup, Args),
Pid.