Skip to content

Commit

Permalink
Fix issues reported by clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Jun 23, 2023
1 parent e9c5732 commit 73b0216
Show file tree
Hide file tree
Showing 17 changed files with 725 additions and 717 deletions.
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ if (OC_DEBUG_ENABLED)
else()
set(OC_LOG_MAXIMUM_LOG_LEVEL "DISABLED" CACHE STRING "Maximum supported log level in compile time.")
endif()
set(OC_INOUT_BUFFER_SIZE "" CACHE STRING "Custom buffer size for network messages.")
set(OC_INOUT_BUFFER_POOL_SIZE "" CACHE STRING "Custom pool size of network messages.")
set(OC_INOUT_BUFFER_SIZE "" CACHE STRING "Custom static buffer size for network messages.")
set(OC_INOUT_BUFFER_POOL "" CACHE STRING "Custom static pool size of network messages.")
set(OC_APP_DATA_BUFFER_SIZE "" CACHE STRING "Custom static buffer size for application messages.")
set(OC_APP_DATA_BUFFER_POOL "" CACHE STRING "Custom static size of application messages.")
set(PLGD_DEV_TIME_ENABLED OFF CACHE BOOL "Enable plgd time feature.")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand Down Expand Up @@ -367,16 +369,34 @@ endif()

if (NOT("${OC_INOUT_BUFFER_SIZE}" STREQUAL ""))
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED)
message(FATAL_ERROR "Cannot set custom buffer size for network messages without dynamic allocation")
message(FATAL_ERROR "Cannot set custom static buffer size for network messages without dynamic allocation")
endif()
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_SIZE=(${OC_INOUT_BUFFER_SIZE})")
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_SIZE=(${OC_INOUT_BUFFER_SIZE})")
endif()
if (NOT("${OC_INOUT_BUFFER_POOL_SIZE}" STREQUAL ""))

if (NOT("${OC_INOUT_BUFFER_POOL}" STREQUAL ""))
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED)
message(FATAL_ERROR "Cannot set custom static pool size for network messages without dynamic allocation")
endif()
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_POOL=(${OC_INOUT_BUFFER_POOL})")
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_POOL=(${OC_INOUT_BUFFER_POOL})")
endif()

if (NOT("${OC_APP_DATA_BUFFER_SIZE}" STREQUAL ""))
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED)
message(FATAL_ERROR "Cannot set custom static buffer size for application messages without dynamic allocation")
endif()
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_SIZE=(${OC_APP_DATA_BUFFER_SIZE})")
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_SIZE=(${OC_APP_DATA_BUFFER_SIZE})")
endif()

