forked from ros2-java/ros2_java
-
Notifications
You must be signed in to change notification settings - Fork 9
Add offered qos incompatible event and event executor test #11
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
ivanpauno
merged 6 commits into
feature/events
from
ivanpauno/add-offered-qos-incompatible-event
Aug 20, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14505eb
Add OfferedQosIncompatible publisher event status
ivanpauno ca698ed
Add OfferedQosIncompatible publisher event status
ivanpauno d7ad984
Remove unnecesary print
ivanpauno ce1ba9f
Fix string comparisons
ivanpauno 1fbeb17
Compatibility with foxy
ivanpauno 18c020f
Foxy compatibility, take 2
ivanpauno 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
63 changes: 63 additions & 0 deletions
63
rcljava/include/org_ros2_rcljava_events_publisher_statuses_OfferedQosIncompatible.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // 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_events_publisher_statuses_OfferedQosIncompatible */ | ||
|
|
||
| #ifndef ORG_ROS2_RCLJAVA_EVENTS_PUBLISHER_STATUSES_OFFEREDQOSINCOMPATIBLE_H_ | ||
| #define ORG_ROS2_RCLJAVA_EVENTS_PUBLISHER_STATUSES_OFFEREDQOSINCOMPATIBLE_H_ | ||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* | ||
| * Class: org_ros2_rcljava_events_publisher_statuses_OfferedQosIncompatible | ||
| * Method: nAllocateRCLStatusEvent | ||
| * Signature: ()J | ||
| */ | ||
| JNIEXPORT jlong JNICALL | ||
| Java_org_ros2_rcljava_events_publisher_1statuses_OfferedQosIncompatible_nAllocateRCLStatusEvent( | ||
| JNIEnv *, jclass); | ||
|
|
||
| /* | ||
| * Class: org_ros2_rcljava_events_publisher_statuses_OfferedQosIncompatible | ||
| * Method: nDeallocateRCLStatusEvent | ||
| * Signature: (J)V | ||
| */ | ||
| JNIEXPORT void JNICALL | ||
| Java_org_ros2_rcljava_events_publisher_1statuses_OfferedQosIncompatible_nDeallocateRCLStatusEvent( | ||
| JNIEnv *, jclass, jlong); | ||
|
|
||
| /* | ||
| * Class: org_ros2_rcljava_events_publisher_statuses_OfferedQosIncompatible | ||
| * Method: nFromRCLEvent | ||
| * Signature: (J)V | ||
| */ | ||
| JNIEXPORT void JNICALL | ||
| Java_org_ros2_rcljava_events_publisher_1statuses_OfferedQosIncompatible_nFromRCLEvent( | ||
| JNIEnv *, jobject, jlong); | ||
|
|
||
| /* | ||
| * Class: org_ros2_rcljava_events_publisher_statuses_OfferedQosIncompatible | ||
| * Method: nGetPublisherEventType | ||
| * Signature: ()I | ||
| */ | ||
| JNIEXPORT jint JNICALL | ||
| Java_org_ros2_rcljava_events_publisher_1statuses_OfferedQosIncompatible_nGetPublisherEventType( | ||
| JNIEnv *, jclass); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #endif // ORG_ROS2_RCLJAVA_EVENTS_PUBLISHER_STATUSES_OFFEREDQOSINCOMPATIBLE_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
120 changes: 120 additions & 0 deletions
120
rcljava/src/main/cpp/org_ros2_rcljava_events_publisher_statuses_OfferedQosIncompatible.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,120 @@ | ||
| // 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_events_publisher_statuses_OfferedQosIncompatible.h" | ||
|
|
||
| #include <jni.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #include "rmw/incompatible_qos_events_statuses.h" | ||
| #include "rmw/types.h" | ||
| #include "rcl/event.h" | ||
| #include "rcljava_common/exceptions.hpp" | ||
|
|
||
| using rcljava_common::exceptions::rcljava_throw_exception; | ||
|
|
||
| JNIEXPORT jlong JNICALL | ||
| Java_org_ros2_rcljava_events_publisher_1statuses_OfferedQosIncompatible_nAllocateRCLStatusEvent( | ||
| JNIEnv * env, jclass) | ||
| { | ||
| void * p = malloc(sizeof(rmw_offered_qos_incompatible_event_status_t)); | ||
| if (!p) { | ||
| rcljava_throw_exception( | ||
| env, "java/lang/OutOfMemoryError", "failed to allocate offered qos incompatible status"); | ||
| } | ||
| return reinterpret_cast<jlong>(p); | ||
| } | ||
|
|
||
| JNIEXPORT void JNICALL | ||
| Java_org_ros2_rcljava_events_publisher_1statuses_OfferedQosIncompatible_nDeallocateRCLStatusEvent( | ||
| JNIEnv *, jclass, jlong handle) | ||
| { | ||
| free(reinterpret_cast<void *>(handle)); | ||
| } | ||
|
|
||
| JNIEXPORT void JNICALL | ||
| Java_org_ros2_rcljava_events_publisher_1statuses_OfferedQosIncompatible_nFromRCLEvent( | ||
| JNIEnv * env, jobject self, jlong handle) | ||
| { | ||
| auto * p = reinterpret_cast<rmw_offered_qos_incompatible_event_status_t *>(handle); | ||
| if (!p) { | ||
| rcljava_throw_exception( | ||
| env, "java/lang/IllegalArgumentException", "passed rmw object handle is NULL"); | ||
| } | ||
| // TODO(ivanpauno): class and field lookup could be done at startup time | ||
| jclass clazz = env->GetObjectClass(self); | ||
| jclass qos_kind_clazz = env->FindClass( | ||
| "org/ros2/rcljava/events/publisher_statuses/OfferedQosIncompatible$PolicyKind"); | ||
| if (env->ExceptionCheck()) { | ||
| return; | ||
| } | ||
| jfieldID total_count_fid = env->GetFieldID(clazz, "totalCount", "I"); | ||
| if (env->ExceptionCheck()) { | ||
| return; | ||
| } | ||
| jfieldID total_count_change_fid = env->GetFieldID(clazz, "totalCountChange", "I"); | ||
| if (env->ExceptionCheck()) { | ||
| return; | ||
| } | ||
| const char * enum_class_path = | ||
| "Lorg/ros2/rcljava/events/publisher_statuses/OfferedQosIncompatible$PolicyKind;"; | ||
| jfieldID policy_kind_fid = env->GetFieldID(clazz, "lastPolicyKind", enum_class_path); | ||
| if (env->ExceptionCheck()) { | ||
| return; | ||
| } | ||
|
|
||
| jfieldID enum_value_fid; | ||
| switch (p->last_policy_kind) { | ||
| case RMW_QOS_POLICY_INVALID: | ||
| enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "INVALID", enum_class_path); | ||
| break; | ||
| case RMW_QOS_POLICY_DURABILITY: | ||
| enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "DURABILITY", enum_class_path); | ||
| break; | ||
| case RMW_QOS_POLICY_DEADLINE: | ||
| enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "DEADLINE", enum_class_path); | ||
| break; | ||
| case RMW_QOS_POLICY_LIVELINESS: | ||
| enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "LIVELINESS", enum_class_path); | ||
| break; | ||
| case RMW_QOS_POLICY_RELIABILITY: | ||
| enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "RELIABILITY", enum_class_path); | ||
| break; | ||
| case RMW_QOS_POLICY_HISTORY: | ||
| enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "HISTORY", enum_class_path); | ||
| break; | ||
| case RMW_QOS_POLICY_LIFESPAN: | ||
| enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "LIFESPAN", enum_class_path); | ||
| break; | ||
| default: | ||
| rcljava_throw_exception( | ||
| env, "java/lang/IllegalStateException", "unknown rmw qos policy kind"); | ||
| break; | ||
| } | ||
| if (env->ExceptionCheck()) { | ||
| return; | ||
| } | ||
| jobject enum_value = env->GetStaticObjectField(qos_kind_clazz, enum_value_fid); | ||
|
|
||
| env->SetIntField(self, total_count_fid, p->total_count); | ||
| env->SetIntField(self, total_count_change_fid, p->total_count_change); | ||
| env->SetObjectField(self, policy_kind_fid, enum_value); | ||
| } | ||
|
|
||
| JNIEXPORT jint JNICALL | ||
| Java_org_ros2_rcljava_events_publisher_1statuses_OfferedQosIncompatible_nGetPublisherEventType( | ||
| JNIEnv *, jclass) | ||
| { | ||
| return RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS; | ||
| } |
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
76 changes: 76 additions & 0 deletions
76
rcljava/src/main/java/org/ros2/rcljava/events/publisher_statuses/OfferedQosIncompatible.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,76 @@ | ||
| // 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.events.publisher_statuses; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| import org.ros2.rcljava.common.JNIUtils; | ||
| import org.ros2.rcljava.events.PublisherEventStatus; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * This class serves as a bridge between a rmw_qos_incompatible_event_status_t and RCLJava. | ||
| */ | ||
| public class OfferedQosIncompatible implements PublisherEventStatus { | ||
| public int totalCount; | ||
| public int totalCountChange; | ||
| public PolicyKind lastPolicyKind; | ||
|
|
||
| public enum PolicyKind { | ||
| INVALID, | ||
| DURABILITY, | ||
| DEADLINE, | ||
| LIVELINESS, | ||
| RELIABILITY, | ||
| HISTORY, | ||
| LIFESPAN; | ||
| } | ||
|
|
||
| public final long allocateRCLStatusEvent() { | ||
| return nAllocateRCLStatusEvent(); | ||
| } | ||
| public final void deallocateRCLStatusEvent(long handle) { | ||
| nDeallocateRCLStatusEvent(handle); | ||
| } | ||
| public final void fromRCLEvent(long handle) { | ||
| nFromRCLEvent(handle); | ||
| } | ||
| public final int getPublisherEventType() { | ||
| return nGetPublisherEventType(); | ||
| } | ||
| // TODO(ivanpauno): Remove this when -source 8 can be used (method references for the win) | ||
| public static final Supplier<OfferedQosIncompatible> factory = new Supplier<OfferedQosIncompatible>() { | ||
| public OfferedQosIncompatible get() { | ||
| return new OfferedQosIncompatible(); | ||
| } | ||
| }; | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(OfferedQosIncompatible.class); | ||
| static { | ||
| try { | ||
| JNIUtils.loadImplementation(OfferedQosIncompatible.class); | ||
| } catch (UnsatisfiedLinkError ule) { | ||
| logger.error("Native code library failed to load.\n" + ule); | ||
| System.exit(1); | ||
| } | ||
| } | ||
|
|
||
| private static native long nAllocateRCLStatusEvent(); | ||
| private static native void nDeallocateRCLStatusEvent(long handle); | ||
| private native void nFromRCLEvent(long handle); | ||
| private static native int nGetPublisherEventType(); | ||
| } | ||
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.