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 authored and Daniel Adam committed Jun 26, 2023
1 parent a6a5324 commit 664e718
Show file tree
Hide file tree
Showing 58 changed files with 1,889 additions and 1,819 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ jobs:
- args: "-DOC_IPV4_ENABLED=ON -DOC_TCP_ENABLED=ON -DOC_PKI_ENABLED=OFF"
# cloud on (ipv4+tcp on), collections create on
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON"
# cloud on (ipv4+tcp on), collections create on, custom message buffer size
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_INOUT_BUFFER_SIZE=1024"
# cloud on (ipv4+tcp on), collections create on, custom message buffer size, custom message buffer pool size, custom app data buffer size, custom app data buffer pool size
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_INOUT_BUFFER_SIZE=2048 -DOC_INOUT_BUFFER_POOL=4 -DOC_APP_DATA_BUFFER_SIZE=2048 -DOC_APP_DATA_BUFFER_POOL=4"
# debug on
- args: "-DOC_DEBUG_ENABLED=ON"
# debug on, cloud on (ipv4+tcp on)
Expand Down
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
12 changes: 6 additions & 6 deletions api/oc_blockwise.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ oc_blockwise_free_response_buffer(oc_blockwise_state_t *buffer)

#ifdef OC_CLIENT
void
oc_blockwise_scrub_buffers_for_client_cb(void *cb)
oc_blockwise_scrub_buffers_for_client_cb(const void *cb)
{
oc_blockwise_state_t *buffer =
(oc_blockwise_state_t *)oc_list_head(oc_blockwise_requests);
Expand Down Expand Up @@ -321,7 +321,7 @@ oc_blockwise_find_response_buffer_by_mid(uint16_t mid)
static oc_blockwise_state_t *
oc_blockwise_find_buffer_by_client_cb(oc_list_t list,
const oc_endpoint_t *endpoint,
void *client_cb)
const void *client_cb)
{
oc_blockwise_state_t *buffer = (oc_blockwise_state_t *)oc_list_head(list);
while (buffer) {
Expand All @@ -336,15 +336,15 @@ oc_blockwise_find_buffer_by_client_cb(oc_list_t list,

oc_blockwise_state_t *
oc_blockwise_find_request_buffer_by_client_cb(const oc_endpoint_t *endpoint,
void *client_cb)
const void *client_cb)
{
return oc_blockwise_find_buffer_by_client_cb(oc_blockwise_requests, endpoint,
client_cb);
}

oc_blockwise_state_t *
oc_blockwise_find_response_buffer_by_client_cb(const oc_endpoint_t *endpoint,
void *client_cb)
const void *client_cb)
{
return oc_blockwise_find_buffer_by_client_cb(oc_blockwise_responses, endpoint,
client_cb);
Expand Down Expand Up @@ -391,7 +391,7 @@ oc_blockwise_find_response_buffer(const char *href, size_t href_len,
endpoint, method, query, query_len, role);
}

const void *
void *
oc_blockwise_dispatch_block(oc_blockwise_state_t *buffer, uint32_t block_offset,
uint32_t requested_block_size,
uint32_t *payload_size)
Expand All @@ -404,7 +404,7 @@ oc_blockwise_dispatch_block(oc_blockwise_state_t *buffer, uint32_t block_offset,
(uint32_t)(buffer->payload_size - block_offset));
}
buffer->next_block_offset = block_offset + *payload_size;
return (const void *)&buffer->buffer[block_offset];
return (void *)&buffer->buffer[block_offset];
}
return NULL;
}
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
7 changes: 4 additions & 3 deletions api/oc_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dispatch_coap_request(void)
#else /* OC_TCP */
if ((long)payload_size > OC_BLOCK_SIZE) {
#endif /* !OC_TCP */
const void *payload = oc_blockwise_dispatch_block(
void *payload = oc_blockwise_dispatch_block(
g_request_buffer, 0, (uint32_t)OC_BLOCK_SIZE, &block_size);
if (payload) {
coap_set_payload(g_request, payload, block_size);
Expand Down Expand Up @@ -219,7 +219,8 @@ prepare_coap_request(oc_client_cb_t *cb)
}

if (oc_string_len(cb->query) > 0) {
coap_set_header_uri_query(g_request, oc_string(cb->query));
coap_set_header_uri_query(g_request, oc_string(cb->query),
oc_string_len(cb->query));
}

g_dispatch.client_cb = cb;
Expand Down Expand Up @@ -314,7 +315,7 @@ oc_init_multicast_update(const char *uri, const char *query)
coap_set_header_uri_path(g_request, uri, strlen(uri));

if (query) {
coap_set_header_uri_query(g_request, query);
coap_set_header_uri_query(g_request, query, strlen(query));
}

return true;
Expand Down
5 changes: 2 additions & 3 deletions api/oc_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,20 +637,19 @@ oc_core_1_1_discovery_handler(oc_request_t *request,
{
(void)data;
int matches = 0;
size_t device;

switch (iface_mask) {
case OC_IF_LL: {
oc_rep_start_links_array();
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
matches += process_oic_1_1_device_object(oc_rep_array(links), request,
device, false);
}
oc_rep_end_links_array();
} break;
case OC_IF_BASELINE: {
oc_rep_start_links_array();
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
matches += process_oic_1_1_device_object(oc_rep_array(links), request,
device, true);
}
Expand Down
3 changes: 1 addition & 2 deletions api/oc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ oc_get_block_size(void)
static void
oc_shutdown_all_devices(void)
{
size_t device;
for (device = 0; device < oc_core_get_num_devices(); device++) {
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
oc_connectivity_shutdown(device);
}

Expand Down
5 changes: 3 additions & 2 deletions api/oc_resource_factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ oc_rt_factory_create_resource(oc_collection_t *collection,
}

void
oc_rt_factory_free_created_resource(oc_rt_created_t *rtc, oc_rt_factory_t *rf)
oc_rt_factory_free_created_resource(oc_rt_created_t *rtc,
const oc_rt_factory_t *rf)
{
if (oc_list_remove2(created_res, rtc) == NULL) {
/* protection against cyclical call of oc_rt_factory_free_created_resource
Expand All @@ -231,7 +232,7 @@ oc_fi_factory_free_all_created_resources(void)
}

oc_rt_created_t *
oc_rt_get_factory_create_for_resource(oc_resource_t *resource)
oc_rt_get_factory_create_for_resource(const oc_resource_t *resource)
{
oc_rt_created_t *rtc = (oc_rt_created_t *)oc_list_head(created_res);
while (rtc) {
Expand Down
5 changes: 3 additions & 2 deletions api/oc_resource_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ oc_rt_created_t *oc_rt_factory_create_resource(oc_collection_t *collection,
size_t device);

void oc_rt_factory_free_created_resource(oc_rt_created_t *rtc,
oc_rt_factory_t *rf);
const oc_rt_factory_t *rf);

void oc_rt_factory_free_created_resources(size_t device);

oc_rt_created_t *oc_rt_get_factory_create_for_resource(oc_resource_t *resource);
oc_rt_created_t *oc_rt_get_factory_create_for_resource(
const oc_resource_t *resource);

void oc_fi_factory_free_all_created_resources(void);

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
9 changes: 4 additions & 5 deletions api/oc_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ oc_reset_delayed_callback_ms(void *cb_data, oc_trigger_t callback,
}

bool
oc_has_delayed_callback(void *cb_data, oc_trigger_t callback,
oc_has_delayed_callback(const void *cb_data, oc_trigger_t callback,
bool ignore_cb_data)
{
return oc_ri_has_timed_event_callback(cb_data, callback, ignore_cb_data);
Expand All @@ -242,7 +242,7 @@ oc_remove_delayed_callback_by_filter(oc_trigger_t cb,
}

void
oc_remove_delayed_callback(void *cb_data, oc_trigger_t callback)
oc_remove_delayed_callback(const void *cb_data, oc_trigger_t callback)
{
oc_ri_remove_timed_event_callback(cb_data, callback);
}
Expand Down Expand Up @@ -653,8 +653,7 @@ oc_resource_set_secure_mcast(oc_resource_t *resource, bool supported)
void
oc_set_con_write_cb(oc_con_write_cb_t callback)
{
size_t i;
for (i = 0; i < oc_core_get_num_devices(); i++) {
for (size_t i = 0; i < oc_core_get_num_devices(); i++) {
oc_resource_t *res = oc_core_get_resource_by_index(OCF_CON, i);
if (res) {
res->post_handler.user_data = *(void **)(&callback);
Expand Down Expand Up @@ -754,7 +753,7 @@ handle_separate_response_request(coap_separate_t *request,
response_state->payload_size = (uint32_t)response_buffer->response_length;

uint32_t payload_size = 0;
const void *payload = oc_blockwise_dispatch_block(
void *payload = oc_blockwise_dispatch_block(
response_state, 0, request->block2_size, &payload_size);
if (payload != NULL) {
coap_set_payload(&response, payload, payload_size);
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
2 changes: 1 addition & 1 deletion apps/client_block_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ stop_observe(void *data)

if (oc_init_post(array_1, array_server, NULL, &post_array, LOW_QOS, NULL)) {
for (int i = 0; i < 100; i++) {
large_array[i] = oc_random_value();
large_array[i] = (int)oc_random_value();
OC_PRINTF("(%d %d) ", i, large_array[i]);
}
OC_PRINTF("\n");
Expand Down
Loading

0 comments on commit 664e718

Please sign in to comment.