Skip to content

Commit b313f0b

Browse files
authored
Remove config header include in coreMQTT headers (#189)
core_mqtt.h and other coreMQTT headers pull in core_mqtt_config.h and core_mqtt_config_defaults.h. core_mqtt_config_defaults.h defines empty logging macros. This means every application that uses coreMQTT needs to be careful to set up the logging stack before including core_mqtt.h or they may mysteriously not have logging output. The logging setup should be in each compilation object, not set up in headers. This moves the inclusion of default logging macros from the headers to the library c files. This fixes the issue with the logging macros for customers who do not set the logging macros in their core_mqtt_config.h. However, those who do enable logging for coreMQTT will still have their coreMQTT logging setup in all their c files using coreMQTT.
1 parent 76eb955 commit b313f0b

File tree

6 files changed

+134
-80
lines changed

6 files changed

+134
-80
lines changed

lexicon.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ headersize
9999
html
100100
http
101101
https
102+
ifdef
102103
ifndef
103104
img
104105
inc

source/core_mqtt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "core_mqtt.h"
3131
#include "core_mqtt_state.h"
32+
#include "core_mqtt_default_logging.h"
3233

3334
/*-----------------------------------------------------------*/
3435

source/core_mqtt_serializer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <assert.h>
2929

3030
#include "core_mqtt_serializer.h"
31+
#include "core_mqtt_default_logging.h"
3132

3233
/**
3334
* @brief MQTT protocol version 3.1.1.

source/core_mqtt_state.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <assert.h>
2828
#include <string.h>
2929
#include "core_mqtt_state.h"
30+
#include "core_mqtt_default_logging.h"
3031

3132
/*-----------------------------------------------------------*/
3233

source/include/core_mqtt_config_defaults.h

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -173,86 +173,6 @@
173173
#define MQTT_SEND_RETRY_TIMEOUT_MS ( 10U )
174174
#endif
175175

176-
/**
177-
* @brief Macro that is called in the MQTT library for logging "Error" level
178-
* messages.
179-
*
180-
* To enable error level logging in the MQTT library, this macro should be mapped to the
181-
* application-specific logging implementation that supports error logging.
182-
*
183-
* @note This logging macro is called in the MQTT library with parameters wrapped in
184-
* double parentheses to be ISO C89/C90 standard compliant. For a reference
185-
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
186-
* logging-stack in demos folder of the
187-
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C).
188-
*
189-
* <b>Default value</b>: Error logging is turned off, and no code is generated for calls
190-
* to the macro in the MQTT library on compilation.
191-
*/
192-
#ifndef LogError
193-
#define LogError( message )
194-
#endif
195-
196-
/**
197-
* @brief Macro that is called in the MQTT library for logging "Warning" level
198-
* messages.
199-
*
200-
* To enable warning level logging in the MQTT library, this macro should be mapped to the
201-
* application-specific logging implementation that supports warning logging.
202-
*
203-
* @note This logging macro is called in the MQTT library with parameters wrapped in
204-
* double parentheses to be ISO C89/C90 standard compliant. For a reference
205-
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
206-
* logging-stack in demos folder of the
207-
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
208-
*
209-
* <b>Default value</b>: Warning logs are turned off, and no code is generated for calls
210-
* to the macro in the MQTT library on compilation.
211-
*/
212-
#ifndef LogWarn
213-
#define LogWarn( message )
214-
#endif
215-
216-
/**
217-
* @brief Macro that is called in the MQTT library for logging "Info" level
218-
* messages.
219-
*
220-
* To enable info level logging in the MQTT library, this macro should be mapped to the
221-
* application-specific logging implementation that supports info logging.
222-
*
223-
* @note This logging macro is called in the MQTT library with parameters wrapped in
224-
* double parentheses to be ISO C89/C90 standard compliant. For a reference
225-
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
226-
* logging-stack in demos folder of the
227-
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
228-
*
229-
* <b>Default value</b>: Info logging is turned off, and no code is generated for calls
230-
* to the macro in the MQTT library on compilation.
231-
*/
232-
#ifndef LogInfo
233-
#define LogInfo( message )
234-
#endif
235-
236-
/**
237-
* @brief Macro that is called in the MQTT library for logging "Debug" level
238-
* messages.
239-
*
240-
* To enable debug level logging from MQTT library, this macro should be mapped to the
241-
* application-specific logging implementation that supports debug logging.
242-
*
243-
* @note This logging macro is called in the MQTT library with parameters wrapped in
244-
* double parentheses to be ISO C89/C90 standard compliant. For a reference
245-
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
246-
* logging-stack in demos folder of the
247-
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
248-
*
249-
* <b>Default value</b>: Debug logging is turned off, and no code is generated for calls
250-
* to the macro in the MQTT library on compilation.
251-
*/
252-
#ifndef LogDebug
253-
#define LogDebug( message )
254-
#endif
255-
256176
/* *INDENT-OFF* */
257177
#ifdef __cplusplus
258178
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* coreMQTT v1.2.0
3+
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
* this software and associated documentation files (the "Software"), to deal in
7+
* the Software without restriction, including without limitation the rights to
8+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
* the Software, and to permit persons to whom the Software is furnished to do so,
10+
* subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
/**
24+
* @file core_mqtt_default_logging.h
25+
* @brief This represents the default values for the logging macros for the MQTT
26+
* library.
27+
*
28+
* @note This file SHOULD NOT be modified. If custom values are needed for
29+
* any configuration macro, a core_mqtt_config.h file should be provided to
30+
* the MQTT library to override the default values defined in this file.
31+
* To use the custom config file, the MQTT_DO_NOT_USE_CUSTOM_CONFIG preprocessor
32+
* macro SHOULD NOT be set.
33+
*/
34+
35+
#ifndef CORE_MQTT_DEFAULT_LOGGING_H_
36+
#define CORE_MQTT_DEFAULT_LOGGING_H_
37+
38+
/* *INDENT-OFF* */
39+
#ifdef __cplusplus
40+
extern "C" {
41+
#endif
42+
/* *INDENT-ON* */
43+
44+
/**
45+
* @brief Macro that is called in the MQTT library for logging "Error" level
46+
* messages.
47+
*
48+
* To enable error level logging in the MQTT library, this macro should be mapped to the
49+
* application-specific logging implementation that supports error logging.
50+
*
51+
* @note This logging macro is called in the MQTT library with parameters wrapped in
52+
* double parentheses to be ISO C89/C90 standard compliant. For a reference
53+
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
54+
* logging-stack in demos folder of the
55+
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C).
56+
*
57+
* <b>Default value</b>: Error logging is turned off, and no code is generated for calls
58+
* to the macro in the MQTT library on compilation.
59+
*/
60+
#ifndef LogError
61+
#define LogError( message )
62+
#endif
63+
64+
/**
65+
* @brief Macro that is called in the MQTT library for logging "Warning" level
66+
* messages.
67+
*
68+
* To enable warning level logging in the MQTT library, this macro should be mapped to the
69+
* application-specific logging implementation that supports warning logging.
70+
*
71+
* @note This logging macro is called in the MQTT library with parameters wrapped in
72+
* double parentheses to be ISO C89/C90 standard compliant. For a reference
73+
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
74+
* logging-stack in demos folder of the
75+
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
76+
*
77+
* <b>Default value</b>: Warning logs are turned off, and no code is generated for calls
78+
* to the macro in the MQTT library on compilation.
79+
*/
80+
#ifndef LogWarn
81+
#define LogWarn( message )
82+
#endif
83+
84+
/**
85+
* @brief Macro that is called in the MQTT library for logging "Info" level
86+
* messages.
87+
*
88+
* To enable info level logging in the MQTT library, this macro should be mapped to the
89+
* application-specific logging implementation that supports info logging.
90+
*
91+
* @note This logging macro is called in the MQTT library with parameters wrapped in
92+
* double parentheses to be ISO C89/C90 standard compliant. For a reference
93+
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
94+
* logging-stack in demos folder of the
95+
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
96+
*
97+
* <b>Default value</b>: Info logging is turned off, and no code is generated for calls
98+
* to the macro in the MQTT library on compilation.
99+
*/
100+
#ifndef LogInfo
101+
#define LogInfo( message )
102+
#endif
103+
104+
/**
105+
* @brief Macro that is called in the MQTT library for logging "Debug" level
106+
* messages.
107+
*
108+
* To enable debug level logging from MQTT library, this macro should be mapped to the
109+
* application-specific logging implementation that supports debug logging.
110+
*
111+
* @note This logging macro is called in the MQTT library with parameters wrapped in
112+
* double parentheses to be ISO C89/C90 standard compliant. For a reference
113+
* POSIX implementation of the logging macros, refer to core_mqtt_config.h files, and the
114+
* logging-stack in demos folder of the
115+
* [AWS IoT Embedded C SDK repository](https://github.com/aws/aws-iot-device-sdk-embedded-C/).
116+
*
117+
* <b>Default value</b>: Debug logging is turned off, and no code is generated for calls
118+
* to the macro in the MQTT library on compilation.
119+
*/
120+
#ifndef LogDebug
121+
#define LogDebug( message )
122+
#endif
123+
124+
/* *INDENT-OFF* */
125+
#ifdef __cplusplus
126+
}
127+
#endif
128+
/* *INDENT-ON* */
129+
130+
#endif /* ifndef CORE_MQTT_DEFAULT_LOGGING_H_ */

0 commit comments

Comments
 (0)