From 6f1e72c6786c41da829c2ab3002e7edaec1f66e1 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 15 Dec 2011 16:43:37 +0100 Subject: [PATCH] add new tcap_user module This is what a user process will call in order to initiate TCAP transactions. --- TCAP/src/Makefile | 5 +++-- TCAP/src/tcap_user.erl | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 TCAP/src/tcap_user.erl diff --git a/TCAP/src/Makefile b/TCAP/src/Makefile index 9f9b3ef..9312aef 100644 --- a/TCAP/src/Makefile +++ b/TCAP/src/Makefile @@ -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 diff --git a/TCAP/src/tcap_user.erl b/TCAP/src/tcap_user.erl new file mode 100644 index 0000000..156d883 --- /dev/null +++ b/TCAP/src/tcap_user.erl @@ -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. +