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.

Wednesday, August 05, 2009

Friday, July 03, 2009

Gentoo ebuild for rst2pdf

Ebuild for rst2pdf — Tool for transforming reStructuredText to PDF using ReportLab

rst2pdf

New gentoo ebuilds for RabbitMQ server and client

RabbitMQ server and client version 1.6.0 ebuild in ngerakines gentoo overlay

rabbitmq-server
rabbitmq-client

Python AMQP-related gentoo ebuilds

Gentoo ebuilds for qpid-python, txAMQP and amqplib — python libraries for AMQP
http://github.com/Zert/zert-portage/tree/master

Friday, June 05, 2009

Paste on showmecode.com is easy now

Simple Python script which pastes code on showmecode.com with support of syntax highlighing: showmecode.py

Friday, May 29, 2009

Dialyzer warning: no local return

When you have analyzing erlang beams with a dialyzer and see that warning:

module.erl:51: Function init/1 has no local return

check out all used records in this function for right type definitions of its items. For example, if record defined as

-record(state, {
name :: string(),
data :: binary()
}

and usage of state is

init([]) ->
{ok, #state{name = "Name", data = "Data"}}

this warning will appears.

Wednesday, May 20, 2009

Trivial examples of AMQP usage

Trivial examples of AMQP dispatcher and client in Erlang:
http://github.com/Zert/amqp-erlang-sample/tree/master

make_ref() hint

BIF make_ref() returns built-in type ref() which is unique on this node. Type ref() contains name of node if erl started with -sname or -name parameters, therefore we can use ref() in distributed systems for some unique value through all nodes. BTW, keep in mind that reference will re-occur after approximately 2^82 calls.