if (NOT("${OC_APP_DATA_BUFFER_POOL}" STREQUAL ""))
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED)
message(FATAL_ERROR "Cannot set custom pool size for network messages without dynamic allocation")
message(FATAL_ERROR "Cannot set custom static pool size for application messages without dynamic allocation")
endif()
list(APPEND PRIVATE_COMPILE_DEFINITIONS "OC_INOUT_BUFFER_POOL_SIZE=(${OC_INOUT_BUFFER_POOL_SIZE})")
list(APPEND PUBLIC_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_POOL=(${OC_APP_DATA_BUFFER_POOL})")
list(APPEND MBEDTLS_COMPILE_DEFINITIONS "OC_APP_DATA_BUFFER_POOL=(${OC_APP_DATA_BUFFER_POOL})")
endif()

if(PLGD_DEV_TIME_ENABLED)
Expand Down
10 changes: 5 additions & 5 deletions api/oc_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
#endif /* OC_DYNAMIC_ALLOCATION */

OC_PROCESS(oc_message_buffer_handler, "OC Message Buffer Handler");
#ifdef OC_INOUT_BUFFER_POOL_SIZE
OC_MEMB_STATIC(oc_incoming_buffers, oc_message_t, OC_INOUT_BUFFER_POOL_SIZE);
OC_MEMB_STATIC(oc_outgoing_buffers, oc_message_t, OC_INOUT_BUFFER_POOL_SIZE);
#else /* OC_INOUT_BUFFER_POOL_SIZE */
#ifdef OC_INOUT_BUFFER_POOL
OC_MEMB_STATIC(oc_incoming_buffers, oc_message_t, OC_INOUT_BUFFER_POOL);
OC_MEMB_STATIC(oc_outgoing_buffers, oc_message_t, OC_INOUT_BUFFER_POOL);
#else /* !OC_INOUT_BUFFER_POOL */
OC_MEMB(oc_incoming_buffers, oc_message_t, OC_MAX_NUM_CONCURRENT_REQUESTS);
OC_MEMB(oc_outgoing_buffers, oc_message_t, OC_MAX_NUM_CONCURRENT_REQUESTS);
#endif /* !OC_INOUT_BUFFER_POOL_SIZE */
#endif /* OC_INOUT_BUFFER_POOL */

static void
message_deallocate(oc_message_t *message, struct oc_memb *pool)
Expand Down
46 changes: 30 additions & 16 deletions api/oc_ri.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,29 +1388,43 @@ oc_ri_invoke_coap_entity_handler(const coap_packet_t *request,
bool response_state_allocated = false;
bool enable_realloc_rep = false;
#endif /* OC_DYNAMIC_ALLOCATION */
if (cur_resource && !bad_request && *ctx.response_state == NULL) {
OC_DBG("creating new block-wise response state");
*ctx.response_state = oc_blockwise_alloc_response_buffer(
uri_path, uri_path_len, endpoint, method, OC_BLOCKWISE_SERVER,
OC_MIN_APP_DATA_SIZE);
if (cur_resource && !bad_request) {
if (*ctx.response_state == NULL) {
OC_ERR("failure to alloc response state");
bad_request = true;
} else {
OC_DBG("creating new block-wise response state");
*ctx.response_state = oc_blockwise_alloc_response_buffer(
uri_path, uri_path_len, endpoint, method, OC_BLOCKWISE_SERVER,
OC_MIN_APP_DATA_SIZE);
if (*ctx.response_state == NULL) {
OC_ERR("failure to alloc response state");
bad_request = true;
} else {
#ifdef OC_DYNAMIC_ALLOCATION
#ifdef OC_APP_DATA_BUFFER_POOL
if (!request_buffer->block)
if (!(*ctx.response_state)->block)
#endif /* OC_APP_DATA_BUFFER_POOL */
{
response_state_allocated = true;
}
{
response_state_allocated = true;
}
#endif /* OC_DYNAMIC_ALLOCATION */
if (uri_query_len > 0) {
oc_new_string(&(*ctx.response_state)->uri_query, uri_query,
uri_query_len);
}
response_buffer.buffer = (*ctx.response_state)->buffer;
#ifdef OC_DYNAMIC_ALLOCATION
response_buffer.buffer_size = (*ctx.response_state)->buffer_size;
#else /* !OC_DYNAMIC_ALLOCATION */
response_buffer.buffer_size = sizeof((*ctx.response_state)->buffer);
#endif /* OC_DYNAMIC_ALLOCATION */
if (uri_query_len > 0) {
oc_new_string(&(*ctx.response_state)->uri_query, uri_query,
uri_query_len);
}
} else {
OC_DBG("using existing block-wise response state");
response_buffer.buffer = (*ctx.response_state)->buffer;
response_buffer.buffer_size = OC_MIN_APP_DATA_SIZE;
#ifdef OC_DYNAMIC_ALLOCATION
response_buffer.buffer_size = (*ctx.response_state)->buffer_size;
#else /* !OC_DYNAMIC_ALLOCATION */
response_buffer.buffer_size = sizeof((*ctx.response_state)->buffer);
#endif /* OC_DYNAMIC_ALLOCATION */
}
}
#else /* OC_BLOCK_WISE */
Expand Down
2 changes: 0 additions & 2 deletions api/unittest/eventcallbacktest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,6 @@ class TestObserveCallbackWithServer : public testing::Test {

static void SetUpTestCase()
{
oc_log_set_level(OC_LOG_LEVEL_DEBUG);

ASSERT_TRUE(oc::TestDevice::StartServer());

#if defined(OC_SERVER) && defined(OC_COLLECTIONS)
Expand Down
1 change: 0 additions & 1 deletion api/unittest/introspectiontest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class TestIntrospectionWithServer : public testing::Test {

static void SetUpTestCase()
{
oc_log_set_level(OC_LOG_LEVEL_DEBUG);
ASSERT_EQ(0, oc::TestStorage.Config());

#ifdef OC_IDD_API
Expand Down
6 changes: 4 additions & 2 deletions api/unittest/ocapitest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
#include <stdexcept>
#endif /* _WIN32 */

#ifdef OC_DYNAMIC_ALLOCATION
#if defined(OC_DYNAMIC_ALLOCATION) && !defined(OC_INOUT_BUFFER_POOL) && \
!defined(OC_APP_DATA_BUFFER_POOL)
// discovery requests are so large that they only work with dynamic allocation

static constexpr uint16_t kMaxWaitTime{ 10 };
Expand Down Expand Up @@ -923,4 +924,5 @@ TEST_F(TestObt, DiscoverUnownedResources)
}

#endif /* OC_SECURITY */
#endif /* OC_DYNAMIC_ALLOCATION */
#endif /* OC_DYNAMIC_ALLOCATION && !OC_INOUT_BUFFER_POOL && \
!OC_APP_DATA_BUFFER_POOL */
4 changes: 4 additions & 0 deletions api/unittest/plgdtimetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ TEST_F(TestPlgdTimeWithServer, FetchTimeFail)
#endif /* OC_SECURITY */
}

#ifndef OC_INOUT_BUFFER_POOL

#if defined(OC_TCP) && defined(OC_SESSION_EVENTS)

struct TCPSessionData
Expand Down Expand Up @@ -801,6 +803,8 @@ TEST_F(TestPlgdTimeWithServer, FetchTimeAlreadyConnectedSecure)

#endif /* OC_SECURITY && OC_PKI */

#endif /* !OC_INOUT_BUFFER_POOL */

#endif /* OC_CLIENT */

#ifdef OC_SECURITY
Expand Down
Loading

0 comments on commit 73b0216

Please sign in to comment.