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

Add OC_API annotations to oc_buffer_settings.h #647

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion api/cloud/oc_cloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
#include "oc_api.h"
#include "oc_collection.h"
#include "oc_core_res.h"
#include "oc_network_monitor.h"
#include "port/oc_assert.h"
#include "util/oc_endpoint_address_internal.h"
#include "util/oc_mmem_internal.h"
#include "util/oc_secure_string_internal.h"

#ifdef OC_NETWORK_MONITOR
#include "oc_network_monitor.h"
#endif /* OC_NETWORK_MONITOR */

#ifdef OC_SECURITY
#include "security/oc_tls_internal.h"
#endif /* OC_SECURITY */
Expand Down
172 changes: 172 additions & 0 deletions api/oc_buffer_settings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/****************************************************************************
*
* Copyright (c) 2017 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License"),
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/

#include "oc_buffer_settings.h"
#include "port/oc_log_internal.h"
#include "util/oc_features.h"

#include <stddef.h>

#ifdef OC_DYNAMIC_ALLOCATION

#include "messaging/coap/conf.h"

#ifdef OC_INOUT_BUFFER_SIZE
static size_t _OC_MTU_SIZE = OC_INOUT_BUFFER_SIZE;
#else /* OC_INOUT_BUFFER_SIZE */
static size_t _OC_MTU_SIZE = 2048 + COAP_MAX_HEADER_SIZE;
#endif /* !OC_INOUT_BUFFER_SIZE */

static size_t _OC_MAX_APP_DATA_SIZE = 7168;
#if defined(OC_APP_DATA_BUFFER_SIZE) || !defined(OC_REP_ENCODING_REALLOC)
static size_t _OC_MIN_APP_DATA_SIZE = 7168;
#else /* OC_APP_DATA_BUFFER_SIZE || !OC_REP_ENCODING_REALLOC */
static size_t _OC_MIN_APP_DATA_SIZE = 256;
#endif /* !OC_APP_DATA_BUFFER_SIZE && OC_REP_ENCODING_REALLOC */
static size_t _OC_BLOCK_SIZE = 1024; // FIX
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Address the FIX comment for _OC_BLOCK_SIZE.

The line:

static size_t _OC_BLOCK_SIZE = 1024; // FIX

includes a // FIX comment. This suggests that this value or implementation needs attention. Ensure that the block size is correctly calculated or defined, and remove the temporary comment once resolved.


int
oc_set_mtu_size(size_t mtu_size)
{
(void)mtu_size;
#ifdef OC_INOUT_BUFFER_SIZE
return -1;
#else /* !OC_INOUT_BUFFER_SIZE */
#ifdef OC_BLOCK_WISE
if (mtu_size < (COAP_MAX_HEADER_SIZE + 16)) {
return -1;
}
#ifdef OC_OSCORE
_OC_MTU_SIZE = mtu_size + COAP_MAX_HEADER_SIZE;
#else /* OC_OSCORE */
_OC_MTU_SIZE = mtu_size;
#endif /* !OC_OSCORE */
mtu_size -= COAP_MAX_HEADER_SIZE;
size_t i;
for (i = 10; i >= 4 && (mtu_size >> i) == 0; i--)
;
_OC_BLOCK_SIZE = ((size_t)1) << i;
#endif /* OC_BLOCK_WISE */
return 0;
#endif /* OC_INOUT_BUFFER_SIZE */
}

long
oc_get_mtu_size(void)
{
return (long)_OC_MTU_SIZE;
}

void
oc_set_max_app_data_size(size_t size)
{
#ifdef OC_APP_DATA_BUFFER_SIZE
(void)size;
#else /* !OC_APP_DATA_BUFFER_SIZE */
_OC_MAX_APP_DATA_SIZE = size;
#ifndef OC_REP_ENCODING_REALLOC
_OC_MIN_APP_DATA_SIZE = size;
#endif /* !OC_REP_ENCODING_REALLOC */
#ifndef OC_BLOCK_WISE
_OC_BLOCK_SIZE = size;
_OC_MTU_SIZE = size + COAP_MAX_HEADER_SIZE;
#endif /* !OC_BLOCK_WISE */
#endif /* OC_APP_DATA_BUFFER_SIZE */
}

long
oc_get_max_app_data_size(void)
{
return (long)_OC_MAX_APP_DATA_SIZE;
}
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved

void
oc_set_min_app_data_size(size_t size)
{
#if defined(OC_APP_DATA_BUFFER_SIZE) || !defined(OC_REP_ENCODING_REALLOC)
(void)size;
#else /* !OC_APP_DATA_BUFFER_SIZE && !OC_REP_ENCODING_REALLOC */
_OC_MIN_APP_DATA_SIZE = size;
#endif /* OC_APP_DATA_BUFFER_SIZE || !OC_REP_ENCODING_REALLOC */
}

