diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dd6dd2..3407c4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ set(headers + src/espcppmacros.h src/espcrc32builder.h src/esprandom.h src/espstrutils.h diff --git a/src/espcppmacros.h b/src/espcppmacros.h new file mode 100644 index 0000000..0a1b73b --- /dev/null +++ b/src/espcppmacros.h @@ -0,0 +1,21 @@ +#pragma once + +namespace espcpputils { + +#define CALL_AND_EXIT_ON_ERROR(METHOD, ...) \ + if (const auto result = METHOD(__VA_ARGS__); result != ESP_OK) \ + { \ + ESP_LOGE(TAG, "%s() failed with %s", #METHOD, esp_err_to_name(result)); \ + return result; \ + } + +#define CALL_AND_EXIT(METHOD, ...) \ + if (const auto result = METHOD(__VA_ARGS__); result != ESP_OK) \ + { \ + ESP_LOGE(TAG, "%s() failed with %s", #METHOD, esp_err_to_name(result)); \ + return result; \ + } \ + else \ + return result; + +} // namespace espcpputils