forked from ernestmc/rosjava_actionlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...b/rosjava_actionlib/src/main/java/com/github/ekumen/rosjava_actionlib/ActionFeedback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |