From a13aa77e4f298945a43eaf3a67b4e575a2c79373 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 11 Nov 2015 04:42:02 +0100 Subject: Event stub --- src/pbx_acse.erl | 42 ++++++++++++++++++++++++++++++++++++++++++ src/pbx_conn.erl | 2 ++ 2 files changed, 44 insertions(+) diff --git a/src/pbx_acse.erl b/src/pbx_acse.erl index 3b17614..9a3cf47 100644 --- a/src/pbx_acse.erl +++ b/src/pbx_acse.erl @@ -1,8 +1,12 @@ -module(pbx_acse). +-behaviour(gen_event). -include("ACSE-1.hrl"). -include("CSTA-application-context-information-csta3.hrl"). +-export([start_link/0, add_handler/2]). +-export([init/1, handle_event/2, handle_call/2, handle_info/2, + terminate/2, code_change/3]). -export([encode/1, decode/1]). encode(userinformation) -> @@ -37,3 +41,41 @@ decode({asn1_ExtAlt, Data}) -> decode(<>) -> {ok, Pdu} = 'ACSE-1':decode('ACSE-apdu', Data), decode(Pdu). + +%%% + +start_link() -> + gen_event:start_link({local, ?MODULE}). + +add_handler(Handler, Args) -> + gen_event:add_handler(?MODULE, Handler, Args). + +init(_Args) -> + {ok, []}. + +handle_event({aare, #'AARE-apdu'{result = Result}}, _State) -> + io:format("AARE ~p~n", [Result]), + {ok, Result}; % accepted or rejected +handle_event({rlre, _}, _State) -> + io:format("RLRE~n"), + {ok, released}; +handle_event({abrt, _}, _State) -> + io:format("ABRT~n"), + {ok, aborted}; +handle_event(_Event, State) -> + io:format("ELSE~n"), + {ok, State}. + +handle_call(association, State) -> + {ok, State, State}; +handle_call(_Request, State) -> + {ok, ok, State}. + +handle_info(_Info, State) -> + {ok, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. diff --git a/src/pbx_conn.erl b/src/pbx_conn.erl index 8326b84..b79aa80 100644 --- a/src/pbx_conn.erl +++ b/src/pbx_conn.erl @@ -10,6 +10,7 @@ -include("config.hrl"). start_link() -> + %pbx_acse:start_link(), gen_server:start_link({local, ?SERVER}, ?MODULE, [?HOST, ?PORT], []). init(Args) -> @@ -30,6 +31,7 @@ handle_info({tcp, _, Data}, Socket) -> pbx_acse:decode(Data), Pdu = pbx_pdu:decode(Data), io:format("PDU ~p~n", [Pdu]), + %gen_event:notify(pbx_acse, Pdu), {noreply, Socket}; handle_info({tcp_closed, _}, Socket) -> -- cgit v1.2.3