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

Mauro/add events executor #24

Open
wants to merge 2 commits into
base: irobot/add-events-executor
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions rcl/include/rcl/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C"

#include "rosidl_runtime_c/service_type_support_struct.h"

#include "rcl/event_callback.h"
#include "rcl/macros.h"
#include "rcl/node.h"
#include "rcl/visibility_control.h"
Expand Down Expand Up @@ -461,6 +462,37 @@ RCL_WARN_UNUSED
const rmw_qos_profile_t *
rcl_client_response_subscription_get_actual_qos(const rcl_client_t * client);

/// Set the on new response callback function for the client.
/**
* This API sets the callback function to be called whenever the
* client is notified about a new response.
*
* \sa rmw_client_set_on_new_response_callback for details about this function.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | Maybe [1]
* Lock-Free | Maybe [1]
* <i>[1] rmw implementation defined</i>
*
* \param[in] client The client on which to set the callback
* \param[in] callback The callback to be called when new responses arrive, may be NULL
* \param[in] user_data Given to the callback when called later, may be NULL
* \return `RCL_RET_OK` if callback was set to the listener, or
* \return `RCL_RET_INVALID_ARGUMENT` if `client` is NULL, or
* \return `RCL_RET_UNSUPPORTED` if the API is not implemented in the dds implementation
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_client_set_on_new_response_callback(
const rcl_client_t * client,
rcl_event_callback_t callback,
const void * user_data);

#ifdef __cplusplus
}
#endif
Expand Down
32 changes: 32 additions & 0 deletions rcl/include/rcl/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C"
#include <rmw/event.h>

#include "rcl/client.h"
#include "rcl/event_callback.h"
#include "rcl/macros.h"
#include "rcl/publisher.h"
#include "rcl/service.h"
Expand Down Expand Up @@ -198,6 +199,37 @@ RCL_PUBLIC
bool
rcl_event_is_valid(const rcl_event_t * event);

/// Set the callback function for the event.
/**
* This API sets the callback function to be called whenever the
* event is notified about a new instance of the event.
*
* \sa rmw_event_set_callback for more details about this function.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | Maybe [1]
* Lock-Free | Maybe [1]
* <i>[1] rmw implementation defined</i>
*
* \param[in] event The event on which to set the callback
* \param[in] callback The callback to be called when new events occur, may be NULL
* \param[in] user_data Given to the callback when called later, may be NULL
* \return `RCL_RET_OK` if callback was set to the listener, or
* \return `RCL_RET_INVALID_ARGUMENT` if `event` is NULL, or
* \return `RCL_RET_UNSUPPORTED` if the API is not implemented in the dds implementation
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_event_set_callback(
const rcl_event_t * event,
rcl_event_callback_t callback,
const void * user_data);

#ifdef __cplusplus
}
#endif
Expand Down
31 changes: 31 additions & 0 deletions rcl/include/rcl/event_callback.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2021 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.

#ifndef RCL__EVENT_CALLBACK_H_
#define RCL__EVENT_CALLBACK_H_

#include "rmw/event_callback_type.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef rmw_event_callback_t rcl_event_callback_t;

#ifdef __cplusplus
}
#endif

#endif // RCL__EVENT_CALLBACK_H_
32 changes: 32 additions & 0 deletions rcl/include/rcl/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C"

#include "rosidl_runtime_c/service_type_support_struct.h"

#include "rcl/event_callback.h"
#include "rcl/macros.h"
#include "rcl/node.h"
#include "rcl/visibility_control.h"
Expand Down Expand Up @@ -492,6 +493,37 @@ RCL_WARN_UNUSED
const rmw_qos_profile_t *
rcl_service_response_publisher_get_actual_qos(const rcl_service_t * service);

/// Set the on new request callback function for the service.
/**
* This API sets the callback function to be called whenever the
* service is notified about a new request.
*
* \sa rmw_service_set_on_new_request_callback for details about this function.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | Maybe [1]
* Lock-Free | Maybe [1]
* <i>[1] rmw implementation defined</i>
*
* \param[in] service The service on which to set the callback
* \param[in] callback The callback to be called when new requests arrive, may be NULL
* \param[in] user_data Given to the callback when called later, may be NULL
* \return `RCL_RET_OK` if callback was set to the listener, or
* \return `RCL_RET_INVALID_ARGUMENT` if `service` is NULL, or
* \return `RCL_RET_UNSUPPORTED` if the API is not implemented in the dds implementation
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_service_set_on_new_request_callback(
const rcl_service_t * service,
rcl_event_callback_t callback,
const void * user_data);

#ifdef __cplusplus
}
#endif
Expand Down
33 changes: 33 additions & 0 deletions rcl/include/rcl/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C"

#include "rosidl_runtime_c/message_type_support_struct.h"

#include "rcl/event_callback.h"
#include "rcl/macros.h"
#include "rcl/node.h"
#include "rcl/visibility_control.h"
Expand Down Expand Up @@ -611,6 +612,38 @@ RCL_PUBLIC
bool
rcl_subscription_can_loan_messages(const rcl_subscription_t * subscription);

/// Set the on new message callback function for the subscription.
/**
* This API sets the callback function to be called whenever the
* subscription is notified about a new message.
*
* \sa rmw_subscription_set_on_new_message_callback for details about this
* function.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | Maybe [1]
* Lock-Free | Maybe [1]
* <i>[1] rmw implementation defined</i>
*
* \param[in] subscription The subscription on which to set the callback
* \param[in] callback The callback to be called when new messages arrive, may be NULL
* \param[in] user_data Given to the callback when called later, may be NULL
* \return `RCL_RET_OK` if successful, or
* \return `RCL_RET_INVALID_ARGUMENT` if `subscription` is NULL, or
* \return `RCL_RET_UNSUPPORTED` if the API is not implemented in the dds implementation
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_set_on_new_message_callback(
const rcl_subscription_t * subscription,
rcl_event_callback_t callback,
const void * user_data);

#ifdef __cplusplus
}
#endif
Expand Down
27 changes: 27 additions & 0 deletions rcl/include/rcl/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,33 @@ RCL_WARN_UNUSED
rcl_ret_t
rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_until_next_call);

/// Retrieve the time point value for the next timer call.
/**
* This function will populate the data of the time_point_value object with the
* value corresponding to when the next timer call should happen.
*
* The `time_point_value` argument must point to an allocated rcl_time_point_value_t, as
* the time point is copied into that instance.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | Yes
* Uses Atomics | Yes
* Lock-Free | Yes [1]
* <i>[1] if `atomic_is_lock_free()` returns true for `atomic_int_least64_t`</i>
*
* \param[in] timer the handle to the timer that is being queried
* \param[out] time_point_value the output variable for the result
* \return #RCL_RET_OK if the timer until next call was successfully calculated, or
* \return #RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_timer_get_next_call_time(const rcl_timer_t * timer, rcl_time_point_value_t * time_point_value);

/// Retrieve the time since the previous call to rcl_timer_call() occurred.
/**
* This function calculates the time since the last call and copies it into
Expand Down
18 changes: 18 additions & 0 deletions rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,24 @@ rcl_client_response_subscription_get_actual_qos(const rcl_client_t * client)
}
return &client->impl->actual_response_subscription_qos;
}

rcl_ret_t
rcl_client_set_on_new_response_callback(
const rcl_client_t * client,
rcl_event_callback_t callback,
const void * user_data)
{
if (!rcl_client_is_valid(client)) {
// error state already set
return RCL_RET_INVALID_ARGUMENT;
}

return rmw_client_set_on_new_response_callback(
client->impl->rmw_handle,
callback,
user_data);
}

#ifdef __cplusplus
}
#endif
17 changes: 17 additions & 0 deletions rcl/src/rcl/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ rcl_event_is_valid(const rcl_event_t * event)
return true;
}

rcl_ret_t
rcl_event_set_callback(
const rcl_event_t * event,
rcl_event_callback_t callback,
const void * user_data)
{
if (!rcl_event_is_valid(event)) {
// error state already set
return RCL_RET_INVALID_ARGUMENT;
}

return rmw_event_set_callback(
&event->impl->rmw_handle,
callback,
user_data);
}

#ifdef __cplusplus
}
#endif
17 changes: 17 additions & 0 deletions rcl/src/rcl/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,23 @@ rcl_service_response_publisher_get_actual_qos(const rcl_service_t * service)
return &service->impl->actual_response_publisher_qos;
}

rcl_ret_t
rcl_service_set_on_new_request_callback(
const rcl_service_t * service,
rcl_event_callback_t callback,
const void * user_data)
{
if (!rcl_service_is_valid(service)) {
// error state already set
return RCL_RET_INVALID_ARGUMENT;
}

return rmw_service_set_on_new_request_callback(
service->impl->rmw_handle,
callback,
user_data);
}

#ifdef __cplusplus
}
#endif
17 changes: 17 additions & 0 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,23 @@ rcl_subscription_can_loan_messages(const rcl_subscription_t * subscription)
return subscription->impl->rmw_handle->can_loan_messages;
}

rcl_ret_t
rcl_subscription_set_on_new_message_callback(
const rcl_subscription_t * subscription,
rcl_event_callback_t callback,
const void * user_data)
{
if (!rcl_subscription_is_valid(subscription)) {
// error state already set
return RCL_RET_INVALID_ARGUMENT;
}

return rmw_subscription_set_on_new_message_callback(
subscription->impl->rmw_handle,
callback,
user_data);
}

#ifdef __cplusplus
}
#endif
10 changes: 10 additions & 0 deletions rcl/src/rcl/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ rcl_timer_get_time_until_next_call(const rcl_timer_t * timer, int64_t * time_unt
return RCL_RET_OK;
}

rcl_ret_t
rcl_timer_get_next_call_time(const rcl_timer_t * timer, rcl_time_point_value_t * time_point_value)
{
RCL_CHECK_ARGUMENT_FOR_NULL(timer, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(time_point_value, RCL_RET_INVALID_ARGUMENT);

*time_point_value = rcutils_atomic_load_int64_t(&timer->impl->next_call_time);
return RCL_RET_OK;
}

rcl_ret_t
rcl_timer_get_time_since_last_call(
const rcl_timer_t * timer,
Expand Down
Loading