From e4b351b682fd0ed7a6c13e4d2d113dc23ad7c4bc Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Fri, 27 Sep 2024 19:56:08 +0200 Subject: [PATCH] Add OC_API annotations to oc_buffer_settings.h --- api/oc_buffer_settings.c | 176 +++++++++++++++++++++++++++++++++++ api/oc_main.c | 148 ----------------------------- include/oc_buffer_settings.h | 9 ++ 3 files changed, 185 insertions(+), 148 deletions(-) create mode 100644 api/oc_buffer_settings.c diff --git a/api/oc_buffer_settings.c b/api/oc_buffer_settings.c new file mode 100644 index 0000000000..d9977da5eb --- /dev/null +++ b/api/oc_buffer_settings.c @@ -0,0 +1,176 @@ +/**************************************************************************** + * + * 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 + +#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 */ +#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 */ diff --git a/api/oc_main.c b/api/oc_main.c index b3b3f91463..6ba495d2bc 100644 --- a/api/oc_main.c +++ b/api/oc_main.c @@ -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) { diff --git a/include/oc_buffer_settings.h b/include/oc_buffer_settings.h index 1f88472a9f..a9735c19a4 100644 --- a/include/oc_buffer_settings.h +++ b/include/oc_buffer_settings.h @@ -21,6 +21,8 @@ #ifndef OC_BUFFER_SETTINGS_H #define OC_BUFFER_SETTINGS_H +#include "oc_export.h" + #include #ifdef __cplusplus @@ -33,6 +35,7 @@ extern "C" { * @param mtu_size size in bytes * @return int 0-success */ +OC_API int oc_set_mtu_size(size_t mtu_size); /** @@ -40,6 +43,7 @@ int oc_set_mtu_size(size_t mtu_size); * * @return long the MTU size in bytes */ +OC_API long oc_get_mtu_size(void); /** @@ -47,6 +51,7 @@ long oc_get_mtu_size(void); * * @param size size in bytes */ +OC_API void oc_set_max_app_data_size(size_t size); /** @@ -54,6 +59,7 @@ void oc_set_max_app_data_size(size_t size); * * @return long size in bytes */ +OC_API long oc_get_max_app_data_size(void); /** @@ -62,6 +68,7 @@ long oc_get_max_app_data_size(void); * * @param size size in bytes */ +OC_API void oc_set_min_app_data_size(size_t size); /** @@ -69,6 +76,7 @@ void oc_set_min_app_data_size(size_t size); * * @return long size in bytes */ +OC_API long oc_get_min_app_data_size(void); /** @@ -76,6 +84,7 @@ long oc_get_min_app_data_size(void); * * @return long the block size in bytes */ +OC_API long oc_get_block_size(void); #ifdef __cplusplus