From e4108735e1226395d4956e1d87d83e7a06f261c9 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 11 Nov 2015 20:19:56 +0100 Subject: Notify self --- src/pbx_rose.erl | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/pbx_rose.erl') 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}). -- cgit v1.2.3