Skip to content

Commit

Permalink
Added feedback message class.
Browse files Browse the repository at this point in the history
Encapsulates the needed reflection methods.
  • Loading branch information
Ernesto Corbellini committed Jan 19, 2016
1 parent a0c7df8 commit 5aaded2
Showing 1 changed file with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright 2015 Ekumen www.ekumenlabs.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.github.ekumen.rosjava_actionlib;

import java.lang.reflect.Method;
import org.ros.internal.message.Message;
import org.ros.message.Time;
import std_msgs.Header;
import actionlib_msgs.GoalID;
import actionlib_msgs.GoalStatus;

/**
* Class to encapsulate the action feedback object.
* @author Ernesto Corbellini [email protected]
*/
public class ActionFeedback<T_ACTION_FEEDBACK extends Message> {
private T_ACTION_FEEDBACK actionFeedbackMessage = null;

public ActionFeedback(T_ACTION_FEEDBACK fmsg) {
actionFeedbackMessage = fmsg;
}

public Header getHeaderMessage() {
Header h = null;
if (actionFeedbackMessage != null) {
try {
Method m = actionFeedbackMessage.getClass().getMethod("getHeader");
m.setAccessible(true); // workaround for known bug http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6924232
h = (Header)m.invoke(actionFeedbackMessage);
}
catch (Exception e) {
e.printStackTrace(System.out);
}
}
return h;
}

public GoalStatus getGoalStatusMessage() {
GoalStatus gs = null;
if (actionFeedbackMessage != null) {
try {
Method m = actionFeedbackMessage.getClass().getMethod("getStatus");
m.setAccessible(true); // workaround for known bug http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6924232
gs = (GoalStatus)m.invoke(actionFeedbackMessage);
}
catch (Exception e) {
e.printStackTrace(System.out);
}
}
return gs;
}

public Message getFeedbackMessage() {
Message x = null;
if (actionFeedbackMessage != null) {
try {
Method m = actionFeedbackMessage.getClass().getMethod("getFeedback");
m.setAccessible(true); // workaround for known bug http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6924232
x = (Message)m.invoke(actionFeedbackMessage);
}
catch (Exception e) {
e.printStackTrace(System.out);
}
}
return x;
}
}

0 comments on commit 5aaded2

Please sign in to comment.