libe3 0.2.5
C++ library for E3AP RAN vendor integration
Loading...
Searching...
No Matches
error_codes.h
Go to the documentation of this file.
1/**
2 * @file error_codes.h
3 * @brief libe3 error codes - shared C/C++ definitions
4 *
5 * Provides a single source of truth for all libe3 error codes via an
6 * X-macro list. Both the C API (@ref e3_error_code_e) and the C++ API
7 * (@ref libe3::ErrorCode) are generated from this list.
8 *
9 * SPDX-FileCopyrightText: Copyright (c) 2026 Northeastern University
10 * SPDX-License-Identifier: Apache-2.0
11 */
12// Shared X-macro list of libe3 error codes and C helpers
13#ifndef LIBE3_ERROR_CODES_H
14#define LIBE3_ERROR_CODES_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/**
21 * @defgroup error_codes libe3 Error Codes
22 * @brief Error codes returned by libe3 operations.
23 *
24 * All libe3 API functions that can fail return either @ref libe3::ErrorCode
25 * (C++ API) or @ref e3_error_t (C API). A return value of 0 always means
26 * success; all error values are negative.
27 * @{
28 */
29
30/**
31 * @brief X-macro list of all libe3 error codes.
32 *
33 * Expand with `#define X(name, val) ...` before using this macro,
34 * and `#undef X` afterwards. Each entry exposes a symbolic name and its
35 * corresponding integer value.
36 *
37 * | Name | Value | Meaning |
38 * |--------------------------|-------|------------------------------------------------|
39 * | SUCCESS | 0 | Operation completed successfully |
40 * | INVALID_PARAM | -1 | One or more parameters are invalid |
41 * | NOT_INITIALIZED | -2 | Component has not been initialized yet |
42 * | ALREADY_INITIALIZED | -3 | Component is already initialized |
43 * | NOT_CONNECTED | -4 | No active connection available |
44 * | CONNECTION_FAILED | -5 | Failed to establish a connection |
45 * | TIMEOUT | -6 | Operation timed out |
46 * | ENCODE_FAILED | -7 | PDU encoding failed |
47 * | DECODE_FAILED | -8 | PDU decoding failed |
48 * | SM_NOT_FOUND | -9 | Requested Service Model was not found |
49 * | SM_ALREADY_REGISTERED | -10 | Service Model is already registered |
50 * | BUFFER_TOO_SMALL | -11 | Provided buffer is too small |
51 * | INTERNAL_ERROR | -12 | Unexpected internal error |
52 * | SUBSCRIPTION_EXISTS | -13 | Subscription already exists |
53 * | SUBSCRIPTION_NOT_FOUND | -14 | Subscription was not found |
54 * | DAPP_NOT_REGISTERED | -15 | Requested dApp is not registered |
55 * | TRANSPORT_ERROR | -16 | Transport layer error |
56 * | STATE_ERROR | -17 | Operation not valid in current state |
57 * | SM_START_FAILED | -18 | Service Model failed to start |
58 * | NOT_FOUND | -19 | Requested resource was not found |
59 * | SM_ERROR_INVALID_PARAM | -20 | Service Model received invalid parameter |
60 * | SM_ERROR_NOT_FOUND | -21 | Service Model resource not found |
61 * | SM_ERROR_ALREADY_EXISTS | -22 | Service Model resource already exists |
62 * | SM_ERROR_THREAD_FAILED | -23 | Service Model thread failed to start |
63 * | SM_ERROR_MEMORY | -24 | Service Model memory allocation failure |
64 * | CANCELLED | -25 | Operation was cancelled |
65 * | GENERIC_ERROR | -100 | Unclassified generic error |
66 */
67#define LIBE3_ERROR_CODE_LIST \
68 X(SUCCESS, 0) \
69 X(INVALID_PARAM, -1) \
70 X(NOT_INITIALIZED, -2) \
71 X(ALREADY_INITIALIZED, -3) \
72 X(NOT_CONNECTED, -4) \
73 X(CONNECTION_FAILED, -5) \
74 X(TIMEOUT, -6) \
75 X(ENCODE_FAILED, -7) \
76 X(DECODE_FAILED, -8) \
77 X(SM_NOT_FOUND, -9) \
78 X(SM_ALREADY_REGISTERED, -10) \
79 X(BUFFER_TOO_SMALL, -11) \
80 X(INTERNAL_ERROR, -12) \
81 X(SUBSCRIPTION_EXISTS, -13) \
82 X(SUBSCRIPTION_NOT_FOUND, -14) \
83 X(DAPP_NOT_REGISTERED, -15) \
84 X(TRANSPORT_ERROR, -16) \
85 X(STATE_ERROR, -17) \
86 X(SM_START_FAILED, -18) \
87 X(NOT_FOUND, -19) \
88 X(SM_ERROR_INVALID_PARAM, -20) \
89 X(SM_ERROR_NOT_FOUND, -21) \
90 X(SM_ERROR_ALREADY_EXISTS, -22) \
91 X(SM_ERROR_THREAD_FAILED, -23) \
92 X(SM_ERROR_MEMORY, -24) \
93 X(CANCELLED, -25) \
94 X(GENERIC_ERROR, -100)
95
96/** @} */ /* end of error_codes group */
97
98/**
99 * @brief C-compatible error code enumeration.
100 *
101 * Values match those in @ref libe3::ErrorCode. Use the `E3_` prefix
102 * to avoid collisions with C++ symbols.
103 */
105#define X(name, val) E3_##name = val,
107#undef X
108};
109
110/**
111 * @brief C error type alias.
112 *
113 * An `int` whose value is one of the @ref e3_error_code_e constants.
114 * Zero means success; all error values are negative.
115 */
116typedef int e3_error_t;
117
118/**
119 * @brief Convert a numeric error code to a human-readable name.
120 *
121 * @param code Error code value (one of @ref e3_error_code_e)
122 * @return Null-terminated string with the symbolic name, or
123 * `"UNKNOWN_ERROR"` if the value is not recognised.
124 */
125const char* e3_error_to_string(e3_error_t code);
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif // LIBE3_ERROR_CODES_H
const char * e3_error_to_string(e3_error_t code)
Convert a numeric error code to a human-readable name.
Definition c_api.cpp:428
int e3_error_t
C error type alias.
e3_error_code_e
C-compatible error code enumeration.
#define LIBE3_ERROR_CODE_LIST
X-macro list of all libe3 error codes.
Definition error_codes.h:67