Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues reported by clang-tidy #473

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ jobs:
- args: "-DOC_IPV4_ENABLED=ON -DOC_TCP_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF"
# ipv4 on, tcp on, pki off
- args: "-DOC_IPV4_ENABLED=ON -DOC_TCP_ENABLED=ON -DOC_PKI_ENABLED=OFF"
# cloud on (ipv4+tcp on), collections create on, maintenance resource on
# 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, 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 All @@ -66,7 +68,7 @@ jobs:
- args: "-DOC_SECURITY_ENABLED=OFF -DOC_TCP_ENABLED=ON -DOC_IPV4_ENABLED=ON"
# /oic/res observable on, rep realloc on
- args: "-DOC_DISCOVERY_RESOURCE_OBSERVABLE_ENABLED=ON -DOC_REPRESENTATION_REALLOC_ENCODING_ENABLED=ON"
# everything off (dynamic allocation off, secure off, pki off, idd off, oscore off, well-known core resource off, software update off, push notifications off, plgd-time off, introspection off)
# everything off (dynamic allocation off, secure off, pki off, idd off, oscore off, well-known core resource off, software update off, , maintenance resource off, push notifications off, plgd-time off, introspection off)
- args: "-DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_SECURITY_ENABLED=OFF -DOC_PKI_ENABLED=OFF -DOC_IDD_API_ENABLED=OFF -DOC_OSCORE_ENABLED=OFF -DOC_WKCORE_ENABLED=OFF -DOC_SOFTWARE_UPDATE_ENABLED=OFF -DOC_MNT_ENABLED=OFF -DOC_PUSH_ENABLED=OFF -DPLGD_DEV_TIME_ENABLED=OFF -DOC_INTROSPECTION_ENABLED=OFF"
uses: ./.github/workflows/unit-test-with-cfg.yml
with:
Expand Down
36 changes: 36 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +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 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 @@ -363,6 +367,38 @@ if(OC_MEMORY_TRACE_ENABLED)
list(APPEND TEST_COMPILE_DEFINITIONS "OC_MEMORY_TRACE")
endif()

if (NOT("${OC_INOUT_BUFFER_SIZE}" STREQUAL ""))
if(NOT OC_DYNAMIC_ALLOCATION_ENABLED)
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}" 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 static pool size for application messages without dynamic allocation")
endif()
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)
list(APPEND PUBLIC_COMPILE_DEFINITIONS "PLGD_DEV_TIME")
if(BUILD_MBEDTLS)
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
4 changes: 2 additions & 2 deletions api/oc_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ OC_PROCESS(oc_message_buffer_handler, "OC Message Buffer Handler");
#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 */
#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 */
#endif /* OC_INOUT_BUFFER_POOL */

static void
message_deallocate(oc_message_t *message, struct oc_memb *pool)
Expand Down
15 changes: 8 additions & 7 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 @@ -108,8 +108,8 @@ dispatch_coap_request(void)
}

bool success = false;
g_dispatch.transaction->message->length =
coap_serialize_message(g_request, g_dispatch.transaction->message->data);
g_dispatch.transaction->message->length = coap_serialize_message(
g_request, g_dispatch.transaction->message->data, oc_message_buffer_size());
if (g_dispatch.transaction->message->length > 0) {
coap_send_transaction(g_dispatch.transaction);

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 @@ -265,8 +266,8 @@ oc_do_multicast_update(void)
coap_set_header_content_format(g_request, APPLICATION_VND_OCF_CBOR);
}

g_multicast_update->length =
coap_serialize_message(g_request, g_multicast_update->data);
g_multicast_update->length = coap_serialize_message(
g_request, g_multicast_update->data, oc_message_buffer_size());
if (g_multicast_update->length > 0) {
oc_send_message(g_multicast_update);
} else {
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
15 changes: 8 additions & 7 deletions api/oc_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
****************************************************************************/

#include "oc_server_api_internal.h"
#include "api/oc_buffer_internal.h"
#include "api/oc_ri_internal.h"
#include "messaging/coap/engine.h"
#include "messaging/coap/oc_coap.h"
Expand All @@ -25,6 +25,7 @@
#include "oc_api.h"
#include "oc_core_res.h"
#include "oc_core_res_internal.h"
#include "oc_server_api_internal.h"
#include "port/oc_log_internal.h"
#include "util/oc_features.h"
#include "util/oc_macros_internal.h"
Expand Down Expand Up @@ -224,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 @@ -241,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 @@ -652,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 @@ -697,7 +697,8 @@ handle_separate_response_transaction(coap_transaction_t *t,
uint8_t response_code)
{
coap_set_status_code(response, response_code);
t->message->length = coap_serialize_message(response, t->message->data);
t->message->length = coap_serialize_message(response, t->message->data,
oc_message_buffer_size());
if (t->message->length <= 0) {
coap_clear_transaction(t);
return;
Expand Down Expand Up @@ -752,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
Loading