Monday, August 17, 2009

Erlang OTP: Megaco digit map handler

Erlang OTP Megaco (H.248) stack has digit map handler which starts up with given digit map, receives dialing events then returns result of dialing. To better working with digitmap let's wrote wrapper:

start(Pid) ->
start_dm_proc(Pid, "(8|0x|[0-79]xxxxx|8xxxxxxxxxx|[0-9]x|E|F|x.F|[0-9].L)", 0, 2, 3, 100).

start_dm_proc(Pid, DM, St, Sh, Ln, Dr) ->
DMV = #'DigitMapValue'{startTimer = St, shortTimer = Sh, longTimer = Ln, digitMapBody = DM, durationTimer = Dr},
spawn(?MODULE, tde_proc, [Pid, DMV]).

tde_proc(Pid, DMV) ->
Res = megaco:eval_digit_map(DMV),
gen_fsm:send_event(Pid, {dial_result, Res}).


Spawned tde_proc/2 (with parent process ID and digit map) can receive digit-events with function megaco:report_digit_event/2 call with eval process ID and dialed digit symbol:

megaco:report_digit_event(EvalPid, Evt)


When reported digits matches with digit map, megaco:eval_digit_map/1 returns such result as: {ok, {full, Number}} or {ok, {unambiguous, Number}} if '#' pressed (dial event 'F').

gen_fsm:send_event(Pid, {dial_result, Res}) sends this result to parent process.

No comments: