Skip to content

Commit 56f9d74

Browse files
committed
Moving the external logging library and rosout functions out to rcl. Also automatically uncrustifying and fixing unit tests.
1 parent 454e5a4 commit 56f9d74

File tree

11 files changed

+114
-334
lines changed

11 files changed

+114
-334
lines changed

CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ if(NOT CMAKE_CXX_STANDARD)
1111
set(CMAKE_CXX_STANDARD 14)
1212
endif()
1313

14-
include(cmake/get_default_rc_logging_implementation.cmake)
15-
16-
1714
find_package(ament_cmake_python REQUIRED)
1815
find_package(ament_cmake_ros REQUIRED)
1916

20-
get_default_rc_logging_implementation(RC_LOGGING_IMPL)
21-
2217
ament_python_install_package(${PROJECT_NAME})
2318

2419
include_directories(include)
@@ -96,8 +91,6 @@ add_library(
9691
${PROJECT_NAME}
9792
${rcutils_sources})
9893

99-
target_link_libraries(${PROJECT_NAME} ${${RC_LOGGING_IMPL}_LIBRARIES})
100-
10194
# Causes the visibility macros to use dllexport rather than dllimport,
10295
# which is appropriate when building the dll but not consuming it.
10396
target_compile_definitions(${PROJECT_NAME} PRIVATE "RCUTILS_BUILDING_DLL")

cmake/get_default_rc_logging_implementation.cmake

Lines changed: 0 additions & 46 deletions
This file was deleted.

include/rcutils/logging.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,6 @@ RCUTILS_PUBLIC
142142
RCUTILS_WARN_UNUSED
143143
rcutils_ret_t rcutils_logging_shutdown(void);
144144