long
oc_get_min_app_data_size(void)
{
return (long)_OC_MIN_APP_DATA_SIZE;
}

long
oc_get_block_size(void)
{
return (long)_OC_BLOCK_SIZE;
}

#else /* !OC_DYNAMIC_ALLOCATION */

int
oc_set_mtu_size(size_t mtu_size)
{
(void)mtu_size;
OC_WRN("Dynamic memory not available");
return -1;
}

long
oc_get_mtu_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

void
oc_set_max_app_data_size(size_t size)
{
(void)size;
OC_WRN("Dynamic memory not available");
}

long
oc_get_max_app_data_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

void
oc_set_min_app_data_size(size_t size)
{
(void)size;
OC_WRN("Dynamic memory not available");
}

long
oc_get_min_app_data_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

long
oc_get_block_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}
Danielius1922 marked this conversation as resolved.
Show resolved Hide resolved

#endif /* OC_DYNAMIC_ALLOCATION */
148 changes: 0 additions & 148 deletions api/oc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,154 +98,6 @@ oc_get_factory_presets_cb(void)
return &g_factory_presets;
}

#ifdef OC_DYNAMIC_ALLOCATION
#include "oc_buffer_settings.h"
#ifdef OC_INOUT_BUFFER_SIZE
static size_t _OC_MTU_SIZE = OC_INOUT_BUFFER_SIZE;
#else /* OC_INOUT_BUFFER_SIZE */
static size_t _OC_MTU_SIZE = 2048 + COAP_MAX_HEADER_SIZE;
#endif /* !OC_INOUT_BUFFER_SIZE */
#ifdef OC_APP_DATA_BUFFER_SIZE
static size_t _OC_MAX_APP_DATA_SIZE = 7168;
static size_t _OC_MIN_APP_DATA_SIZE = 7168;
#else /* OC_APP_DATA_BUFFER_SIZE */
static size_t _OC_MAX_APP_DATA_SIZE = 7168;
#ifdef OC_REP_ENCODING_REALLOC
static size_t _OC_MIN_APP_DATA_SIZE = 256;
#else /* OC_REP_ENCODING_REALLOC */
static size_t _OC_MIN_APP_DATA_SIZE = 7168;
#endif /* !OC_REP_ENCODING_REALLOC */
#endif /* !OC_APP_DATA_BUFFER_SIZE */
static size_t _OC_BLOCK_SIZE = 1024; // FIX

int
oc_set_mtu_size(size_t mtu_size)
{
(void)mtu_size;
#ifdef OC_INOUT_BUFFER_SIZE
return -1;
#else /* !OC_INOUT_BUFFER_SIZE */
#ifdef OC_BLOCK_WISE
if (mtu_size < (COAP_MAX_HEADER_SIZE + 16)) {
return -1;
}
#ifdef OC_OSCORE
_OC_MTU_SIZE = mtu_size + COAP_MAX_HEADER_SIZE;
#else /* OC_OSCORE */
_OC_MTU_SIZE = mtu_size;
#endif /* !OC_OSCORE */
mtu_size -= COAP_MAX_HEADER_SIZE;
size_t i;
for (i = 10; i >= 4 && (mtu_size >> i) == 0; i--)
;
_OC_BLOCK_SIZE = ((size_t)1) << i;
#endif /* OC_BLOCK_WISE */
return 0;
#endif /* OC_INOUT_BUFFER_SIZE */
}

long
oc_get_mtu_size(void)
{
return (long)_OC_MTU_SIZE;
}

void
oc_set_max_app_data_size(size_t size)
{
#ifdef OC_APP_DATA_BUFFER_SIZE
(void)size;
#else /* !OC_APP_DATA_BUFFER_SIZE */
_OC_MAX_APP_DATA_SIZE = size;
#ifndef OC_REP_ENCODING_REALLOC
_OC_MIN_APP_DATA_SIZE = size;
#endif /* !OC_REP_ENCODING_REALLOC */
#ifndef OC_BLOCK_WISE
_OC_BLOCK_SIZE = size;
_OC_MTU_SIZE = size + COAP_MAX_HEADER_SIZE;
#endif /* !OC_BLOCK_WISE */
#endif /* OC_APP_DATA_BUFFER_SIZE */
}

long
oc_get_max_app_data_size(void)
{
return (long)_OC_MAX_APP_DATA_SIZE;
}

