Skip to content

Commit

Permalink
Made 2 action_client callbacks as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ziopio committed Jan 8, 2022
1 parent b0c65a5 commit f1b628c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
12 changes: 8 additions & 4 deletions demos/cancel_action_client/src/cancel_action_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ handle_cast({on_get_result_reply,
io:format("Result received: ~p\n", [Seq]),
{noreply, S};
handle_cast({on_cancel_goal_reply,
#action_msgs_cancel_goal_rp{return_code = Code, goals_canceling = Seq}},
#action_msgs_cancel_goal_rp{return_code = 0, goals_canceling = Seq}},
S) ->
io:format("Cancel operation returned: ~p \nGoals that are being cancelled:\n", [Code]),
[io:format("\t~p\n", [ID])
|| #action_msgs_goal_info{goal_id = #unique_identifier_msgs_u_u_i_d{uuid = ID}} <- Seq],
io:format("Cancel operation succeded\nGoals that are being cancelled:\n"),
[io:format("\t~p\n", [ID]) || #action_msgs_goal_info{goal_id = #unique_identifier_msgs_u_u_i_d{uuid = ID}} <- Seq],
{noreply, S};
handle_cast({on_cancel_goal_reply,
#action_msgs_cancel_goal_rp{return_code = 1}},
S) ->
io:format("Goal failed to cancel\n"),
{noreply, S};
handle_cast({on_feedback_message,
#example_interfaces_fibonacci_feedback_message{sequence = Seq}},
Expand Down
2 changes: 1 addition & 1 deletion rosie/ros/src/behaviours/gen_action_client_listener.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
-callback on_cancel_goal_reply(Listener :: pid(), Msg :: term()) -> term().
-callback on_feedback_message(Listener :: pid(), Msg :: term()) -> term().

-optional_callbacks([on_cancel_goal_reply/2]).
-optional_callbacks([on_cancel_goal_reply/2,on_feedback_message/2]).
16 changes: 11 additions & 5 deletions rosie/ros/src/ros_action_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ handle_call(_, _, S) ->
{reply, ok, S}.

handle_cast({on_service_reply, Msg},
#state{action_interface = AI, callback_handler = {M, Pid}} = S) ->
#state{action_interface = AI, callback_handler = { M, Pid} = CA} = S) ->
case AI:identify_msg(Msg) of
send_goal_rp ->
M:on_send_goal_reply(Pid, Msg);
get_result_rp ->
M:on_get_result_reply(Pid, Msg);
cancel_goal_rp ->
M:on_cancel_goal_reply(Pid, Msg);
h_handle_cancel_goal_reply(Msg, CA);
_ ->
io:format("[ROS_ACTION_CLIENT]: BAD MSG RECEIVED FROM SERVICE\n")
end,
Expand Down Expand Up @@ -222,7 +222,13 @@ h_handle_status_update(GoalStatusArrayMsg, S) ->
S.

h_handle_feedback_message(Msg, #state{action_interface= ActionModule, callback_handler = {M, Pid}, goal_id = CURRENT_GOAL_ID}) ->
case ActionModule:get_goal_id(Msg) of
CURRENT_GOAL_ID -> M:on_feedback_message(Pid, Msg);
case {erlang:function_exported(M, on_feedback_message, 2), ActionModule:get_goal_id(Msg)} of
{true, CURRENT_GOAL_ID} -> M:on_feedback_message(Pid, Msg);
_ -> ok
end.
end.

h_handle_cancel_goal_reply(Msg, { M, Pid}) ->
case erlang:function_exported(M, on_cancel_goal_reply, 2) of
true -> M:on_cancel_goal_reply(Pid, Msg);
false -> ok
end.

0 comments on commit f1b628c

Please sign in to comment.