summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-11 20:19:56 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-11 20:19:56 +0100
commite4108735e1226395d4956e1d87d83e7a06f261c9 (patch)
tree7b0bf87e0f0148907172ac536c4180902838ad2a
parent7bf02af36d8aabcd108547bb8ef700d1a039a2ad (diff)
Notify self
-rw-r--r--src/pbx_api.erl33
-rw-r--r--src/pbx_pdu.erl10
-rw-r--r--src/pbx_rose.erl44
3 files changed, 45 insertions, 42 deletions
diff --git a/src/pbx_api.erl b/src/pbx_api.erl
index e5fa5fd..9d76ad4 100644
--- a/src/pbx_api.erl
+++ b/src/pbx_api.erl
@@ -4,32 +4,35 @@
-export([ext/0, co/0, snapshot/1, monitor/1, button/1, dial/2, fco/1, type/0]).
ext() ->
- pbx_conn:send(pbx_rose:invoke(?ESCAPE,
- pbx_escape:lines(station))).
+ pbx_pdu:notify({invoke, ?ESCAPE,
+ pbx_escape:lines(station)}).
co() ->
- pbx_conn:send(pbx_rose:invoke(?ESCAPE,
- pbx_escape:lines(networkInterface))).
+ pbx_pdu:notify({invoke, ?ESCAPE,
+ pbx_escape:lines(networkInterface)}).
snapshot(Device) ->
- pbx_conn:send(pbx_rose:invoke(?SNAPSHOT,
- pbx_snapshot:encode({dialingNumber, Device}))).
+ pbx_pdu:notify({invoke, ?SNAPSHOT,
+ pbx_snapshot:encode({dialingNumber, Device})}).
button(Device) ->
- pbx_conn:send(pbx_rose:invoke(?BUTTON,
- pbx_button:encode({dialingNumber, Device}))).
+ pbx_pdu:notify({invoke, ?BUTTON,
+ pbx_button:encode({dialingNumber, Device})}).
monitor(Device) ->
- pbx_conn:send(pbx_rose:invoke(?MONITOR,
- pbx_monitor:encode({dialingNumber, Device}))).
+ pbx_pdu:notify({invoke, ?MONITOR,
+ pbx_monitor:encode({dialingNumber, Device})}).
dial(From, To) ->
- pbx_conn:send(pbx_rose:invoke(?MAKECALL,
- pbx_dial:encode({dialingNumber, From}, {dialingNumber, To}))).
+ pbx_pdu:notify({invoke, ?MAKECALL,
+ pbx_dial:encode({dialingNumber, From},
+ {dialingNumber, To})}).
fco(Device) ->
- pbx_conn:send(pbx_rose:invoke(?ESCAPE,
- pbx_escape:deviceData({dialingNumber, Device}))).
+ pbx_pdu:notify({invoke, ?ESCAPE,
+ pbx_escape:deviceData({dialingNumber, Device})}).
type() ->
- pbx_conn:send(pbx_rose:invoke(?ESCAPE, pbx_escape:pbxType())).
+ pbx_pdu:notify({invoke, ?ESCAPE,
+ pbx_escape:pbxType()}).
+
diff --git a/src/pbx_pdu.erl b/src/pbx_pdu.erl
index 2fc5854..3ca5df3 100644
--- a/src/pbx_pdu.erl
+++ b/src/pbx_pdu.erl
@@ -1,7 +1,7 @@
-module(pbx_pdu).
--export([start_link/0, add_handler/2, delete_handler/2, notify/1]).
--export([decode/1, call/2]).
+-export([start_link/0, add_handler/2, delete_handler/2, notify/1, call/2]).
+-export([decode/1]).
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
-include("ACSE-1.hrl").
@@ -18,6 +18,9 @@ delete_handler(Handler, Args) ->
notify(Args) ->
gen_event:notify(?MODULE, Args).
+call(Handler, Args) ->
+ gen_event:call(?MODULE, Handler, Args).
+
%%%
decode({asn1_ExtAlt, <<Data/binary>>}) ->
@@ -28,6 +31,3 @@ decode(<<Data/binary>>) ->
decode(Pdu);
decode(Pdu) ->
Pdu.
-
-call(Handler, Args) ->
- gen_event:call(?MODULE, Handler, Args).
diff --git a/src/pbx_rose.erl b/src/pbx_rose.erl
index de81aa5..d5dba2c 100644
--- a/src/pbx_rose.erl
+++ b/src/pbx_rose.erl
@@ -3,7 +3,6 @@
-export([init/1, handle_event/2, handle_call/2, handle_info/2,
terminate/2, code_change/3]).
--export([invoke/2]).
-include("opcodes.hrl").
-include("Remote-Operations-Generic-ROS-PDUs.hrl").
@@ -16,11 +15,16 @@
init(_Args) ->
{ok, {present, 0}}.
-handle_event({invoke, Invoke = ?INVOKE(Id, ?STATUS, Data)}, _State) ->
+handle_event({invoke, ?INVOKE(Id, ?STATUS, Data)}, _State) ->
Status = pbx_status:decode(Data),
Value = pbx_status:value(Status),
io:format("Status: ~p~n", [Value]),
- reply(Invoke, Value),
+ case Value of
+ normal ->
+ pbx_pdu:notify({status, ?STATUS, pbx_status:encode()});
+ _ ->
+ ok
+ end,
{ok, Id};
handle_event({invoke, ?INVOKE(Id, ?EVENT, Data)}, _State) ->
{ok, Event} = pbx_event:decode(Data),
@@ -63,11 +67,24 @@ handle_event({returnError, ReturnError = #'ReturnError'{invokeId = Id}}, _State)
handle_event({reject, #'Reject'{invokeId = Id, problem = Problem}}, _State) ->
io:format("Reject ~p~n", [Problem]),
{ok, Id};
+handle_event({invoke, Op, {ok, Data}}, State) ->
+ NewState = next(State),
+ Invoke = #'Invoke'{invokeId = NewState, opcode = Op, argument = Data},
+ Reply = 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {invoke, Invoke}),
+ pbx_conn:send(Reply),
+ {ok, NewState};
+handle_event({status, Op, {ok, Data}}, State) ->
+ Result = #'ReturnResult_result'{opcode = Op, result = Data},
+ ReturnResult = #'ReturnResult'{invokeId = State, result = Result},
+ Reply = 'Remote-Operations-Generic-ROS-PDUs':encode('ROS', {returnResult, ReturnResult}),
+ pbx_conn:send(Reply),
+ {ok, State};
handle_event(_Event, State) ->
{ok, State}.
-handle_call(nextInvoke, State) ->
- {ok, next(State), next(State)};
+handle_call({nextInvoke}, State) ->
+ NewState = next(State),
+ {ok, NewState, NewState};
handle_call(_Request, State) ->
{ok, ok, State}.
@@ -84,20 +101,3 @@ code_change(_OldVsn, State, _Extra) ->
next({present, N}) ->
{present, N+1}.
-
-reply(Invoke = #'Invoke'{}, normal) ->
- Data = pbx_status:encode(),
- Reply = return(Invoke, Data),
- pbx_conn:send(Reply);
-reply(_Invoke, _) ->
- ok.
-
-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}).