2 * Amazon FreeRTOS Common V1.0.0
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://aws.amazon.com/freertos
\r
23 * http://www.FreeRTOS.org
\r
28 * @brief Provides macros for error checking and function cleanup.
\r
30 * The macros in this file are generic. They may be customized by each library
\r
31 * by setting the library prefix.
\r
34 #ifndef IOT_ERROR_H_
\r
35 #define IOT_ERROR_H_
\r
37 /* The config header is always included first. */
\r
38 #include "iot_config.h"
\r
41 * @brief Declare the status variable and an initial value.
\r
43 * This macro should be at the beginning of any functions that use cleanup sections.
\r
45 * @param[in] statusType The type of the status variable for this function.
\r
46 * @param[in] initialValue The initial value to assign to the status variable.
\r
48 #define IOT_FUNCTION_ENTRY( statusType, initialValue ) statusType status = initialValue
\r
51 * @brief Declares the label that begins a cleanup section.
\r
53 * This macro should be placed at the end of a function and followed by
\r
54 * #IOT_FUNCTION_CLEANUP_END.
\r
56 #define IOT_FUNCTION_CLEANUP_BEGIN() iotCleanup:
\r
59 * @brief Declares the end of a cleanup section.
\r
61 * This macro should be placed at the end of a function and preceded by
\r
62 * #IOT_FUNCTION_CLEANUP_BEGIN.
\r
64 #define IOT_FUNCTION_CLEANUP_END() return status
\r
67 * @brief Declares an empty cleanup section.
\r
69 * This macro should be placed at the end of a function to exit on error if no
\r
70 * cleanup is required.
\r
72 #define IOT_FUNCTION_EXIT_NO_CLEANUP() IOT_FUNCTION_CLEANUP_BEGIN(); IOT_FUNCTION_CLEANUP_END()
\r
75 * @brief Jump to the cleanup section.
\r
77 #define IOT_GOTO_CLEANUP() goto iotCleanup
\r
80 * @brief Assign a value to the status variable and jump to the cleanup section.
\r
82 * @param[in] statusValue The value to assign to the status variable.
\r
84 #define IOT_SET_AND_GOTO_CLEANUP( statusValue ) { status = ( statusValue ); IOT_GOTO_CLEANUP(); }
\r
87 * @brief Jump to the cleanup section if a condition is `false`.
\r
89 * This macro may be used in place of `assert` to exit a function is a condition
\r
92 * @param[in] condition The condition to check.
\r
94 #define IOT_GOTO_CLEANUP_IF_FALSE( condition ) { if( ( condition ) == false ) { IOT_GOTO_CLEANUP(); } }
\r
97 * @brief Assign a value to the status variable and jump to the cleanup section
\r
98 * if a condition is `false`.
\r
100 * @param[in] statusValue The value to assign to the status variable.
\r
101 * @param[in] condition The condition to check.
\r
103 #define IOT_SET_AND_GOTO_CLEANUP_IF_FALSE( statusValue, condition ) \
\r
104 if( ( condition ) == false ) \
\r
105 IOT_SET_AND_GOTO_CLEANUP( statusValue )
\r
108 * @brief Check a condition; if `false`, assign the "Bad parameter" status value
\r
109 * and jump to the cleanup section.
\r
111 * @param[in] libraryPrefix The library prefix of the status variable.
\r
112 * @param[in] condition The condition to check.
\r
114 #define IOT_VALIDATE_PARAMETER( libraryPrefix, condition ) \
\r
115 IOT_SET_AND_GOTO_CLEANUP_IF_FALSE( libraryPrefix ## _BAD_PARAMETER, condition )
\r
117 #endif /* ifndef IOT_ERROR_H_ */
\r