summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-11 18:16:31 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-11 18:16:31 +0100
commitbd447ae4c97c7df7eb60a8a8c5ffbfecc89c5742 (patch)
tree1625dacd35c8279623314bca7d3122a743eeaa0c
parent0ebc8a64a51ff4255c931c23039e7485cbaee08a (diff)
WIP
-rw-r--r--src/pbx_acse.erl38
-rw-r--r--src/pbx_conn.erl4
-rw-r--r--src/pbx_pdu.erl8
-rw-r--r--src/pbx_rose.erl6
4 files changed, 30 insertions, 26 deletions
diff --git a/src/pbx_acse.erl b/src/pbx_acse.erl
index c3ef94e..f225eda 100644
--- a/src/pbx_acse.erl
+++ b/src/pbx_acse.erl
@@ -8,24 +8,8 @@
terminate/2, code_change/3]).
-export([encode/1]).
-encode(associate) ->
- UIforCSTA = #'NewACSEUserInformationForCSTA'{
- cSTAVersion = [versionFive]},
- {ok, UI} = 'CSTA-application-context-information-csta3':encode(
- 'ACSEUserInformationForCSTA', {newDefinition, UIforCSTA}),
- Ext = #'EXTERNAL'{'direct-reference' = {1, 3, 12, 0, 285, 200},
- encoding = {'single-ASN1-type', UI}},
- AARQ = #'AARQ-apdu'{
- 'protocol-version' = [version1], % required
- 'application-context-name' = {1, 3, 12, 0, 218},
- 'user-information' = [Ext]},
- 'ACSE-1':encode('ACSE-apdu', {aarq, AARQ});
-encode(release) ->
- 'ACSE-1':encode('ACSE-apdu', {rlrq, #'RLRQ-apdu'{}}).
-
-%%%
-
init(_Args) ->
+ pbx_conn:send(encode(associate)),
{ok, undefined}.
handle_event({aare, #'AARE-apdu'{result = Result}}, _State) ->
@@ -48,8 +32,28 @@ handle_call(_Request, State) ->
handle_info(_Info, State) ->
{ok, State}.
+terminate(_Reason, accepted) ->
+ pbx_conn:send(encode(release)),
+ ok;
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+
+%%%
+
+encode(associate) ->
+ UIforCSTA = #'NewACSEUserInformationForCSTA'{
+ cSTAVersion = [versionFive]},
+ {ok, UI} = 'CSTA-application-context-information-csta3':encode(
+ 'ACSEUserInformationForCSTA', {newDefinition, UIforCSTA}),
+ Ext = #'EXTERNAL'{'direct-reference' = {1, 3, 12, 0, 285, 200},
+ encoding = {'single-ASN1-type', UI}},
+ AARQ = #'AARQ-apdu'{
+ 'protocol-version' = [version1], % required
+ 'application-context-name' = {1, 3, 12, 0, 218},
+ 'user-information' = [Ext]},
+ 'ACSE-1':encode('ACSE-apdu', {aarq, AARQ});
+encode(release) ->
+ 'ACSE-1':encode('ACSE-apdu', {rlrq, #'RLRQ-apdu'{}}).
diff --git a/src/pbx_conn.erl b/src/pbx_conn.erl
index 9ee0a93..f819fdd 100644
--- a/src/pbx_conn.erl
+++ b/src/pbx_conn.erl
@@ -16,7 +16,6 @@ init([Host, Port]) ->
pbx_pdu:start_link(),
pbx_pdu:add_handler(pbx_acse, []),
pbx_pdu:add_handler(pbx_rose, []),
- send(pbx_acse:encode(associate)),
gen_tcp:connect(Host, Port, [binary, {packet, 2}]).
handle_call(_Request, _From, Socket) ->
@@ -30,7 +29,6 @@ handle_cast({error, Reason}, Socket) ->
{stop, Reason, Socket}.
handle_info({tcp, _, Data}, Socket) ->
- %pbx_acse:decode(Data),
Pdu = pbx_pdu:decode(Data),
io:format("PDU: ~p~n", [Pdu]),
gen_event:notify(pbx_pdu, Pdu),
@@ -40,7 +38,7 @@ handle_info({tcp_closed, _}, Socket) ->
{stop, normal, Socket}.
terminate(_Reason, Socket) ->
- send(pbx_acse:encode(release)),
+ pbx_pdu:delete_handler(pbx_acse, []),
gen_tcp:close(Socket).
code_change(_OldVsn, Socket, _Extra) ->
diff --git a/src/pbx_pdu.erl b/src/pbx_pdu.erl
index 64a03ea..21350f9 100644
--- a/src/pbx_pdu.erl
+++ b/src/pbx_pdu.erl
@@ -1,8 +1,7 @@
-module(pbx_pdu).
--export([decode/1]).
--export([start_link/0, add_handler/2]).
--export([call/2]).
+-export([start_link/0, add_handler/2, delete_handler/2]).
+-export([decode/1, call/2]).
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
-include("ACSE-1.hrl").
@@ -22,5 +21,8 @@ start_link() ->
add_handler(Handler, Args) ->
gen_event:add_handler(?MODULE, Handler, Args).
+delete_handler(Handler, Args) ->
+ gen_event:delete_handler(?MODULE, Handler, Args).
+
call(Handler, Args) ->
gen_event:call(?MODULE, Handler, Args).
diff --git a/src/pbx_rose.erl b/src/pbx_rose.erl
index 0447d8b..6328226 100644
--- a/src/pbx_rose.erl
+++ b/src/pbx_rose.erl
@@ -3,7 +3,7 @@
-export([init/1, handle_event/2, handle_call/2, handle_info/2,
terminate/2, code_change/3]).
--export([decode/1, invoke/2]).
+-export([invoke/2]).
-include("opcodes.hrl").
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
@@ -92,8 +92,8 @@ handle_event({returnResult, ReturnResult = #'ReturnResult'{}}, _State) ->
handle_event({returnError, ReturnError = #'ReturnError'{}}, _State) ->
io:format("ReturnError ~p~n", [ReturnError]),
{ok, ReturnError#'ReturnError'.invokeId};
-handle_event({reject, Reject = #'Reject'{}}, _State) ->
- io:format("Reject ~p~n", [Reject]),
+handle_event({reject, Reject = #'Reject'{problem = Problem}}, _State) ->
+ io:format("Reject ~p~n", [Problem]),
{ok, Reject#'Reject'.invokeId};
handle_event(_Event, State) ->
{ok, State}.