Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Deadline, Liveliness, and Lifespan QoS Event (rcl_event_t type) and their rcl_take_* Function #396

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ find_package(rosidl_generator_c REQUIRED)
find_package(tinydir_vendor REQUIRED)

include_directories(include)

include(cmake/rcl_set_symbol_visibility_hidden.cmake)
include(cmake/get_default_rcl_logging_implementation.cmake)
get_default_rcl_logging_implementation(RCL_LOGGING_IMPL)

Expand All @@ -35,6 +35,7 @@ set(${PROJECT_NAME}_sources
src/rcl/client.c
src/rcl/common.c
src/rcl/context.c
src/rcl/event.c
src/rcl/expand_topic_name.c
src/rcl/graph.c
src/rcl/guard_condition.c
Expand Down Expand Up @@ -73,6 +74,7 @@ ament_target_dependencies(${PROJECT_NAME}
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "RCL_BUILDING_DLL")
rcl_set_symbol_visibility_hidden(${PROJECT_NAME} LANGUAGE "C")

install(
TARGETS ${PROJECT_NAME}
Expand Down Expand Up @@ -105,8 +107,12 @@ if(BUILD_TESTING)
add_subdirectory(test)
endif()

ament_package()
ament_package(CONFIG_EXTRAS "rcl-extras.cmake")

install(
DIRECTORY cmake
DESTINATION share/${PROJECT_NAME}
)
install(
DIRECTORY include/
DESTINATION include
Expand Down
67 changes: 67 additions & 0 deletions rcl/cmake/rcl_set_symbol_visibility_hidden.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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.

#
# Configures ros client library with custom settings.
# The custom settings are all related to library symbol visibility, see:
# https://gcc.gnu.org/wiki/Visibility
# http://www.ibm.com/developerworks/aix/library/au-aix-symbol-visibility/
#
# Below code is heavily referenced from a similar functionality in rmw:
# https://github.com/ros2/rmw/blob/master/rmw/cmake/configure_rmw_library.cmake
#
# :param library_target: the library target
# :type library_target: string
# :param LANGUAGE: Optional flag for the language of the library.
# Allowed values are "C" and "CXX". The default is "CXX".
# :type LANGUAGE: string
#
# @public
#
function(rcl_set_symbol_visibility_hidden library_target)
cmake_parse_arguments(ARG "" "LANGUAGE" "" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "rcl_set_symbol_visibility_hidden() called with unused arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()

if(NOT ARG_LANGUAGE)
set(ARG_LANGUAGE "CXX")
endif()

if(ARG_LANGUAGE STREQUAL "C")
# Set the visibility to hidden by default if possible
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
# Set the visibility of symbols to hidden by default for gcc and clang
# (this is already the default on Windows)
set_target_properties(${library_target}
PROPERTIES
COMPILE_FLAGS "-fvisibility=hidden"
)
endif()

elseif(ARG_LANGUAGE STREQUAL "CXX")
# Set the visibility to hidden by default if possible
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Set the visibility of symbols to hidden by default for gcc and clang
# (this is already the default on Windows)
set_target_properties(${library_target}
PROPERTIES
COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden"
)
endif()

else()
message(FATAL_ERROR "rcl_set_symbol_visibility_hidden() called with unsupported LANGUAGE: '${ARG_LANGUAGE}'")
endif()
endfunction()
149 changes: 149 additions & 0 deletions rcl/include/rcl/event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Copyright 2015 Open Source Robotics Foundation, Inc.
mm318 marked this conversation as resolved.
Show resolved Hide resolved
//
// 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.

#ifndef RCL__EVENT_H_
#define RCL__EVENT_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "rcl/client.h"
#include "rcl/macros.h"
#include "rcl/publisher.h"
#include "rcl/service.h"
#include "rcl/subscription.h"
#include "rcl/visibility_control.h"


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's lots of redundant whitespace in this file, please just use one blank line in all these places.

typedef enum rcl_publisher_event_type_t
{
RCL_PUBLISHER_DEADLINE,
RCL_PUBLISHER_LIVELINESS
} rcl_publisher_event_type_t;


typedef enum rcl_subscription_event_type_t
{
RCL_SUBSCRIPTION_DEADLINE,
RCL_SUBSCRIPTION_LIVELINESS
} rcl_subscription_event_type_t;
mm318 marked this conversation as resolved.
Show resolved Hide resolved


/// Internal rcl implementation struct.
struct rcl_event_impl_t;

/// Structure which encapsulates a ROS Subscription.
typedef struct rcl_event_t
{
struct rcl_event_impl_t * impl;
} rcl_event_t;


/// Return a rcl_event_t struct with members set to `NULL`.
/**
* Should be called to get a null rcl_event_t before passing to
* rcl_event_init().
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_event_t
rcl_get_zero_initialized_event(void);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_publisher_event_init(
rcl_event_t * event,
const rcl_publisher_t * publisher,
const rcl_publisher_event_type_t event_type);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_event_init(
rcl_event_t * event,
const rcl_subscription_t * subscription,
const rcl_subscription_event_type_t event_type);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_client_event_init(
rcl_event_t * event,
const rcl_client_t * client);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_service_event_init(
rcl_event_t * event,
const rcl_service_t * service);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_take_event(
const rcl_event_t * event,
void * event_info);


RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_event_fini(rcl_event_t * event);


/// Return the rmw event handle.
/**
* The handle returned is a pointer to the internally held rmw handle.
* This function can fail, and therefore return `NULL`, if the:
* - event is `NULL`
* - event is invalid (never called init, called fini, or invalid node)
*
* The returned handle is made invalid if the event is finalized or if
* rcl_shutdown() is called.
* The returned handle is not guaranteed to be valid for the life time of the
* event as it may be finalized and recreated itself.
* Therefore it is recommended to get the handle from the event using
* this function each time it is needed and avoid use of the handle
* concurrently with functions that might change it.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] event pointer to the rcl event
* \return rmw event handle if successful, otherwise `NULL`
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rmw_event_t *
rcl_event_get_rmw_handle(const rcl_event_t * event);

#ifdef __cplusplus
}
#endif

#endif // RCL__EVENT_H_
7 changes: 7 additions & 0 deletions rcl/include/rcl/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ typedef rmw_ret_t rcl_ret_t;
/// Argument is not a valid log level rule
#define RCL_RET_INVALID_LOG_LEVEL_RULE 1020

// rcl event specific ret codes in 20XX
/// Invalid rcl_event_t given return code.
#define RCL_RET_EVENT_INVALID 2000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not 1030?

/// Failed to take an event from the event handle
#define RCL_RET_EVENT_TAKE_FAILED 2001


/// typedef for rmw_serialized_message_t;
typedef rmw_serialized_message_t rcl_serialized_message_t;

Expand Down
21 changes: 20 additions & 1 deletion rcl/include/rcl/wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern "C"
#include "rcl/service.h"
#include "rcl/subscription.h"
#include "rcl/timer.h"
#include "rcl/event.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"

Expand All @@ -52,6 +53,9 @@ typedef struct rcl_wait_set_t
/// Storage for service pointers.
const rcl_service_t ** services;
size_t size_of_services;
/// Storage for event pointers.
const rcl_event_t ** events;
size_t size_of_events;
/// Implementation specific storage.
struct rcl_wait_set_impl_t * impl;
} rcl_wait_set_t;
Expand Down Expand Up @@ -124,6 +128,7 @@ rcl_wait_set_init(
size_t number_of_timers,
size_t number_of_clients,
size_t number_of_services,
size_t number_of_events,
rcl_context_t * context,
rcl_allocator_t allocator);

Expand Down Expand Up @@ -289,7 +294,8 @@ rcl_wait_set_resize(
size_t guard_conditions_size,
size_t timers_size,
size_t clients_size,
size_t services_size);
size_t services_size,
size_t events_size);

/// Store a pointer to the guard condition in the next empty spot in the set.
/**
Expand Down Expand Up @@ -343,6 +349,19 @@ rcl_wait_set_add_service(
const rcl_service_t * service,
size_t * index);

/// Store a pointer to the event in the next empty spot in the set.
/**
* This function behaves exactly the same as for subscriptions.
* \see rcl_wait_set_add_subscription
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_wait_set_add_event(
rcl_wait_set_t * wait_set,
const rcl_event_t * event,
size_t * index);

/// Block until the wait set is ready or until the timeout has been exceeded.
/**
* This function will collect the items in the rcl_wait_set_t and pass them
Expand Down
1 change: 1 addition & 0 deletions rcl/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<test_depend>rmw</test_depend>
<test_depend>rmw_implementation_cmake</test_depend>
<test_depend>launch</test_depend>
<test_depend>launch_testing</test_depend>
<test_depend>osrf_testing_tools_cpp</test_depend>
<test_depend>test_msgs</test_depend>

Expand Down
15 changes: 15 additions & 0 deletions rcl/rcl-extras.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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("${rcl_DIR}/rcl_set_symbol_visibility_hidden.cmake")
10 changes: 2 additions & 8 deletions rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,12 @@ extern "C"
#include "rcl/expand_topic_name.h"
#include "rcl/remap.h"
#include "rcutils/logging_macros.h"
#include "rcutils/stdatomic_helper.h"
#include "rmw/error_handling.h"
#include "rmw/rmw.h"
#include "rmw/validate_full_topic_name.h"

#include "./common.h"
#include "./types_impl.h"

typedef struct rcl_client_impl_t
{
rcl_client_options_t options;
rmw_client_t * rmw_handle;
atomic_int_least64_t sequence_number;
} rcl_client_impl_t;

rcl_client_t
rcl_get_zero_initialized_client()
Expand Down Expand Up @@ -175,6 +168,7 @@ rcl_client_init(
}
// options
client->impl->options = *options;
atomic_init(&client->impl->sequence_number, 0);
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Client initialized");
ret = RCL_RET_OK;
goto cleanup;
Expand Down
Loading