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

Remove dependency on config from coreMQTT headers #274

Merged
merged 4 commits into from
Feb 1, 2024
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
2 changes: 0 additions & 2 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
/* Include config defaults header to get default values of configs. */
#include "core_mqtt_config_defaults.h"

#include "core_mqtt_default_logging.h"

#ifndef MQTT_PRE_SEND_HOOK

/**
Expand Down
2 changes: 0 additions & 2 deletions source/core_mqtt_serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
/* Include config defaults header to get default values of configs. */
#include "core_mqtt_config_defaults.h"

#include "core_mqtt_default_logging.h"

/**
* @brief MQTT protocol version 3.1.1.
*/
Expand Down
2 changes: 0 additions & 2 deletions source/core_mqtt_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
/* Include config defaults header to get default values of configs. */
#include "core_mqtt_config_defaults.h"

#include "core_mqtt_default_logging.h"

/*-----------------------------------------------------------*/

/**
Expand Down
80 changes: 80 additions & 0 deletions source/include/core_mqtt_config_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,86 @@
#error MQTT_SEND_RETRY_TIMEOUT_MS is deprecated. Instead use MQTT_SEND_TIMEOUT_MS.
#endif

/**
* @brief Macro that is called in the MQTT library for logging "Error" level
* messages.
*
* To enable error level logging in the MQTT library, this macro should be mapped to the
* application-specific logging implementation that supports error logging.
*
* @note This logging macro is called in the MQTT library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C).
*
* <b>Default value</b>: Error logging is turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogError
#define LogError( message )
#endif

/**
* @brief Macro that is called in the MQTT library for logging "Warning" level
* messages.
*
* To enable warning level logging in the MQTT library, this macro should be mapped to the
* application-specific logging implementation that supports warning logging.
*
* @note This logging macro is called in the MQTT library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
*
* <b>Default value</b>: Warning logs are turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogWarn
#define LogWarn( message )
#endif

/**
* @brief Macro that is called in the MQTT library for logging "Info" level
* messages.
*
* To enable info level logging in the MQTT library, this macro should be mapped to the
* application-specific logging implementation that supports info logging.
*
* @note This logging macro is called in the MQTT library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
*
* <b>Default value</b>: Info logging is turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogInfo
#define LogInfo( message )
#endif

/**
* @brief Macro that is called in the MQTT library for logging "Debug" level
* messages.
*
* To enable debug level logging from MQTT library, this macro should be mapped to the
* application-specific logging implementation that supports debug logging.
*
* @note This logging macro is called in the MQTT library with parameters wrapped in
* double parentheses to be ISO C89/C90 standard compliant. For a reference
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
* logging-stack in demos folder of the
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
*
* <b>Default value</b>: Debug logging is turned off, and no code is generated for calls
* to the macro in the MQTT library on compilation.
*/
#ifndef LogDebug
#define LogDebug( message )
#endif

/* *INDENT-OFF* */
#ifdef __cplusplus
}
Expand Down
132 changes: 0 additions & 132 deletions source/include/core_mqtt_default_logging.h

This file was deleted.

12 changes: 0 additions & 12 deletions source/include/core_mqtt_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@
#endif
/* *INDENT-ON */

/* MQTT_DO_NOT_USE_CUSTOM_CONFIG allows building the MQTT library
* without a custom config. If a custom config is provided, the
* MQTT_DO_NOT_USE_CUSTOM_CONFIG macro should not be defined. */
#ifndef MQTT_DO_NOT_USE_CUSTOM_CONFIG
/* Include custom config file before other headers. */
#include "core_mqtt_config.h"
#endif

/* Include config defaults header to get default values of configs not
* defined in core_mqtt_config.h file. */
#include "core_mqtt_config_defaults.h"

#include "transport_interface.h"

/* MQTT packet types. */
Expand Down
6 changes: 0 additions & 6 deletions test/cbmc/include/core_mqtt_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
#ifndef CORE_MQTT_CONFIG_H_
#define CORE_MQTT_CONFIG_H_

/* Mock a network context for the CBMC proofs. */
struct NetworkContext
{
int NetworkContext;
};

/**
* @brief Determines the maximum number of MQTT PUBLISH messages, pending
* acknowledgement at a time, that are supported for incoming and outgoing
Expand Down
1 change: 1 addition & 0 deletions test/cbmc/proofs/MQTT_Connect/MQTT_Connect_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
#include "core_mqtt.h"
#include "mqtt_cbmc_state.h"
#include "core_mqtt_config_defaults.h"

/**
* @brief Implement a get time function to return timeout after certain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include "network_interface_stubs.h"
#include "mqtt_cbmc_state.h"

struct NetworkContext
{
int NetworkContext;
};

void harness()
{
/* NetworkContext_t is an application defined network interface context. It
Expand Down
1 change: 1 addition & 0 deletions test/cbmc/proofs/MQTT_Publish/MQTT_Publish_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
#include "core_mqtt.h"
#include "mqtt_cbmc_state.h"
#include "core_mqtt_config_defaults.h"

/**
* @brief Implement a get time function to return timeout after certain
Expand Down
1 change: 1 addition & 0 deletions test/cbmc/proofs/MQTT_Subscribe/MQTT_Subscribe_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
#include "core_mqtt.h"
#include "mqtt_cbmc_state.h"
#include "core_mqtt_config_defaults.h"

/**
* @brief Implement a get time function to return timeout after certain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
#include "core_mqtt.h"
#include "mqtt_cbmc_state.h"
#include "core_mqtt_config_defaults.h"

/**
* @brief Implement a get time function to return timeout after certain
Expand Down
36 changes: 36 additions & 0 deletions test/unit-test/cmock_opaque_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* coreMQTT v2.1.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef CMOCK_OPAQUE_TYPES_H_
#define CMOCK_OPAQUE_TYPES_H_

/* CMock does not support opaque types so needs concrete definitions for them.
* This file is included in CMock .c files. */

struct NetworkContext
{
int a;
};

#endif /* ifndef CMOCK_OPAQUE_TYPES_H_ */
10 changes: 2 additions & 8 deletions test/unit-test/core_mqtt_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,8 @@
*/
#define MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT ( 2U )

/* Set network context to double pointer to buffer (uint8_t**). */
struct NetworkContext
{
uint8_t ** buffer;
};
#define MQTT_SUB_UNSUB_MAX_VECTORS ( 6U )

#define MQTT_SUB_UNSUB_MAX_VECTORS ( 6U )

#define MQTT_SEND_TIMEOUT_MS ( 20U )
#define MQTT_SEND_TIMEOUT_MS ( 20U )

#endif /* ifndef CORE_MQTT_CONFIG_H_ */
7 changes: 7 additions & 0 deletions test/unit-test/core_mqtt_serializer_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@
* @brief Unit tests for functions in core_mqtt_serializer.h.
*/
#include <string.h>
#include <stdint.h>

#include "unity.h"

/* Include paths for public enums, structures, and macros. */
#include "core_mqtt_serializer.h"

/* Set network context to double pointer to buffer (uint8_t**). */
struct NetworkContext
{
uint8_t ** buffer;
};

#define MQTT_MAX_REMAINING_LENGTH ( 268435455UL )
#define MQTT_PACKET_CONNACK_REMAINING_LENGTH ( ( uint8_t ) 2U ) /**< @brief A CONNACK packet always has a "Remaining length" of 2. */
#define MQTT_PACKET_CONNACK_SESSION_PRESENT_MASK ( ( uint8_t ) 0x01U ) /**< @brief The "Session Present" bit is always the lowest bit. */
Expand Down
Loading
Loading