void
oc_set_min_app_data_size(size_t size)
{
#if defined(OC_APP_DATA_BUFFER_SIZE) || !defined(OC_REP_ENCODING_REALLOC)
(void)size;
#else /* !OC_APP_DATA_BUFFER_SIZE && !OC_REP_ENCODING_REALLOC */
_OC_MIN_APP_DATA_SIZE = size;
#endif /* OC_APP_DATA_BUFFER_SIZE || !OC_REP_ENCODING_REALLOC */
}

long
oc_get_min_app_data_size(void)
{
return (long)_OC_MIN_APP_DATA_SIZE;
}

long
oc_get_block_size(void)
{
return (long)_OC_BLOCK_SIZE;
}
#else /* !OC_DYNAMIC_ALLOCATION */
int
oc_set_mtu_size(size_t mtu_size)
{
(void)mtu_size;
OC_WRN("Dynamic memory not available");
return -1;
}

long
oc_get_mtu_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

void
oc_set_max_app_data_size(size_t size)
{
(void)size;
OC_WRN("Dynamic memory not available");
}

long
oc_get_max_app_data_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

void
oc_set_min_app_data_size(size_t size)
{
(void)size;
OC_WRN("Dynamic memory not available");
}

long
oc_get_min_app_data_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}

long
oc_get_block_size(void)
{
OC_WRN("Dynamic memory not available");
return -1;
}
#endif /* OC_DYNAMIC_ALLOCATION */

static void
oc_shutdown_all_devices(void)
{
Expand Down
2 changes: 1 addition & 1 deletion api/oc_message_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "messaging/coap/engine_internal.h"
#include "oc_signal_event_loop.h"
#include "oc_buffer.h"
#include "port/oc_connectivity.h"
#include "port/oc_connectivity_internal.h"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Inconsistent usage of connectivity headers detected.

The switch to oc_connectivity_internal.h in api/oc_message_buffer.c is not reflected across the codebase, as many other files still include the old oc_connectivity.h.

  • Numerous files continue to include oc_connectivity.h.
  • Ensure that this change is part of a comprehensive refactoring effort and update all dependent files accordingly to prevent potential build or runtime issues.
🔗 Analysis chain

Verify the impact of switching to the internal connectivity header.

The change from oc_connectivity.h to oc_connectivity_internal.h suggests a shift from a public API to an internal one. This could affect the visibility and accessibility of functions or structures used in this file.

Please ensure that:

  1. All functions and structures used from the connectivity header are still accessible.
  2. This change aligns with any ongoing refactoring efforts or API changes in the project.

Run the following script to check for any potential issues:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential issues after changing to internal header

# Test: Look for any connectivity-related function calls that might be affected
rg --type c "oc_(send|recv)_(buffer|message)" api/oc_message_buffer.c

# Test: Check if there are any other files still using the old header
rg --type c '#include.*oc_connectivity\.h'

# Test: Verify if the new internal header exists
fd oc_connectivity_internal.h

Length of output: 3521

#include "util/oc_features.h"
#include "util/oc_process.h"

Expand Down
1 change: 0 additions & 1 deletion api/oc_session_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "api/oc_session_events_internal.h"
#include "oc_api.h"
#include "oc_buffer.h"
#include "oc_network_monitor.h"
#include "oc_session_events.h"
#include "oc_signal_event_loop.h"
#include "port/oc_connectivity_internal.h"
Expand Down
7 changes: 7 additions & 0 deletions api/plgd/device-provisioning-client/plgd_dps.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
#include "api/oc_tcp_internal.h"
#include "oc_certs.h"
#include "oc_core_res.h"

#ifdef OC_NETWORK_MONITOR
#include "oc_network_monitor.h"
#endif /* OC_NETWORK_MONITOR */

#include <assert.h>
#include <inttypes.h>
Expand Down Expand Up @@ -226,13 +229,17 @@ plgd_dps_session_callbacks_deinit(plgd_dps_context_t *ctx)
void
plgd_dps_interface_callbacks_init(void)
{
#ifdef OC_NETWORK_MONITOR
oc_add_network_interface_event_callback(dps_interface_event_handler);
#endif /* OC_NETWORK_MONITOR */
}

void
plgd_dps_interface_callbacks_deinit(void)
{
#ifdef OC_NETWORK_MONITOR
oc_remove_network_interface_event_callback(dps_interface_event_handler);
#endif /* OC_NETWORK_MONITOR */
}

#endif /* OC_SESSION_EVENTS */
Expand Down
1 change: 0 additions & 1 deletion api/plgd/device-provisioning-client/plgd_dps_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "plgd_dps_internal.h"

#include "oc_cred.h"
#include "oc_network_monitor.h"
#include "security/oc_cred_util_internal.h"
#include "util/oc_list.h"

Expand Down
Loading
Loading