|
| 1 | +#ifndef ENTSERVICES_ERRORCODES_H |
| 2 | +#define ENTSERVICES_ERRORCODES_H |
| 3 | +#pragma once |
| 4 | +#include <stdio.h> |
| 5 | + |
| 6 | +// 1. The single source of truth: a list of all errors. |
| 7 | +#define ERROR_LIST \ |
| 8 | + X(ERROR_FILE_IO, "File Read or Write error") \ |
| 9 | + X(ERROR_INVALID_PARAMETER, "Invalid Parameter") \ |
| 10 | + X(ERROR_INVALID_DEVICENAME, "Invalid device name") \ |
| 11 | + X(ERROR_INVALID_MOUNTPOINT, "Invalid mount path") \ |
| 12 | + X(ERROR_FIRMWAREUPDATE_INPROGRESS, "Firmware update already in progress") \ |
| 13 | + X(ERROR_FIRMWAREUPDATE_UPTODATE, "Firmware is already upto date") \ |
| 14 | + |
| 15 | +/******** PLEASE DO NOT MODIFY ANYTHING BELOW THIS **********/ |
| 16 | +// 2. Define the 'X' macro to generate the enum. |
| 17 | +#define X(name, string) name, |
| 18 | +enum ErrorCodeEnum{ |
| 19 | + // Start the first error code at 1000 |
| 20 | + ERROR_BASE = 1000, |
| 21 | + ERROR_LIST |
| 22 | + MAX_ERROR_CODE |
| 23 | +}; |
| 24 | +// Undefine 'X' to avoid conflicts. |
| 25 | +#undef X |
| 26 | + |
| 27 | +// 3. Define the 'X' macro to generate the string array. |
| 28 | +#define X(name, string) string, |
| 29 | +const char* const error_strings[] = { |
| 30 | + "Error base", |
| 31 | + ERROR_LIST |
| 32 | + "Unknown error code" |
| 33 | +}; |
| 34 | + |
| 35 | +//4.Check if Error code is within the entservices error code range. |
| 36 | +#define IS_ENTSERVICES_ERRORCODE(errorcode) \ |
| 37 | + ((errorcode) >= ERROR_BASE && \ |
| 38 | + (errorcode) < MAX_ERROR_CODE) |
| 39 | + |
| 40 | + |
| 41 | +//5.Fetch Error strings |
| 42 | +#define ERROR_MESSAGE(errorcode) (error_strings[(errorcode) - ERROR_BASE]) |
| 43 | + |
| 44 | +#endif //ENTSERVICES_ERRORCODES_H |
0 commit comments