Skip to content

Commit

Permalink
Moving the external logging library and rosout functions out to rcl. …
Browse files Browse the repository at this point in the history
…Also automatically uncrustifying and fixing unit tests.
  • Loading branch information
nburek committed Dec 4, 2018
1 parent 454e5a4 commit 56f9d74
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 334 deletions.
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

include(cmake/get_default_rc_logging_implementation.cmake)


find_package(ament_cmake_python REQUIRED)
find_package(ament_cmake_ros REQUIRED)

get_default_rc_logging_implementation(RC_LOGGING_IMPL)

ament_python_install_package(${PROJECT_NAME})

include_directories(include)
Expand Down Expand Up @@ -96,8 +91,6 @@ add_library(
${PROJECT_NAME}
${rcutils_sources})

target_link_libraries(${PROJECT_NAME} ${${RC_LOGGING_IMPL}_LIBRARIES})

# 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 "RCUTILS_BUILDING_DLL")
Expand Down
46 changes: 0 additions & 46 deletions cmake/get_default_rc_logging_implementation.cmake

This file was deleted.

25 changes: 0 additions & 25 deletions include/rcutils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,6 @@ RCUTILS_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t rcutils_logging_shutdown(void);

/// Configures the logging system.
/**
* This function should be called during the ROS initialization process. It will
* add the enabled log output appenders to the root logger.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | Yes
*
* \param default_level The default severity level to log at
* \param config_file The configuration file for the external logging library to use. Should be a null terminated string.
* If NULL or an empty string the default configuration will be used
* \param enable_stdout Should the stdout output appender be enabled
* \param enable_rosout Should the rosout output appender be enabled
* \param enable_ext_lib Should the external logger library output appender be enabled
* \return `RCUTILS_RET_OK` if successful.
* \return `RCUTILS_RET_ERR` if a general error occurs
*/
RCUTILS_PUBLIC
rcutils_ret_t rcutils_logging_configure(int default_level, const char * config_file, bool enable_stdout, bool enable_rosout, bool enable_ext_lib);

