From dce546912ccf42f36a28e94eac80f3022c50f080 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Tue, 1 Oct 2019 15:15:02 -0700 Subject: [PATCH 01/15] Update API for getting rcl error string Signed-off-by: Jacob Perron --- .../src/main/cpp/org_ros2_rcljava_RCLJava.cpp | 6 ++-- .../src/main/cpp/org_ros2_rcljava_Time.cpp | 4 +-- .../org_ros2_rcljava_client_ClientImpl.cpp | 4 +-- ...rg_ros2_rcljava_executors_BaseExecutor.cpp | 30 +++++++++---------- .../cpp/org_ros2_rcljava_node_NodeImpl.cpp | 12 ++++---- ...g_ros2_rcljava_publisher_PublisherImpl.cpp | 4 +-- .../org_ros2_rcljava_service_ServiceImpl.cpp | 2 +- ..._rcljava_subscription_SubscriptionImpl.cpp | 2 +- .../org_ros2_rcljava_timer_WallTimerImpl.cpp | 20 ++++++------- 9 files changed, 42 insertions(+), 42 deletions(-) diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp index 3604b22c..d4140789 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp @@ -41,7 +41,7 @@ Java_org_ros2_rcljava_RCLJava_nativeRCLJavaInit(JNIEnv * env, jclass) // TODO(esteve): parse args rcl_ret_t ret = rcl_init(0, nullptr, rcl_get_default_allocator()); if (ret != RCL_RET_OK) { - std::string msg = "Failed to init: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to init: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -65,7 +65,7 @@ Java_org_ros2_rcljava_RCLJava_nativeCreateNodeHandle( rcl_node_options_t default_options = rcl_node_get_default_options(); rcl_ret_t ret = rcl_node_init(node, node_name.c_str(), namespace_.c_str(), &default_options); if (ret != RCL_RET_OK) { - std::string msg = "Failed to create node: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to create node: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return 0; @@ -93,7 +93,7 @@ Java_org_ros2_rcljava_RCLJava_nativeShutdown(JNIEnv * env, jclass) { rcl_ret_t ret = rcl_shutdown(); if (ret != RCL_RET_OK) { - std::string msg = "Failed to shutdown: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to shutdown: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_Time.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_Time.cpp index fb9f1de1..1f287b7f 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_Time.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_Time.cpp @@ -32,7 +32,7 @@ Java_org_ros2_rcljava_Time_nativeRCLSystemTimeNow(JNIEnv * env, jclass) rcutils_ret_t ret = RCUTILS_RET_ERROR; ret = rcutils_system_time_now(&rcutils_now); if (ret != RCUTILS_RET_OK) { - std::string msg = "Could not get current time: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Could not get current time: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -46,7 +46,7 @@ Java_org_ros2_rcljava_Time_nativeRCLSteadyTimeNow(JNIEnv * env, jclass) rcutils_ret_t ret = RCUTILS_RET_ERROR; ret = rcutils_steady_time_now(&rcutils_now); if (ret != RCUTILS_RET_OK) { - std::string msg = "Could not get current time: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Could not get current time: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_client_ClientImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_client_ClientImpl.cpp index 9dd0c724..aec896e9 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_client_ClientImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_client_ClientImpl.cpp @@ -60,7 +60,7 @@ Java_org_ros2_rcljava_client_ClientImpl_nativeSendClientRequest( if (ret != RCL_RET_OK) { std::string msg = - "Failed to send request from a client: " + std::string(rcl_get_error_string_safe()); + "Failed to send request from a client: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -91,7 +91,7 @@ Java_org_ros2_rcljava_client_ClientImpl_nativeDispose( rcl_ret_t ret = rcl_client_fini(client, node); if (ret != RCL_RET_OK) { - std::string msg = "Failed to destroy client: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to destroy client: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp index 62ac4af3..2fc951f9 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp @@ -114,7 +114,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetInit( wait_set, number_of_subscriptions, number_of_guard_conditions, number_of_timers, number_of_clients, number_of_services, rcl_get_default_allocator()); if (ret != RCL_RET_OK) { - std::string msg = "Failed to initialize wait set: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to initialize wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -128,7 +128,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeDisposeWaitSet( rcl_ret_t ret = rcl_wait_set_fini(wait_set); if (ret != RCL_RET_OK) { - std::string msg = "Failed to destroy timer: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to destroy timer: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -142,7 +142,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearSubscriptions( rcl_ret_t ret = rcl_wait_set_clear_subscriptions(wait_set); if (ret != RCL_RET_OK) { std::string msg = - "Failed to clear subscriptions from wait set: " + std::string(rcl_get_error_string_safe()); + "Failed to clear subscriptions from wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -157,7 +157,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddSubscription( rcl_ret_t ret = rcl_wait_set_add_subscription(wait_set, subscription); if (ret != RCL_RET_OK) { std::string msg = - "Failed to add subscription to wait set: " + std::string(rcl_get_error_string_safe()); + "Failed to add subscription to wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -170,7 +170,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWait( rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); rcl_ret_t ret = rcl_wait(wait_set, timeout); if (ret != RCL_RET_OK && ret != RCL_RET_TIMEOUT) { - std::string msg = "Failed to wait on wait set: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to wait on wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -205,7 +205,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeTake( destroy_ros_message(taken_msg); std::string msg = - "Failed to take from a subscription: " + std::string(rcl_get_error_string_safe()); + "Failed to take from a subscription: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return nullptr; @@ -238,7 +238,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearTimers( rcl_ret_t ret = rcl_wait_set_clear_timers(wait_set); if (ret != RCL_RET_OK) { std::string msg = - "Failed to clear timers from wait set: " + std::string(rcl_get_error_string_safe()); + "Failed to clear timers from wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -252,7 +252,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearServices( rcl_ret_t ret = rcl_wait_set_clear_services(wait_set); if (ret != RCL_RET_OK) { std::string msg = - "Failed to clear services from wait set: " + std::string(rcl_get_error_string_safe()); + "Failed to clear services from wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -267,7 +267,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddService( rcl_ret_t ret = rcl_wait_set_add_service(wait_set, service); if (ret != RCL_RET_OK) { std::string msg = - "Failed to add service to wait set: " + std::string(rcl_get_error_string_safe()); + "Failed to add service to wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -281,7 +281,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearClients( rcl_ret_t ret = rcl_wait_set_clear_clients(wait_set); if (ret != RCL_RET_OK) { std::string msg = - "Failed to clear clients from wait set: " + std::string(rcl_get_error_string_safe()); + "Failed to clear clients from wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -296,7 +296,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddClient( rcl_ret_t ret = rcl_wait_set_add_client(wait_set, client); if (ret != RCL_RET_OK) { std::string msg = - "Failed to add client to wait set: " + std::string(rcl_get_error_string_safe()); + "Failed to add client to wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -311,7 +311,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddTimer( rcl_ret_t ret = rcl_wait_set_add_timer(wait_set, timer); if (ret != RCL_RET_OK) { std::string msg = - "Failed to add timer to wait set: " + std::string(rcl_get_error_string_safe()); + "Failed to add timer to wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -348,7 +348,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeTakeRequest( destroy_ros_message(taken_msg); std::string msg = - "Failed to take request from a service: " + std::string(rcl_get_error_string_safe()); + "Failed to take request from a service: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return nullptr; @@ -399,7 +399,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeSendServiceResponse( if (ret != RCL_RET_OK) { std::string msg = - "Failed to send response from a service: " + std::string(rcl_get_error_string_safe()); + "Failed to send response from a service: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -438,7 +438,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeTakeResponse( destroy_ros_message(taken_msg); std::string msg = - "Failed to take request from a service: " + std::string(rcl_get_error_string_safe()); + "Failed to take request from a service: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return nullptr; diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp index a5b7a78a..f09950e1 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp @@ -59,7 +59,7 @@ Java_org_ros2_rcljava_node_NodeImpl_nativeCreatePublisherHandle( rcl_ret_t ret = rcl_publisher_init(publisher, node, ts, topic.c_str(), &publisher_ops); if (ret != RCL_RET_OK) { - std::string msg = "Failed to create publisher: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to create publisher: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return 0; @@ -98,7 +98,7 @@ Java_org_ros2_rcljava_node_NodeImpl_nativeCreateSubscriptionHandle( rcl_ret_t ret = rcl_subscription_init(subscription, node, ts, topic.c_str(), &subscription_ops); if (ret != RCL_RET_OK) { - std::string msg = "Failed to create subscription: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to create subscription: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return 0; @@ -141,7 +141,7 @@ Java_org_ros2_rcljava_node_NodeImpl_nativeCreateServiceHandle( rcl_ret_t ret = rcl_service_init(service, node, ts, service_name.c_str(), &service_ops); if (ret != RCL_RET_OK) { - std::string msg = "Failed to create service: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to create service: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return 0; @@ -184,7 +184,7 @@ Java_org_ros2_rcljava_node_NodeImpl_nativeCreateClientHandle( rcl_ret_t ret = rcl_client_init(client, node, ts, service_name.c_str(), &client_ops); if (ret != RCL_RET_OK) { - std::string msg = "Failed to create client: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to create client: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return 0; @@ -207,7 +207,7 @@ Java_org_ros2_rcljava_node_NodeImpl_nativeDispose(JNIEnv * env, jclass, jlong no rcl_ret_t ret = rcl_node_fini(node); if (ret != RCL_RET_OK) { - std::string msg = "Failed to destroy node: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to destroy node: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -223,7 +223,7 @@ Java_org_ros2_rcljava_node_NodeImpl_nativeCreateTimerHandle( rcl_ret_t ret = rcl_timer_init(timer, timer_period, NULL, rcl_get_default_allocator()); if (ret != RCL_RET_OK) { - std::string msg = "Failed to create timer: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to create timer: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return 0; diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp index d4ffcc9f..d60ac6b5 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp @@ -56,7 +56,7 @@ Java_org_ros2_rcljava_publisher_PublisherImpl_nativePublish( destroy_ros_message(raw_ros_message); if (ret != RCL_RET_OK) { - std::string msg = "Failed to publish: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to publish: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -85,7 +85,7 @@ Java_org_ros2_rcljava_publisher_PublisherImpl_nativeDispose( rcl_ret_t ret = rcl_publisher_fini(publisher, node); if (ret != RCL_RET_OK) { - std::string msg = "Failed to destroy publisher: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to destroy publisher: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_service_ServiceImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_service_ServiceImpl.cpp index fcfbdbe0..e56289d8 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_service_ServiceImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_service_ServiceImpl.cpp @@ -56,7 +56,7 @@ Java_org_ros2_rcljava_service_ServiceImpl_nativeDispose( rcl_ret_t ret = rcl_service_fini(service, node); if (ret != RCL_RET_OK) { - std::string msg = "Failed to destroy service: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to destroy service: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_subscription_SubscriptionImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_subscription_SubscriptionImpl.cpp index b2a30ac2..d0e84bdf 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_subscription_SubscriptionImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_subscription_SubscriptionImpl.cpp @@ -56,7 +56,7 @@ Java_org_ros2_rcljava_subscription_SubscriptionImpl_nativeDispose( rcl_ret_t ret = rcl_subscription_fini(subscription, node); if (ret != RCL_RET_OK) { - std::string msg = "Failed to destroy subscription: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to destroy subscription: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_timer_WallTimerImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_timer_WallTimerImpl.cpp index 0db954e6..dd0ed3a3 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_timer_WallTimerImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_timer_WallTimerImpl.cpp @@ -45,7 +45,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeIsReady( rcl_ret_t ret = rcl_timer_is_ready(timer, &is_ready); if (ret != RCL_RET_OK) { - std::string msg = "Failed to check timer ready: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to check timer ready: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); } @@ -65,7 +65,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeIsCanceled( rcl_ret_t ret = rcl_timer_is_canceled(timer, &is_canceled); if (ret != RCL_RET_OK) { - std::string msg = "Failed to check timer canceled: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to check timer canceled: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); } @@ -89,7 +89,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeDispose( rcl_ret_t ret = rcl_timer_fini(timer); if (ret != RCL_RET_OK) { - std::string msg = "Failed to destroy timer: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to destroy timer: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); } @@ -107,7 +107,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeReset(JNIEnv * env, jclass, jlon rcl_ret_t ret = rcl_timer_reset(timer); if (ret != RCL_RET_OK) { - std::string msg = "Failed to reset timer: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to reset timer: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); } @@ -126,7 +126,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeCancel( rcl_ret_t ret = rcl_timer_cancel(timer); if (ret != RCL_RET_OK) { - std::string msg = "Failed to cancel timer: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to cancel timer: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); } @@ -147,7 +147,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeTimeUntilNextCall( if (ret != RCL_RET_OK) { std::string msg = - "Failed to get time until next timer call: " + std::string(rcl_get_error_string_safe()); + "Failed to get time until next timer call: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); return 0; @@ -171,7 +171,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeTimeSinceLastCall( if (ret != RCL_RET_OK) { std::string msg = - "Failed to get time until next timer call: " + std::string(rcl_get_error_string_safe()); + "Failed to get time until next timer call: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); return 0; @@ -194,7 +194,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeGetTimerPeriodNS( rcl_ret_t ret = rcl_timer_get_period(timer, &timer_period); if (ret != RCL_RET_OK) { - std::string msg = "Failed to get timer period: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to get timer period: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); return 0; @@ -217,7 +217,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeSetTimerPeriodNS( rcl_ret_t ret = rcl_timer_exchange_period(timer, timer_period, &old_period); if (ret != RCL_RET_OK) { - std::string msg = "Failed to set timer period: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to set timer period: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); } @@ -236,7 +236,7 @@ Java_org_ros2_rcljava_timer_WallTimerImpl_nativeCallTimer( rcl_ret_t ret = rcl_timer_call(timer); if (ret != RCL_RET_OK) { - std::string msg = "Failed to call timer: " + std::string(rcl_get_error_string_safe()); + std::string msg = "Failed to call timer: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_exception(env, "java/lang/IllegalStateException", msg); } From 26e94b967c807a365d7a20e049fd6faaa40a7d90 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 4 Oct 2019 14:41:12 -0700 Subject: [PATCH 02/15] Add implementation for ROS Context A context represents an init/shutdown cycle and is used in the creation of top level entities like nodes and guard conditions. For convenience, a default context is created when rcljava is initialized. Signed-off-by: Jacob Perron --- rcljava/CMakeLists.txt | 3 + rcljava/include/org_ros2_rcljava_RCLJava.h | 14 +-- .../org_ros2_rcljava_context_ContextImpl.h | 56 +++++++++ .../src/main/cpp/org_ros2_rcljava_RCLJava.cpp | 26 +--- .../org_ros2_rcljava_context_ContextImpl.cpp | 90 +++++++++++++ .../main/java/org/ros2/rcljava/RCLJava.java | 58 ++++++++- .../org/ros2/rcljava/contexts/Context.java | 49 ++++++++ .../ros2/rcljava/contexts/ContextImpl.java | 118 ++++++++++++++++++ 8 files changed, 378 insertions(+), 36 deletions(-) create mode 100644 rcljava/include/org_ros2_rcljava_context_ContextImpl.h create mode 100644 rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp create mode 100644 rcljava/src/main/java/org/ros2/rcljava/contexts/Context.java create mode 100644 rcljava/src/main/java/org/ros2/rcljava/contexts/ContextImpl.java diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index 2e6005fb..308bbbdd 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -57,6 +57,7 @@ set(${PROJECT_NAME}_jni_sources "src/main/cpp/org_ros2_rcljava_RCLJava.cpp" "src/main/cpp/org_ros2_rcljava_Time.cpp" "src/main/cpp/org_ros2_rcljava_client_ClientImpl.cpp" + "src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp" "src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp" "src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp" "src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp" @@ -118,6 +119,8 @@ set(${PROJECT_NAME}_sources "src/main/java/org/ros2/rcljava/client/ClientImpl.java" "src/main/java/org/ros2/rcljava/concurrent/Callback.java" "src/main/java/org/ros2/rcljava/concurrent/RCLFuture.java" + "src/main/java/org/ros2/rcljava/contexts/Context.java" + "src/main/java/org/ros2/rcljava/contexts/ContextImpl.java" "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" diff --git a/rcljava/include/org_ros2_rcljava_RCLJava.h b/rcljava/include/org_ros2_rcljava_RCLJava.h index e064bcd0..39f9fe20 100644 --- a/rcljava/include/org_ros2_rcljava_RCLJava.h +++ b/rcljava/include/org_ros2_rcljava_RCLJava.h @@ -22,10 +22,11 @@ extern "C" { #endif /* * Class: org_ros2_rcljava_RCLJava - * Method: nativeRCLJavaInit - * Signature: ()V + * Method: nativeCreateContextHandle + * Signature: ()J */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_RCLJava_nativeRCLJavaInit(JNIEnv *, jclass); +JNIEXPORT jlong JNICALL + Java_org_ros2_rcljava_RCLJava_nativeCreateContextHandle(JNIEnv *, jclass); /* * Class: org_ros2_rcljava_RCLJava @@ -49,13 +50,6 @@ JNIEXPORT jstring JNICALL Java_org_ros2_rcljava_RCLJava_nativeGetRMWIdentifier(J */ JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_RCLJava_nativeOk(JNIEnv *, jclass); -/* - * Class: org_ros2_rcljava_RCLJava - * Method: nativeShutdown - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_RCLJava_nativeShutdown(JNIEnv *, jclass); - /* * Class: org_ros2_rcljava_RCLJava * Method: nativeConvertQoSProfileToHandle diff --git a/rcljava/include/org_ros2_rcljava_context_ContextImpl.h b/rcljava/include/org_ros2_rcljava_context_ContextImpl.h new file mode 100644 index 00000000..a264f1a1 --- /dev/null +++ b/rcljava/include/org_ros2_rcljava_context_ContextImpl.h @@ -0,0 +1,56 @@ +// Copyright 2019 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_context_ContextImpl */ + +#ifndef ORG_ROS2_RCLJAVA_CONTEXT_CONTEXTIMPL_H_ +#define ORG_ROS2_RCLJAVA_CONTEXT_CONTEXTIMPL_H_ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: org_ros2_rcljava_context_ContextImpl + * Method: nativeInit + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_ros2_rcljava_context_ContextImpl_nativeInit(JNIEnv *, jclass, jlong); + +/* + * Class: org_ros2_rcljava_context_ContextImpl + * Method: nativeShutdown + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_ros2_rcljava_context_ContextImpl_nativeShutdown(JNIEnv *, jclass, jlong); + +/* + * Class: org_ros2_rcljava_context_ContextImpl + * Method: nativeIsValid + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_context_ContextImpl_nativeIsValid( + JNIEnv *, jclass, jlong); + +/* + * Class: org_ros2_rcljava_context_ContextImpl + * Method: nativeDispose + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_ros2_rcljava_context_ContextImpl_nativeDispose(JNIEnv *, jclass, jlong); + +#ifdef __cplusplus +} +#endif +#endif // ORG_ROS2_RCLJAVA_CONTEXT_CONTEXTIMPL_H_ diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp index d4140789..6a7e8674 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp @@ -35,16 +35,13 @@ using rcljava_common::signatures::convert_from_java_signature; using rcljava_common::signatures::convert_to_java_signature; using rcljava_common::signatures::destroy_ros_message_signature; -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_RCLJava_nativeRCLJavaInit(JNIEnv * env, jclass) +JNIEXPORT jlong JNICALL +Java_org_ros2_rcljava_RCLJava_nativeCreateContextHandle(JNIEnv * env, jclass) { - // TODO(esteve): parse args - rcl_ret_t ret = rcl_init(0, nullptr, rcl_get_default_allocator()); - if (ret != RCL_RET_OK) { - std::string msg = "Failed to init: " + std::string(rcl_get_error_string().str); - rcl_reset_error(); - rcljava_throw_rclexception(env, ret, msg); - } + rcl_context_t * context = static_cast(malloc(sizeof(rcl_context_t))); + *context = rcl_get_zero_initialized_context(); + jlong context_handle = reinterpret_cast(context); + return context_handle; } JNIEXPORT jlong JNICALL @@ -88,17 +85,6 @@ Java_org_ros2_rcljava_RCLJava_nativeOk(JNIEnv *, jclass) return rcl_ok(); } -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_RCLJava_nativeShutdown(JNIEnv * env, jclass) -{ - rcl_ret_t ret = rcl_shutdown(); - if (ret != RCL_RET_OK) { - std::string msg = "Failed to shutdown: " + std::string(rcl_get_error_string().str); - rcl_reset_error(); - rcljava_throw_rclexception(env, ret, msg); - } -} - JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_RCLJava_nativeConvertQoSProfileToHandle( JNIEnv *, jclass, jint history, jint depth, jint reliability, jint durability, diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp new file mode 100644 index 00000000..11fbe160 --- /dev/null +++ b/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp @@ -0,0 +1,90 @@ +// Copyright 2019 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 + +#include "rcl/context.h" +#include "rcl/error_handling.h" +#include "rcl/init.h" + +#include "rcljava_common/exceptions.h" +#include "rcljava_common/signatures.h" + +#include "org_ros2_rcljava_context_ContextImpl.h" + +using rcljava_common::exceptions::rcljava_throw_rclexception; + +JNIEXPORT jboolean JNICALL +Java_org_ros2_rcljava_context_ContextImpl_nativeIsValid(JNIEnv *, jclass, jlong context_handle) +{ + rcl_context_t * context = reinterpret_cast(context_handle); + bool is_valid = rcl_context_is_valid(context); + return is_valid; +} + +JNIEXPORT void JNICALL +Java_org_ros2_rcljava_context_ContextImpl_nativeInit(JNIEnv * env, jclass, jlong context_handle) +{ + // TODO(jacobperron): Encapsulate init options into a Java class + rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); + rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator()); + if (RCL_RET_OK != ret) { + std::string msg = "Failed to init context options: " + std::string(rcl_get_error_string().str); + rcl_reset_error(); + rcljava_throw_rclexception(env, ret, msg); + return; + } + + rcl_context_t * context = reinterpret_cast(context_handle); + // TODO(esteve): parse args + ret = rcl_init(0, nullptr, &init_options, context); + rcl_init_options_fini(&init_options); + if (RCL_RET_OK != ret) { + std::string msg = "Failed to init context: " + std::string(rcl_get_error_string().str); + rcl_reset_error(); + rcljava_throw_rclexception(env, ret, msg); + return; + } +} + +JNIEXPORT void JNICALL +Java_org_ros2_rcljava_context_ContextImpl_nativeShutdown(JNIEnv * env, jclass, jlong context_handle) +{ + rcl_context_t * context = reinterpret_cast(context_handle); + rcl_ret_t ret = rcl_shutdown(context); + if (RCL_RET_OK != ret) { + std::string msg = "Failed to shutdown context: " + std::string(rcl_get_error_string().str); + rcl_reset_error(); + rcljava_throw_rclexception(env, ret, msg); + } +} + +JNIEXPORT void JNICALL +Java_org_ros2_rcljava_context_ContextImpl_nativeDispose(JNIEnv * env, jclass, jlong context_handle) +{ + if (0 == context_handle) { + // already destroyed + return; + } + + rcl_context_t * context = reinterpret_cast(context_handle); + + rcl_ret_t ret = rcl_context_fini(context); + + if (RCL_RET_OK != ret) { + std::string msg = "Failed to destroy context: " + std::string(rcl_get_error_string().str); + rcl_reset_error(); + rcljava_throw_rclexception(env, ret, msg); + } +} diff --git a/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java b/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java index 666ffcd7..3fc6df03 100644 --- a/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java +++ b/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java @@ -25,6 +25,8 @@ import org.ros2.rcljava.client.Client; import org.ros2.rcljava.common.JNIUtils; +import org.ros2.rcljava.contexts.Context; +import org.ros2.rcljava.contexts.ContextImpl; import org.ros2.rcljava.executors.SingleThreadedExecutor; import org.ros2.rcljava.interfaces.MessageDefinition; import org.ros2.rcljava.interfaces.ServiceDefinition; @@ -60,6 +62,17 @@ private static SingleThreadedExecutor getGlobalExecutor() { */ private RCLJava() {} + /** + * The default context. + */ + private static Context defaultContext; + + /** + * All the @{link Context}s that have been created. + * Does not include the default context. + */ + private static Collection contexts; + /** * All the @{link Node}s that have been created. */ @@ -89,6 +102,9 @@ private static void cleanup() { node.dispose(); } + for (Context context : contexts) { + context.dispose(); + } } static { @@ -108,6 +124,17 @@ private static void cleanup() { */ private static boolean initialized = false; + /** + * Get the default context. + */ + public static Context getDefaultContext() { + if (this.defaultContext == null) { + long contextHandle = RCLJava.nativeCreateContextHandle(); + this.defaultContext = new ContextImpl(contextHandle); + } + return this.defaultContext; + } + /** * @return true if RCLJava has been fully initialized, false otherwise. */ @@ -129,7 +156,10 @@ public static void rclJavaInit() { logger.error("Native code library failed to load.\n" + ule); System.exit(1); } - RCLJava.nativeRCLJavaInit(); + + // Initialize default context + getDefaultContext().init(); + logger.info("Using RMW implementation: {}", RCLJava.getRMWIdentifier()); initialized = true; } @@ -137,9 +167,11 @@ public static void rclJavaInit() { } /** - * Initialize the underlying rcl layer. + * Create a context (rcl_context_t) and return a pointer to it as an integer. + * + * @return A pointer to the underlying context structure. */ - private static native void nativeRCLJavaInit(); + private static native long nativeCreateContextHandle(); /** * Create a ROS2 node (rcl_node_t) and return a pointer to it as an integer. @@ -178,6 +210,18 @@ public static boolean ok() { return nativeOk(); } + /** + * Create a @{link Context}. + * + * @return A @{link Context} that represents the underlying context structure. + */ + public static Context createContext() { + long contextHandle = nativeCreateContextHandle(); + Context context = new ContextImpl(contextHandle); + contexts.add(context); + return context; + } + /** * Create a @{link Node}. * @@ -255,11 +299,13 @@ public static void spinSome(final ComposableNode composableNode) { getGlobalExecutor().removeNode(composableNode); } - private static native void nativeShutdown(); - public static void shutdown() { cleanup(); - nativeShutdown(); + if (this.defaultContext != null) { + this.defaultContext.shutdown(); + this.defaultContext.dispose(); + this.defaultContext = null; + } } public static long convertQoSProfileToHandle(final QoSProfile qosProfile) { diff --git a/rcljava/src/main/java/org/ros2/rcljava/contexts/Context.java b/rcljava/src/main/java/org/ros2/rcljava/contexts/Context.java new file mode 100644 index 00000000..717eea77 --- /dev/null +++ b/rcljava/src/main/java/org/ros2/rcljava/contexts/Context.java @@ -0,0 +1,49 @@ +/* Copyright 2019 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.contexts; + +import org.ros2.rcljava.interfaces.Disposable; + +/** + * Encapsulates the non-global state of a ROS init/shutdown cycle. + * + * Generally, after a context is created it is initialized with @{link #init()} + * and before it is disposed @{link #shutdown()} is called. + * + * For more information on the lifecylce of a context, see the RCL documentation: + * http://docs.ros2.org/dashing/api/rcl/context_8h.html#ae051a6821ad89dc78910a557029c8ae2 + * + * This class serves as a bridge between a rcl_context_t and RCLJava. + * A Context must be created via @{link RCLJava#createContext()} + */ +public interface Context extends Disposable { + /** + * Initialize the context. + * // TODO(jacobperron): Pass arguments for parsing + * // TODO(jacobperron): Pass in InitOptions object + */ + void init(); + + /** + * Shutdown the context. + */ + void shutdown(); + + /** + * return true if the Context is valid, false otherwise. + */ + boolean isValid(); +} diff --git a/rcljava/src/main/java/org/ros2/rcljava/contexts/ContextImpl.java b/rcljava/src/main/java/org/ros2/rcljava/contexts/ContextImpl.java new file mode 100644 index 00000000..3d6bf9f0 --- /dev/null +++ b/rcljava/src/main/java/org/ros2/rcljava/contexts/ContextImpl.java @@ -0,0 +1,118 @@ +/* Copyright 2019 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.contexts; + +import org.ros2.rcljava.common.JNIUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * {@inheritDoc} + */ +public class ContextImpl implements Context { + private static final Logger logger = LoggerFactory.getLogger(ContextImpl.class); + + static { + try { + JNIUtils.loadImplementation(ContextImpl.class); + } catch (UnsatisfiedLinkError ule) { + logger.error("Native code library failed to load.\n" + ule); + System.exit(1); + } + } + + /** + * An integer that represents a pointer to the underlying context structure (rcl_context_t). + */ + private long handle; + + /** + * Constructor. + * + * @param handle A pointer to the underlying context structure. + * Must not be zero. + */ + public ContextImpl(final long handle) { + this.handle = handle; + } + + /** + * Destroy a context (rcl_context_t). + * + * @param handle A pointer to the underlying context structure. + */ + private static native void nativeDispose(long handle); + + /** + * {@inheritDoc} + */ + public final void dispose() { + // Ensure the context is shutdown first + shutdown(); + nativeDispose(this.handle); + this.handle = 0; + } + + /** + * {@inheritDoc} + */ + public final long getHandle() { + return this.handle; + } + + /** + * Initialize a rcl_context_t. + * + * @param contextHandle The pointer to the context structure. + */ + private static native void nativeInit(long contextHandle); + + /** + * {@inheritDoc} + */ + public final void init() { + nativeInit(this.handle); + } + + /** + * Shutdown a rcl_context_t. + * + * @param contextHandle The pointer to the context structure. + */ + private static native void nativeShutdown(long contextHandle); + + /** + * {@inheritDoc} + */ + public final void shutdown() { + nativeShutdown(this.handle); + } + + /** + * Check if a context is valid (rcl_context_t). + * + * @param handle A pointer to the underlying context structure. + */ + private static native boolean nativeIsValid(long handle); + + /** + * {@inheritDoc} + */ + public final boolean isValid() { + return nativeIsValid(this.handle); + } +} From 88345874cfd3eb91251493aceabaca3abb72961d Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 4 Oct 2019 17:46:38 -0700 Subject: [PATCH 03/15] Add implementation for Clock Signed-off-by: Jacob Perron --- rcljava/CMakeLists.txt | 2 + rcljava/include/org_ros2_rcljava_time_Clock.h | 41 +++++++++ .../main/cpp/org_ros2_rcljava_time_Clock.cpp | 83 +++++++++++++++++++ .../java/org/ros2/rcljava/time/Clock.java | 78 +++++++++++++++++ 4 files changed, 204 insertions(+) create mode 100644 rcljava/include/org_ros2_rcljava_time_Clock.h create mode 100644 rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp create mode 100644 rcljava/src/main/java/org/ros2/rcljava/time/Clock.java diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index 308bbbdd..ab38ad0f 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -63,6 +63,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_time_Clock.cpp" "src/main/cpp/org_ros2_rcljava_timer_WallTimerImpl.cpp" ) @@ -154,6 +155,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/time/Clock.java" "src/main/java/org/ros2/rcljava/time/ClockType.java" "src/main/java/org/ros2/rcljava/timer/Timer.java" "src/main/java/org/ros2/rcljava/timer/WallTimer.java" diff --git a/rcljava/include/org_ros2_rcljava_time_Clock.h b/rcljava/include/org_ros2_rcljava_time_Clock.h new file mode 100644 index 00000000..6d52d9da --- /dev/null +++ b/rcljava/include/org_ros2_rcljava_time_Clock.h @@ -0,0 +1,41 @@ +// Copyright 2019 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_time_Clock */ + +#ifndef ORG_ROS2_RCLJAVA_TIME_CLOCK_H_ +#define ORG_ROS2_RCLJAVA_TIME_CLOCK_H_ +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: org_ros2_rcljava_time_Clock + * Method: nativeCreateClock + * Signature: (Lorg/ros2/rcljava/time/ClockType;)J + */ +JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_time_Clock_nativeCreateClock(JNIEnv *, jclass, jobject); + +/* + * Class: org_ros2_rcljava_time_Clock + * Method: nativeDispose + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_ros2_rcljava_time_Clock_nativeDispose(JNIEnv *, jclass, jlong); + +#ifdef __cplusplus +} +#endif +#endif // ORG_ROS2_RCLJAVA_TIME_CLOCK_H_ diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp new file mode 100644 index 00000000..25689bb8 --- /dev/null +++ b/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp @@ -0,0 +1,83 @@ +// Copyright 2019 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 +#include + +#include "rcl/error_handling.h" +#include "rcl/time.h" + +#include "rcljava_common/exceptions.h" +#include "rcljava_common/signatures.h" + +#include "org_ros2_rcljava_context_ContextImpl.h" + +using rcljava_common::exceptions::rcljava_throw_exception; +using rcljava_common::exceptions::rcljava_throw_rclexception; + +JNIEXPORT jlong JNICALL +Java_org_ros2_rcljava_time_Clock_nativeCreateClock(JNIEnv * env, jclass, jobject jclock_type) +{ + // Convert from Java ClockType to rcl_clock_type_t + jclass clock_type_enum = env->FindClass("org.ros2.rcljava.time/ClockType"); + jmethodID get_name_method = env->GetMethodID(clock_type_enum, "name", "()Ljava/lang/String;"); + jstring clock_type_name = (jstring)env->CallObjectMethod(jclock_type, get_name_method); + const char * clock_type_name_native = env->GetStringUTFChars(clock_type_name, 0); + rcl_clock_type_t clock_type; + if (strcmp(clock_type_name_native, "TIME_SOURCE_UNINITIALIZED") == 0) { + clock_type = RCL_CLOCK_UNINITIALIZED; + } else if (strcmp(clock_type_name_native, "ROS_TIME") == 0) { + clock_type = RCL_ROS_TIME; + } else if (strcmp(clock_type_name_native, "SYSTEM_TIME") == 0) { + clock_type = RCL_SYSTEM_TIME; + } else if (strcmp(clock_type_name_native, "STEADY_TIME") == 0) { + clock_type = RCL_STEADY_TIME; + } else { + std::string msg = "Unexpected clock type: " + std::string(clock_type_name_native); + rcljava_throw_exception(env, "java/lang/EnumConstantNotPresentException", msg); + return 0; + } + + // Initialize clock + rcl_clock_t * clock = static_cast(malloc(sizeof(rcl_clock_t))); + rcl_allocator_t allocator = rcl_get_default_allocator(); + rcl_ret_t ret = rcl_clock_init(clock_type, clock, &allocator); + if (RCL_RET_OK != ret) { + std::string msg = "Failed to init clock: " + std::string(rcl_get_error_string().str); + rcl_reset_error(); + rcljava_throw_rclexception(env, ret, msg); + return 0; + } + + jlong clock_handle = reinterpret_cast(clock); + return clock_handle; +} + +JNIEXPORT void JNICALL +Java_org_ros2_rcljava_time_Clock_nativeDispose(JNIEnv * env, jclass, jlong clock_handle) +{ + if (0 == clock_handle) { + // already destroyed + return; + } + + rcl_clock_t * clock = reinterpret_cast(clock_handle); + + rcl_ret_t ret = rcl_clock_fini(clock); + if (RCL_RET_OK != ret) { + std::string msg = "Failed to destroy clock: " + std::string(rcl_get_error_string().str); + rcl_reset_error(); + rcljava_throw_rclexception(env, ret, msg); + } +} diff --git a/rcljava/src/main/java/org/ros2/rcljava/time/Clock.java b/rcljava/src/main/java/org/ros2/rcljava/time/Clock.java new file mode 100644 index 00000000..4ad2aae2 --- /dev/null +++ b/rcljava/src/main/java/org/ros2/rcljava/time/Clock.java @@ -0,0 +1,78 @@ +/* Copyright 2019 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.time; + +import org.ros2.rcljava.interfaces.Disposable; + +public class Clock implements Disposable { + + /** + * The underlying clock handle (rcl_clock_t). + */ + private long handle; + + /** + * The clock type. + */ + private final ClockType clockType; + + /** + * Create an RCL clock (rcl_clock_t). + * + * @param clockType The RCL clock type. + * @return A pointer to the underlying clock structure as an integer. + */ + private static native long nativeCreateClock(ClockType clockType); + + /** + * Constructor. + * + * @param clockType The type of clock to create. + */ + public Clock(ClockType clockType) { + this.clockType = clockType; + this.handle = Clock.nativeCreateClock(clockType); + } + + /** + * @return The clock type. + */ + public ClockType getClockType() { + return clockType; + } + + /** + * Destroy an RCL clock (rcl_clock_t). + * + * @param handle A pointer to the underlying clock structure. + */ + private static native void nativeDispose(long handle); + + /** + * {@inheritDoc} + */ + public final void dispose() { + Clock.nativeDispose(this.handle); + this.handle = 0; + } + + /** + * {@inheritDoc} + */ + public final long getHandle() { + return this.handle; + } +} From bb188f9eed563242e9c974f2831f4825feedfee3 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 4 Oct 2019 17:47:24 -0700 Subject: [PATCH 04/15] Update for Dashing support * Update wait set API calls * Update entity creation API calls * Use Context objects to check 'ok()' status * Add Clock and Context members to NodeImpl * Fix static member reference: 'this.defaultContext' -> 'RCLJava.defaultContext' Signed-off-by: Jacob Perron --- rcljava/include/org_ros2_rcljava_RCLJava.h | 11 +--- .../org_ros2_rcljava_executors_BaseExecutor.h | 32 ++------- .../src/main/cpp/org_ros2_rcljava_RCLJava.cpp | 14 ++-- ...rg_ros2_rcljava_executors_BaseExecutor.cpp | 65 ++++--------------- .../cpp/org_ros2_rcljava_node_NodeImpl.cpp | 7 +- ...g_ros2_rcljava_publisher_PublisherImpl.cpp | 2 +- .../main/java/org/ros2/rcljava/RCLJava.java | 34 ++++++---- .../ros2/rcljava/executors/BaseExecutor.java | 25 +++---- .../java/org/ros2/rcljava/node/NodeImpl.java | 21 +++++- 9 files changed, 76 insertions(+), 135 deletions(-) diff --git a/rcljava/include/org_ros2_rcljava_RCLJava.h b/rcljava/include/org_ros2_rcljava_RCLJava.h index 39f9fe20..36f70456 100644 --- a/rcljava/include/org_ros2_rcljava_RCLJava.h +++ b/rcljava/include/org_ros2_rcljava_RCLJava.h @@ -31,10 +31,10 @@ JNIEXPORT jlong JNICALL /* * Class: org_ros2_rcljava_RCLJava * Method: nativeCreateNodeHandle - * Signature: (Ljava/lang/String;Ljava/lang/String;)J + * Signature: (Ljava/lang/String;Ljava/lang/String;J)J */ JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_RCLJava_nativeCreateNodeHandle(JNIEnv *, jclass, jstring, jstring); + Java_org_ros2_rcljava_RCLJava_nativeCreateNodeHandle(JNIEnv *, jclass, jstring, jstring, jlong); /* * Class: org_ros2_rcljava_RCLJava @@ -43,13 +43,6 @@ JNIEXPORT jlong JNICALL */ JNIEXPORT jstring JNICALL Java_org_ros2_rcljava_RCLJava_nativeGetRMWIdentifier(JNIEnv *, jclass); -/* - * Class: org_ros2_rcljava_RCLJava - * Method: nativeOk - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_RCLJava_nativeOk(JNIEnv *, jclass); - /* * Class: org_ros2_rcljava_RCLJava * Method: nativeConvertQoSProfileToHandle diff --git a/rcljava/include/org_ros2_rcljava_executors_BaseExecutor.h b/rcljava/include/org_ros2_rcljava_executors_BaseExecutor.h index f9cefbbd..6987ddcf 100644 --- a/rcljava/include/org_ros2_rcljava_executors_BaseExecutor.h +++ b/rcljava/include/org_ros2_rcljava_executors_BaseExecutor.h @@ -32,10 +32,10 @@ JNIEXPORT jlong JNICALL /* * Class: org_ros2_rcljava_executors_BaseExecutor * Method: nativeWaitSetInit - * Signature: (JIIIII)V + * Signature: (JJIIIIII)V */ JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetInit( - JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint); + JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint); /* * Class: org_ros2_rcljava_executors_BaseExecutor @@ -47,28 +47,12 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeDispos /* * Class: org_ros2_rcljava_executors_BaseExecutor - * Method: nativeWaitSetClearSubscriptions + * Method: nativeWaitSetClear * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearSubscriptions( +JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClear( JNIEnv *, jclass, jlong); -/* - * Class: org_ros2_rcljava_executors_BaseExecutor - * Method: nativeWaitSetClearTimers - * Signature: (J)V - */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearTimers(JNIEnv *, jclass, jlong); - -/* - * Class: org_ros2_rcljava_executors_BaseExecutor - * Method: nativeWaitSetClearServices - * Signature: (J)V - */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearServices(JNIEnv *, jclass, jlong); - /* * Class: org_ros2_rcljava_executors_BaseExecutor * Method: nativeWaitSetAddSubscription @@ -101,14 +85,6 @@ JNIEXPORT jobject JNICALL JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddService( JNIEnv *, jclass, jlong, jlong); -/* - * Class: org_ros2_rcljava_executors_BaseExecutor - * Method: nativeWaitSetClearClients - * Signature: (J)V - */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearClients(JNIEnv *, jclass, jlong); - /* * Class: org_ros2_rcljava_executors_BaseExecutor * Method: nativeWaitSetAddClient diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp index 6a7e8674..54061642 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp @@ -36,7 +36,7 @@ using rcljava_common::signatures::convert_to_java_signature; using rcljava_common::signatures::destroy_ros_message_signature; JNIEXPORT jlong JNICALL -Java_org_ros2_rcljava_RCLJava_nativeCreateContextHandle(JNIEnv * env, jclass) +Java_org_ros2_rcljava_RCLJava_nativeCreateContextHandle(JNIEnv *, jclass) { rcl_context_t * context = static_cast(malloc(sizeof(rcl_context_t))); *context = rcl_get_zero_initialized_context(); @@ -46,7 +46,7 @@ Java_org_ros2_rcljava_RCLJava_nativeCreateContextHandle(JNIEnv * env, jclass) JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_RCLJava_nativeCreateNodeHandle( - JNIEnv * env, jclass, jstring jnode_name, jstring jnamespace) + JNIEnv * env, jclass, jstring jnode_name, jstring jnamespace, jlong context_handle) { const char * node_name_tmp = env->GetStringUTFChars(jnode_name, 0); std::string node_name(node_name_tmp); @@ -56,11 +56,13 @@ Java_org_ros2_rcljava_RCLJava_nativeCreateNodeHandle( std::string namespace_(namespace_tmp); env->ReleaseStringUTFChars(jnamespace, namespace_tmp); + rcl_context_t * context = reinterpret_cast(context_handle); + rcl_node_t * node = static_cast(malloc(sizeof(rcl_node_t))); *node = rcl_get_zero_initialized_node(); rcl_node_options_t default_options = rcl_node_get_default_options(); - rcl_ret_t ret = rcl_node_init(node, node_name.c_str(), namespace_.c_str(), &default_options); + rcl_ret_t ret = rcl_node_init(node, node_name.c_str(), namespace_.c_str(), context, &default_options); if (ret != RCL_RET_OK) { std::string msg = "Failed to create node: " + std::string(rcl_get_error_string().str); rcl_reset_error(); @@ -79,12 +81,6 @@ Java_org_ros2_rcljava_RCLJava_nativeGetRMWIdentifier(JNIEnv * env, jclass) return env->NewStringUTF(rmw_implementation_identifier); } -JNIEXPORT jboolean JNICALL -Java_org_ros2_rcljava_RCLJava_nativeOk(JNIEnv *, jclass) -{ - return rcl_ok(); -} - JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_RCLJava_nativeConvertQoSProfileToHandle( JNIEnv *, jclass, jint history, jint depth, jint reliability, jint durability, diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp index 2fc951f9..3f948b1b 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp @@ -104,15 +104,16 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeGetZeroInitializedWaitSet(JNI JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetInit( - JNIEnv * env, jclass, jlong wait_set_handle, jint number_of_subscriptions, + JNIEnv * env, jclass, jlong wait_set_handle, jlong context_handle, jint number_of_subscriptions, jint number_of_guard_conditions, jint number_of_timers, jint number_of_clients, - jint number_of_services) + jint number_of_services, jint number_of_events) { rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); + rcl_context_t * context = reinterpret_cast(context_handle); rcl_ret_t ret = rcl_wait_set_init( wait_set, number_of_subscriptions, number_of_guard_conditions, number_of_timers, - number_of_clients, number_of_services, rcl_get_default_allocator()); + number_of_clients, number_of_services, number_of_events, context, rcl_get_default_allocator()); if (ret != RCL_RET_OK) { std::string msg = "Failed to initialize wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); @@ -135,14 +136,14 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeDisposeWaitSet( } JNIEXPORT void JNICALL -Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearSubscriptions( +Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClear( JNIEnv * env, jclass, jlong wait_set_handle) { rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); - rcl_ret_t ret = rcl_wait_set_clear_subscriptions(wait_set); + rcl_ret_t ret = rcl_wait_set_clear(wait_set); if (ret != RCL_RET_OK) { std::string msg = - "Failed to clear subscriptions from wait set: " + std::string(rcl_get_error_string().str); + "Failed to clear wait set: " + std::string(rcl_get_error_string().str); rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); } @@ -154,7 +155,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddSubscription( { rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); rcl_subscription_t * subscription = reinterpret_cast(subscription_handle); - rcl_ret_t ret = rcl_wait_set_add_subscription(wait_set, subscription); + rcl_ret_t ret = rcl_wait_set_add_subscription(wait_set, subscription, nullptr); if (ret != RCL_RET_OK) { std::string msg = "Failed to add subscription to wait set: " + std::string(rcl_get_error_string().str); @@ -199,7 +200,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeTake( void * taken_msg = convert_from_java(jmsg, nullptr); - rcl_ret_t ret = rcl_take(subscription, taken_msg, nullptr); + rcl_ret_t ret = rcl_take(subscription, taken_msg, nullptr, nullptr); if (ret != RCL_RET_OK && ret != RCL_RET_SUBSCRIPTION_TAKE_FAILED) { destroy_ros_message(taken_msg); @@ -230,41 +231,13 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeTake( return nullptr; } -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearTimers( - JNIEnv * env, jclass, jlong wait_set_handle) -{ - rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); - rcl_ret_t ret = rcl_wait_set_clear_timers(wait_set); - if (ret != RCL_RET_OK) { - std::string msg = - "Failed to clear timers from wait set: " + std::string(rcl_get_error_string().str); - rcl_reset_error(); - rcljava_throw_rclexception(env, ret, msg); - } -} - -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearServices( - JNIEnv * env, jclass, jlong wait_set_handle) -{ - rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); - rcl_ret_t ret = rcl_wait_set_clear_services(wait_set); - if (ret != RCL_RET_OK) { - std::string msg = - "Failed to clear services from wait set: " + std::string(rcl_get_error_string().str); - rcl_reset_error(); - rcljava_throw_rclexception(env, ret, msg); - } -} - JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddService( JNIEnv * env, jclass, jlong wait_set_handle, jlong service_handle) { rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); rcl_service_t * service = reinterpret_cast(service_handle); - rcl_ret_t ret = rcl_wait_set_add_service(wait_set, service); + rcl_ret_t ret = rcl_wait_set_add_service(wait_set, service, nullptr); if (ret != RCL_RET_OK) { std::string msg = "Failed to add service to wait set: " + std::string(rcl_get_error_string().str); @@ -273,27 +246,13 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddService( } } -JNIEXPORT void JNICALL -Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClearClients( - JNIEnv * env, jclass, jlong wait_set_handle) -{ - rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); - rcl_ret_t ret = rcl_wait_set_clear_clients(wait_set); - if (ret != RCL_RET_OK) { - std::string msg = - "Failed to clear clients from wait set: " + std::string(rcl_get_error_string().str); - rcl_reset_error(); - rcljava_throw_rclexception(env, ret, msg); - } -} - JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddClient( JNIEnv * env, jclass, jlong wait_set_handle, jlong client_handle) { rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); rcl_client_t * client = reinterpret_cast(client_handle); - rcl_ret_t ret = rcl_wait_set_add_client(wait_set, client); + rcl_ret_t ret = rcl_wait_set_add_client(wait_set, client, nullptr); if (ret != RCL_RET_OK) { std::string msg = "Failed to add client to wait set: " + std::string(rcl_get_error_string().str); @@ -308,7 +267,7 @@ Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddTimer( { rcl_wait_set_t * wait_set = reinterpret_cast(wait_set_handle); rcl_timer_t * timer = reinterpret_cast(timer_handle); - rcl_ret_t ret = rcl_wait_set_add_timer(wait_set, timer); + rcl_ret_t ret = rcl_wait_set_add_timer(wait_set, timer, nullptr); if (ret != RCL_RET_OK) { std::string msg = "Failed to add timer to wait set: " + std::string(rcl_get_error_string().str); diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp index f09950e1..1b5954d6 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp @@ -215,12 +215,15 @@ Java_org_ros2_rcljava_node_NodeImpl_nativeDispose(JNIEnv * env, jclass, jlong no JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateTimerHandle( - JNIEnv * env, jclass, jlong timer_period) + JNIEnv * env, jclass, jlong clock_handle, jlong context_handle, jlong timer_period) { + rcl_clock_t * clock = reinterpret_cast(clock_handle); + rcl_context_t * context = reinterpret_cast(context_handle); + rcl_timer_t * timer = static_cast(malloc(sizeof(rcl_timer_t))); *timer = rcl_get_zero_initialized_timer(); - rcl_ret_t ret = rcl_timer_init(timer, timer_period, NULL, rcl_get_default_allocator()); + rcl_ret_t ret = rcl_timer_init(timer, clock, context, timer_period, NULL, rcl_get_default_allocator()); if (ret != RCL_RET_OK) { std::string msg = "Failed to create timer: " + std::string(rcl_get_error_string().str); diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp index d60ac6b5..fef34631 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp @@ -49,7 +49,7 @@ Java_org_ros2_rcljava_publisher_PublisherImpl_nativePublish( void * raw_ros_message = convert_from_java(jmsg, nullptr); - rcl_ret_t ret = rcl_publish(publisher, raw_ros_message); + rcl_ret_t ret = rcl_publish(publisher, raw_ros_message, nullptr); destroy_ros_message_signature destroy_ros_message = reinterpret_cast(jmsg_destructor_handle); diff --git a/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java b/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java index 3fc6df03..9bdabc2d 100644 --- a/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java +++ b/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java @@ -128,11 +128,11 @@ private static void cleanup() { * Get the default context. */ public static Context getDefaultContext() { - if (this.defaultContext == null) { + if (RCLJava.defaultContext == null) { long contextHandle = RCLJava.nativeCreateContextHandle(); - this.defaultContext = new ContextImpl(contextHandle); + RCLJava.defaultContext = new ContextImpl(contextHandle); } - return this.defaultContext; + return RCLJava.defaultContext; } /** @@ -178,9 +178,10 @@ public static void rclJavaInit() { * * @param nodeName The name that will identify this node in a ROS2 graph. * @param namespace The namespace of the node. + * @param contextHandle Pointer to a context (rcl_context_t) with which to associated the node. * @return A pointer to the underlying ROS2 node structure. */ - private static native long nativeCreateNodeHandle(String nodeName, String namespace); + private static native long nativeCreateNodeHandle(String nodeName, String namespace, long contextHandle); /** * @return The identifier of the currently active RMW implementation via the @@ -207,7 +208,14 @@ public static String getRMWIdentifier() { * @return true if RCLJava hasn't been shut down, false otherwise. */ public static boolean ok() { - return nativeOk(); + return RCLJava.getDefaultContext().isValid(); + } + + /** + * @return true if RCLJava hasn't been shut down, false otherwise. + */ + public static boolean ok(final Context context) { + return context.isValid(); } /** @@ -230,7 +238,7 @@ public static Context createContext() { * structure. */ public static Node createNode(final String nodeName) { - return createNode(nodeName, ""); + return createNode(nodeName, "", RCLJava.getDefaultContext()); } /** @@ -241,9 +249,9 @@ public static Node createNode(final String nodeName) { * @return A @{link Node} that represents the underlying ROS2 node * structure. */ - public static Node createNode(final String nodeName, final String namespace) { - long nodeHandle = nativeCreateNodeHandle(nodeName, namespace); - Node node = new NodeImpl(nodeHandle, nodeName); + public static Node createNode(final String nodeName, final String namespace, final Context context) { + long nodeHandle = nativeCreateNodeHandle(nodeName, namespace, context.getHandle()); + Node node = new NodeImpl(nodeHandle, nodeName, context); nodes.add(node); return node; } @@ -301,10 +309,10 @@ public static void spinSome(final ComposableNode composableNode) { public static void shutdown() { cleanup(); - if (this.defaultContext != null) { - this.defaultContext.shutdown(); - this.defaultContext.dispose(); - this.defaultContext = null; + if (RCLJava.defaultContext != null) { + RCLJava.defaultContext.shutdown(); + RCLJava.defaultContext.dispose(); + RCLJava.defaultContext = null; } } diff --git a/rcljava/src/main/java/org/ros2/rcljava/executors/BaseExecutor.java b/rcljava/src/main/java/org/ros2/rcljava/executors/BaseExecutor.java index 4d7beaac..536e417b 100644 --- a/rcljava/src/main/java/org/ros2/rcljava/executors/BaseExecutor.java +++ b/rcljava/src/main/java/org/ros2/rcljava/executors/BaseExecutor.java @@ -204,15 +204,10 @@ protected void waitForWork(long timeout) { } long waitSetHandle = nativeGetZeroInitializedWaitSet(); - nativeWaitSetInit(waitSetHandle, subscriptionsSize, 0, timersSize, clientsSize, servicesSize); + long contextHandle = RCLJava.getDefaultContext().getHandle(); + nativeWaitSetInit(waitSetHandle, contextHandle, subscriptionsSize, 0, timersSize, clientsSize, servicesSize, 0); - nativeWaitSetClearSubscriptions(waitSetHandle); - - nativeWaitSetClearTimers(waitSetHandle); - - nativeWaitSetClearServices(waitSetHandle); - - nativeWaitSetClearClients(waitSetHandle); + nativeWaitSetClear(waitSetHandle); for (Map.Entry entry : this.subscriptionHandles) { nativeWaitSetAddSubscription(waitSetHandle, entry.getKey()); @@ -362,10 +357,12 @@ protected void spinOnce(long timeout) { private static native long nativeGetZeroInitializedWaitSet(); - private static native void nativeWaitSetInit(long waitSetHandle, int numberOfSubscriptions, - int numberOfGuardConditions, int numberOfTimers, int numberOfClients, int numberOfServices); + private static native void nativeWaitSetInit( + long waitSetHandle, long contextHandle, int numberOfSubscriptions, + int numberOfGuardConditions, int numberOfTimers, int numberOfClients, + int numberOfServices, int numberOfEvents); - private static native void nativeWaitSetClearSubscriptions(long waitSetHandle); + private static native void nativeWaitSetClear(long waitSetHandle); private static native void nativeWaitSetAddSubscription( long waitSetHandle, long subscriptionHandle); @@ -375,14 +372,8 @@ private static native void nativeWaitSetAddSubscription( private static native MessageDefinition nativeTake( long subscriptionHandle, Class messageType); - private static native void nativeWaitSetClearTimers(long waitSetHandle); - - private static native void nativeWaitSetClearServices(long waitSetHandle); - private static native void nativeWaitSetAddService(long waitSetHandle, long serviceHandle); - private static native void nativeWaitSetClearClients(long waitSetHandle); - private static native void nativeWaitSetAddClient(long waitSetHandle, long clientHandle); private static native void nativeWaitSetAddTimer(long waitSetHandle, long timerHandle); diff --git a/rcljava/src/main/java/org/ros2/rcljava/node/NodeImpl.java b/rcljava/src/main/java/org/ros2/rcljava/node/NodeImpl.java index 96797b97..2235fda0 100644 --- a/rcljava/src/main/java/org/ros2/rcljava/node/NodeImpl.java +++ b/rcljava/src/main/java/org/ros2/rcljava/node/NodeImpl.java @@ -22,6 +22,7 @@ import org.ros2.rcljava.concurrent.Callback; import org.ros2.rcljava.consumers.Consumer; import org.ros2.rcljava.consumers.TriConsumer; +import org.ros2.rcljava.contexts.Context; import org.ros2.rcljava.qos.QoSProfile; import org.ros2.rcljava.interfaces.MessageDefinition; import org.ros2.rcljava.interfaces.ServiceDefinition; @@ -34,6 +35,8 @@ import org.ros2.rcljava.service.ServiceImpl; import org.ros2.rcljava.subscription.Subscription; import org.ros2.rcljava.subscription.SubscriptionImpl; +import org.ros2.rcljava.time.Clock; +import org.ros2.rcljava.time.ClockType; import org.ros2.rcljava.timer.Timer; import org.ros2.rcljava.timer.WallTimer; import org.ros2.rcljava.timer.WallTimerImpl; @@ -75,6 +78,16 @@ public class NodeImpl implements Node { */ private long handle; + /** + * The context that this node is associated with. + */ + private Context context; + + /** + * The clock used by this node. + */ + private Clock clock; + /** * All the @{link Subscription}s that have been created through this instance. */ @@ -112,9 +125,11 @@ public class NodeImpl implements Node { * @param handle A pointer to the underlying ROS2 node structure. Must not * be zero. */ - public NodeImpl(final long handle, final String name) { + public NodeImpl(final long handle, final String name, final Context context) { + this.clock = new Clock(ClockType.SYSTEM_TIME); this.handle = handle; this.name = name; + this.context = context; this.publishers = new LinkedBlockingQueue(); this.subscriptions = new LinkedBlockingQueue(); this.services = new LinkedBlockingQueue(); @@ -315,12 +330,12 @@ public final long getHandle() { return this.handle; } - private static native long nativeCreateTimerHandle(long timerPeriod); + private static native long nativeCreateTimerHandle(long clockHandle, long contextHandle, long timerPeriod); public WallTimer createWallTimer( final long period, final TimeUnit unit, final Callback callback) { long timerPeriodNS = TimeUnit.NANOSECONDS.convert(period, unit); - long timerHandle = nativeCreateTimerHandle(timerPeriodNS); + long timerHandle = nativeCreateTimerHandle(clock.getHandle(), context.getHandle(), timerPeriodNS); WallTimer timer = new WallTimerImpl(new WeakReference(this), timerHandle, callback, timerPeriodNS); this.timers.add(timer); From 38eb60d948df7fecb5eb389f9028b4de5e4fa97f Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 7 Oct 2019 10:22:40 -0700 Subject: [PATCH 05/15] Avoid hiding errors when cleaning up init options Signed-off-by: Jacob Perron --- .../cpp/org_ros2_rcljava_context_ContextImpl.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp index 11fbe160..4a2b698a 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp @@ -49,9 +49,20 @@ Java_org_ros2_rcljava_context_ContextImpl_nativeInit(JNIEnv * env, jclass, jlong rcl_context_t * context = reinterpret_cast(context_handle); // TODO(esteve): parse args ret = rcl_init(0, nullptr, &init_options, context); - rcl_init_options_fini(&init_options); if (RCL_RET_OK != ret) { std::string msg = "Failed to init context: " + std::string(rcl_get_error_string().str); + rcl_ret_t ignored_ret = rcl_init_options_fini(&init_options); + (void)ignored_ret; + rcl_reset_error(); + rcljava_throw_rclexception(env, ret, msg); + return; + } + + rcl_ret_t fini_ret = rcl_init_options_fini(&init_options); + if (RCL_RET_OK != fini_ret) { + std::string msg = "Failed to init context: " + std::string(rcl_get_error_string().str); + rcl_ret_t ignored_ret = rcl_shutdown(context); + (void)ignored_ret; rcl_reset_error(); rcljava_throw_rclexception(env, ret, msg); return; From b04797bbbf7714a135824fd74bc2f12f545e5edc Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 7 Oct 2019 10:32:25 -0700 Subject: [PATCH 06/15] Disable tests Signed-off-by: Jacob Perron --- rcljava/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index ab38ad0f..b6bc8b23 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -175,7 +175,7 @@ add_jar("${PROJECT_NAME}_jar" install_jar("${PROJECT_NAME}_jar" "share/${PROJECT_NAME}/java") ament_export_jars("share/${PROJECT_NAME}/java/${PROJECT_NAME}.jar") -if(BUILD_TESTING) +if(FALSE) #BUILD_TESTING) find_package(ament_lint_auto REQUIRED) find_package(std_msgs REQUIRED) ament_lint_auto_find_test_dependencies() From e83c37f2a471bd06bb7d61d24621489cfad55ea4 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 7 Oct 2019 11:41:47 -0700 Subject: [PATCH 07/15] Fix typos in JNI library files Signed-off-by: Jacob Perron --- rcljava/CMakeLists.txt | 2 +- ...=> org_ros2_rcljava_contexts_ContextImpl.h} | 18 +++++++++--------- ... org_ros2_rcljava_contexts_ContextImpl.cpp} | 10 +++++----- .../main/cpp/org_ros2_rcljava_time_Clock.cpp | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) rename rcljava/include/{org_ros2_rcljava_context_ContextImpl.h => org_ros2_rcljava_contexts_ContextImpl.h} (62%) rename rcljava/src/main/cpp/{org_ros2_rcljava_context_ContextImpl.cpp => org_ros2_rcljava_contexts_ContextImpl.cpp} (88%) diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index b6bc8b23..01d7bc34 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -57,7 +57,7 @@ set(${PROJECT_NAME}_jni_sources "src/main/cpp/org_ros2_rcljava_RCLJava.cpp" "src/main/cpp/org_ros2_rcljava_Time.cpp" "src/main/cpp/org_ros2_rcljava_client_ClientImpl.cpp" - "src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp" + "src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp" "src/main/cpp/org_ros2_rcljava_executors_BaseExecutor.cpp" "src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp" "src/main/cpp/org_ros2_rcljava_publisher_PublisherImpl.cpp" diff --git a/rcljava/include/org_ros2_rcljava_context_ContextImpl.h b/rcljava/include/org_ros2_rcljava_contexts_ContextImpl.h similarity index 62% rename from rcljava/include/org_ros2_rcljava_context_ContextImpl.h rename to rcljava/include/org_ros2_rcljava_contexts_ContextImpl.h index a264f1a1..a7c1aefe 100644 --- a/rcljava/include/org_ros2_rcljava_context_ContextImpl.h +++ b/rcljava/include/org_ros2_rcljava_contexts_ContextImpl.h @@ -13,7 +13,7 @@ // limitations under the License. #include -/* Header for class org_ros2_rcljava_context_ContextImpl */ +/* Header for class org_ros2_rcljava_contexts_ContextImpl */ #ifndef ORG_ROS2_RCLJAVA_CONTEXT_CONTEXTIMPL_H_ #define ORG_ROS2_RCLJAVA_CONTEXT_CONTEXTIMPL_H_ @@ -22,33 +22,33 @@ extern "C" { #endif /* - * Class: org_ros2_rcljava_context_ContextImpl + * Class: org_ros2_rcljava_contexts_ContextImpl * Method: nativeInit * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_context_ContextImpl_nativeInit(JNIEnv *, jclass, jlong); +JNIEXPORT void JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeInit(JNIEnv *, jclass, jlong); /* - * Class: org_ros2_rcljava_context_ContextImpl + * Class: org_ros2_rcljava_contexts_ContextImpl * Method: nativeShutdown * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_context_ContextImpl_nativeShutdown(JNIEnv *, jclass, jlong); +JNIEXPORT void JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeShutdown(JNIEnv *, jclass, jlong); /* - * Class: org_ros2_rcljava_context_ContextImpl + * Class: org_ros2_rcljava_contexts_ContextImpl * Method: nativeIsValid * Signature: (J)Z */ -JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_context_ContextImpl_nativeIsValid( +JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeIsValid( JNIEnv *, jclass, jlong); /* - * Class: org_ros2_rcljava_context_ContextImpl + * Class: org_ros2_rcljava_contexts_ContextImpl * Method: nativeDispose * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_context_ContextImpl_nativeDispose(JNIEnv *, jclass, jlong); +JNIEXPORT void JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeDispose(JNIEnv *, jclass, jlong); #ifdef __cplusplus } diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp similarity index 88% rename from rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp rename to rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp index 4a2b698a..c8dd747c 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_context_ContextImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp @@ -21,12 +21,12 @@ #include "rcljava_common/exceptions.h" #include "rcljava_common/signatures.h" -#include "org_ros2_rcljava_context_ContextImpl.h" +#include "org_ros2_rcljava_contexts_ContextImpl.h" using rcljava_common::exceptions::rcljava_throw_rclexception; JNIEXPORT jboolean JNICALL -Java_org_ros2_rcljava_context_ContextImpl_nativeIsValid(JNIEnv *, jclass, jlong context_handle) +Java_org_ros2_rcljava_contexts_ContextImpl_nativeIsValid(JNIEnv *, jclass, jlong context_handle) { rcl_context_t * context = reinterpret_cast(context_handle); bool is_valid = rcl_context_is_valid(context); @@ -34,7 +34,7 @@ Java_org_ros2_rcljava_context_ContextImpl_nativeIsValid(JNIEnv *, jclass, jlong } JNIEXPORT void JNICALL -Java_org_ros2_rcljava_context_ContextImpl_nativeInit(JNIEnv * env, jclass, jlong context_handle) +Java_org_ros2_rcljava_contexts_ContextImpl_nativeInit(JNIEnv * env, jclass, jlong context_handle) { // TODO(jacobperron): Encapsulate init options into a Java class rcl_init_options_t init_options = rcl_get_zero_initialized_init_options(); @@ -70,7 +70,7 @@ Java_org_ros2_rcljava_context_ContextImpl_nativeInit(JNIEnv * env, jclass, jlong } JNIEXPORT void JNICALL -Java_org_ros2_rcljava_context_ContextImpl_nativeShutdown(JNIEnv * env, jclass, jlong context_handle) +Java_org_ros2_rcljava_contexts_ContextImpl_nativeShutdown(JNIEnv * env, jclass, jlong context_handle) { rcl_context_t * context = reinterpret_cast(context_handle); rcl_ret_t ret = rcl_shutdown(context); @@ -82,7 +82,7 @@ Java_org_ros2_rcljava_context_ContextImpl_nativeShutdown(JNIEnv * env, jclass, j } JNIEXPORT void JNICALL -Java_org_ros2_rcljava_context_ContextImpl_nativeDispose(JNIEnv * env, jclass, jlong context_handle) +Java_org_ros2_rcljava_contexts_ContextImpl_nativeDispose(JNIEnv * env, jclass, jlong context_handle) { if (0 == context_handle) { // already destroyed diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp index 25689bb8..d487d8c8 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp @@ -21,7 +21,7 @@ #include "rcljava_common/exceptions.h" #include "rcljava_common/signatures.h" -#include "org_ros2_rcljava_context_ContextImpl.h" +#include "org_ros2_rcljava_time_Clock.h" using rcljava_common::exceptions::rcljava_throw_exception; using rcljava_common::exceptions::rcljava_throw_rclexception; From 56e999a4bac8dd216089b09aac07eab8bed39258 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 7 Oct 2019 15:16:22 -0700 Subject: [PATCH 08/15] Fix native node method signature Signed-off-by: Jacob Perron --- rcljava/include/org_ros2_rcljava_node_NodeImpl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rcljava/include/org_ros2_rcljava_node_NodeImpl.h b/rcljava/include/org_ros2_rcljava_node_NodeImpl.h index 260efc68..51675da5 100644 --- a/rcljava/include/org_ros2_rcljava_node_NodeImpl.h +++ b/rcljava/include/org_ros2_rcljava_node_NodeImpl.h @@ -62,10 +62,10 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeDispose(JNIEnv /* * Class: org_ros2_rcljava_node_NodeImpl * Method: nativeCreateTimerHandle - * Signature: (J)J + * Signature: (JJJ)J */ JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_node_NodeImpl_nativeCreateTimerHandle(JNIEnv *, jclass, jlong); + Java_org_ros2_rcljava_node_NodeImpl_nativeCreateTimerHandle(JNIEnv *, jclass, jlong, jlong, jlong); #ifdef __cplusplus } From 600ba0a3f266b6a0f57489e8da53f9e0edce6cb4 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 7 Oct 2019 15:17:07 -0700 Subject: [PATCH 09/15] Populate missing QoS settings with defaults Otherwise we run into a runtime error about Fast-RTPS not supporting liveliness. Signed-off-by: Jacob Perron --- rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp index 54061642..5e1de3b8 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp @@ -92,6 +92,11 @@ Java_org_ros2_rcljava_RCLJava_nativeConvertQoSProfileToHandle( qos_profile->depth = depth; qos_profile->reliability = static_cast(reliability); qos_profile->durability = static_cast(durability); + // TODO(jacobperron): Expose deadline, lifespan, and liveliness settings as parameters + qos_profile->deadline = rmw_qos_profile_default.deadline; + qos_profile->lifespan = rmw_qos_profile_default.lifespan; + qos_profile->liveliness = rmw_qos_profile_default.liveliness; + qos_profile->liveliness_lease_duration = rmw_qos_profile_default.liveliness_lease_duration; qos_profile->avoid_ros_namespace_conventions = avoidROSNamespaceConventions; return reinterpret_cast(qos_profile); } From 68f4e611db8b7ea84adc20393e97be483041e293 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 7 Oct 2019 15:20:24 -0700 Subject: [PATCH 10/15] Fix issues with Clock class * Load with JNIUtils * Rename native create method for consistency * Fix bug in native implementation Signed-off-by: Jacob Perron --- rcljava/include/org_ros2_rcljava_time_Clock.h | 3 +-- .../main/cpp/org_ros2_rcljava_time_Clock.cpp | 4 ++-- .../java/org/ros2/rcljava/time/Clock.java | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/rcljava/include/org_ros2_rcljava_time_Clock.h b/rcljava/include/org_ros2_rcljava_time_Clock.h index 6d52d9da..8c75f165 100644 --- a/rcljava/include/org_ros2_rcljava_time_Clock.h +++ b/rcljava/include/org_ros2_rcljava_time_Clock.h @@ -20,13 +20,12 @@ #ifdef __cplusplus extern "C" { #endif - /* * Class: org_ros2_rcljava_time_Clock * Method: nativeCreateClock * Signature: (Lorg/ros2/rcljava/time/ClockType;)J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_time_Clock_nativeCreateClock(JNIEnv *, jclass, jobject); +JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_time_Clock_nativeCreateClockHandle(JNIEnv *, jclass, jobject); /* * Class: org_ros2_rcljava_time_Clock diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp index d487d8c8..654b131d 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp @@ -27,10 +27,10 @@ using rcljava_common::exceptions::rcljava_throw_exception; using rcljava_common::exceptions::rcljava_throw_rclexception; JNIEXPORT jlong JNICALL -Java_org_ros2_rcljava_time_Clock_nativeCreateClock(JNIEnv * env, jclass, jobject jclock_type) +Java_org_ros2_rcljava_time_Clock_nativeCreateClockHandle(JNIEnv * env, jclass, jobject jclock_type) { // Convert from Java ClockType to rcl_clock_type_t - jclass clock_type_enum = env->FindClass("org.ros2.rcljava.time/ClockType"); + jclass clock_type_enum = env->FindClass("org/ros2/rcljava/time/ClockType"); jmethodID get_name_method = env->GetMethodID(clock_type_enum, "name", "()Ljava/lang/String;"); jstring clock_type_name = (jstring)env->CallObjectMethod(jclock_type, get_name_method); const char * clock_type_name_native = env->GetStringUTFChars(clock_type_name, 0); diff --git a/rcljava/src/main/java/org/ros2/rcljava/time/Clock.java b/rcljava/src/main/java/org/ros2/rcljava/time/Clock.java index 4ad2aae2..69936c33 100644 --- a/rcljava/src/main/java/org/ros2/rcljava/time/Clock.java +++ b/rcljava/src/main/java/org/ros2/rcljava/time/Clock.java @@ -15,9 +15,24 @@ package org.ros2.rcljava.time; +import org.ros2.rcljava.common.JNIUtils; + import org.ros2.rcljava.interfaces.Disposable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class Clock implements Disposable { + private static final Logger logger = LoggerFactory.getLogger(Clock.class); + + static { + try { + JNIUtils.loadImplementation(Clock.class); + } catch (UnsatisfiedLinkError ule) { + logger.error("Native code library failed to load.\n" + ule); + System.exit(1); + } + } /** * The underlying clock handle (rcl_clock_t). @@ -35,7 +50,7 @@ public class Clock implements Disposable { * @param clockType The RCL clock type. * @return A pointer to the underlying clock structure as an integer. */ - private static native long nativeCreateClock(ClockType clockType); + private static native long nativeCreateClockHandle(ClockType clockType); /** * Constructor. @@ -44,7 +59,7 @@ public class Clock implements Disposable { */ public Clock(ClockType clockType) { this.clockType = clockType; - this.handle = Clock.nativeCreateClock(clockType); + this.handle = Clock.nativeCreateClockHandle(clockType); } /** From 09f6d51891c1a8b031d3dd529462bb3cf6bd4e8e Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Wed, 15 Jan 2020 14:39:41 -0800 Subject: [PATCH 11/15] Enable linter tests Signed-off-by: Jacob Perron --- rcljava/CMakeLists.txt | 252 ++++++++++++++++++++--------------------- 1 file changed, 126 insertions(+), 126 deletions(-) diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index 01d7bc34..6495e784 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -175,135 +175,135 @@ add_jar("${PROJECT_NAME}_jar" install_jar("${PROJECT_NAME}_jar" "share/${PROJECT_NAME}/java") ament_export_jars("share/${PROJECT_NAME}/java/${PROJECT_NAME}.jar") -if(FALSE) #BUILD_TESTING) +if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) - find_package(std_msgs REQUIRED) + # find_package(std_msgs REQUIRED) ament_lint_auto_find_test_dependencies() - set(${PROJECT_NAME}_message_files - "msg/BoundedArrayNested.msg" - "msg/BoundedArrayPrimitives.msg" - "msg/Builtins.msg" - "msg/DynamicArrayNested.msg" - "msg/DynamicArrayPrimitives.msg" - "msg/Empty.msg" - "msg/FieldsWithSameType.msg" - "msg/Nested.msg" - "msg/Primitives.msg" - "msg/StaticArrayNested.msg" - "msg/StaticArrayPrimitives.msg" - "msg/UInt32.msg" - ) - - set(${PROJECT_NAME}_service_files - "srv/AddTwoInts.srv" - ) - - rosidl_generate_interfaces(${PROJECT_NAME} - ${${PROJECT_NAME}_message_files} - ${${PROJECT_NAME}_service_files} - DEPENDENCIES - builtin_interfaces - rcl_interfaces - SKIP_INSTALL - ) - - get_property(_${PROJECT_NAME}_jar_file - TARGET "${PROJECT_NAME}_jar" - PROPERTY "JAR_FILE") - - get_property(_${PROJECT_NAME}_messages_jar_file - TARGET "${PROJECT_NAME}_messages_jar" - PROPERTY "JAR_FILE") - - set(${PROJECT_NAME}_test_sources - "src/test/java/org/ros2/rcljava/RCLJavaTest.java" - "src/test/java/org/ros2/rcljava/TimeTest.java" - "src/test/java/org/ros2/rcljava/client/ClientTest.java" - "src/test/java/org/ros2/rcljava/node/NodeTest.java" - "src/test/java/org/ros2/rcljava/parameters/AsyncParametersClientTest.java" - "src/test/java/org/ros2/rcljava/parameters/SyncParametersClientTest.java" - "src/test/java/org/ros2/rcljava/publisher/PublisherTest.java" - "src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java" - "src/test/java/org/ros2/rcljava/timer/TimerTest.java" - ) - - set(${PROJECT_NAME}_testsuites - "org.ros2.rcljava.RCLJavaTest" - "org.ros2.rcljava.TimeTest" - "org.ros2.rcljava.client.ClientTest" - "org.ros2.rcljava.node.NodeTest" - "org.ros2.rcljava.parameters.SyncParametersClientTest" - "org.ros2.rcljava.publisher.PublisherTest" - "org.ros2.rcljava.subscription.SubscriptionTest" - "org.ros2.rcljava.timer.TimerTest" - ) - - set(_deps_library_dirs "") - foreach(_dep_lib ${rcljava_test_msgs_LIBRARIES}) - get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - list_append_unique(_deps_library_dirs ${_dep_dir}) - endforeach() - foreach(_dep_lib ${rcljava_test_msgs_JNI_LIBRARIES}) - get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - list_append_unique(_deps_library_dirs ${_dep_dir}) - endforeach() - - foreach(_dep_lib ${std_msgs_LIBRARIES}) - get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - list_append_unique(_deps_library_dirs ${_dep_dir}) - endforeach() - foreach(_dep_lib ${std_msgs_JNI_LIBRARIES}) - get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - list_append_unique(_deps_library_dirs ${_dep_dir}) - endforeach() - - foreach(_dep_lib ${builtin_interfaces_LIBRARIES}) - get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - list_append_unique(_deps_library_dirs ${_dep_dir}) - endforeach() - foreach(_dep_lib ${builtin_interfaces_JNI_LIBRARIES}) - get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - list_append_unique(_deps_library_dirs ${_dep_dir}) - endforeach() - - foreach(_dep_lib ${rcl_interfaces_LIBRARIES}) - get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - list_append_unique(_deps_library_dirs ${_dep_dir}) - endforeach() - foreach(_dep_lib ${rcl_interfaces_JNI_LIBRARIES}) - get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - list_append_unique(_deps_library_dirs ${_dep_dir}) - endforeach() - - list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}) - list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rcljava) - list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_java/rcljava/msg/) - list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_java/rcljava/srv/) - - foreach(testsuite ${${PROJECT_NAME}_testsuites}) - ament_add_junit_tests("${PROJECT_NAME}_tests_${testsuite}" - TIMEOUT 90 - WORKING_DIRECTORY - "${CMAKE_CURRENT_BINARY_DIR}" - SOURCES - "${${PROJECT_NAME}_test_sources}" - TESTS - "${testsuite}" - INCLUDE_JARS - "${rcljava_common_JARS}" - "${rcljava_test_msgs_JARS}" - "${std_msgs_JARS}" - "${builtin_interfaces_JARS}" - "${rcl_interfaces_JARS}" - "${_${PROJECT_NAME}_jar_file}" - "${_${PROJECT_NAME}_messages_jar_file}" - APPEND_LIBRARY_DIRS - "${_deps_library_dirs}" - ) - - add_dependencies("${PROJECT_NAME}_tests_${testsuite}" "${PROJECT_NAME}_messages_jar") - endforeach() + # set(${PROJECT_NAME}_message_files + # "msg/BoundedArrayNested.msg" + # "msg/BoundedArrayPrimitives.msg" + # "msg/Builtins.msg" + # "msg/DynamicArrayNested.msg" + # "msg/DynamicArrayPrimitives.msg" + # "msg/Empty.msg" + # "msg/FieldsWithSameType.msg" + # "msg/Nested.msg" + # "msg/Primitives.msg" + # "msg/StaticArrayNested.msg" + # "msg/StaticArrayPrimitives.msg" + # "msg/UInt32.msg" + # ) + + # set(${PROJECT_NAME}_service_files + # "srv/AddTwoInts.srv" + # ) + + # rosidl_generate_interfaces(${PROJECT_NAME} + # ${${PROJECT_NAME}_message_files} + # ${${PROJECT_NAME}_service_files} + # DEPENDENCIES + # builtin_interfaces + # rcl_interfaces + # SKIP_INSTALL + # ) + + # get_property(_${PROJECT_NAME}_jar_file + # TARGET "${PROJECT_NAME}_jar" + # PROPERTY "JAR_FILE") + + # get_property(_${PROJECT_NAME}_messages_jar_file + # TARGET "${PROJECT_NAME}_messages_jar" + # PROPERTY "JAR_FILE") + + # set(${PROJECT_NAME}_test_sources + # "src/test/java/org/ros2/rcljava/RCLJavaTest.java" + # "src/test/java/org/ros2/rcljava/TimeTest.java" + # "src/test/java/org/ros2/rcljava/client/ClientTest.java" + # "src/test/java/org/ros2/rcljava/node/NodeTest.java" + # "src/test/java/org/ros2/rcljava/parameters/AsyncParametersClientTest.java" + # "src/test/java/org/ros2/rcljava/parameters/SyncParametersClientTest.java" + # "src/test/java/org/ros2/rcljava/publisher/PublisherTest.java" + # "src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java" + # "src/test/java/org/ros2/rcljava/timer/TimerTest.java" + # ) + + # set(${PROJECT_NAME}_testsuites + # "org.ros2.rcljava.RCLJavaTest" + # "org.ros2.rcljava.TimeTest" + # "org.ros2.rcljava.client.ClientTest" + # "org.ros2.rcljava.node.NodeTest" + # "org.ros2.rcljava.parameters.SyncParametersClientTest" + # "org.ros2.rcljava.publisher.PublisherTest" + # "org.ros2.rcljava.subscription.SubscriptionTest" + # "org.ros2.rcljava.timer.TimerTest" + # ) + + # set(_deps_library_dirs "") + # foreach(_dep_lib ${rcljava_test_msgs_LIBRARIES}) + # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + # list_append_unique(_deps_library_dirs ${_dep_dir}) + # endforeach() + # foreach(_dep_lib ${rcljava_test_msgs_JNI_LIBRARIES}) + # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + # list_append_unique(_deps_library_dirs ${_dep_dir}) + # endforeach() + + # foreach(_dep_lib ${std_msgs_LIBRARIES}) + # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + # list_append_unique(_deps_library_dirs ${_dep_dir}) + # endforeach() + # foreach(_dep_lib ${std_msgs_JNI_LIBRARIES}) + # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + # list_append_unique(_deps_library_dirs ${_dep_dir}) + # endforeach() + + # foreach(_dep_lib ${builtin_interfaces_LIBRARIES}) + # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + # list_append_unique(_deps_library_dirs ${_dep_dir}) + # endforeach() + # foreach(_dep_lib ${builtin_interfaces_JNI_LIBRARIES}) + # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + # list_append_unique(_deps_library_dirs ${_dep_dir}) + # endforeach() + + # foreach(_dep_lib ${rcl_interfaces_LIBRARIES}) + # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + # list_append_unique(_deps_library_dirs ${_dep_dir}) + # endforeach() + # foreach(_dep_lib ${rcl_interfaces_JNI_LIBRARIES}) + # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + # list_append_unique(_deps_library_dirs ${_dep_dir}) + # endforeach() + + # list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}) + # list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rcljava) + # list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_java/rcljava/msg/) + # list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_java/rcljava/srv/) + + # foreach(testsuite ${${PROJECT_NAME}_testsuites}) + # ament_add_junit_tests("${PROJECT_NAME}_tests_${testsuite}" + # TIMEOUT 90 + # WORKING_DIRECTORY + # "${CMAKE_CURRENT_BINARY_DIR}" + # SOURCES + # "${${PROJECT_NAME}_test_sources}" + # TESTS + # "${testsuite}" + # INCLUDE_JARS + # "${rcljava_common_JARS}" + # "${rcljava_test_msgs_JARS}" + # "${std_msgs_JARS}" + # "${builtin_interfaces_JARS}" + # "${rcl_interfaces_JARS}" + # "${_${PROJECT_NAME}_jar_file}" + # "${_${PROJECT_NAME}_messages_jar_file}" + # APPEND_LIBRARY_DIRS + # "${_deps_library_dirs}" + # ) + + # add_dependencies("${PROJECT_NAME}_tests_${testsuite}" "${PROJECT_NAME}_messages_jar") + # endforeach() endif() From 1554c3dfa35e044133407b56b78919ec9e403fab Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 16 Jan 2020 17:45:41 -0800 Subject: [PATCH 12/15] Fix lint errors Signed-off-by: Jacob Perron --- rcljava/include/org_ros2_rcljava_RCLJava.h | 19 +++--- rcljava/include/org_ros2_rcljava_Time.h | 6 +- .../org_ros2_rcljava_client_ClientImpl.h | 7 ++- .../org_ros2_rcljava_contexts_ContextImpl.h | 19 +++--- .../org_ros2_rcljava_executors_BaseExecutor.h | 58 +++++++++++-------- .../include/org_ros2_rcljava_node_NodeImpl.h | 20 ++++--- ...org_ros2_rcljava_publisher_PublisherImpl.h | 8 ++- .../org_ros2_rcljava_service_ServiceImpl.h | 4 +- ...s2_rcljava_subscription_SubscriptionImpl.h | 5 +- rcljava/include/org_ros2_rcljava_time_Clock.h | 6 +- .../org_ros2_rcljava_timer_WallTimerImpl.h | 41 ++++++------- .../src/main/cpp/org_ros2_rcljava_RCLJava.cpp | 3 +- .../org_ros2_rcljava_contexts_ContextImpl.cpp | 5 +- .../cpp/org_ros2_rcljava_node_NodeImpl.cpp | 3 +- .../main/cpp/org_ros2_rcljava_time_Clock.cpp | 2 + 15 files changed, 123 insertions(+), 83 deletions(-) diff --git a/rcljava/include/org_ros2_rcljava_RCLJava.h b/rcljava/include/org_ros2_rcljava_RCLJava.h index 36f70456..5ef6aff1 100644 --- a/rcljava/include/org_ros2_rcljava_RCLJava.h +++ b/rcljava/include/org_ros2_rcljava_RCLJava.h @@ -25,30 +25,33 @@ extern "C" { * Method: nativeCreateContextHandle * Signature: ()J */ -JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_RCLJava_nativeCreateContextHandle(JNIEnv *, jclass); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_RCLJava_nativeCreateContextHandle(JNIEnv *, jclass); /* * Class: org_ros2_rcljava_RCLJava * Method: nativeCreateNodeHandle * Signature: (Ljava/lang/String;Ljava/lang/String;J)J */ -JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_RCLJava_nativeCreateNodeHandle(JNIEnv *, jclass, jstring, jstring, jlong); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_RCLJava_nativeCreateNodeHandle( + JNIEnv *, jclass, jstring, jstring, jlong); /* * Class: org_ros2_rcljava_RCLJava * Method: nativeGetRMWIdentifier * Signature: ()Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_org_ros2_rcljava_RCLJava_nativeGetRMWIdentifier(JNIEnv *, jclass); +JNIEXPORT jstring +JNICALL Java_org_ros2_rcljava_RCLJava_nativeGetRMWIdentifier(JNIEnv *, jclass); /* * Class: org_ros2_rcljava_RCLJava * Method: nativeConvertQoSProfileToHandle * Signature: (IIIIZ)J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_RCLJava_nativeConvertQoSProfileToHandle( +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_RCLJava_nativeConvertQoSProfileToHandle( JNIEnv *, jclass, jint, jint, jint, jint, jboolean); /* @@ -56,8 +59,8 @@ JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_RCLJava_nativeConvertQoSProfileToH * Method: nativeDisposeQoSProfile * Signature: (J)V */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_RCLJava_nativeDisposeQoSProfile(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_RCLJava_nativeDisposeQoSProfile(JNIEnv *, jclass, jlong); #ifdef __cplusplus } diff --git a/rcljava/include/org_ros2_rcljava_Time.h b/rcljava/include/org_ros2_rcljava_Time.h index a65b1866..9528f4db 100644 --- a/rcljava/include/org_ros2_rcljava_Time.h +++ b/rcljava/include/org_ros2_rcljava_Time.h @@ -25,14 +25,16 @@ extern "C" { * Method: nativeRCLSystemTimeNow * Signature: ()J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_Time_nativeRCLSystemTimeNow(JNIEnv *, jclass); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_Time_nativeRCLSystemTimeNow(JNIEnv *, jclass); /* * Class: org_ros2_rcljava_Time * Method: nativeRCLSteadyTimeNow * Signature: ()J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_Time_nativeRCLSteadyTimeNow(JNIEnv *, jclass); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_Time_nativeRCLSteadyTimeNow(JNIEnv *, jclass); #ifdef __cplusplus } diff --git a/rcljava/include/org_ros2_rcljava_client_ClientImpl.h b/rcljava/include/org_ros2_rcljava_client_ClientImpl.h index 49018e3e..ab71b022 100644 --- a/rcljava/include/org_ros2_rcljava_client_ClientImpl.h +++ b/rcljava/include/org_ros2_rcljava_client_ClientImpl.h @@ -25,7 +25,8 @@ extern "C" { * Method: nativeSendClientRequest * Signature: (JJJJJLorg/ros2/rcljava/interfaces/MessageDefinition;)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_client_ClientImpl_nativeSendClientRequest( +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_client_ClientImpl_nativeSendClientRequest( JNIEnv *, jclass, jlong, jlong, jlong, jlong, jlong, jobject); /* @@ -33,8 +34,8 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_client_ClientImpl_nativeSendClientR * Method: nativeDispose * Signature: (JJ)V */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_client_ClientImpl_nativeDispose(JNIEnv *, jclass, jlong, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_client_ClientImpl_nativeDispose(JNIEnv *, jclass, jlong, jlong); #ifdef __cplusplus } diff --git a/rcljava/include/org_ros2_rcljava_contexts_ContextImpl.h b/rcljava/include/org_ros2_rcljava_contexts_ContextImpl.h index a7c1aefe..049891d6 100644 --- a/rcljava/include/org_ros2_rcljava_contexts_ContextImpl.h +++ b/rcljava/include/org_ros2_rcljava_contexts_ContextImpl.h @@ -15,8 +15,8 @@ #include /* Header for class org_ros2_rcljava_contexts_ContextImpl */ -#ifndef ORG_ROS2_RCLJAVA_CONTEXT_CONTEXTIMPL_H_ -#define ORG_ROS2_RCLJAVA_CONTEXT_CONTEXTIMPL_H_ +#ifndef ORG_ROS2_RCLJAVA_CONTEXTS_CONTEXTIMPL_H_ +#define ORG_ROS2_RCLJAVA_CONTEXTS_CONTEXTIMPL_H_ #ifdef __cplusplus extern "C" { #endif @@ -26,31 +26,34 @@ extern "C" { * Method: nativeInit * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeInit(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeInit(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_contexts_ContextImpl * Method: nativeShutdown * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeShutdown(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeShutdown(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_contexts_ContextImpl * Method: nativeIsValid * Signature: (J)Z */ -JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeIsValid( - JNIEnv *, jclass, jlong); +JNIEXPORT jboolean +JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeIsValid(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_contexts_ContextImpl * Method: nativeDispose * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeDispose(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_contexts_ContextImpl_nativeDispose(JNIEnv *, jclass, jlong); #ifdef __cplusplus } #endif -#endif // ORG_ROS2_RCLJAVA_CONTEXT_CONTEXTIMPL_H_ +#endif // ORG_ROS2_RCLJAVA_CONTEXTS_CONTEXTIMPL_H_ diff --git a/rcljava/include/org_ros2_rcljava_executors_BaseExecutor.h b/rcljava/include/org_ros2_rcljava_executors_BaseExecutor.h index 6987ddcf..c94a7959 100644 --- a/rcljava/include/org_ros2_rcljava_executors_BaseExecutor.h +++ b/rcljava/include/org_ros2_rcljava_executors_BaseExecutor.h @@ -26,15 +26,17 @@ extern "C" { * Method: nativeGetZeroInitializedWaitSet * Signature: ()J */ -JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_executors_BaseExecutor_nativeGetZeroInitializedWaitSet(JNIEnv *, jclass); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeGetZeroInitializedWaitSet( + JNIEnv *, jclass); /* * Class: org_ros2_rcljava_executors_BaseExecutor * Method: nativeWaitSetInit * Signature: (JJIIIIII)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetInit( +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetInit( JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint); /* @@ -42,23 +44,24 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSe * Method: nativeDisposeWaitSet * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeDisposeWaitSet( - JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeDisposeWaitSet(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_executors_BaseExecutor * Method: nativeWaitSetClear * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClear( - JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClear(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_executors_BaseExecutor * Method: nativeWaitSetAddSubscription * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddSubscription( +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddSubscription( JNIEnv *, jclass, jlong, jlong); /* @@ -66,23 +69,24 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSe * Method: nativeWait * Signature: (JJ)V */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_executors_BaseExecutor_nativeWait(JNIEnv *, jclass, jlong, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWait(JNIEnv *, jclass, jlong, jlong); /* * Class: org_ros2_rcljava_executors_BaseExecutor * Method: nativeTake * Signature: (JLjava/lang/Class;)Lorg/ros2/rcljava/interfaces/MessageDefinition; */ -JNIEXPORT jobject JNICALL - Java_org_ros2_rcljava_executors_BaseExecutor_nativeTake(JNIEnv *, jclass, jlong, jclass); +JNIEXPORT jobject +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeTake(JNIEnv *, jclass, jlong, jclass); /* * Class: org_ros2_rcljava_executors_BaseExecutor * Method: nativeWaitSetAddService * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddService( +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddService( JNIEnv *, jclass, jlong, jlong); /* @@ -90,7 +94,8 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSe * Method: nativeWaitSetAddClient * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddClient( +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddClient( JNIEnv *, jclass, jlong, jlong); /* @@ -98,7 +103,8 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSe * Method: nativeTakeRequest * Signature: (JJJJLorg/ros2/rcljava/interfaces/MessageDefinition;)Lorg/ros2/rcljava/RMWRequestId; */ -JNIEXPORT jobject JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeTakeRequest( +JNIEXPORT jobject +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeTakeRequest( JNIEnv *, jclass, jlong, jlong, jlong, jlong, jobject); /* @@ -106,7 +112,8 @@ JNIEXPORT jobject JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeTak * Method: nativeSendServiceResponse * Signature: (JLorg/ros2/rcljava/RMWRequestId;JJJLorg/ros2/rcljava/interfaces/MessageDefinition;)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeSendServiceResponse( +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeSendServiceResponse( JNIEnv *, jclass, jlong, jobject, jlong, jlong, jlong, jobject); /* @@ -114,7 +121,8 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeSendSe * Method: nativeTakeResponse * Signature: (JJJJLorg/ros2/rcljava/interfaces/MessageDefinition;)Lorg/ros2/rcljava/RMWRequestId; */ -JNIEXPORT jobject JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeTakeResponse( +JNIEXPORT jobject +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeTakeResponse( JNIEnv *, jclass, jlong, jlong, jlong, jlong, jobject); /* @@ -122,7 +130,8 @@ JNIEXPORT jobject JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeTak * Method: nativeWaitSetAddTimer * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddTimer( +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetAddTimer( JNIEnv *, jclass, jlong, jlong); /* @@ -130,8 +139,8 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSe * Method: nativeWaitSetSubscriptionIsReady * Signature: (JJ)Z */ -JNIEXPORT jboolean JNICALL - Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetSubscriptionIsReady( +JNIEXPORT jboolean +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetSubscriptionIsReady( JNIEnv *, jclass, jlong, jlong); /* @@ -139,7 +148,8 @@ JNIEXPORT jboolean JNICALL * Method: nativeWaitSetTimerIsReady * Signature: (JJ)Z */ -JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetTimerIsReady( +JNIEXPORT jboolean +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetTimerIsReady( JNIEnv *, jclass, jlong, jlong); /* @@ -147,7 +157,8 @@ JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWa * Method: nativeWaitSetServiceIsReady * Signature: (JJ)Z */ -JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetServiceIsReady( +JNIEXPORT jboolean +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetServiceIsReady( JNIEnv *, jclass, jlong, jlong); /* @@ -155,7 +166,8 @@ JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWa * Method: nativeWaitSetClientIsReady * Signature: (JJ)Z */ -JNIEXPORT jboolean JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClientIsReady( +JNIEXPORT jboolean +JNICALL Java_org_ros2_rcljava_executors_BaseExecutor_nativeWaitSetClientIsReady( JNIEnv *, jclass, jlong, jlong); #ifdef __cplusplus diff --git a/rcljava/include/org_ros2_rcljava_node_NodeImpl.h b/rcljava/include/org_ros2_rcljava_node_NodeImpl.h index 51675da5..181c0c30 100644 --- a/rcljava/include/org_ros2_rcljava_node_NodeImpl.h +++ b/rcljava/include/org_ros2_rcljava_node_NodeImpl.h @@ -25,7 +25,8 @@ extern "C" { * Method: nativeCreatePublisherHandle * Signature: (JLjava/lang/Class;Ljava/lang/String;J)J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreatePublisherHandle( +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreatePublisherHandle( JNIEnv *, jclass, jlong, jclass, jstring, jlong); /* @@ -33,7 +34,8 @@ JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreatePublishe * Method: nativeCreateSubscriptionHandle * Signature: (JLjava/lang/Class;Ljava/lang/String;J)J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateSubscriptionHandle( +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateSubscriptionHandle( JNIEnv *, jclass, jlong, jclass, jstring, jlong); /* @@ -41,7 +43,8 @@ JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateSubscrip * Method: nativeCreateServiceHandle * Signature: (JLjava/lang/Class;Ljava/lang/String;J)J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateServiceHandle( +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateServiceHandle( JNIEnv *, jclass, jlong, jclass, jstring, jlong); /* @@ -49,7 +52,8 @@ JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateServiceH * Method: nativeCreateClientHandle * Signature: (JLjava/lang/Class;Ljava/lang/String;J)J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateClientHandle( +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateClientHandle( JNIEnv *, jclass, jlong, jclass, jstring, jlong); /* @@ -57,15 +61,17 @@ JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateClientHa * Method: nativeDispose * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeDispose(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeDispose(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_node_NodeImpl * Method: nativeCreateTimerHandle * Signature: (JJJ)J */ -JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_node_NodeImpl_nativeCreateTimerHandle(JNIEnv *, jclass, jlong, jlong, jlong); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_node_NodeImpl_nativeCreateTimerHandle( + JNIEnv *, jclass, jlong, jlong, jlong); #ifdef __cplusplus } diff --git a/rcljava/include/org_ros2_rcljava_publisher_PublisherImpl.h b/rcljava/include/org_ros2_rcljava_publisher_PublisherImpl.h index 6a4b09e7..befe7447 100644 --- a/rcljava/include/org_ros2_rcljava_publisher_PublisherImpl.h +++ b/rcljava/include/org_ros2_rcljava_publisher_PublisherImpl.h @@ -25,7 +25,8 @@ extern "C" { * Method: nativePublish * Signature: (JJLorg/ros2/rcljava/interfaces/MessageDefinition;)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_publisher_PublisherImpl_nativePublish( +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_publisher_PublisherImpl_nativePublish( JNIEnv *, jclass, jlong, jlong, jobject); /* @@ -33,8 +34,9 @@ JNIEXPORT void JNICALL Java_org_ros2_rcljava_publisher_PublisherImpl_nativePubli * Method: nativeDispose * Signature: (JJ)V */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_publisher_PublisherImpl_nativeDispose(JNIEnv *, jclass, jlong, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_publisher_PublisherImpl_nativeDispose( + JNIEnv *, jclass, jlong, jlong); #ifdef __cplusplus } diff --git a/rcljava/include/org_ros2_rcljava_service_ServiceImpl.h b/rcljava/include/org_ros2_rcljava_service_ServiceImpl.h index 27457dcf..d83cf74c 100644 --- a/rcljava/include/org_ros2_rcljava_service_ServiceImpl.h +++ b/rcljava/include/org_ros2_rcljava_service_ServiceImpl.h @@ -25,8 +25,8 @@ extern "C" { * Method: nativeDispose * Signature: (JJ)V */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_service_ServiceImpl_nativeDispose(JNIEnv *, jclass, jlong, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_service_ServiceImpl_nativeDispose(JNIEnv *, jclass, jlong, jlong); #ifdef __cplusplus } diff --git a/rcljava/include/org_ros2_rcljava_subscription_SubscriptionImpl.h b/rcljava/include/org_ros2_rcljava_subscription_SubscriptionImpl.h index 8cb7b141..afb3456c 100644 --- a/rcljava/include/org_ros2_rcljava_subscription_SubscriptionImpl.h +++ b/rcljava/include/org_ros2_rcljava_subscription_SubscriptionImpl.h @@ -25,8 +25,9 @@ extern "C" { * Method: nativeDispose * Signature: (JJ)V */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_subscription_SubscriptionImpl_nativeDispose(JNIEnv *, jclass, jlong, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_subscription_SubscriptionImpl_nativeDispose( + JNIEnv *, jclass, jlong, jlong); #ifdef __cplusplus } diff --git a/rcljava/include/org_ros2_rcljava_time_Clock.h b/rcljava/include/org_ros2_rcljava_time_Clock.h index 8c75f165..430ca4b0 100644 --- a/rcljava/include/org_ros2_rcljava_time_Clock.h +++ b/rcljava/include/org_ros2_rcljava_time_Clock.h @@ -25,14 +25,16 @@ extern "C" { * Method: nativeCreateClock * Signature: (Lorg/ros2/rcljava/time/ClockType;)J */ -JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_time_Clock_nativeCreateClockHandle(JNIEnv *, jclass, jobject); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_time_Clock_nativeCreateClockHandle(JNIEnv *, jclass, jobject); /* * Class: org_ros2_rcljava_time_Clock * Method: nativeDispose * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_ros2_rcljava_time_Clock_nativeDispose(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_time_Clock_nativeDispose(JNIEnv *, jclass, jlong); #ifdef __cplusplus } diff --git a/rcljava/include/org_ros2_rcljava_timer_WallTimerImpl.h b/rcljava/include/org_ros2_rcljava_timer_WallTimerImpl.h index 3094dc16..88c9daeb 100644 --- a/rcljava/include/org_ros2_rcljava_timer_WallTimerImpl.h +++ b/rcljava/include/org_ros2_rcljava_timer_WallTimerImpl.h @@ -26,80 +26,81 @@ extern "C" { * Method: nativeDispose * Signature: (J)V */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeDispose(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeDispose(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeIsReady * Signature: (J)Z */ -JNIEXPORT jboolean JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeIsReady(JNIEnv *, jclass, jlong); +JNIEXPORT jboolean +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeIsReady(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeIsCanceled * Signature: (J)Z */ -JNIEXPORT jboolean JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeIsCanceled(JNIEnv *, jclass, jlong); +JNIEXPORT jboolean +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeIsCanceled(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeReset * Signature: (J)Z */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeReset(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeReset(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeCancel * Signature: (J)Z */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeCancel(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeCancel(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeTimeUntilNextCall * Signature: (J)J */ -JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeTimeUntilNextCall(JNIEnv *, jclass, jlong); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeTimeUntilNextCall(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeTimeSinceLastCall * Signature: (J)J */ -JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeTimeSinceLastCall(JNIEnv *, jclass, jlong); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeTimeSinceLastCall(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeGetTimerPeriodNS * Signature: (J)J */ -JNIEXPORT jlong JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeGetTimerPeriodNS(JNIEnv *, jclass, jlong); +JNIEXPORT jlong +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeGetTimerPeriodNS(JNIEnv *, jclass, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeSetTimerPeriodNS * Signature: (JJ)Z */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeSetTimerPeriodNS(JNIEnv *, jclass, jlong, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeSetTimerPeriodNS( + JNIEnv *, jclass, jlong, jlong); /* * Class: org_ros2_rcljava_timer_WallTimerImpl * Method: nativeCallTimer * Signature: (J)Z */ -JNIEXPORT void JNICALL - Java_org_ros2_rcljava_timer_WallTimerImpl_nativeCallTimer(JNIEnv *, jclass, jlong); +JNIEXPORT void +JNICALL Java_org_ros2_rcljava_timer_WallTimerImpl_nativeCallTimer(JNIEnv *, jclass, jlong); #ifdef __cplusplus } diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp index 5e1de3b8..00249c2b 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp @@ -62,7 +62,8 @@ Java_org_ros2_rcljava_RCLJava_nativeCreateNodeHandle( *node = rcl_get_zero_initialized_node(); rcl_node_options_t default_options = rcl_node_get_default_options(); - rcl_ret_t ret = rcl_node_init(node, node_name.c_str(), namespace_.c_str(), context, &default_options); + rcl_ret_t ret = rcl_node_init( + node, node_name.c_str(), namespace_.c_str(), context, &default_options); if (ret != RCL_RET_OK) { std::string msg = "Failed to create node: " + std::string(rcl_get_error_string().str); rcl_reset_error(); diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp index c8dd747c..1684e8c5 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp @@ -14,6 +14,8 @@ #include +#include + #include "rcl/context.h" #include "rcl/error_handling.h" #include "rcl/init.h" @@ -70,7 +72,8 @@ Java_org_ros2_rcljava_contexts_ContextImpl_nativeInit(JNIEnv * env, jclass, jlon } JNIEXPORT void JNICALL -Java_org_ros2_rcljava_contexts_ContextImpl_nativeShutdown(JNIEnv * env, jclass, jlong context_handle) +Java_org_ros2_rcljava_contexts_ContextImpl_nativeShutdown( + JNIEnv * env, jclass, jlong context_handle) { rcl_context_t * context = reinterpret_cast(context_handle); rcl_ret_t ret = rcl_shutdown(context); diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp index 1b5954d6..16db9d04 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_node_NodeImpl.cpp @@ -223,7 +223,8 @@ Java_org_ros2_rcljava_node_NodeImpl_nativeCreateTimerHandle( rcl_timer_t * timer = static_cast(malloc(sizeof(rcl_timer_t))); *timer = rcl_get_zero_initialized_timer(); - rcl_ret_t ret = rcl_timer_init(timer, clock, context, timer_period, NULL, rcl_get_default_allocator()); + rcl_ret_t ret = rcl_timer_init( + timer, clock, context, timer_period, NULL, rcl_get_default_allocator()); if (ret != RCL_RET_OK) { std::string msg = "Failed to create timer: " + std::string(rcl_get_error_string().str); diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp index 654b131d..fe54ed1b 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_time_Clock.cpp @@ -13,7 +13,9 @@ // limitations under the License. #include + #include +#include #include "rcl/error_handling.h" #include "rcl/time.h" From e1aa2bca4aa0470e638dda792751121813b4c480 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Tue, 21 Jan 2020 15:10:06 -0800 Subject: [PATCH 13/15] Enable RCLJava test and fix bugs * Use Context.ok() and deprecate RCLJava.isInitialized(). * Move implementation loading to static initialization code. Otherwise, calls to getDefaultContext() fail if called before rclJavaInit(). It wasn't clear to me why the implementation should be loaded in a separate function call. We can probably refactor the code to avoid the error if we want to move the loading back into rclJavaInit(). * Refactor test into one init/shutdown test. Previously, not calling RCLJava.shutdown() was leaving a context around between tests. Signed-off-by: Jacob Perron --- rcljava/CMakeLists.txt | 253 +++++++++--------- .../org_ros2_rcljava_contexts_ContextImpl.cpp | 4 + .../main/java/org/ros2/rcljava/RCLJava.java | 49 ++-- .../java/org/ros2/rcljava/RCLJavaTest.java | 18 +- 4 files changed, 160 insertions(+), 164 deletions(-) diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index 6495e784..d4ad03ad 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -177,133 +177,136 @@ ament_export_jars("share/${PROJECT_NAME}/java/${PROJECT_NAME}.jar") if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) - # find_package(std_msgs REQUIRED) + find_package(std_msgs REQUIRED) ament_lint_auto_find_test_dependencies() - # set(${PROJECT_NAME}_message_files - # "msg/BoundedArrayNested.msg" - # "msg/BoundedArrayPrimitives.msg" - # "msg/Builtins.msg" - # "msg/DynamicArrayNested.msg" - # "msg/DynamicArrayPrimitives.msg" - # "msg/Empty.msg" - # "msg/FieldsWithSameType.msg" - # "msg/Nested.msg" - # "msg/Primitives.msg" - # "msg/StaticArrayNested.msg" - # "msg/StaticArrayPrimitives.msg" - # "msg/UInt32.msg" - # ) - - # set(${PROJECT_NAME}_service_files - # "srv/AddTwoInts.srv" - # ) - - # rosidl_generate_interfaces(${PROJECT_NAME} - # ${${PROJECT_NAME}_message_files} - # ${${PROJECT_NAME}_service_files} - # DEPENDENCIES - # builtin_interfaces - # rcl_interfaces - # SKIP_INSTALL - # ) - - # get_property(_${PROJECT_NAME}_jar_file - # TARGET "${PROJECT_NAME}_jar" - # PROPERTY "JAR_FILE") - - # get_property(_${PROJECT_NAME}_messages_jar_file - # TARGET "${PROJECT_NAME}_messages_jar" - # PROPERTY "JAR_FILE") - - # set(${PROJECT_NAME}_test_sources - # "src/test/java/org/ros2/rcljava/RCLJavaTest.java" - # "src/test/java/org/ros2/rcljava/TimeTest.java" - # "src/test/java/org/ros2/rcljava/client/ClientTest.java" - # "src/test/java/org/ros2/rcljava/node/NodeTest.java" - # "src/test/java/org/ros2/rcljava/parameters/AsyncParametersClientTest.java" - # "src/test/java/org/ros2/rcljava/parameters/SyncParametersClientTest.java" - # "src/test/java/org/ros2/rcljava/publisher/PublisherTest.java" - # "src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java" - # "src/test/java/org/ros2/rcljava/timer/TimerTest.java" - # ) - - # set(${PROJECT_NAME}_testsuites - # "org.ros2.rcljava.RCLJavaTest" - # "org.ros2.rcljava.TimeTest" - # "org.ros2.rcljava.client.ClientTest" - # "org.ros2.rcljava.node.NodeTest" - # "org.ros2.rcljava.parameters.SyncParametersClientTest" - # "org.ros2.rcljava.publisher.PublisherTest" - # "org.ros2.rcljava.subscription.SubscriptionTest" - # "org.ros2.rcljava.timer.TimerTest" - # ) - - # set(_deps_library_dirs "") - # foreach(_dep_lib ${rcljava_test_msgs_LIBRARIES}) - # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - # list_append_unique(_deps_library_dirs ${_dep_dir}) - # endforeach() - # foreach(_dep_lib ${rcljava_test_msgs_JNI_LIBRARIES}) - # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - # list_append_unique(_deps_library_dirs ${_dep_dir}) - # endforeach() - - # foreach(_dep_lib ${std_msgs_LIBRARIES}) - # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - # list_append_unique(_deps_library_dirs ${_dep_dir}) - # endforeach() - # foreach(_dep_lib ${std_msgs_JNI_LIBRARIES}) - # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - # list_append_unique(_deps_library_dirs ${_dep_dir}) - # endforeach() - - # foreach(_dep_lib ${builtin_interfaces_LIBRARIES}) - # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - # list_append_unique(_deps_library_dirs ${_dep_dir}) - # endforeach() - # foreach(_dep_lib ${builtin_interfaces_JNI_LIBRARIES}) - # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - # list_append_unique(_deps_library_dirs ${_dep_dir}) - # endforeach() - - # foreach(_dep_lib ${rcl_interfaces_LIBRARIES}) - # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - # list_append_unique(_deps_library_dirs ${_dep_dir}) - # endforeach() - # foreach(_dep_lib ${rcl_interfaces_JNI_LIBRARIES}) - # get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) - # list_append_unique(_deps_library_dirs ${_dep_dir}) - # endforeach() - - # list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}) - # list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rcljava) - # list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_java/rcljava/msg/) - # list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_java/rcljava/srv/) - - # foreach(testsuite ${${PROJECT_NAME}_testsuites}) - # ament_add_junit_tests("${PROJECT_NAME}_tests_${testsuite}" - # TIMEOUT 90 - # WORKING_DIRECTORY - # "${CMAKE_CURRENT_BINARY_DIR}" - # SOURCES - # "${${PROJECT_NAME}_test_sources}" - # TESTS - # "${testsuite}" - # INCLUDE_JARS - # "${rcljava_common_JARS}" - # "${rcljava_test_msgs_JARS}" - # "${std_msgs_JARS}" - # "${builtin_interfaces_JARS}" - # "${rcl_interfaces_JARS}" - # "${_${PROJECT_NAME}_jar_file}" - # "${_${PROJECT_NAME}_messages_jar_file}" - # APPEND_LIBRARY_DIRS - # "${_deps_library_dirs}" - # ) - - # add_dependencies("${PROJECT_NAME}_tests_${testsuite}" "${PROJECT_NAME}_messages_jar") - # endforeach() + set(${PROJECT_NAME}_message_files + "msg/BoundedArrayNested.msg" + "msg/BoundedArrayPrimitives.msg" + "msg/Builtins.msg" + "msg/DynamicArrayNested.msg" + "msg/DynamicArrayPrimitives.msg" + "msg/Empty.msg" + "msg/FieldsWithSameType.msg" + "msg/Nested.msg" + "msg/Primitives.msg" + "msg/StaticArrayNested.msg" + "msg/StaticArrayPrimitives.msg" + "msg/UInt32.msg" + ) + + set(${PROJECT_NAME}_service_files + "srv/AddTwoInts.srv" + ) + + rosidl_generator_java_get_typesupports(_java_type_supports) + + rosidl_generate_interfaces(${PROJECT_NAME} + ${${PROJECT_NAME}_message_files} + ${${PROJECT_NAME}_service_files} + DEPENDENCIES + builtin_interfaces + rcl_interfaces + ${_java_type_supports} + SKIP_INSTALL + ) + + get_property(_${PROJECT_NAME}_jar_file + TARGET "${PROJECT_NAME}_jar" + PROPERTY "JAR_FILE") + + get_property(_${PROJECT_NAME}_messages_jar_file + TARGET "${PROJECT_NAME}_messages_jar" + PROPERTY "JAR_FILE") + + set(${PROJECT_NAME}_test_sources + "src/test/java/org/ros2/rcljava/RCLJavaTest.java" + # "src/test/java/org/ros2/rcljava/TimeTest.java" + # "src/test/java/org/ros2/rcljava/client/ClientTest.java" + # "src/test/java/org/ros2/rcljava/node/NodeTest.java" + # "src/test/java/org/ros2/rcljava/parameters/AsyncParametersClientTest.java" + # "src/test/java/org/ros2/rcljava/parameters/SyncParametersClientTest.java" + # "src/test/java/org/ros2/rcljava/publisher/PublisherTest.java" + # "src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java" + # "src/test/java/org/ros2/rcljava/timer/TimerTest.java" + ) + + set(${PROJECT_NAME}_testsuites + "org.ros2.rcljava.RCLJavaTest" + # "org.ros2.rcljava.TimeTest" + # "org.ros2.rcljava.client.ClientTest" + # "org.ros2.rcljava.node.NodeTest" + # "org.ros2.rcljava.parameters.SyncParametersClientTest" + # "org.ros2.rcljava.publisher.PublisherTest" + # "org.ros2.rcljava.subscription.SubscriptionTest" + # "org.ros2.rcljava.timer.TimerTest" + ) + + set(_deps_library_dirs "") + foreach(_dep_lib ${rcljava_test_msgs_LIBRARIES}) + get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + list_append_unique(_deps_library_dirs ${_dep_dir}) + endforeach() + foreach(_dep_lib ${rcljava_test_msgs_JNI_LIBRARIES}) + get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + list_append_unique(_deps_library_dirs ${_dep_dir}) + endforeach() + + foreach(_dep_lib ${std_msgs_LIBRARIES}) + get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + list_append_unique(_deps_library_dirs ${_dep_dir}) + endforeach() + foreach(_dep_lib ${std_msgs_JNI_LIBRARIES}) + get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + list_append_unique(_deps_library_dirs ${_dep_dir}) + endforeach() + + foreach(_dep_lib ${builtin_interfaces_LIBRARIES}) + get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + list_append_unique(_deps_library_dirs ${_dep_dir}) + endforeach() + foreach(_dep_lib ${builtin_interfaces_JNI_LIBRARIES}) + get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + list_append_unique(_deps_library_dirs ${_dep_dir}) + endforeach() + + foreach(_dep_lib ${rcl_interfaces_LIBRARIES}) + get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + list_append_unique(_deps_library_dirs ${_dep_dir}) + endforeach() + foreach(_dep_lib ${rcl_interfaces_JNI_LIBRARIES}) + get_filename_component(_dep_dir "${_dep_lib}" DIRECTORY) + list_append_unique(_deps_library_dirs ${_dep_dir}) + endforeach() + + list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}) + list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rcljava) + list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_java/rcljava/msg/) + list_append_unique(_deps_library_dirs ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_java/rcljava/srv/) + + foreach(testsuite ${${PROJECT_NAME}_testsuites}) + ament_add_junit_tests("${PROJECT_NAME}_tests_${testsuite}" + TIMEOUT 90 + WORKING_DIRECTORY + "${CMAKE_CURRENT_BINARY_DIR}" + SOURCES + "${${PROJECT_NAME}_test_sources}" + TESTS + "${testsuite}" + INCLUDE_JARS + "${rcljava_common_JARS}" + "${rcljava_test_msgs_JARS}" + "${std_msgs_JARS}" + "${builtin_interfaces_JARS}" + "${rcl_interfaces_JARS}" + "${_${PROJECT_NAME}_jar_file}" + "${_${PROJECT_NAME}_messages_jar_file}" + APPEND_LIBRARY_DIRS + "${_deps_library_dirs}" + ) + + add_dependencies("${PROJECT_NAME}_tests_${testsuite}" "${PROJECT_NAME}_messages_jar") + endforeach() endif() diff --git a/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp b/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp index 1684e8c5..4b2f8695 100644 --- a/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp +++ b/rcljava/src/main/cpp/org_ros2_rcljava_contexts_ContextImpl.cpp @@ -76,6 +76,10 @@ Java_org_ros2_rcljava_contexts_ContextImpl_nativeShutdown( JNIEnv * env, jclass, jlong context_handle) { rcl_context_t * context = reinterpret_cast(context_handle); + // Only attempt shutdown if the context is valid + if (!rcl_context_is_valid(context)) { + return; + } rcl_ret_t ret = rcl_shutdown(context); if (RCL_RET_OK != ret) { std::string msg = "Failed to shutdown context: " + std::string(rcl_get_error_string().str); diff --git a/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java b/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java index 9bdabc2d..ef58b7ae 100644 --- a/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java +++ b/rcljava/src/main/java/org/ros2/rcljava/RCLJava.java @@ -108,7 +108,15 @@ private static void cleanup() { } static { + try { + JNIUtils.loadImplementation(RCLJava.class); + } catch (UnsatisfiedLinkError ule) { + logger.error("Native code library failed to load.\n" + ule); + System.exit(1); + } + nodes = new LinkedBlockingQueue(); + contexts = new LinkedBlockingQueue(); // NOTE(esteve): disabling shutdown hook for now to avoid JVM crashes // Runtime.getRuntime().addShutdownHook(new Thread() { @@ -118,18 +126,12 @@ private static void cleanup() { // }); } - /** - * Flag to indicate if RCLJava has been fully initialized, with a valid RMW - * implementation. - */ - private static boolean initialized = false; - /** * Get the default context. */ - public static Context getDefaultContext() { + public static synchronized Context getDefaultContext() { if (RCLJava.defaultContext == null) { - long contextHandle = RCLJava.nativeCreateContextHandle(); + long contextHandle = nativeCreateContextHandle(); RCLJava.defaultContext = new ContextImpl(contextHandle); } return RCLJava.defaultContext; @@ -138,32 +140,26 @@ public static Context getDefaultContext() { /** * @return true if RCLJava has been fully initialized, false otherwise. */ + @Deprecated public static boolean isInitialized() { - return RCLJava.initialized; + return RCLJava.ok(); } /** * Initialize the RCLJava API. If successful, a valid RMW implementation will * be loaded and accessible, enabling the creating of ROS2 entities * (@{link Node}s, @{link Publisher}s and @{link Subscription}s. + * This also initializes the default context. */ - public static void rclJavaInit() { - synchronized (RCLJava.class) { - if (!RCLJava.initialized) { - try { - JNIUtils.loadImplementation(RCLJava.class); - } catch (UnsatisfiedLinkError ule) { - logger.error("Native code library failed to load.\n" + ule); - System.exit(1); - } - - // Initialize default context - getDefaultContext().init(); - - logger.info("Using RMW implementation: {}", RCLJava.getRMWIdentifier()); - initialized = true; - } + public static synchronized void rclJavaInit() { + if (RCLJava.ok()) { + return; } + + // Initialize default context + getDefaultContext().init(); + + logger.info("Using RMW implementation: {}", RCLJava.getRMWIdentifier()); } /** @@ -307,10 +303,9 @@ public static void spinSome(final ComposableNode composableNode) { getGlobalExecutor().removeNode(composableNode); } - public static void shutdown() { + public static synchronized void shutdown() { cleanup(); if (RCLJava.defaultContext != null) { - RCLJava.defaultContext.shutdown(); RCLJava.defaultContext.dispose(); RCLJava.defaultContext = null; } diff --git a/rcljava/src/test/java/org/ros2/rcljava/RCLJavaTest.java b/rcljava/src/test/java/org/ros2/rcljava/RCLJavaTest.java index 349e95ee..dba322cf 100644 --- a/rcljava/src/test/java/org/ros2/rcljava/RCLJavaTest.java +++ b/rcljava/src/test/java/org/ros2/rcljava/RCLJavaTest.java @@ -15,24 +15,18 @@ package org.ros2.rcljava; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import org.junit.Test; public class RCLJavaTest { @Test - public final void testInit() { - assertEquals(false, RCLJava.isInitialized()); + public final void testInitShutdown() { + assertFalse(RCLJava.ok()); RCLJava.rclJavaInit(); - assertEquals(true, RCLJava.isInitialized()); - } - - @Test - public final void testOk() { - RCLJava.rclJavaInit(); - assertEquals(true, RCLJava.ok()); + assertTrue(RCLJava.ok()); RCLJava.shutdown(); - assertEquals(false, RCLJava.ok()); + assertFalse(RCLJava.ok()); } } From 7c2f5f8ebdcf014384ed3702606ba0ab5c5cf00d Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 6 Feb 2020 16:48:08 -0800 Subject: [PATCH 14/15] Fix NodeTest Signed-off-by: Jacob Perron --- rcljava/CMakeLists.txt | 8 ++++---- .../test/java/org/ros2/rcljava/node/NodeTest.java | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index d4ad03ad..7fd15118 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -221,9 +221,9 @@ if(BUILD_TESTING) set(${PROJECT_NAME}_test_sources "src/test/java/org/ros2/rcljava/RCLJavaTest.java" - # "src/test/java/org/ros2/rcljava/TimeTest.java" + "src/test/java/org/ros2/rcljava/TimeTest.java" # "src/test/java/org/ros2/rcljava/client/ClientTest.java" - # "src/test/java/org/ros2/rcljava/node/NodeTest.java" + "src/test/java/org/ros2/rcljava/node/NodeTest.java" # "src/test/java/org/ros2/rcljava/parameters/AsyncParametersClientTest.java" # "src/test/java/org/ros2/rcljava/parameters/SyncParametersClientTest.java" # "src/test/java/org/ros2/rcljava/publisher/PublisherTest.java" @@ -233,9 +233,9 @@ if(BUILD_TESTING) set(${PROJECT_NAME}_testsuites "org.ros2.rcljava.RCLJavaTest" - # "org.ros2.rcljava.TimeTest" + "org.ros2.rcljava.TimeTest" # "org.ros2.rcljava.client.ClientTest" - # "org.ros2.rcljava.node.NodeTest" + "org.ros2.rcljava.node.NodeTest" # "org.ros2.rcljava.parameters.SyncParametersClientTest" # "org.ros2.rcljava.publisher.PublisherTest" # "org.ros2.rcljava.subscription.SubscriptionTest" diff --git a/rcljava/src/test/java/org/ros2/rcljava/node/NodeTest.java b/rcljava/src/test/java/org/ros2/rcljava/node/NodeTest.java index 7c6a2010..8dd5aa30 100644 --- a/rcljava/src/test/java/org/ros2/rcljava/node/NodeTest.java +++ b/rcljava/src/test/java/org/ros2/rcljava/node/NodeTest.java @@ -47,7 +47,7 @@ public class NodeTest { private boolean boolValue1, boolValue2; private byte byteValue1, byteValue2; - private char charValue1, charValue2; + private byte charValue1, charValue2; private float float32Value1, float32Value2; private double float64Value1, float64Value2; private byte int8Value1, int8Value2; @@ -61,7 +61,7 @@ public class NodeTest { private String stringValue1, stringValue2; boolean checkPrimitives(rcljava.msg.Primitives primitives, boolean booleanValue, byte byteValue, - char charValue, float float32Value, double float64Value, byte int8Value, byte uint8Value, + byte charValue, float float32Value, double float64Value, byte int8Value, byte uint8Value, short int16Value, short uint16Value, int int32Value, int uint32Value, long int64Value, long uint64Value, String stringValue) { boolean result = true; @@ -112,7 +112,7 @@ public void setUp() { boolValue1 = true; byteValue1 = (byte) 123; - charValue1 = '\u0012'; + charValue1 = (byte) '\u0012'; float32Value1 = 12.34f; float64Value1 = 43.21; int8Value1 = (byte) -12; @@ -142,7 +142,7 @@ public void setUp() { boolValue2 = false; byteValue2 = (byte) 42; - charValue2 = '\u0021'; + charValue2 = (byte) '\u0021'; float32Value2 = 13.34f; float64Value2 = 44.21; int8Value2 = (byte) -13; @@ -275,7 +275,7 @@ public final void testPubSubBoundedArrayPrimitives() throws Exception { List boolValues = Arrays.asList(new Boolean[] {true, false, true}); List byteValues = Arrays.asList(new Byte[] {123, 42}); - List charValues = Arrays.asList(new Character[] {'\u0012', '\u0021'}); + List charValues = Arrays.asList(new Byte[] {'\u0012', '\u0021'}); List float32Values = Arrays.asList(new Float[] {12.34f, 13.34f}); List float64Values = Arrays.asList(new Double[] {43.21, 44.21}); List int8Values = Arrays.asList(new Byte[] {-12, -13}); @@ -437,7 +437,7 @@ public final void testPubSubDynamicArrayPrimitives() throws Exception { List boolValues = Arrays.asList(new Boolean[] {true, false, true}); List byteValues = Arrays.asList(new Byte[] {123, 42}); - List charValues = Arrays.asList(new Character[] {'\u0012', '\u0021'}); + List charValues = Arrays.asList(new Byte[] {'\u0012', '\u0021'}); List float32Values = Arrays.asList(new Float[] {12.34f, 13.34f}); List float64Values = Arrays.asList(new Double[] {43.21, 44.21}); List int8Values = Arrays.asList(new Byte[] {-12, -13}); @@ -703,7 +703,7 @@ public final void testPubSubStaticArrayPrimitives() throws Exception { List boolValues = Arrays.asList(new Boolean[] {true, false, true}); List byteValues = Arrays.asList(new Byte[] {123, 42, 24}); - List charValues = Arrays.asList(new Character[] {'\u0012', '\u0021', '\u0008'}); + List charValues = Arrays.asList(new Byte[] {'\u0012', '\u0021', '\u0008'}); List float32Values = Arrays.asList(new Float[] {12.34f, 13.34f, 14.34f}); List float64Values = Arrays.asList(new Double[] {43.21, 54.21, 65.21}); List int8Values = Arrays.asList(new Byte[] {-12, -13, -14}); From e46dc1ca98f89d96329868ab014de85954558802 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 6 Feb 2020 18:10:17 -0800 Subject: [PATCH 15/15] Enable most tests Tests that involve services are broken due to issues related to interface generation. There's a separate PR for a fix: https://github.com/ros2-java/ros2_java/pull/76. Signed-off-by: Jacob Perron --- rcljava/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rcljava/CMakeLists.txt b/rcljava/CMakeLists.txt index 7fd15118..a6b4211f 100644 --- a/rcljava/CMakeLists.txt +++ b/rcljava/CMakeLists.txt @@ -226,9 +226,9 @@ if(BUILD_TESTING) "src/test/java/org/ros2/rcljava/node/NodeTest.java" # "src/test/java/org/ros2/rcljava/parameters/AsyncParametersClientTest.java" # "src/test/java/org/ros2/rcljava/parameters/SyncParametersClientTest.java" - # "src/test/java/org/ros2/rcljava/publisher/PublisherTest.java" - # "src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java" - # "src/test/java/org/ros2/rcljava/timer/TimerTest.java" + "src/test/java/org/ros2/rcljava/publisher/PublisherTest.java" + "src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java" + "src/test/java/org/ros2/rcljava/timer/TimerTest.java" ) set(${PROJECT_NAME}_testsuites @@ -237,9 +237,9 @@ if(BUILD_TESTING) # "org.ros2.rcljava.client.ClientTest" "org.ros2.rcljava.node.NodeTest" # "org.ros2.rcljava.parameters.SyncParametersClientTest" - # "org.ros2.rcljava.publisher.PublisherTest" - # "org.ros2.rcljava.subscription.SubscriptionTest" - # "org.ros2.rcljava.timer.TimerTest" + "org.ros2.rcljava.publisher.PublisherTest" + "org.ros2.rcljava.subscription.SubscriptionTest" + "org.ros2.rcljava.timer.TimerTest" ) set(_deps_library_dirs "")