diff --git a/rcljava_common/CMakeLists.txt b/rcljava_common/CMakeLists.txt index 3bc04fde..46715393 100644 --- a/rcljava_common/CMakeLists.txt +++ b/rcljava_common/CMakeLists.txt @@ -38,6 +38,8 @@ set(${PROJECT_NAME}_java_sources "src/main/java/org/ros2/rcljava/exceptions/RCLReturn.java" "src/main/java/org/ros2/rcljava/interfaces/ActionDefinition.java" "src/main/java/org/ros2/rcljava/interfaces/Disposable.java" + "src/main/java/org/ros2/rcljava/interfaces/GoalRequestDefinition.java" + "src/main/java/org/ros2/rcljava/interfaces/GoalResponseDefinition.java" "src/main/java/org/ros2/rcljava/interfaces/MessageDefinition.java" "src/main/java/org/ros2/rcljava/interfaces/ServiceDefinition.java" ) diff --git a/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/ActionDefinition.java b/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/ActionDefinition.java index 9681463b..e39d65d8 100644 --- a/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/ActionDefinition.java +++ b/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/ActionDefinition.java @@ -15,4 +15,9 @@ package org.ros2.rcljava.interfaces; -public interface ActionDefinition {} +public interface ActionDefinition { + Class getSendGoalRequestType(); + Class getSendGoalResponseType(); + Class getGetResultRequestType(); + Class getGetResultResponseType(); +} diff --git a/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/GoalRequestDefinition.java b/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/GoalRequestDefinition.java new file mode 100644 index 00000000..cf6dc177 --- /dev/null +++ b/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/GoalRequestDefinition.java @@ -0,0 +1,23 @@ +/* Copyright 2020 Open Source Robotics Foundation, Inc. + * + * 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 org.ros2.rcljava.interfaces; + +import java.util.List; + +public interface GoalRequestDefinition extends MessageDefinition { + MessageDefinition getGoal(); + List getGoalUuid(); +} diff --git a/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/GoalResponseDefinition.java b/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/GoalResponseDefinition.java new file mode 100644 index 00000000..c645cf8f --- /dev/null +++ b/rcljava_common/src/main/java/org/ros2/rcljava/interfaces/GoalResponseDefinition.java @@ -0,0 +1,21 @@ +/* Copyright 2020 Open Source Robotics Foundation, Inc. + * + * 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 org.ros2.rcljava.interfaces; + +public interface GoalResponseDefinition extends MessageDefinition { + void accept(boolean accepted); + void setStamp(int sec, int nanosec); +} diff --git a/rosidl_generator_java/resource/action.java.em b/rosidl_generator_java/resource/action.java.em index 5e7ebbe9..cb6c1dd3 100644 --- a/rosidl_generator_java/resource/action.java.em +++ b/rosidl_generator_java/resource/action.java.em @@ -63,8 +63,12 @@ expand_template( template_basepath=template_basepath) action_imports = [ + 'java.util.List', 'org.ros2.rcljava.common.JNIUtils', 'org.ros2.rcljava.interfaces.ActionDefinition', + 'org.ros2.rcljava.interfaces.GoalRequestDefinition', + 'org.ros2.rcljava.interfaces.GoalResponseDefinition', + 'org.ros2.rcljava.interfaces.MessageDefinition', 'org.slf4j.Logger', 'org.slf4j.LoggerFactory', ] @@ -76,6 +80,42 @@ import @(action_import); public class @(type_name) implements ActionDefinition { + public static class SendGoalRequest extends @(type_name)_SendGoal_Request implements GoalRequestDefinition<@(type_name)> { + public List getGoalUuid() { + // Return List since it's hash is based on the values (not the object pointer) + return super.getGoalId().getUuidAsList(); + } + } + + public static class SendGoalResponse extends @(type_name)_SendGoal_Response implements GoalResponseDefinition<@(type_name)> { + public void accept(boolean accepted) { + super.setAccepted(accepted); + } + + public void setStamp(int sec, int nanosec) { + builtin_interfaces.msg.Time msg = new builtin_interfaces.msg.Time(); + msg.setSec(sec); + msg.setNanosec(nanosec); + super.setStamp(msg); + } + } + + public Class getSendGoalRequestType() { + return SendGoalRequest.class; + } + + public Class getSendGoalResponseType() { + return SendGoalResponse.class; + } + + public Class getGetResultRequestType() { + return @(type_name)_GetResult_Request.class; + } + + public Class getGetResultResponseType() { + return @(type_name)_GetResult_Response.class; + } + private static final Logger logger = LoggerFactory.getLogger(@(type_name).class); static { diff --git a/rosidl_generator_java/resource/msg.java.em b/rosidl_generator_java/resource/msg.java.em index c8912488..9dcb2a42 100644 --- a/rosidl_generator_java/resource/msg.java.em +++ b/rosidl_generator_java/resource/msg.java.em @@ -38,7 +38,7 @@ import @('.'.join(member.type.namespaced_name())); @[ end if]@ @[end for]@ -public final class @(type_name) implements MessageDefinition { +public class @(type_name) implements MessageDefinition { private static final Logger logger = LoggerFactory.getLogger(@(type_name).class);