Skip to content

Commit

Permalink
fix (NetworkEvents lib) remove checks for duplicated event handlers (#…
Browse files Browse the repository at this point in the history
…10376)

* lib Network: add cpp syntax to structs

* [Network] deprecate NetworkEvents::removeEvent() for std::function callbacks

removing event callback via std::function pointer does not work as expected for lambdas (issue #10365)
here mark NetworkEvents::removeEvent(NetworkEventFuncCb cbEvent, arduino_event_id_t event = ARDUINO_EVENT_MAX)
as deprecated in favor of removing by callback's id

for NetworkEvents::onEvent remove checking for dublicate event handler, this does not work for lambdas too

remove NetworkEvents::find methods as unnecessary

move cbEventList container inside the class

declare NetworkEventCbList_t as a cpp struct with constructor, allows using std::vector.emplace() when adding new items to container

optimize NetworkEvents::remove() calls to use erase-remove idiom for std::vector

* [Network] hide event task under private member of NetworkEvents class

prevent checkForEvent loop to be callable from outside the task's thread

* refactor(NetworkEvents) code polishing and comments

- rename NetworkEvents::cbEventList as private member NetworkEvents_cbEventList
- NetworkEvents::getStatusBits() add const qualifier
- turn statics into constexpr
- add indexes to enum::arduino_event_id_t to make events indexing consistent for SOCs with/without WiFi
  also leave some index gaps to minimize renumbering on adding new events
- add doxygen help to NetworkEvents:: methods
- declare NetworkEvents::eventName() as static, that could be used without creating class scope
- potential mem leak in postEvent

* refactor(NetworkEvents) add (optional) mutex lock for container operations

provide thread safety for dual core SoCs
since std::mutex brings additional componetns of libstdc++ lib it impacts resulting image size significantly (around 50k)
Might be enabled on-demand if thread-safety is required

* ci(pre-commit): Apply automatic fixes

* fix(spelling): Fix spelling mistakes

---------

Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 24, 2024
1 parent 330beb4 commit 07c510e
Show file tree
Hide file tree
Showing 2 changed files with 289 additions and 216 deletions.
Loading

0 comments on commit 07c510e

Please sign in to comment.