/// The structure identifying the caller location in the source code.
typedef struct rcutils_log_location_t
{
Expand Down
66 changes: 0 additions & 66 deletions include/rcutils/logging_external_interface.h

This file was deleted.

5 changes: 3 additions & 2 deletions include/rcutils/types/char_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern "C"
#endif

#include <stdarg.h>

#include "rcutils/allocator.h"
#include "rcutils/types/rcutils_ret.h"
#include "rcutils/visibility_control.h"
Expand Down Expand Up @@ -134,7 +135,7 @@ rcutils_char_array_resize(rcutils_char_array_t * char_array, size_t new_size);
RCUTILS_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t
rcutils_char_array_expand_as_needed(rcutils_char_array_t *char_array, size_t new_size);
rcutils_char_array_expand_as_needed(rcutils_char_array_t * char_array, size_t new_size);

/// Produce output according to format and args.
/**
Expand All @@ -154,7 +155,7 @@ rcutils_char_array_expand_as_needed(rcutils_char_array_t *char_array, size_t new
RCUTILS_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t
rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char *format, va_list args);
rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char * format, va_list args);

/// Append a string (or part of it) to the string in buffer.
/**
Expand Down
5 changes: 1 addition & 4 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<package format="2">
<name>rcutils</name>
<version>0.6.0</version>
<description>Package containing various utility types and functions for C</description>
Expand All @@ -10,9 +10,6 @@
<buildtool_depend>ament_cmake_ros</buildtool_depend>
<buildtool_depend>python3-empy</buildtool_depend>

<depend>rc_logging_log4cxx</depend>
<group_depend>rc_logging_packages</group_depend>

<test_depend>ament_cmake_gmock</test_depend>
<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
Expand Down
61 changes: 26 additions & 35 deletions src/char_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@

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

#define RCUTILS_VALIDATE_CHAR_ARRAY(char_array) \
RCUTILS_CHECK_FOR_NULL_WITH_MSG( \
char_array, \
"char array pointer is null", \
return RCUTILS_RET_ERROR);

#define RCUTILS_VALIDATE_ALLOCATOR(allocator) \
if (!rcutils_allocator_is_valid(allocator)) { \
RCUTILS_SET_ERROR_MSG("char array has no valid allocator"); \
return RCUTILS_RET_ERROR; \
}

rcutils_char_array_t
rcutils_get_zero_initialized_char_array(void)
{
Expand All @@ -49,8 +37,9 @@ rcutils_char_array_init(
size_t buffer_capacity,
const rcutils_allocator_t * allocator)
{
RCUTILS_VALIDATE_CHAR_ARRAY(char_array);
RCUTILS_VALIDATE_ALLOCATOR(allocator);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
return RCUTILS_RET_ERROR);

char_array->owns_buffer = true;
char_array->buffer_length = 0lu;
Expand All @@ -74,16 +63,16 @@ rcutils_char_array_init(
rcutils_ret_t
rcutils_char_array_fini(rcutils_char_array_t * char_array)
{
RCUTILS_VALIDATE_CHAR_ARRAY(char_array);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);

if (!char_array->owns_buffer) {
return RCUTILS_RET_OK;
}
if (char_array->owns_buffer) {
rcutils_allocator_t * allocator = &char_array->allocator;
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
return RCUTILS_RET_ERROR);

rcutils_allocator_t * allocator = &char_array->allocator;
RCUTILS_VALIDATE_ALLOCATOR(allocator);
allocator->deallocate(char_array->buffer, allocator->state);
}

allocator->deallocate(char_array->buffer, allocator->state);
char_array->buffer = NULL;
char_array->buffer_length = 0lu;
char_array->buffer_capacity = 0lu;
Expand All @@ -94,15 +83,16 @@ rcutils_char_array_fini(rcutils_char_array_t * char_array)
rcutils_ret_t
rcutils_char_array_resize(rcutils_char_array_t * char_array, size_t new_size)
{
RCUTILS_VALIDATE_CHAR_ARRAY(char_array);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);

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

rcutils_allocator_t * allocator = &char_array->allocator;
RCUTILS_VALIDATE_ALLOCATOR(allocator);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(allocator, "char array has no valid allocator",
return RCUTILS_RET_ERROR);

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

if (char_array->owns_buffer) { // we own the buffer, we can do whatever we want
if (char_array->owns_buffer) { // we own the buffer, we can do whatever we want
char_array->buffer = rcutils_reallocf(char_array->buffer, new_size * sizeof(char), allocator);
RCUTILS_CHECK_FOR_NULL_WITH_MSG(
char_array->buffer,
"failed to reallocate memory for char array",
return RCUTILS_RET_BAD_ALLOC);
} else { // we don't realloc memory we don't own. instead, we alloc some new space
char_array->buffer,
"failed to reallocate memory for char array",
return RCUTILS_RET_BAD_ALLOC);
} else { // we don't realloc memory we don't own. instead, we alloc some new space
rcutils_ret_t ret = rcutils_char_array_init(char_array, new_size, allocator);
if (ret != RCUTILS_RET_OK) {
return ret;
Expand All @@ -136,9 +126,9 @@ rcutils_char_array_resize(rcutils_char_array_t * char_array, size_t new_size)
}

rcutils_ret_t
rcutils_char_array_expand_as_needed(rcutils_char_array_t *char_array, size_t new_size)
rcutils_char_array_expand_as_needed(rcutils_char_array_t * char_array, size_t new_size)
{
RCUTILS_VALIDATE_CHAR_ARRAY(char_array);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(char_array, RCUTILS_RET_ERROR);

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

static int
_rcutils_char_array_vsprintf(rcutils_char_array_t *char_array, const char *format, va_list args)
_rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char * format, va_list args)
{
va_list args_clone;
va_copy(args_clone, args);

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

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

rcutils_ret_t
rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char *format, va_list args)
rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char * format, va_list args)
{
int size = _rcutils_char_array_vsprintf(char_array, format, args);

Expand All @@ -171,7 +162,7 @@ rcutils_char_array_vsprintf(rcutils_char_array_t * char_array, const char *forma
return RCUTILS_RET_ERROR;
}

size_t new_size = (size_t) size + 1; // with the terminating null byte
size_t new_size = (size_t) size + 1; // with the terminating null byte

if (new_size > char_array->buffer_capacity) {
rcutils_ret_t ret = rcutils_char_array_expand_as_needed(char_array, new_size);
Expand Down Expand Up @@ -211,7 +202,7 @@ rcutils_char_array_memcpy(rcutils_char_array_t * char_array, const char * src, s
rcutils_ret_t
rcutils_char_array_strcpy(rcutils_char_array_t * char_array, const char * src)
{
return rcutils_char_array_memcpy(char_array, src, strlen(src) + 1);
return rcutils_char_array_memcpy(char_array, src, strlen(src) + 1);
}

rcutils_ret_t
Expand Down
Loading

0 comments on commit 56f9d74

Please sign in to comment.