-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: 🥅 Change all error handling to use errno, add int32_t return codes #25
Merged
+208
−91
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
458d0de
refactor: :goal_net: Change error handling in screen code to use errno
ion098 366415f
style: :art: Fix formatting
ion098 1473733
refactor: :goal_net: Add return value to functions that set errno
ion098 277b084
refactor: :recycle: Change functions to return 0 on success
ion098 4da1dc5
refactor: :technologist: Hide TODO messages from compiler output
ion098 5a5fced
refactor: :recycle: Change functions to return int32_t error codes
ion098 f127b09
style: :art: Format code
ion098 08e6723
refactor: :label: Change functions returning uint32_t to return int32_t
ion098 0ac0ebd
fix: :bug: Fix broken impl of Button::removeListener
ion098 607f3fc
fix(display): :bug: Add handling for too big messages
ion098 38aa8d9
refactor(buttons): :heavy_minus_sign: Remove unneeded include
ion098 739c0f5
docs(display): :memo: Document all possible errno values
ion098 0ffae91
chore: :technologist: Add conventional commits scopes
ion098 5ce9764
fix(display): :bug: Return error code from clear method
ion098 f584161
docs(display): :memo: Fix incorrect docs for error codes
ion098 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,33 +24,33 @@ template <typename Key, typename... Args> class EventHandler { | |||||
* | ||||||
* @param key The listener key (this must be a unique key value) | ||||||
* @param func The function to run when this event is fired | ||||||
* @return true The listener was successfully added | ||||||
* @return false The listener was NOT successfully added (there is already a listener with the same key) | ||||||
* @return 0 The listener was successfully added | ||||||
* @return UINT32_MAX The listener was NOT successfully added (there is already a listener with the same key) | ||||||
*/ | ||||||
bool addListener(Key key, Listener func) { | ||||||
uint32_t addListener(Key key, Listener func) { | ||||||
std::lock_guard lock(m_mutex); | ||||||
if (std::find(m_keys.begin(), m_keys.end(), key) != m_keys.end()) return false; | ||||||
if (std::find(m_keys.begin(), m_keys.end(), key) != m_keys.end()) return UINT32_MAX; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions should return
Suggested change
|
||||||
m_keys.push_back(key); | ||||||
m_listeners.push_back(func); | ||||||
return true; | ||||||
return 0; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @brief Remove a listener from the list of listeners | ||||||
* | ||||||
* @param key The listener key (this must be a unique key value) | ||||||
* @return true The listener was successfully removed | ||||||
* @return false The listener was NOT successfully removed (there is no listener with the same key) | ||||||
* @return 0 The listener was successfully removed | ||||||
* @return UINT32_MAX The listener was NOT successfully removed (there is no listener with the same key) | ||||||
*/ | ||||||
bool removeListener(Key key) { | ||||||
uint32_t removeListener(Key key) { | ||||||
std::lock_guard lock(m_mutex); | ||||||
auto i = std::find(m_keys.begin(), m_keys.end(), key); | ||||||
if (i != m_keys.end()) { | ||||||
m_keys.erase(i); | ||||||
m_listeners.erase(m_listeners.begin() + (i - m_keys.begin())); | ||||||
return true; | ||||||
return 0; | ||||||
} | ||||||
return false; | ||||||
return UINT32_MAX; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
#pragma once | ||
|
||
#define DO_PRAGMA(x) _Pragma(#x) | ||
#define TODO(x) DO_PRAGMA(message("TODO - " #x)) | ||
#define FIXME(x) DO_PRAGMA(warning("FIXME - " #x)) | ||
|
||
// We only define the TODO/FIXME macros if the file is being compiled by Microsoft Intellisense | ||
// or clangd. This way, the TODO/FIXME messages don't clutter the compilation messages. | ||
#if defined(_debug) || defined(__clang__) | ||
#define TODO(x) DO_PRAGMA(message("TODO - " x)) | ||
#define FIXME(x) DO_PRAGMA(warning("FIXME - " x)) | ||
#else | ||
#define TODO(x) | ||
#define FIXME(x) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the functions return
INT_MAX
when errno is set, which is the maximum value of anint32_t
. Consider changing them toint32_t
for clarity, but this is not a requirement