Skip to content

Commit 8594729

Browse files
pablogs9Acuadros95
andauthored
Add timing API for handling XRCE-DDS session (#153) (backport) (#157)
* Add timing API for handling XRCE-DDS session * Update * Add source file to cmake * Apply suggestions from code review Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> * Update .github/workflows/ci.yml Co-authored-by: Antonio cuadros <acuadros1995@gmail.com> Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> Co-authored-by: Antonio cuadros <acuadros1995@gmail.com> Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com>
1 parent e483ca6 commit 8594729

11 files changed

Lines changed: 154 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ jobs:
5555
gcovr -x -r . -o coverage.xml ../../build --exclude-unreachable-branches --exclude rmw_microxrcedds_c/test
5656
curl -s https://codecov.io/bash -o codecov.bash && chmod +x codecov.bash
5757
./codecov.bash -t ${{ secrets.CODECOV_TOKEN }}
58-

rmw_microxrcedds_c/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maxim
5757
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a topic name.")
5858
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a type name.")
5959
set(RMW_UXRCE_REF_BUFFER_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a reference buffer.")
60-
set(RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT "1000" CACHE STRING "This value sets the maximum time to wait for an XRCE entity creation and destroy in milliseconds. If set to 0 best effort is used.")
61-
set(RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT "1000" CACHE STRING "This value sets the maximum time to wait for a publication in a reliable mode in milliseconds.")
60+
set(RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT "1000" CACHE STRING
61+
"This value sets the maximum time to wait for an XRCE entity creation and destroy in milliseconds.
62+
If set to 0 best effort is used.")
63+
set(RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT "1000" CACHE STRING
64+
"This value sets the default time to wait for a publication in a reliable mode in milliseconds.")
6265

6366
set(RMW_UXRCE_STREAM_HISTORY "4" CACHE STRING "This value sets the number of MTUs to buffer, both input and output. Micro XRCE-DDS client configuration provides their size")
6467
set(RMW_UXRCE_STREAM_HISTORY_INPUT "" CACHE STRING "This value sets the number of MTUs to input buffer. It will be ignored if RMW_UXRCE_STREAM_HISTORY_OUTPUT is blank. Micro XRCE-DDS client configuration provides their size")
@@ -155,6 +158,7 @@ set(SRCS
155158
src/rmw_microros/init_options.c
156159
src/rmw_microros/time_sync.c
157160
src/rmw_microros/ping.c
161+
src/rmw_microros/timing.c
158162
$<$<BOOL:${RMW_UXRCE_TRANSPORT_UDP}>:src/rmw_microros/discovery.c>
159163
$<$<BOOL:${RMW_UXRCE_TRANSPORT_CUSTOM}>:src/rmw_microros/custom_transport.c>
160164
$<$<BOOL:${RMW_UXRCE_GRAPH}>:src/rmw_graph.c>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file
17+
*/
18+
19+
#ifndef RMW_MICROROS__TIMING_H_
20+
#define RMW_MICROROS__TIMING_H_
21+
22+
#include <rmw/rmw.h>
23+
#include <rmw/ret_types.h>
24+
#include <rmw/init_options.h>
25+
#include <rmw/error_handling.h>
26+
#include <uxr/client/util/time.h>
27+
28+
#if defined(__cplusplus)
29+
extern "C"
30+
{
31+
#endif // if defined(__cplusplus)
32+
33+
/** \addtogroup rmw micro-ROS RMW API
34+
* @{
35+
*/
36+
37+
/**
38+
* \brief Sets the DDS-XRCE session spin time in reliable publication
39+
*
40+
* \param[in] publisher publisher where the spin time is configured
41+
* \param[in] session_timeout time in milliseconds
42+
* \return RMW_RET_OK when success.
43+
* \return RMW_RET_INVALID_ARGUMENT If publisher is not valid or unexpected arguments.
44+
*/
45+
rmw_ret_t rmw_uros_set_publisher_session_timeout(
46+
rmw_publisher_t * publisher,
47+
int session_timeout);
48+
49+
/**
50+
* \brief Sets the DDS-XRCE session spin time in reliable service server
51+
*
52+
* \param[in] service service where the spin time is configured
53+
* \param[in] session_timeout time in milliseconds
54+
* \return RMW_RET_OK when success.
55+
* \return RMW_RET_INVALID_ARGUMENT If service is not valid or unexpected arguments.
56+
*/
57+
rmw_ret_t rmw_uros_set_service_session_timeout(
58+
rmw_service_t * service,
59+
int session_timeout);
60+
61+
/**
62+
* \brief Sets the DDS-XRCE session spin time in reliable service client
63+
*
64+
* \param[in] client client where the spin time is configured
65+
* \param[in] session_timeout time in milliseconds
66+
* \return RMW_RET_OK when success.
67+
* \return RMW_RET_INVALID_ARGUMENT If client is not valid or unexpected arguments.
68+
*/
69+
rmw_ret_t rmw_uros_set_client_session_timeout(
70+
rmw_client_t * client,
71+
int session_timeout);
72+
73+
/** @}*/
74+
75+
#if defined(__cplusplus)
76+
}
77+
#endif // if defined(__cplusplus)
78+
79+
#endif // RMW_MICROROS__TIMING_H_

rmw_microxrcedds_c/src/rmw_client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ rmw_create_client(
6969
rmw_uxrce_client_t * custom_client = (rmw_uxrce_client_t *)memory_node->data;
7070
custom_client->rmw_handle = rmw_client;
7171
custom_client->owner_node = custom_node;
72+
custom_client->session_timeout = RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT;
7273

7374
const rosidl_service_type_support_t * type_support_xrce = NULL;
7475
#ifdef ROSIDL_TYPESUPPORT_MICROXRCEDDS_C__IDENTIFIER_VALUE
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <rmw_microxrcedds_c/config.h>
16+
#include <rmw/rmw.h>
17+
#include <rmw/allocators.h>
18+
#include <rmw/ret_types.h>
19+
#include <rmw/error_handling.h>
20+
21+
#include "../types.h"
22+
23+
rmw_ret_t rmw_uros_set_publisher_session_timeout(
24+
rmw_publisher_t * publisher,
25+
int session_timeout)
26+
{
27+
RMW_CHECK_ARGUMENT_FOR_NULL(publisher, RMW_RET_INVALID_ARGUMENT);
28+
rmw_uxrce_publisher_t * custom_publisher = (rmw_uxrce_publisher_t *)publisher->data;
29+
30+
custom_publisher->session_timeout = session_timeout;
31+
return RMW_RET_OK;
32+
}
33+
34+
rmw_ret_t rmw_uros_set_service_session_timeout(
35+
rmw_service_t * service,
36+
int session_timeout)
37+
{
38+
RMW_CHECK_ARGUMENT_FOR_NULL(service, RMW_RET_INVALID_ARGUMENT);
39+
rmw_uxrce_service_t * custom_service = (rmw_uxrce_service_t *)service->data;
40+
41+
custom_service->session_timeout = session_timeout;
42+
return RMW_RET_OK;
43+
}
44+
45+
rmw_ret_t rmw_uros_set_client_session_timeout(
46+
rmw_client_t * client,
47+
int session_timeout)
48+
{
49+
RMW_CHECK_ARGUMENT_FOR_NULL(client, RMW_RET_INVALID_ARGUMENT);
50+
rmw_uxrce_client_t * custom_client = (rmw_uxrce_client_t *)client->data;
51+
52+
custom_client->session_timeout = session_timeout;
53+
return RMW_RET_OK;
54+
}

rmw_microxrcedds_c/src/rmw_publish.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
#include "./utils.h"
2222

2323
bool flush_session(
24-
uxrSession * session)
24+
uxrSession * session,
25+
void * args)
2526
{
26-
return uxr_run_session_until_confirm_delivery(session, RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT);
27+
rmw_uxrce_publisher_t * custom_publisher = (rmw_uxrce_publisher_t *)args;
28+
return uxr_run_session_until_confirm_delivery(session, custom_publisher->session_timeout);
2729
}
2830

2931
rmw_ret_t
@@ -64,7 +66,7 @@ rmw_publish(
6466
uxr_prepare_output_stream_fragmented(
6567
&custom_publisher->owner_node->context->session,
6668
custom_publisher->stream_id, custom_publisher->datawriter_id, &mb,
67-
topic_length, flush_session))
69+
topic_length, flush_session, custom_publisher))
6870
{
6971
written = functions->cdr_serialize(ros_message, &mb);
7072
if (custom_publisher->cs_cb_serialization) {
@@ -79,7 +81,7 @@ rmw_publish(
7981
uxr_flash_output_streams(&custom_publisher->owner_node->context->session);
8082
} else {
8183
written &= uxr_run_session_until_confirm_delivery(
82-
&custom_publisher->owner_node->context->session, RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT);
84+
&custom_publisher->owner_node->context->session, custom_publisher->session_timeout);
8385
}
8486
}
8587
if (!written) {

rmw_microxrcedds_c/src/rmw_publisher.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ rmw_create_publisher(
101101
rmw_uxrce_publisher_t * custom_publisher = (rmw_uxrce_publisher_t *)memory_node->data;
102102
custom_publisher->rmw_handle = rmw_publisher;
103103
custom_publisher->owner_node = custom_node;
104+
custom_publisher->session_timeout = RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT;
105+
104106
memcpy(&custom_publisher->qos, qos_policies, sizeof(rmw_qos_profile_t));
105107

106108
custom_publisher->stream_id =

rmw_microxrcedds_c/src/rmw_request.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ rmw_send_request(
5757
uxr_flash_output_streams(&custom_node->context->session);
5858
} else {
5959
uxr_run_session_until_confirm_delivery(
60-
&custom_node->context->session, RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT);
60+
&custom_node->context->session, custom_client->session_timeout);
6161
}
6262

6363
return RMW_RET_OK;

rmw_microxrcedds_c/src/rmw_response.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ rmw_send_response(
7171
uxr_flash_output_streams(&custom_node->context->session);
7272
} else {
7373
uxr_run_session_until_confirm_delivery(
74-
&custom_node->context->session, RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT);
74+
&custom_node->context->session, custom_service->session_timeout);
7575
}
7676

7777
return RMW_RET_OK;

rmw_microxrcedds_c/src/rmw_service.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ rmw_create_service(
6868
custom_service->rmw_handle = rmw_service;
6969

7070
custom_service->owner_node = custom_node;
71-
custom_service->history_write_index = 0;
72-
custom_service->history_read_index = 0;
71+
custom_service->session_timeout = RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT;
7372

7473
const rosidl_service_type_support_t * type_support_xrce = NULL;
7574
#ifdef ROSIDL_TYPESUPPORT_MICROXRCEDDS_C__IDENTIFIER_VALUE

0 commit comments

Comments
 (0)