From 3dc1efd38dcea8946eb684a1bebf4ff79d0c4112 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 15 Jul 2021 17:04:35 +0200 Subject: [PATCH] Added espcppmacros.h --- CMakeLists.txt | 1 + src/espcppmacros.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/espcppmacros.h 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