Skip to content
Merged
15 changes: 11 additions & 4 deletions rcljava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ find_package(ament_cmake REQUIRED)
find_package(ament_cmake_export_jars REQUIRED)
find_package(ament_cmake_export_jni_libraries REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rcl REQUIRED)
find_package(rcl_interfaces REQUIRED)
find_package(rcljava_common REQUIRED)
Expand Down Expand Up @@ -61,11 +62,13 @@ set(${PROJECT_NAME}_jni_sources
"src/main/cpp/org_ros2_rcljava_detail_QosIncompatibleStatus.cpp"
"src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp"
"src/main/cpp/org_ros2_rcljava_events_EventHandlerImpl.cpp"
"src/main/cpp/org_ros2_rcljava_graph_EndpointInfo"
"src/main/cpp/org_ros2_rcljava_publisher_statuses_LivelinessLost.cpp"
"src/main/cpp/org_ros2_rcljava_publisher_statuses_OfferedDeadlineMissed.cpp"
"src/main/cpp/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.cpp"
"src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp"
"src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp"
"src/main/cpp/org_ros2_rcljava_qos_QoSProfile.cpp"
"src/main/cpp/org_ros2_rcljava_service_ServiceImpl.cpp"
"src/main/cpp/org_ros2_rcljava_subscription_SubscriptionImpl.cpp"
"src/main/cpp/org_ros2_rcljava_subscription_statuses_LivelinessChanged.cpp"
Expand Down Expand Up @@ -102,10 +105,11 @@ foreach(_jni_source ${${PROJECT_NAME}_jni_sources})
endif()

ament_target_dependencies(${_target_name}
"builtin_interfaces"
"rcl"
"rcljava_common"
"builtin_interfaces"
"rcl_interfaces"
"rcpputils"
)

target_include_directories(${_target_name}
Expand Down Expand Up @@ -140,14 +144,14 @@ set(${PROJECT_NAME}_sources
"src/main/java/org/ros2/rcljava/events/EventStatus.java"
"src/main/java/org/ros2/rcljava/events/PublisherEventStatus.java"
"src/main/java/org/ros2/rcljava/events/SubscriptionEventStatus.java"
"src/main/java/org/ros2/rcljava/publisher/statuses/LivelinessLost.java"
"src/main/java/org/ros2/rcljava/publisher/statuses/OfferedDeadlineMissed.java"
"src/main/java/org/ros2/rcljava/publisher/statuses/OfferedQosIncompatible.java"
"src/main/java/org/ros2/rcljava/graph/NameAndTypes.java"
"src/main/java/org/ros2/rcljava/graph/NodeNameInfo.java"
"src/main/java/org/ros2/rcljava/executors/AnyExecutable.java"
"src/main/java/org/ros2/rcljava/executors/BaseExecutor.java"
"src/main/java/org/ros2/rcljava/executors/Executor.java"
"src/main/java/org/ros2/rcljava/executors/MultiThreadedExecutor.java"
"src/main/java/org/ros2/rcljava/executors/SingleThreadedExecutor.java"
"src/main/java/org/ros2/rcljava/graph/EndpointInfo.java"
"src/main/java/org/ros2/rcljava/node/BaseComposableNode.java"
"src/main/java/org/ros2/rcljava/node/ComposableNode.java"
"src/main/java/org/ros2/rcljava/node/Node.java"
Expand All @@ -169,6 +173,9 @@ set(${PROJECT_NAME}_sources
"src/main/java/org/ros2/rcljava/parameters/service/ParameterServiceImpl.java"
"src/main/java/org/ros2/rcljava/publisher/Publisher.java"
"src/main/java/org/ros2/rcljava/publisher/PublisherImpl.java"
"src/main/java/org/ros2/rcljava/publisher/statuses/LivelinessLost.java"
"src/main/java/org/ros2/rcljava/publisher/statuses/OfferedDeadlineMissed.java"
"src/main/java/org/ros2/rcljava/publisher/statuses/OfferedQosIncompatible.java"
"src/main/java/org/ros2/rcljava/qos/policies/Durability.java"
"src/main/java/org/ros2/rcljava/qos/policies/History.java"
"src/main/java/org/ros2/rcljava/qos/policies/Liveliness.java"
Expand Down
34 changes: 34 additions & 0 deletions rcljava/include/org_ros2_rcljava_graph_EndpointInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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.

#include <jni.h>
/* Header for class org_ros2_rcljava_graph_EndpointInfo */

#ifndef ORG_ROS2_RCLJAVA_GRAPH_ENDPOINTINFO_H_
#define ORG_ROS2_RCLJAVA_GRAPH_ENDPOINTINFO_H_
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_ros2_rcljava_graph_EndpointInfo
* Method: nativeFromRCL
* Signature: (J)V
*/
JNIEXPORT void
JNICALL Java_org_ros2_rcljava_graph_EndpointInfo_nativeFromRCL(JNIEnv *, jobject, jlong);

#ifdef __cplusplus
}
#endif
#endif // ORG_ROS2_RCLJAVA_GRAPH_ENDPOINTINFO_H_
45 changes: 45 additions & 0 deletions rcljava/include/org_ros2_rcljava_node_NodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,51 @@ JNIEXPORT jlong
JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateTimerHandle(
JNIEnv *, jclass, jlong, jlong, jlong);

/*
* Class: org_ros2_rcljava_node_NodeImpl
* Method: nativeGetNodeNames
* Signature: (JLjava/util/List;)V
*/
JNIEXPORT void
JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeGetNodeNames(
JNIEnv *, jclass, jlong, jobject);

/*
* Class: org_ros2_rcljava_node_NodeImpl
* Method: nativeGetTopicNamesAndTypes
* Signature: (JLjava/util/Collection;)V
*/
JNIEXPORT void
JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeGetTopicNamesAndTypes(
JNIEnv *, jclass, jlong, jobject);

/*
* Class: org_ros2_rcljava_node_NodeImpl
* Method: nativeGetServiceNamesAndTypes
* Signature: (JLjava/util/Collection;)V
*/
JNIEXPORT void
JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeGetServiceNamesAndTypes(
JNIEnv *, jclass, jlong, jobject);

/*
* Class: org_ros2_rcljava_node_NodeImpl
* Method: nativeGetPublishersInfo
* Signature: (JLjava/lang/String;Ljava/util/List;)V
*/
JNIEXPORT void
JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeGetPublishersInfo(
JNIEnv *, jclass, jlong, jstring, jobject);

/*
* Class: org_ros2_rcljava_node_NodeImpl
* Method: nativeGetSubscriptionsInfo
* Signature: (JLjava/lang/String;Ljava/util/List;)V
*/
JNIEXPORT void
JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeGetSubscriptionsInfo(
JNIEnv *, jclass, jlong, jstring, jobject);

#ifdef __cplusplus
}
#endif
Expand Down
41 changes: 41 additions & 0 deletions rcljava/include/org_ros2_rcljava_qos_QoSProfile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.

#include <jni.h>
/* Header for class org_ros2_rcljava_qos_QoSProfile */

#ifndef ORG_ROS2_RCLJAVA_QOS_QOSPROFILE_H_
#define ORG_ROS2_RCLJAVA_QOS_QOSPROFILE_H_
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_ros2_rcljava_qos_QoSProfile
* Method: nativeFromRCL
* Signature: (J)V
*/
JNIEXPORT void
JNICALL Java_org_ros2_rcljava_qos_QoSProfile_nativeFromRCL(JNIEnv *, jobject, jlong);

/*
* Class: org_ros2_rcljava_qos_QoSProfile
* Method: nativeGetHandleFromName
* Signature: (Ljava/lang/String;)J
*/
JNIEXPORT jlong
JNICALL Java_org_ros2_rcljava_qos_QoSProfile_nativeGetHandleFromName(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
#endif
#endif // ORG_ROS2_RCLJAVA_QOS_QOSPROFILE_H_
2 changes: 2 additions & 0 deletions rcljava/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<build_depend>builtin_interfaces</build_depend>
<build_depend>rcl_interfaces</build_depend>
<build_depend>rcl</build_depend>
<build_depend>rcpputils</build_depend>
<build_depend>rmw_implementation_cmake</build_depend>
<build_depend>rmw</build_depend>
<build_depend>rosidl_generator_c</build_depend>
Expand All @@ -29,6 +30,7 @@
<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>rcl_interfaces</exec_depend>
<exec_depend>rcl</exec_depend>
<exec_depend>rcpputils</exec_depend>
<exec_depend>rmw_implementation_cmake</exec_depend>
<exec_depend>rmw_implementation</exec_depend>
<exec_depend>rosidl_runtime_c</exec_depend>
Expand Down
109 changes: 109 additions & 0 deletions rcljava/src/main/cpp/org_ros2_rcljava_graph_EndpointInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// 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.

#include "org_ros2_rcljava_graph_EndpointInfo.h"

#include <jni.h>
#include <limits>

#include "rcl/graph.h"
#include "rcljava_common/exceptions.hpp"

using rcljava_common::exceptions::rcljava_throw_exception;

JNIEXPORT void JNICALL
Java_org_ros2_rcljava_graph_EndpointInfo_nativeFromRCL(JNIEnv * env, jobject self, jlong handle)
{
auto * p = reinterpret_cast<rcl_topic_endpoint_info_t *>(handle);
if (!p) {
rcljava_throw_exception(
env, "java/lang/IllegalArgumentException", "passed rcl endpoint info handle is NULL");
return;
}
const char * endpoint_type_enum_path =
"Lorg/ros2/rcljava/graph/EndpointInfo$EndpointType;";
// TODO(ivanpauno): class and field lookup could be done at startup time
jclass endpoint_type_clazz = env->FindClass("org/ros2/rcljava/graph/EndpointInfo$EndpointType");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jclass clazz = env->GetObjectClass(self);
jfieldID node_name_fid = env->GetFieldID(clazz, "nodeName", "Ljava/lang/String;");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jfieldID node_namespace_fid = env->GetFieldID(clazz, "nodeNamespace", "Ljava/lang/String;");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jfieldID topic_type_fid = env->GetFieldID(clazz, "topicType", "Ljava/lang/String;");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jfieldID endpoint_type_fid = env->GetFieldID(clazz, "endpointType", endpoint_type_enum_path);
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jfieldID endpoint_gid_fid = env->GetFieldID(clazz, "endpointGID", "[B");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jfieldID qos_fid = env->GetFieldID(clazz, "qos", "Lorg/ros2/rcljava/qos/QoSProfile;");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);

jstring jnode_name = env->NewStringUTF(p->node_name);
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
env->SetObjectField(self, node_name_fid, jnode_name);
jstring jnode_namespace = env->NewStringUTF(p->node_namespace);
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
env->SetObjectField(self, node_namespace_fid, jnode_namespace);
jstring jtopic_type = env->NewStringUTF(p->topic_type);
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
env->SetObjectField(self, topic_type_fid, jtopic_type);
jfieldID enum_value_fid;
switch (p->endpoint_type) {
case RMW_ENDPOINT_INVALID:
enum_value_fid = env->GetStaticFieldID(
endpoint_type_clazz, "INVALID", endpoint_type_enum_path);
break;
case RMW_ENDPOINT_PUBLISHER:
enum_value_fid = env->GetStaticFieldID(
endpoint_type_clazz, "PUBLISHER", endpoint_type_enum_path);
break;
case RMW_ENDPOINT_SUBSCRIPTION:
enum_value_fid = env->GetStaticFieldID(
endpoint_type_clazz, "SUBSCRIPTION", endpoint_type_enum_path);
break;
default:
rcljava_throw_exception(
env, "java/lang/IllegalArgumentException", "unknown endpoint type");
break;
}
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jobject enum_value = env->GetStaticObjectField(endpoint_type_clazz, enum_value_fid);
env->SetObjectField(self, endpoint_type_fid, enum_value);
jbyteArray jgid = env->NewByteArray(RMW_GID_STORAGE_SIZE);
if (jgid == NULL) {
rcljava_throw_exception(
env, "java/lang/OutOfMemoryError", "cannot allocate java gid byte array");
return;
}
jbyte * gid_content = env->GetByteArrayElements(jgid, nullptr);
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
for (size_t i = 0; i < RMW_GID_STORAGE_SIZE; ++i) {
gid_content[i] = p->endpoint_gid[i];
}
env->ReleaseByteArrayElements(jgid, gid_content, 0);
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
env->SetObjectField(self, endpoint_gid_fid, jgid);
jclass qos_clazz = env->FindClass("org/ros2/rcljava/qos/QoSProfile");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jmethodID qos_init_mid = env->GetMethodID(qos_clazz, "<init>", "()V");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jobject jqos = env->NewObject(qos_clazz, qos_init_mid);
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
jmethodID qos_from_rcl_mid = env->GetMethodID(qos_clazz, "nativeFromRCL", "(J)V");
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
env->CallObjectMethod(jqos, qos_from_rcl_mid, &p->qos_profile);
RCLJAVA_COMMON_CHECK_FOR_EXCEPTION(env);
env->SetObjectField(self, qos_fid, jqos);
}
Loading