Skip to content

Commit 6c41709

Browse files
committed
Add RequestedQosIncompatible subscription event status (osrf#14)
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
1 parent 1a50f3f commit 6c41709

10 files changed

+363
-155
lines changed

rcljava/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ set(${PROJECT_NAME}_jni_sources
5858
"src/main/cpp/org_ros2_rcljava_Time.cpp"
5959
"src/main/cpp/org_ros2_rcljava_client_ClientImpl.cpp"
6060
"src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp"
61+
"src/main/cpp/org_ros2_rcljava_detail_QosIncompatibleStatus.cpp"
6162
"src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp"
6263
"src/main/cpp/org_ros2_rcljava_events_EventHandlerImpl.cpp"
6364
"src/main/cpp/org_ros2_rcljava_publisher_statuses_LivelinessLost.cpp"
@@ -66,6 +67,7 @@ set(${PROJECT_NAME}_jni_sources
6667
"src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp"
6768
"src/main/cpp/org_ros2_rcljava_service_ServiceImpl.cpp"
6869
"src/main/cpp/org_ros2_rcljava_subscription_SubscriptionImpl.cpp"
70+
"src/main/cpp/org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible.cpp"
6971
"src/main/cpp/org_ros2_rcljava_time_Clock.cpp"
7072
"src/main/cpp/org_ros2_rcljava_timer_WallTimerImpl.cpp"
7173
)
@@ -128,6 +130,7 @@ set(${PROJECT_NAME}_sources
128130
"src/main/java/org/ros2/rcljava/consumers/BiConsumer.java"
129131
"src/main/java/org/ros2/rcljava/consumers/Consumer.java"
130132
"src/main/java/org/ros2/rcljava/consumers/TriConsumer.java"
133+
"src/main/java/org/ros2/rcljava/detail/QosIncompatibleStatus.java"
131134
"src/main/java/org/ros2/rcljava/events/EventHandler.java"
132135
"src/main/java/org/ros2/rcljava/events/EventHandlerImpl.java"
133136
"src/main/java/org/ros2/rcljava/events/EventStatus.java"
@@ -172,6 +175,7 @@ set(${PROJECT_NAME}_sources
172175
"src/main/java/org/ros2/rcljava/service/ServiceImpl.java"
173176
"src/main/java/org/ros2/rcljava/subscription/Subscription.java"
174177
"src/main/java/org/ros2/rcljava/subscription/SubscriptionImpl.java"
178+
"src/main/java/org/ros2/rcljava/subscription/statuses/RequestedQosIncompatible.java"
175179
"src/main/java/org/ros2/rcljava/time/Clock.java"
176180
"src/main/java/org/ros2/rcljava/time/ClockType.java"
177181
"src/main/java/org/ros2/rcljava/timer/Timer.java"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2020 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <jni.h>
16+
/* Header for class org_ros2_rcljava_detail_QosIncompatibleStatus */
17+
18+
#ifndef ORG_ROS2_RCLJAVA_DETAIL_QOSINCOMPATIBLESTATUS_H_
19+
#define ORG_ROS2_RCLJAVA_DETAIL_QOSINCOMPATIBLESTATUS_H_
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/*
25+
* Class: org_ros2_rcljava_detail_QosIncompatibleStatus
26+
* Method: nativeAllocateRCLStatusEvent
27+
* Signature: ()J
28+
*/
29+
JNIEXPORT jlong JNICALL
30+
Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeAllocateRCLStatusEvent(
31+
JNIEnv *, jclass);
32+
33+
/*
34+
* Class: org_ros2_rcljava_detail_QosIncompatibleStatus
35+
* Method: nativeDeallocateRCLStatusEvent
36+
* Signature: (J)V
37+
*/
38+
JNIEXPORT void JNICALL
39+
Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeDeallocateRCLStatusEvent(
40+
JNIEnv *, jclass, jlong);
41+
42+
/*
43+
* Class: org_ros2_rcljava_detail_QosIncompatibleStatus
44+
* Method: nativeFromRCLEvent
45+
* Signature: (J)V
46+
*/
47+
JNIEXPORT void JNICALL
48+
Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeFromRCLEvent(
49+
JNIEnv *, jobject, jlong);
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
#endif // ORG_ROS2_RCLJAVA_DETAIL_QOSINCOMPATIBLESTATUS_H_

rcljava/include/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.h

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,11 @@ extern "C" {
2323

2424
/*
2525
* Class: org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible
26-
* Method: nAllocateRCLStatusEvent
27-
* Signature: ()J
28-
*/
29-
JNIEXPORT jlong JNICALL
30-
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nAllocateRCLStatusEvent(
31-
JNIEnv *, jclass);
32-
33-
/*
34-
* Class: org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible
35-
* Method: nDeallocateRCLStatusEvent
36-
* Signature: (J)V
37-
*/
38-
JNIEXPORT void JNICALL
39-
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nDeallocateRCLStatusEvent(
40-
JNIEnv *, jclass, jlong);
41-
42-
/*
43-
* Class: org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible
44-
* Method: nFromRCLEvent
45-
* Signature: (J)V
46-
*/
47-
JNIEXPORT void JNICALL
48-
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nFromRCLEvent(
49-
JNIEnv *, jobject, jlong);
50-
51-
/*
52-
* Class: org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible
53-
* Method: nGetPublisherEventType
26+
* Method: nativeGetEventType
5427
* Signature: ()I
5528
*/
5629
JNIEXPORT jint JNICALL
57-
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nGetPublisherEventType(
30+
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nativeGetEventType(
5831
JNIEnv *, jclass);
5932

6033
#ifdef __cplusplus
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2020 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <jni.h>
16+
/* Header for class org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible */
17+
18+
#ifndef ORG_ROS2_RCLJAVA_SUBSCRIPTION_STATUSES_REQUESTEDQOSINCOMPATIBLE_H_
19+
#define ORG_ROS2_RCLJAVA_SUBSCRIPTION_STATUSES_REQUESTEDQOSINCOMPATIBLE_H_
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/*
25+
* Class: org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible
26+
* Method: nativeGetEventType
27+
* Signature: ()I
28+
*/
29+
JNIEXPORT jint JNICALL
30+
Java_org_ros2_rcljava_subscription_statuses_RequestedQosIncompatible_nativeGetEventType(
31+
JNIEnv *, jclass);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
#endif // ORG_ROS2_RCLJAVA_SUBSCRIPTION_STATUSES_REQUESTEDQOSINCOMPATIBLE_H_
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2020 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "org_ros2_rcljava_detail_QosIncompatibleStatus.h"
16+
17+
#include <jni.h>
18+
#include <stdlib.h>
19+
20+
#include "rmw/incompatible_qos_events_statuses.h"
21+
#include "rmw/types.h"
22+
#include "rcl/event.h"
23+
#include "rcljava_common/exceptions.hpp"
24+
25+
using rcljava_common::exceptions::rcljava_throw_exception;
26+
27+
JNIEXPORT jlong JNICALL
28+
Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeAllocateRCLStatusEvent(
29+
JNIEnv * env, jclass)
30+
{
31+
void * p = malloc(sizeof(rmw_qos_incompatible_event_status_t));
32+
if (!p) {
33+
rcljava_throw_exception(
34+
env, "java/lang/OutOfMemoryError", "failed to allocate qos incompatible status");
35+
}
36+
return reinterpret_cast<jlong>(p);
37+
}
38+
39+
JNIEXPORT void JNICALL
40+
Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeDeallocateRCLStatusEvent(
41+
JNIEnv *, jclass, jlong handle)
42+
{
43+
free(reinterpret_cast<void *>(handle));
44+
}
45+
46+
JNIEXPORT void JNICALL
47+
Java_org_ros2_rcljava_detail_QosIncompatibleStatus_nativeFromRCLEvent(
48+
JNIEnv * env, jobject self, jlong handle)
49+
{
50+
auto * p = reinterpret_cast<rmw_qos_incompatible_event_status_t *>(handle);
51+
if (!p) {
52+
rcljava_throw_exception(
53+
env, "java/lang/IllegalArgumentException", "passed rmw object handle is NULL");
54+
}
55+
// TODO(ivanpauno): class and field lookup could be done at startup time
56+
jclass clazz = env->GetObjectClass(self);
57+
jclass qos_kind_clazz = env->FindClass(
58+
"org/ros2/rcljava/detail/QosIncompatibleStatus$PolicyKind");
59+
if (env->ExceptionCheck()) {
60+
return;
61+
}
62+
jfieldID total_count_fid = env->GetFieldID(clazz, "totalCount", "I");
63+
if (env->ExceptionCheck()) {
64+
return;
65+
}
66+
jfieldID total_count_change_fid = env->GetFieldID(clazz, "totalCountChange", "I");
67+
if (env->ExceptionCheck()) {
68+
return;
69+
}
70+
const char * enum_class_path =
71+
"Lorg/ros2/rcljava/detail/QosIncompatibleStatus$PolicyKind;";
72+
jfieldID policy_kind_fid = env->GetFieldID(clazz, "lastPolicyKind", enum_class_path);
73+
if (env->ExceptionCheck()) {
74+
return;
75+
}
76+
77+
jfieldID enum_value_fid;
78+
switch (p->last_policy_kind) {
79+
case RMW_QOS_POLICY_INVALID:
80+
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "INVALID", enum_class_path);
81+
break;
82+
case RMW_QOS_POLICY_DURABILITY:
83+
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "DURABILITY", enum_class_path);
84+
break;
85+
case RMW_QOS_POLICY_DEADLINE:
86+
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "DEADLINE", enum_class_path);
87+
break;
88+
case RMW_QOS_POLICY_LIVELINESS:
89+
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "LIVELINESS", enum_class_path);
90+
break;
91+
case RMW_QOS_POLICY_RELIABILITY:
92+
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "RELIABILITY", enum_class_path);
93+
break;
94+
case RMW_QOS_POLICY_HISTORY:
95+
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "HISTORY", enum_class_path);
96+
break;
97+
case RMW_QOS_POLICY_LIFESPAN:
98+
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "LIFESPAN", enum_class_path);
99+
break;
100+
default:
101+
rcljava_throw_exception(
102+
env, "java/lang/IllegalArgumentException", "unknown rmw qos policy kind");
103+
break;
104+
}
105+
if (env->ExceptionCheck()) {
106+
return;
107+
}
108+
jobject enum_value = env->GetStaticObjectField(qos_kind_clazz, enum_value_fid);
109+
110+
env->SetIntField(self, total_count_fid, p->total_count);
111+
env->SetIntField(self, total_count_change_fid, p->total_count_change);
112+
env->SetObjectField(self, policy_kind_fid, enum_value);
113+
}

