Skip to content

Commit 0e1f6c0

Browse files
authored
Merge pull request #6 from bringauto/default_error_message
Default error message
2 parents 8c42eaf + e8e7cde commit 0e1f6c0

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PROJECT(example_module CXX)
33

44
SET(CMAKE_CXX_STANDARD 20)
55

6-
SET(EXAMPLE_MODULE_VERSION 1.1.1)
6+
SET(EXAMPLE_MODULE_VERSION 1.1.2)
77

88
OPTION(BRINGAUTO_PACKAGE "Package creation" OFF)
99
OPTION(BRINGAUTO_INSTALL "Disable install" OFF)

include/common/example_module.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
22

33
static constexpr unsigned int BUTTON_DEVICE_TYPE{0};
4-
static constexpr unsigned int MODULE_NUMBER{1000};
4+
static constexpr unsigned int MODULE_NUMBER{1000};
5+
static constexpr char DEFAULT_ERROR_MESSAGE[]{"Default error"};

source/module_gateway/module_manager.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ int aggregate_status(struct buffer *aggregated_status, const struct buffer curre
5454

5555
int aggregate_error(struct buffer *error_message, const struct buffer current_error_message, const struct buffer status,
5656
unsigned int device_type) {
57-
allocate(error_message, current_error_message.size_in_bytes);
58-
std::memcpy(error_message->data, current_error_message.data,
59-
current_error_message.size_in_bytes );
57+
if (current_error_message.data != nullptr) {
58+
allocate(error_message, current_error_message.size_in_bytes);
59+
std::memcpy(error_message->data, current_error_message.data,
60+
current_error_message.size_in_bytes);
61+
} else {
62+
const std::string current_error_message_str = DEFAULT_ERROR_MESSAGE;
63+
allocate(error_message, current_error_message_str.size());
64+
std::memcpy(error_message->data, current_error_message_str.c_str(),
65+
current_error_message_str.size());
66+
}
6067
return OK;
6168
}
6269

0 commit comments

Comments
 (0)