summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-11 17:54:08 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-11 17:54:08 +0100
commit0ebc8a64a51ff4255c931c23039e7485cbaee08a (patch)
treef779dd15bb61a93d90cbdb573828801eb7804a9a
parentd5f00862816454c7a025e8a0bebc12d6a8f611ed (diff)
Cleanup
-rw-r--r--src/pbx_acse.erl40
-rw-r--r--src/pbx_conn.erl3
-rw-r--r--src/pbx_pdu.erl4
-rw-r--r--src/pbx_rose.erl38
-rw-r--r--src/pbx_status.erl29
5 files changed, 45 insertions, 69 deletions
diff --git a/src/pbx_acse.erl b/src/pbx_acse.erl
index 84a3bb3..c3ef94e 100644
--- a/src/pbx_acse.erl
+++ b/src/pbx_acse.erl
@@ -6,40 +6,22 @@
-export([init/1, handle_event/2, handle_call/2, handle_info/2,
terminate/2, code_change/3]).
--export([encode/1, decode/1]).
+-export([encode/1]).
-encode(userinformation) ->
- 'CSTA-application-context-information-csta3':encode(
- 'ACSEUserInformationForCSTA', {newDefinition,
- #'NewACSEUserInformationForCSTA'{cSTAVersion = [versionFive]}});
encode(associate) ->
- {ok, UI} = encode(userinformation),
- AARQ = {aarq, #'AARQ-apdu'{
+ 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' = [#'EXTERNAL'{
- 'direct-reference' = {1, 3, 12, 0, 285, 200},
- encoding = {'single-ASN1-type', UI}}]}},
- encode(AARQ);
+ 'user-information' = [Ext]},
+ 'ACSE-1':encode('ACSE-apdu', {aarq, AARQ});
encode(release) ->
- RLRQ = {rlrq, #'RLRQ-apdu'{}},
- encode(RLRQ);
-encode(Data) ->
- 'ACSE-1':encode('ACSE-apdu', Data).
-
-decode({aare, #'AARE-apdu'{result = accepted}}) ->
- ok;
-decode({aare, #'AARE-apdu'{}}) ->
- error;
-decode({rlre, _}) ->
- ok;
-decode({abrt, _}) ->
- error;
-decode({asn1_ExtAlt, Data}) ->
- pbx_rose:decode(Data);
-decode(<<Data/binary>>) ->
- {ok, Pdu} = 'ACSE-1':decode('ACSE-apdu', Data),
- decode(Pdu).
+ 'ACSE-1':encode('ACSE-apdu', {rlrq, #'RLRQ-apdu'{}}).
%%%
diff --git a/src/pbx_conn.erl b/src/pbx_conn.erl
index bb5f478..9ee0a93 100644
--- a/src/pbx_conn.erl
+++ b/src/pbx_conn.erl
@@ -23,6 +23,7 @@ handle_call(_Request, _From, Socket) ->
{reply, ok, Socket}.
handle_cast({ok, Reply}, Socket) ->
+ io:format("Send: ~p~n", [Reply]),
gen_tcp:send(Socket, Reply),
{noreply, Socket};
handle_cast({error, Reason}, Socket) ->
@@ -31,7 +32,7 @@ handle_cast({error, Reason}, Socket) ->
handle_info({tcp, _, Data}, Socket) ->
%pbx_acse:decode(Data),
Pdu = pbx_pdu:decode(Data),
- io:format("PDU ~p~n", [Pdu]),
+ io:format("PDU: ~p~n", [Pdu]),
gen_event:notify(pbx_pdu, Pdu),
{noreply, Socket};
diff --git a/src/pbx_pdu.erl b/src/pbx_pdu.erl
index a5d4d79..64a03ea 100644
--- a/src/pbx_pdu.erl
+++ b/src/pbx_pdu.erl
@@ -2,6 +2,7 @@
-export([decode/1]).
-export([start_link/0, add_handler/2]).
+-export([call/2]).
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
-include("ACSE-1.hrl").
@@ -20,3 +21,6 @@ start_link() ->
add_handler(Handler, Args) ->
gen_event:add_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 76cb89e..0447d8b 100644
--- a/src/pbx_rose.erl
+++ b/src/pbx_rose.erl
@@ -8,16 +8,6 @@
-include("opcodes.hrl").
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
-return(Id, Op, {ok, Data}) ->
- 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {returnResult,
- #'ReturnResult'{invokeId = Id,
- result = #'ReturnResult_result'{opcode = Op, result = Data}}}).
-
-invoke(Op, {ok, Data}) ->
- Id = pbx_invoke:next(),
- 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {invoke,
- #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}).
-
decode({invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}) ->
pbx_invoke:set(Id),
case Op of
@@ -37,7 +27,8 @@ decode({invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}) ->
ok;
?STATUS ->
%io:format("Status: ~p~n", [pbx_status:value(Data)]),
- pbx_conn:send(return(Id, Op, pbx_status:encode()));
+ %%% pbx_conn:send(return(Id, Op, pbx_status:encode()));
+ ok;
_ ->
error
end;
@@ -83,6 +74,15 @@ decode(<<Data/binary>>) ->
init(_Args) ->
{ok, {present, 0}}.
+handle_event({invoke, Invoke = #'Invoke'{opcode = ?STATUS}}, _State) ->
+ Status = pbx_status:decode(Invoke#'Invoke'.argument),
+ case pbx_status:value(Status) of
+ normal ->
+ reply(Invoke, pbx_status:encode());
+ _ ->
+ ok
+ end,
+ {ok, Invoke#'Invoke'.invokeId};
handle_event({invoke, Invoke = #'Invoke'{}}, _State) ->
io:format("Invoke ~p~n", [Invoke]),
{ok, Invoke#'Invoke'.invokeId};
@@ -112,5 +112,21 @@ terminate(_Reason, _State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
+%%%
+
next({present, N}) ->
{present, N+1}.
+
+reply(Invoke = #'Invoke'{}, Data) ->
+ pbx_conn:send(return(Invoke, Data)).
+
+return(#'Invoke'{invokeId = Id, opcode = Op}, {ok, Data}) ->
+ Result = #'ReturnResult_result'{opcode = Op, result = Data},
+ ReturnResult = #'ReturnResult'{invokeId = Id, result = Result},
+ 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {returnResult,
+ ReturnResult}).
+
+invoke(Op, {ok, Data}) ->
+ Id = pbx_pdu:call(?MODULE, nextInvoke),
+ Invoke = #'Invoke'{invokeId = Id, opcode = Op, argument = Data},
+ 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {invoke, Invoke}).
diff --git a/src/pbx_status.erl b/src/pbx_status.erl
index 0b90a94..74a60af 100644
--- a/src/pbx_status.erl
+++ b/src/pbx_status.erl
@@ -1,8 +1,4 @@
-module(pbx_status).
--behaviour(gen_event).
-
--export([init/1, handle_event/2, handle_call/2, handle_info/2,
- terminate/2, code_change/3]).
-export([decode/1, encode/0, value/1]).
@@ -15,27 +11,4 @@ encode() ->
'CSTA-system-status':encode('SystemStatusRes', {noData, []}).
value({ok, #'SystemStatusArg'{systemStatus = Status}}) ->
- Status;
-
-value(Data) ->
- value(decode(Data)).
-
-%%%
-
-init(_Args) ->
- {ok, []}.
-
-handle_event(_Event, State) ->
- {ok, 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}.
+ Status.