rcljava/src/main/cpp/org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.cpp

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -15,105 +15,11 @@
1515
#include "org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible.h"
1616

1717
#include <jni.h>
18-
#include <stdlib.h>
1918

20-
#include "rmw/incompatible_qos_events_statuses.h"
21-
#include "rmw/types.h"
2219
#include "rcl/event.h"
23-
#include "rcljava_common/exceptions.hpp"
24-
25-
using rcljava_common::exceptions::rcljava_throw_exception;
26-
27-
JNIEXPORT jlong JNICALL
28-
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nAllocateRCLStatusEvent(
29-
JNIEnv * env, jclass)
30-
{
31-
void * p = malloc(sizeof(rmw_offered_qos_incompatible_event_status_t));
32-
if (!p) {
33-
rcljava_throw_exception(
34-
env, "java/lang/OutOfMemoryError", "failed to allocate offered qos incompatible status");
35-
}
36-
return reinterpret_cast<jlong>(p);
37-
}
38-
39-
JNIEXPORT void JNICALL
40-
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nDeallocateRCLStatusEvent(
41-
JNIEnv *, jclass, jlong handle)
42-
{
43-
free(reinterpret_cast<void *>(handle));
44-
}
45-
46-
JNIEXPORT void JNICALL
47-
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nFromRCLEvent(
48-
JNIEnv * env, jobject self, jlong handle)
49-
{
50-
auto * p = reinterpret_cast<rmw_offered_qos_incompatible_event_status_t *>(handle);
51-
if (!p) {
52-
rcljava_throw_exception(
53-
env, "java/lang/IllegalArgumentException", "passed rmw object handle is NULL");
54-
}
55-
// TODO(ivanpauno): class and field lookup could be done at startup time
56-
jclass clazz = env->GetObjectClass(self);
57-
jclass qos_kind_clazz = env->FindClass(
58-
"org/ros2/rcljava/publisher/statuses/OfferedQosIncompatible$PolicyKind");
59-
if (env->ExceptionCheck()) {
60-
return;
61-
}
62-
jfieldID total_count_fid = env->GetFieldID(clazz, "totalCount", "I");
63-
if (env->ExceptionCheck()) {
64-
return;
65-
}
66-
jfieldID total_count_change_fid = env->GetFieldID(clazz, "totalCountChange", "I");
67-
if (env->ExceptionCheck()) {
68-
return;
69-
}
70-
const char * enum_class_path =
71-
"Lorg/ros2/rcljava/publisher/statuses/OfferedQosIncompatible$PolicyKind;";
72-
jfieldID policy_kind_fid = env->GetFieldID(clazz, "lastPolicyKind", enum_class_path);
73-
if (env->ExceptionCheck()) {
74-
return;
75-
}
76-
77-
jfieldID enum_value_fid;
78-
switch (p->last_policy_kind) {
79-
case RMW_QOS_POLICY_INVALID:
80-
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "INVALID", enum_class_path);
81-
break;
82-
case RMW_QOS_POLICY_DURABILITY:
83-
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "DURABILITY", enum_class_path);
84-
break;
85-
case RMW_QOS_POLICY_DEADLINE:
86-
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "DEADLINE", enum_class_path);
87-
break;
88-
case RMW_QOS_POLICY_LIVELINESS:
89-
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "LIVELINESS", enum_class_path);
90-
break;
91-
case RMW_QOS_POLICY_RELIABILITY:
92-
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "RELIABILITY", enum_class_path);
93-
break;
94-
case RMW_QOS_POLICY_HISTORY:
95-
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "HISTORY", enum_class_path);
96-
break;
97-
case RMW_QOS_POLICY_LIFESPAN:
98-
enum_value_fid = env->GetStaticFieldID(qos_kind_clazz, "LIFESPAN", enum_class_path);
99-
break;
100-
default:
101-
rcljava_throw_exception(
102-
env, "java/lang/IllegalStateException", "unknown rmw qos policy kind");
103-
break;
104-
}
105-
if (env->ExceptionCheck()) {
106-
return;
107-
}
108-
jobject enum_value = env->GetStaticObjectField(qos_kind_clazz, enum_value_fid);
109-
110-
env->SetIntField(self, total_count_fid, p->total_count);
111-
env->SetIntField(self, total_count_change_fid, p->total_count_change);
112-
env->SetObjectField(self, policy_kind_fid, enum_value);
113-
}
11420

11521
JNIEXPORT jint JNICALL
116-
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nGetPublisherEventType(
22+
Java_org_ros2_rcljava_publisher_statuses_OfferedQosIncompatible_nativeGetEventType(
11723
JNIEnv *, jclass)
11824
{
11925
return RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS;

0 commit comments

Comments
 (0)