-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2170 from elBoberido/iox-1032-port-to-new-error-h…
…andling iox-#1032 Port to new error handling
- Loading branch information
Showing
213 changed files
with
1,435 additions
and
2,356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright (c) 2019 - 2020 by Robert Bosch GmbH. All rights reserved. | ||
// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. | ||
// Copyright (c) 2024 by Mathias Kraus <[email protected]>. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -14,15 +15,28 @@ | |
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#ifndef IOX_BINDING_C_BINDING_ERROR_HANDLING_ERROR_HANDLING_HPP | ||
#define IOX_BINDING_C_BINDING_ERROR_HANDLING_ERROR_HANDLING_HPP | ||
|
||
#include "iceoryx_hoofs/error_handling/error_handler.hpp" | ||
#ifndef IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP | ||
#define IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP | ||
|
||
// Each module (= some unit with its own errors) must provide the following. | ||
|
||
// 1. Define the errors of the module -> see below | ||
|
||
// 2. Include the custom reporting implementation | ||
#include "iox/error_reporting/custom/error_reporting.hpp" | ||
|
||
// 3. Include the error reporting macro API | ||
#include "iox/error_reporting/macros.hpp" | ||
|
||
// additional includes | ||
#include "iox/error_reporting/types.hpp" | ||
|
||
namespace iox | ||
{ | ||
|
||
// clang-format off | ||
#define C_BINDING_ERRORS(error) \ | ||
#define IOX_BINDING_C_ERRORS(error) \ | ||
error(BINDING_C__UNDEFINED_STATE_IN_IOX_QUEUE_FULL_POLICY) \ | ||
error(BINDING_C__UNDEFINED_STATE_IN_IOX_CONSUMER_TOO_SLOW_POLICY) \ | ||
error(BINDING_C__PUBLISHER_OPTIONS_NOT_INITIALIZED) \ | ||
|
@@ -34,19 +48,68 @@ namespace iox | |
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_EVENT_VALUE) \ | ||
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVER_STATE_VALUE) \ | ||
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_SERVICE_DISCOVERY_EVENT_VALUE) \ | ||
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE) | ||
error(BINDING_C__C2CPP_ENUM_TRANSLATION_INVALID_MESSAGING_PATTERN_VALUE) \ | ||
error(DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER) // keep this always at the end of the error list | ||
|
||
// clang-format on | ||
|
||
// DO NOT TOUCH THE ENUM, you can doodle around with the lines above!!! | ||
|
||
enum class CBindingError : uint32_t | ||
enum class CBindingError : iox::er::ErrorCode::type | ||
{ | ||
NO_ERROR = C_BINDING_MODULE_IDENTIFIER << ERROR_ENUM_OFFSET_IN_BITS, | ||
C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_ENUM) | ||
IOX_BINDING_C_ERRORS(IOX_CREATE_ERROR_ENUM) | ||
}; | ||
|
||
const char* asStringLiteral(const CBindingError error) noexcept; | ||
|
||
class CBindingErrorType | ||
{ | ||
public: | ||
explicit CBindingErrorType(CBindingError code) | ||
: m_code(static_cast<iox::er::ErrorCode::type>(code)) | ||
{ | ||
} | ||
|
||
static constexpr iox::er::ModuleId module() | ||
{ | ||
return MODULE_ID; | ||
} | ||
|
||
iox::er::ErrorCode code() const | ||
{ | ||
return m_code; | ||
} | ||
|
||
const char* name() const | ||
{ | ||
return asStringLiteral(static_cast<CBindingError>(m_code.value)); | ||
} | ||
|
||
static const char* moduleName() | ||
{ | ||
return "iceoryx_binding_c"; | ||
} | ||
|
||
static constexpr iox::er::ModuleId MODULE_ID{iox::er::ModuleId::BINDING_C}; | ||
|
||
protected: | ||
iox::er::ErrorCode m_code; | ||
}; | ||
|
||
namespace er | ||
{ | ||
|
||
inline CBindingErrorType toError(CBindingError code) | ||
{ | ||
return CBindingErrorType(code); | ||
} | ||
|
||
inline ModuleId toModule(CBindingError) | ||
{ | ||
return CBindingErrorType::MODULE_ID; | ||
} | ||
|
||
} // namespace er | ||
} // namespace iox | ||
#endif // IOX_BINDING_C_ERROR_HANDLING_ERROR_HANDLING_HPP | ||
|
||
#endif // IOX_BINDING_C_BINDING_C_ERROR_REPORTING_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved. | ||
// Copyright (c) 2024 by Mathias Kraus <[email protected]>. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -14,14 +15,23 @@ | |
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "iceoryx_binding_c/error_handling/error_handling.hpp" | ||
#include "iceoryx_binding_c/internal/binding_c_error_reporting.hpp" | ||
|
||
namespace iox | ||
{ | ||
const char* C_BINDING_ERROR_NAMES[] = {C_BINDING_ERRORS(CREATE_ICEORYX_ERROR_STRING)}; | ||
const char* BINDING_C_ERROR_NAMES[] = {IOX_BINDING_C_ERRORS(IOX_CREATE_ERROR_STRING)}; | ||
|
||
const char* asStringLiteral(const CBindingError error) noexcept | ||
{ | ||
return C_BINDING_ERROR_NAMES[errorToStringIndex(error)]; | ||
auto end = static_cast<std::underlying_type<CBindingError>::type>( | ||
CBindingError::DO_NOT_USE_AS_ERROR_THIS_IS_AN_INTERNAL_MARKER); | ||
auto index = static_cast<std::underlying_type<CBindingError>::type>(error); | ||
if (index >= end) | ||
{ | ||
return "Unknown Error Code!"; | ||
} | ||
// NOLINTJUSTIFICATION Bounds are checked and access is safe | ||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) | ||
return BINDING_C_ERROR_NAMES[index]; | ||
} | ||
} // namespace iox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.