145-
/// Configures the logging system.
146-
/**
147-
* This function should be called during the ROS initialization process. It will
148-
* add the enabled log output appenders to the root logger.
149-
*
150-
* <hr>
151-
* Attribute | Adherence
152-
* ------------------ | -------------
153-
* Allocates Memory | No
154-
* Thread-Safe | No
155-
* Uses Atomics | No
156-
* Lock-Free | Yes
157-
*
158-
* \param default_level The default severity level to log at
159-
* \param config_file The configuration file for the external logging library to use. Should be a null terminated string.
160-
* If NULL or an empty string the default configuration will be used
161-
* \param enable_stdout Should the stdout output appender be enabled
162-
* \param enable_rosout Should the rosout output appender be enabled
163-
* \param enable_ext_lib Should the external logger library output appender be enabled
164-
* \return `RCUTILS_RET_OK` if successful.
165-
* \return `RCUTILS_RET_ERR` if a general error occurs
166-
*/
167-
RCUTILS_PUBLIC
168-
rcutils_ret_t rcutils_logging_configure(int default_level, const char * config_file, bool enable_stdout, bool enable_rosout, bool enable_ext_lib);
169-
170145
/// The structure identifying the caller location in the source code.
171146
typedef struct rcutils_log_location_t
172147
{

include/rcutils/logging_external_interface.h

Lines changed: 0 additions & 66 deletions
This file was deleted.

include/rcutils/types/char_array.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern "C"
2121
#endif
2222

2323
#include <stdarg.h>
24+
2425
#include "rcutils/allocator.h"
2526
#include "rcutils/types/rcutils_ret.h"
2627
#include "rcutils/visibility_control.h"
@@ -134,7 +135,7 @@ rcutils_char_array_resize(rcutils_char_array_t * char_array, size_t new_size);
134135
RCUTILS_PUBLIC
135136
RCUTILS_WARN_UNUSED
136137
rcutils_ret_t
137-
rcutils_char_array_expand_as_needed(rcutils_char_array_t *char_array, size_t new_size);
138+
rcutils_char_array_expand_as_needed(rcutils_char_array_t * char_array, size_t new_size);
138139

139140
/// Produce output according to format and args.
140141
/**
@@ -154,7 +155,7 @@ rcutils_char_array_expand_as_needed(rcutils_char_array_t *char_array, size_t new
154155
RCUTILS_PUBLIC
155156
RCUTILS_WARN_UNUSED
156157
rcutils_ret_t
157-
rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char *format, va_list args);
158+
rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char * format, va_list args);
158159

159160
/// Append a string (or part of it) to the string in buffer.
160161
/**

package.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3-
<package format="3">
3+
<package format="2">
44
<name>rcutils</name>
55
<version>0.6.0</version>
66
<description>Package containing various utility types and functions for C</description>
@@ -10,9 +10,6 @@
1010
<buildtool_depend>ament_cmake_ros</buildtool_depend>
1111
<buildtool_depend>python3-empy</buildtool_depend>
1212

13-
<depend>rc_logging_log4cxx</depend>
14-
<group_depend>rc_logging_packages</group_depend>
15-
1613
<test_depend>ament_cmake_gmock</test_depend>
1714
<test_depend>ament_cmake_gtest</test_depend>
1815
<test_depend>ament_cmake_pytest</test_depend>

src/char_array.c

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@
1818

1919
#define MIN(a, b) ((a) < (b) ? (a) : (b))
2020

21-
#define RCUTILS_VALIDATE_CHAR_ARRAY(char_array) \
22-
RCUTILS_CHECK_FOR_NULL_WITH_MSG( \
23-
char_array, \
24-
"char array pointer is null", \
25-
return RCUTILS_RET_ERROR);
26-
27-
#define RCUTILS_VALIDATE_ALLOCATOR(allocator) \
28-
if (!rcutils_allocator_is_valid(allocator)) { \
29-
RCUTILS_SET_ERROR_MSG("char array has no valid allocator"); \
30-
return RCUTILS_RET_ERROR; \
31-
}
32-
3321
rcutils_char_array_t
3422
rcutils_get_zero_initialized_char_array(void)
3523
{
@@ -49,8 +37,9 @@ rcutils_char_array_init(
4937
size_t buffer_capacity,
5038
const rcutils_allocator_t * allocator)
5139
{
52-
RCUTILS_VALIDATE_CHAR_ARRAY(char_array);
53-
RCUTILS_VALIDATE_ALLOCATOR(allocator);
40+
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);
41+
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
42+
return RCUTILS_RET_ERROR);
5443

5544
char_array->owns_buffer = true;
5645
char_array->buffer_length = 0lu;
@@ -74,16 +63,16 @@ rcutils_char_array_init(
7463
rcutils_ret_t
7564
rcutils_char_array_fini(rcutils_char_array_t * char_array)
7665
{
77-
RCUTILS_VALIDATE_CHAR_ARRAY(char_array);
66+
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);
7867

79-
if (!char_array->owns_buffer) {
80-
return RCUTILS_RET_OK;
81-
}
68+
if (char_array->owns_buffer) {
69+
rcutils_allocator_t * allocator = &char_array->allocator;
70+
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
71+
return RCUTILS_RET_ERROR);
8272

83-
rcutils_allocator_t * allocator = &char_array->allocator;
84-
RCUTILS_VALIDATE_ALLOCATOR(allocator);
73+
allocator->deallocate(char_array->buffer, allocator->state);
74+
}
8575

86-
allocator->deallocate(char_array->buffer, allocator->state);
8776
char_array->buffer = NULL;
8877
char_array->buffer_length = 0lu;
8978
char_array->buffer_capacity = 0lu;
@@ -94,15 +83,16 @@ rcutils_char_array_fini(rcutils_char_array_t * char_array)
9483
rcutils_ret_t
9584
rcutils_char_array_resize(rcutils_char_array_t * char_array, size_t new_size)
9685
{
97-
RCUTILS_VALIDATE_CHAR_ARRAY(char_array);
86+
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);
9887

9988
if (0lu == new_size) {
10089
RCUTILS_SET_ERROR_MSG("new size of char_array has to be greater than zero");
10190
return RCUTILS_RET_INVALID_ARGUMENT;
10291
}
10392

10493
rcutils_allocator_t * allocator = &char_array->allocator;
105-
RCUTILS_VALIDATE_ALLOCATOR(allocator);
94+
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
95+
return RCUTILS_RET_ERROR);
10696

10797
if (new_size == char_array->buffer_capacity) {
10898
// nothing to do here
@@ -113,13 +103,13 @@ rcutils_char_array_resize(rcutils_char_array_t * char_array, size_t new_size)
113103
size_t old_size = char_array->buffer_capacity;
114104
size_t old_length = char_array->buffer_length;
115105

116-
if (char_array->owns_buffer) { // we own the buffer, we can do whatever we want
106+
if (char_array->owns_buffer) { // we own the buffer, we can do whatever we want
117107
char_array->buffer = rcutils_reallocf(char_array->buffer, new_size * sizeof(char), allocator);
118108
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
119-
char_array->buffer,
120-
"failed to reallocate memory for char array",
121-
return RCUTILS_RET_BAD_ALLOC);
122-
} else { // we don't realloc memory we don't own. instead, we alloc some new space
109+
char_array->buffer,
110+
"failed to reallocate memory for char array",
111+
return RCUTILS_RET_BAD_ALLOC);
112+
} else { // we don't realloc memory we don't own. instead, we alloc some new space
123113
rcutils_ret_t ret = rcutils_char_array_init(char_array, new_size, allocator);
124114
if (ret != RCUTILS_RET_OK) {
125115
return ret;
@@ -136,9 +126,9 @@ rcutils_char_array_resize(rcutils_char_array_t * char_array, size_t new_size)
136126
}
137127

138128
rcutils_ret_t
139-
rcutils_char_array_expand_as_needed(rcutils_char_array_t *char_array, size_t new_size)
129+
rcutils_char_array_expand_as_needed(rcutils_char_array_t * char_array, size_t new_size)
140130
{
141-
RCUTILS_VALIDATE_CHAR_ARRAY(char_array);
131+
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);
142132

143133
if (new_size <= char_array->buffer_capacity) {
144134
return RCUTILS_RET_OK;
@@ -148,12 +138,13 @@ rcutils_char_array_expand_as_needed(rcutils_char_array_t *char_array, size_t new
148138
}
149139

150140
static int
151-
_rcutils_char_array_vsprintf(rcutils_char_array_t *char_array, const char *format, va_list args)
141+
_rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char * format, va_list args)
152142
{
153143
va_list args_clone;
154144
va_copy(args_clone, args);
155145

156-
// when doing size calculation, remember the return value of vsnprintf excludes terminating null byte
146+
// when doing size calculation, remember the return value of vsnprintf excludes terminating null
147+
// byte
157148
int size = vsnprintf(char_array->buffer, char_array->buffer_capacity, format, args_clone);
158149

159150
va_end(args_clone);
@@ -162,7 +153,7 @@ _rcutils_char_array_vsprintf(rcutils_char_array_t *char_array, const char *forma
162153
}
163154

164155
rcutils_ret_t
165-
rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char *format, va_list args)
156+
rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char * format, va_list args)
166157
{
167158
int size = _rcutils_char_array_vsprintf(char_array, format, args);
168159

@@ -171,7 +162,7 @@ rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char *forma
171162
return RCUTILS_RET_ERROR;
172163
}
173164

174-
size_t new_size = (size_t) size + 1; // with the terminating null byte
165+
size_t new_size = (size_t) size + 1; // with the terminating null byte
175166

176167
if (new_size > char_array->buffer_capacity) {
177168
rcutils_ret_t ret = rcutils_char_array_expand_as_needed(char_array, new_size);
@@ -211,7 +202,7 @@ rcutils_char_array_memcpy(rcutils_char_array_t * char_array, const char * src, s
211202
rcutils_ret_t
212203
rcutils_char_array_strcpy(rcutils_char_array_t * char_array, const char * src)
213204
{
214-
return rcutils_char_array_memcpy(char_array, src, strlen(src) + 1);
205+
return rcutils_char_array_memcpy(char_array, src, strlen(src) + 1);
215206
}
216207

217208
rcutils_ret_t

0 commit comments

Comments
 (0)