| /* |
| * |
| * Copyright (c) 2020 Project CHIP Authors |
| * Copyright (c) 2016-2017 Nest Labs, Inc. |
| * |
| * 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. |
| */ |
| |
| /** |
| * @file |
| * This file contains declaration statements for CHIP System |
| * Layer-specific errors. |
| * |
| * Error types, ranges, and mappings overrides may be made by |
| * defining the appropriate CHIP_SYSTEM_CONFIG_* or * |
| * _CHIP_SYSTEM_CONFIG_* macros. |
| * |
| * NOTE WELL: On some platforms, this header is included by |
| * C-language programs. |
| */ |
| |
| #ifndef SYSTEMERROR_H |
| #define SYSTEMERROR_H |
| |
| // Include headers |
| #include <SystemConfig.h> |
| |
| #if CHIP_SYSTEM_CONFIG_USE_LWIP |
| #include <lwip/err.h> |
| #endif // CHIP_SYSTEM_CONFIG_USE_LWIP |
| |
| /** |
| * @def CHIP_SYSTEM_NO_ERROR |
| * |
| * @brief |
| * This macro expands to a constant expression representing the error code for success or no error. Its definition may be |
| * configured via the #CHIP_SYSTEM_CONFIG_NO_ERROR configuration variable. |
| */ |
| #define CHIP_SYSTEM_NO_ERROR CHIP_SYSTEM_CONFIG_NO_ERROR |
| |
| /** |
| * @def CHIP_SYSTEM_CONFIG_ERROR_MIN |
| * |
| * @brief |
| * This macro expands to a constant expression representing the minimum code number for error conditions in the CHIP System |
| * Layer. This value may be configured via #CHIP_SYSTEM_CONFIG_ERROR_MIN. |
| */ |
| #ifdef CHIP_SYSTEM_CONFIG_ERROR_MIN |
| #define CHIP_SYSTEM_ERROR_MIN CHIP_SYSTEM_CONFIG_ERROR_MIN |
| #endif // CHIP_SYSTEM_CONFIG_ERROR_MIN |
| |
| /** |
| * @def CHIP_SYSTEM_CONFIG_ERROR_MAX |
| * |
| * @brief |
| * This macro expands to a constant expression representing the maximum code number for error conditions in the CHIP System |
| * Layer. This value may be configured via #CHIP_SYSTEM_CONFIG_ERROR_MAX. |
| */ |
| #ifdef CHIP_SYSTEM_CONFIG_ERROR_MAX |
| #define CHIP_SYSTEM_ERROR_MAX CHIP_SYSTEM_CONFIG_ERROR_MAX |
| #endif // CHIP_SYSTEM_CONFIG_ERROR_MAX |
| |
| #ifdef _CHIP_SYSTEM_CONFIG_ERROR |
| |
| /** |
| * @def _CHIP_SYSTEM_ERROR(e) |
| * |
| * @brief |
| * This defines a mapping function for CHIP System Layer errors that allows mapping such errors into a platform- or |
| * system-specific range. This function may be configured via #_CHIP_SYSTEM_CONFIG_ERROR(e). |
| * |
| * @param[in] e The CHIP System Layer error to map. |
| * |
| * @return The mapped CHIP System Layer error. |
| */ |
| #define _CHIP_SYSTEM_ERROR(e) _CHIP_SYSTEM_CONFIG_ERROR(e) |
| |
| /** |
| * @name Error Definitions |
| * |
| * @{ |
| */ |
| |
| /** |
| * @def CHIP_SYSTEM_ERROR_NOT_IMPLEMENTED |
| * |
| * @brief |
| * A requested function has not been implemented. |
| */ |
| #define CHIP_SYSTEM_ERROR_NOT_IMPLEMENTED _CHIP_SYSTEM_ERROR(0) |
| |
| /** |
| * @def CHIP_SYSTEM_ERROR_NOT_SUPPORTED |
| * |
| * @brief |
| * A requested function or feature is not supported. |
| */ |
| #define CHIP_SYSTEM_ERROR_NOT_SUPPORTED _CHIP_SYSTEM_ERROR(1) |
| |
| /** |
| * @def CHIP_SYSTEM_ERROR_BAD_ARGS |
| * |
| * @brief |
| * An invalid argument or arguments were supplied. |
| */ |
| #define CHIP_SYSTEM_ERROR_BAD_ARGS _CHIP_SYSTEM_ERROR(2) |
| |
| /** |
| * @def CHIP_SYSTEM_ERROR_UNEXPECTED_STATE |
| * |
| * @brief |
| * An unexpected state was encountered. |
| */ |
| #define CHIP_SYSTEM_ERROR_UNEXPECTED_STATE _CHIP_SYSTEM_ERROR(3) |
| |
| /** |
| * @def CHIP_SYSTEM_ERROR_UNEXPECTED_EVENT |
| * |
| * @brief |
| * An unexpected event was encountered. |
| */ |
| #define CHIP_SYSTEM_ERROR_UNEXPECTED_EVENT _CHIP_SYSTEM_ERROR(4) |
| |
| /** |
| * @def CHIP_SYSTEM_ERROR_NO_MEMORY |
| * |
| * @brief |
| * A request for memory could not be fulfilled. |
| */ |
| #define CHIP_SYSTEM_ERROR_NO_MEMORY _CHIP_SYSTEM_ERROR(5) |
| |
| /** |
| * @def CHIP_SYSTEM_ERROR_REAL_TIME_NOT_SYNCED |
| * |
| * @brief |
| * The system's real time clock is not synchronized to an accurate time source. |
| */ |
| #define CHIP_SYSTEM_ERROR_REAL_TIME_NOT_SYNCED _CHIP_SYSTEM_ERROR(6) |
| |
| /** |
| * @def CHIP_SYSTEM_ERROR_ACCESS_DENIED |
| * |
| * @brief |
| * The requestor is not privileged to perform the requested operation. |
| */ |
| #define CHIP_SYSTEM_ERROR_ACCESS_DENIED _CHIP_SYSTEM_ERROR(7) |
| |
| // !!!!! IMPORTANT !!!!! |
| // |
| // If you add new CHIP System Layer errors, please update the translation of error |
| // codes to strings in SystemError.cpp, and add them to unittest in test-apps/TestErrorStr.cpp |
| |
| #endif // _CHIP_SYSTEM_CONFIG_ERROR |
| |
| /** |
| * @} |
| */ |
| |
| #ifdef __cplusplus |
| |
| namespace chip { |
| namespace System { |
| |
| /** |
| * The basic type for all chip::System errors. |
| * |
| * This is defined to a platform- or system-specific type. |
| */ |
| typedef CHIP_SYSTEM_CONFIG_ERROR_TYPE Error; |
| |
| extern void RegisterSystemLayerErrorFormatter(void); |
| extern bool FormatSystemLayerError(char * buf, uint16_t bufSize, int32_t err); |
| |
| extern Error MapErrorPOSIX(int code); |
| extern const char * DescribeErrorPOSIX(Error code); |
| extern bool IsErrorPOSIX(Error code); |
| extern void RegisterPOSIXErrorFormatter(void); |
| extern bool FormatPOSIXError(char * buf, uint16_t bufSize, int32_t err); |
| |
| #if CHIP_SYSTEM_CONFIG_USE_LWIP |
| |
| extern Error MapErrorLwIP(err_t code); |
| extern const char * DescribeErrorLwIP(Error code); |
| extern bool IsErrorLwIP(Error code); |
| extern void RegisterLwIPErrorFormatter(void); |
| extern bool FormatLwIPError(char * buf, uint16_t bufSize, int32_t err); |
| |
| #endif // CHIP_SYSTEM_CONFIG_USE_LWIP |
| |
| } // namespace System |
| } // namespace chip |
| |
| #endif // !defined(__cplusplus) |
| #endif // defined(SYSTEMERROR_H) |