forked from ros2-java/ros2_java
-
Notifications
You must be signed in to change notification settings - Fork 9
Add getPublishersInfo method to Node #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,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_ |
This file contains hidden or 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
This file contains hidden or 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
109 changes: 109 additions & 0 deletions
109
rcljava/src/main/cpp/org_ros2_rcljava_graph_EndpointInfo.cpp
This file contains hidden or 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,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); | ||
| } | ||
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
rcljava/src/main/java/org/ros2/rcljava/graph/EndpointInfo.java
This file contains hidden or 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,58 @@ | ||
| /* 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.graph; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.ros2.rcljava.common.JNIUtils; | ||
| import org.ros2.rcljava.qos.QoSProfile; | ||
|
|
||
| /** | ||
| * Class that represents queried information of an endpoint. | ||
| */ | ||
| public class EndpointInfo { | ||
| /// Name of the node that created the endpoint. | ||
| public String nodeName; | ||
| /// Namespace of the node that created the endpoint. | ||
| public String nodeNamespace; | ||
| /// Topic type. | ||
| public String topicType; | ||
| /// Kind of endpoint, i.e.: publisher or subscription. | ||
| public EndpointType endpointType; | ||
| /// Gid of the endpoint. | ||
| public byte[] endpointGID; | ||
| /// Quality of service of the endpoint. | ||
| public QoSProfile qos; | ||
|
|
||
| public enum EndpointType { | ||
| INVALID, | ||
| PUBLISHER, | ||
| SUBSCRIPTION; | ||
| } | ||
|
|
||
| private native final void nativeFromRCL(long handle); | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(EndpointInfo.class); | ||
| static { | ||
| try { | ||
| JNIUtils.loadImplementation(EndpointInfo.class); | ||
| } catch (UnsatisfiedLinkError ule) { | ||
| logger.error("Native code library failed to load.\n" + ule); | ||
| System.exit(1); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.