diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index 19d7ce8c..8ad37f38 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -58,6 +58,7 @@ set(${PROJECT_NAME}_jni_sources "src/main/cpp/org_ros2_rcljava_Time.cpp" "src/main/cpp/org_ros2_rcljava_client_ClientImpl.cpp" "src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp" + "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_publisher_statuses_LivelinessLost.cpp" @@ -66,6 +67,7 @@ set(${PROJECT_NAME}_jni_sources "src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.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_RequestedQosIncompatible.cpp" "src/main/cpp/org_ros2_rcljava_time_Clock.cpp" "src/main/cpp/org_ros2_rcljava_timer_WallTimerImpl.cpp" ) @@ -128,6 +130,7 @@ set(${PROJECT_NAME}_sources "src/main/java/org/ros2/rcljava/consumers/BiConsumer.java" "src/main/java/org/ros2/rcljava/consumers/Consumer.java" "src/main/java/org/ros2/rcljava/consumers/TriConsumer.java" + "src/main/java/org/ros2/rcljava/detail/QosIncompatibleStatus.java" "src/main/java/org/ros2/rcljava/events/EventHandler.java" "src/main/java/org/ros2/rcljava/events/EventHandlerImpl.java" "src/main/java/org/ros2/rcljava/events/EventStatus.java" @@ -171,6 +174,7 @@ set(${PROJECT_NAME}_sources "src/main/java/org/ros2/rcljava/service/ServiceImpl.java" "src/main/java/org/ros2/rcljava/subscription/Subscription.java" "src/main/java/org/ros2/rcljava/subscription/SubscriptionImpl.java" + "src/main/java/org/ros2/rcljava/subscription/statuses/RequestedQosIncompatible.java" "src/main/java/org/ros2/rcljava/time/Clock.java" "src/main/java/org/ros2/rcljava/time/ClockType.java" "src/main/java/org/ros2/rcljava/timer/Timer.java" diff --git a/rcljava/include/org_ros2_rcljava_detail_QosIncompatibleStatus.h b/rcljava/include/org_ros2_rcljava_detail_QosIncompatibleStatus.h new file mode 100644 index 00000000..af8f7319 --- /dev/null +++ b/rcljava/include/org_ros2_rcljava_detail_QosIncompatibleStatus.h @@ -0,0 +1,54 @@ +// 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 +/* Header for class org_ros2_rcljava_detail_QosIncompatibleStatus */ + +#ifndef ORG_ROS2_RCLJAVA_DETAIL_QOSINCOMPATIBLESTATUS_H_ +#define ORG_ROS2_RCLJAVA_DETAIL_QOSINCOMPATIBLESTATUS_H_ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: org_ros2_rcljava_detail_QosIncompatibleStatus + * Method: nativeAllocateRCLStatusEvent + * Signature: ()J + */ +JNIEXPORT jlong JNICALL +Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeAllocateRCLStatusEvent( + JNIEnv *, jclass); + +/* + * Class: org_ros2_rcljava_detail_QosIncompatibleStatus + * Method: nativeDeallocateRCLStatusEvent + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeDeallocateRCLStatusEvent( + JNIEnv *, jclass, jlong); + +/* + * Class: org_ros2_rcljava_detail_QosIncompatibleStatus + * Method: nativeFromRCLEvent + * Signature: (J)V + */ +JNIEXPORT void JNICALL +Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeFromRCLEvent( + JNIEnv *, jobject, jlong); + +#ifdef __cplusplus +} +#endif +#endif // ORG_ROS2_RCLJAVA_DETAIL_QOSINCOMPATIBLESTATUS_H_ diff --git a/rcljava/include/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.h b/rcljava/include/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.h index 44b8ea07..15860176 100644 --- a/rcljava/include/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.h +++ b/rcljava/include/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.h @@ -23,38 +23,11 @@ extern "C" { /* * Class: org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible - * Method: nAllocateRCLStatusEvent - * Signature: ()J - */ -JNIEXPORT jlong JNICALL -Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nAllocateRCLStatusEvent( - JNIEnv *, jclass); - -/* - * Class: org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible - * Method: nDeallocateRCLStatusEvent - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nDeallocateRCLStatusEvent( - JNIEnv *, jclass, jlong); - -/* - * Class: org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible - * Method: nFromRCLEvent - * Signature: (J)V - */ -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nFromRCLEvent( - JNIEnv *, jobject, jlong); - -/* - * Class: org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible - * Method: nGetPublisherEventType + * Method: nativeGetEventType * Signature: ()I */ JNIEXPORT jint JNICALL -Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nGetPublisherEventType( +Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nativeGetEventType( JNIEnv *, jclass); #ifdef __cplusplus diff --git a/rcljava/include/org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible.h b/rcljava/include/org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible.h new file mode 100644 index 00000000..ef7a0236 --- /dev/null +++ b/rcljava/include/org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible.h @@ -0,0 +1,36 @@ +// 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 +/* Header for class org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible */ + +#ifndef ORG_ROS2_RCLJAVA_SUBSCRIPTION_STATUSES_REQUESTEDQOSINCOMPATIBLE_H_ +#define ORG_ROS2_RCLJAVA_SUBSCRIPTION_STATUSES_REQUESTEDQOSINCOMPATIBLE_H_ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible + * Method: nativeGetEventType + * Signature: ()I + */ +JNIEXPORT jint JNICALL +Java_org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible_nativeGetEventType( + JNIEnv *, jclass); + +#ifdef __cplusplus +} +#endif +#endif // ORG_ROS2_RCLJAVA_SUBSCRIPTION_STATUSES_REQUESTEDQOSINCOMPATIBLE_H_ diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_detail_QosIncompatibleStatus.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_detail_QosIncompatibleStatus.cpp new file mode 100644 index 00000000..85dde30f --- /dev/null +++ b/rcljava/src/main/cpp/org_ros2_rcljava_detail_QosIncompatibleStatus.cpp @@ -0,0 +1,113 @@ +// 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_detail_QosIncompatibleStatus.h" + +#include +#include + +#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_detail_QosIncompatibleStatus_nativeAllocateRCLStatusEvent( + JNIEnv * env, jclass) +{ + void * p = malloc(sizeof(rmw_qos_incompatible_event_status_t)); + if (!p) { + rcljava_throw_exception( + env, "java/lang/OutOfMemoryError", "failed to allocate qos incompatible status"); + } + return reinterpret_cast(p); +} + +JNIEXPORT void JNICALL +Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeDeallocateRCLStatusEvent( + JNIEnv *, jclass, jlong handle) +{ + free(reinterpret_cast(handle)); +} + +JNIEXPORT void JNICALL +Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeFromRCLEvent( + JNIEnv * env, jobject self, jlong handle) +{ + auto * p = reinterpret_cast(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/detail/QosIncompatibleStatus$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/detail/QosIncompatibleStatus$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/IllegalArgumentException", "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); +} diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.cpp index 9fab2f2b..d2e681c3 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.cpp @@ -15,105 +15,11 @@ #include "org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.h" #include -#include -#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_publisher_statuses_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(p); -} - -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nDeallocateRCLStatusEvent( - JNIEnv *, jclass, jlong handle) -{ - free(reinterpret_cast(handle)); -} - -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nFromRCLEvent( - JNIEnv * env, jobject self, jlong handle) -{ - auto * p = reinterpret_cast(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/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/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_publisher_statuses_OfferedQosIncompatible_nGetPublisherEventType( +Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nativeGetEventType( JNIEnv *, jclass) { return RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS; diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible.cpp new file mode 100644 index 00000000..fc506e5e --- /dev/null +++ b/rcljava/src/main/cpp/org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible.cpp @@ -0,0 +1,26 @@ +// 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_subscription_statuses_RequestedQosIncompatible.h" + +#include + +#include "rcl/event.h" + +JNIEXPORT jint JNICALL +Java_org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible_nativeGetEventType( + JNIEnv *, jclass) +{ + return RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS; +} diff --git a/rcljava/src/main/java/org/ros2/rcljava/detail/QosIncompatibleStatus.java b/rcljava/src/main/java/org/ros2/rcljava/detail/QosIncompatibleStatus.java new file mode 100644 index 00000000..91a3e9b4 --- /dev/null +++ b/rcljava/src/main/java/org/ros2/rcljava/detail/QosIncompatibleStatus.java @@ -0,0 +1,65 @@ +// 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.detail; + +import org.ros2.rcljava.common.JNIUtils; +import org.ros2.rcljava.events.EventStatus; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class serves as a bridge between rmw_qos_incompatible_event_status_t + * and RCLJava. + */ +public class QosIncompatibleStatus implements EventStatus { + public int totalCount; + public int totalCountChange; + public PolicyKind lastPolicyKind; + + public enum PolicyKind { + INVALID, + DURABILITY, + DEADLINE, + LIVELINESS, + RELIABILITY, + HISTORY, + LIFESPAN; + } + + public final long allocateRCLStatusEvent() { + return nativeAllocateRCLStatusEvent(); + } + public final void deallocateRCLStatusEvent(long handle) { + nativeDeallocateRCLStatusEvent(handle); + } + public final void fromRCLEvent(long handle) { + nativeFromRCLEvent(handle); + } + + private static final Logger logger = LoggerFactory.getLogger(QosIncompatibleStatus.class); + static { + try { + JNIUtils.loadImplementation(QosIncompatibleStatus.class); + } catch (UnsatisfiedLinkError ule) { + logger.error("Native code library failed to load.\n" + ule); + System.exit(1); + } + } + + private static native long nativeAllocateRCLStatusEvent(); + private static native void nativeDeallocateRCLStatusEvent(long handle); + private native void nativeFromRCLEvent(long handle); +} diff --git a/rcljava/src/main/java/org/ros2/rcljava/publisher/statuses/OfferedQosIncompatible.java b/rcljava/src/main/java/org/ros2/rcljava/publisher/statuses/OfferedQosIncompatible.java index 7f572c71..ba633cd6 100644 --- a/rcljava/src/main/java/org/ros2/rcljava/publisher/statuses/OfferedQosIncompatible.java +++ b/rcljava/src/main/java/org/ros2/rcljava/publisher/statuses/OfferedQosIncompatible.java @@ -17,43 +17,23 @@ import java.util.function.Supplier; import org.ros2.rcljava.common.JNIUtils; +import org.ros2.rcljava.detail.QosIncompatibleStatus; 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. + * This class serves as a bridge between rmw_offered_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 class OfferedQosIncompatible +extends QosIncompatibleStatus implements PublisherEventStatus { public final int getPublisherEventType() { - return nGetPublisherEventType(); + return nativeGetEventType(); } // TODO(ivanpauno): Remove this when -source 8 can be used (method references for the win) - public static final Supplier factory = new Supplier() { + public static final Supplier + factory = new Supplier() { public OfferedQosIncompatible get() { return new OfferedQosIncompatible(); } @@ -69,8 +49,5 @@ public OfferedQosIncompatible get() { } } - private static native long nAllocateRCLStatusEvent(); - private static native void nDeallocateRCLStatusEvent(long handle); - private native void nFromRCLEvent(long handle); - private static native int nGetPublisherEventType(); + private static native int nativeGetEventType(); } diff --git a/rcljava/src/main/java/org/ros2/rcljava/subscription/statuses/RequestedQosIncompatible.java b/rcljava/src/main/java/org/ros2/rcljava/subscription/statuses/RequestedQosIncompatible.java new file mode 100644 index 00000000..33c0ea38 --- /dev/null +++ b/rcljava/src/main/java/org/ros2/rcljava/subscription/statuses/RequestedQosIncompatible.java @@ -0,0 +1,54 @@ +// 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.subscription.statuses; + +import java.util.function.Supplier; + +import org.ros2.rcljava.common.JNIUtils; +import org.ros2.rcljava.detail.QosIncompatibleStatus; +import org.ros2.rcljava.events.SubscriptionEventStatus; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class serves as a bridge between rmw_requested_qos_incompatible_event_status_t + * and RCLJava. + */ +public class RequestedQosIncompatible +extends QosIncompatibleStatus implements SubscriptionEventStatus { + public final int getSubscriptionEventType() { + return nativeGetEventType(); + } + // TODO(ivanpauno): Remove this when -source 8 can be used (method references for the win) + public static final Supplier + factory = new Supplier() { + public RequestedQosIncompatible get() { + return new RequestedQosIncompatible(); + } + }; + + private static final Logger logger = LoggerFactory.getLogger(RequestedQosIncompatible.class); + static { + try { + JNIUtils.loadImplementation(RequestedQosIncompatible.class); + } catch (UnsatisfiedLinkError ule) { + logger.error("Native code library failed to load.\n" + ule); + System.exit(1); + } + } + + private static native int nativeGetEventType(); +}