Skip to content
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

fix (NetworkEvents lib) remove checks for duplicated event handlers #10376

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

vortigont
Copy link
Contributor

A refactoring for NetworkEvents class
This fixes #10365 issue and supersedes #10337, it removes pointer comparison checks for function pointer handlers but adds more safety to the code working with callback handlers container.

  • more cpp friendly code
  • removed checking for duplicate event callbacks via std::function pointer, it does not work as expected for lambdas
  • mark NetworkEvents::removeEvent(NetworkEventFuncCb) as deprecated in favor of removing by callback's id
  • for NetworkEvents::onEvent remove checking for duplicate event handler, this does not work for lambdas too
  • remove NetworkEvents::find methods as unnecessary in favor of using std iterators
  • move cbEventList container inside the NetworkEvents 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
  • hide event task under private member of NetworkEvents class
  • 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()
  • add mutex locking on container access for thread safety on dual core SoCs

…llbacks

removing event callback via std::function pointer does not work as expected for lambdas (issue espressif#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
prevent checkForEvent loop to be callable from outside the task's thread
- 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
Copy link
Contributor

github-actions bot commented Sep 26, 2024

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "[Network] deprecate NetworkEvents::removeEvent() for std::function callbacks":
    • footer's lines must not be longer than 100 characters
    • summary looks empty
    • type/action looks empty
  • the commit message "[Network] hide event task under private member of NetworkEvents class":
    • summary looks empty
    • type/action looks empty
  • the commit message "lib Network: add cpp syntax to structs":
    • summary looks empty
    • type/action looks empty
  • the commit message "refactor(NetworkEvents) add (optional) mutex lock for container operations":
    • body's lines must not be longer than 100 characters
    • summary looks empty
    • type/action looks empty
  • the commit message "refactor(NetworkEvents) code polishing and comments":
    • body's lines must not be longer than 100 characters
    • summary looks empty
    • type/action looks empty

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

Messages
📖 You might consider squashing your 5 commits (simplifying branch history).

👋 Hello vortigont, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- Addressing info messages (📖) is strongly recommended; they're less critical but valuable.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 1a2d988

Copy link
Contributor

github-actions bot commented Sep 26, 2024

Test Results

 56 files   - 83   56 suites   - 83   4m 12s ⏱️ - 32m 52s
 21 tests  - 13   21 ✅ ± 0  0 💤 ±0  0 ❌ ±0 
135 runs   - 98  135 ✅  - 35  0 💤 ±0  0 ❌ ±0 

Results for commit 1a2d988. ± Comparison against base commit b05f18d.

This pull request removes 13 tests.
performance.coremark.test_coremark ‑ test_coremark
performance.fibonacci.test_fibonacci ‑ test_fibonacci
performance.psramspeed.test_psramspeed ‑ test_psramspeed
performance.ramspeed.test_ramspeed ‑ test_ramspeed
performance.superpi.test_superpi ‑ test_superpi
test_touch_errors
test_touch_interrtupt
test_touch_read
validation.periman.test_periman ‑ test_periman
validation.timer.test_timer ‑ test_timer
…

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Sep 26, 2024

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32S3💚 -32⚠️ +5560.00⚠️ +0.06💚 -160💚 -0.070.00
ESP32S2💚 -36⚠️ +5400.00⚠️ +0.06💚 -160💚 -0.040.00
ESP32C30⚠️ +6240.00⚠️ +0.060⚠️ +160.00⚠️ +0.05
ESP32C60⚠️ +6240.00⚠️ +0.060⚠️ +160.00⚠️ +0.04
ESP32H20⚠️ +1180.00⚠️ +0.02000.000.00
ESP32💚 -32⚠️ +560💚 -0.01⚠️ +0.06💚 -160💚 -0.040.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32S3ESP32S2ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
Ethernet/examples/ETH_W5500_Arduino_SPI💚 -20💚 -1600⚠️ +1060⚠️ +1000⚠️ +760💚 -320
Ethernet/examples/ETH_W5500_IDF_SPI💚 -20💚 -16💚 -40⚠️ +1060⚠️ +1000⚠️ +760💚 -320
Ethernet/examples/ETH_WIFI_BRIDGE⚠️ +4920⚠️ +5240⚠️ +6140⚠️ +6220--⚠️ +5040
NetworkClientSecure/examples/WiFiClientInsecure⚠️ +2000⚠️ +2040⚠️ +294⚠️ +16⚠️ +2880--⚠️ +1880
NetworkClientSecure/examples/WiFiClientPSK⚠️ +184💚 -16⚠️ +2000⚠️ +2840⚠️ +2820--⚠️ +2040
NetworkClientSecure/examples/WiFiClientSecure⚠️ +1840⚠️ +2040⚠️ +2820⚠️ +2800--⚠️ +2040
NetworkClientSecure/examples/WiFiClientSecureEnterprise⚠️ +2080⚠️ +2040⚠️ +2780⚠️ +2800--⚠️ +1920
NetworkClientSecure/examples/WiFiClientSecureProtocolUpgrade⚠️ +2040⚠️ +2040⚠️ +294⚠️ +16⚠️ +2880--⚠️ +1920
NetworkClientSecure/examples/WiFiClientShowPeerCredentials⚠️ +2240⚠️ +1760⚠️ +2840⚠️ +2980--⚠️ +1920
NetworkClientSecure/examples/WiFiClientTrustOnFirstUse⚠️ +1880⚠️ +2000⚠️ +296⚠️ +16⚠️ +288⚠️ +16--⚠️ +1880
PPP/examples/PPP_Basic⚠️ +32💚 -16⚠️ +400⚠️ +1200⚠️ +1160⚠️ +1180⚠️ +320
PPP/examples/PPP_WIFI_BRIDGE⚠️ +5560⚠️ +5400⚠️ +6240⚠️ +6240--⚠️ +5600
WebServer/examples/AdvancedWebServer⚠️ +2640⚠️ +2520⚠️ +352⚠️ +16⚠️ +3560--⚠️ +2680
WebServer/examples/FSBrowser⚠️ +2520⚠️ +2480⚠️ +3460⚠️ +3480--⚠️ +236💚 -16
WebServer/examples/Filters⚠️ +2720⚠️ +2520⚠️ +352⚠️ +16⚠️ +3560--⚠️ +2520
WebServer/examples/HelloServer⚠️ +2680⚠️ +2600⚠️ +352⚠️ +16⚠️ +3560--⚠️ +2560
WebServer/examples/HttpAdvancedAuth⚠️ +236💚 -16⚠️ +2720⚠️ +3320⚠️ +3440--⚠️ +2560
WebServer/examples/HttpAuthCallback⚠️ +2600⚠️ +2600⚠️ +3560⚠️ +3560--⚠️ +2560
WebServer/examples/HttpAuthCallbackInline⚠️ +2480⚠️ +2640⚠️ +3520⚠️ +3520--⚠️ +2560
WebServer/examples/HttpBasicAuth⚠️ +2600⚠️ +2720⚠️ +3500⚠️ +3520--⚠️ +2600
WebServer/examples/HttpBasicAuthSHA1⚠️ +2680⚠️ +2560⚠️ +3520⚠️ +3500--⚠️ +2640
WebServer/examples/HttpBasicAuthSHA1orBearerToken⚠️ +2520⚠️ +2720⚠️ +352⚠️ +16⚠️ +352⚠️ +16--⚠️ +2520
WebServer/examples/MultiHomedServers⚠️ +2480⚠️ +244💚 -16⚠️ +3520⚠️ +3540--⚠️ +2440
WebServer/examples/PathArgServer⚠️ +320⚠️ +200⚠️ +1280⚠️ +1360--⚠️ +240
WebServer/examples/SDWebServer⚠️ +248💚 -16⚠️ +2360⚠️ +3460⚠️ +3480--⚠️ +236💚 -16
WebServer/examples/SimpleAuthentification⚠️ +2400⚠️ +2520⚠️ +3540⚠️ +356⚠️ +16--⚠️ +2680
WebServer/examples/UploadHugeFile⚠️ +400⚠️ +360⚠️ +1280⚠️ +1360--⚠️ +240
WebServer/examples/WebServer⚠️ +2800⚠️ +2440⚠️ +3460⚠️ +3480--⚠️ +2520
WebServer/examples/WebUpdate⚠️ +2560⚠️ +2640⚠️ +3560⚠️ +3560--⚠️ +2480
WiFi/examples/FTM/FTM_Initiator⚠️ +480⚠️ +400⚠️ +1440⚠️ +1520--⚠️ +56💚 -16
WiFi/examples/FTM/FTM_Responder⚠️ +1760⚠️ +1640⚠️ +3060⚠️ +3060--⚠️ +1920
WiFi/examples/SimpleWiFiServer⚠️ +2080⚠️ +2000⚠️ +292⚠️ +16⚠️ +2940--⚠️ +2000
WiFi/examples/WPS💚 -120💚 -200⚠️ +1180⚠️ +1280--💚 -280
WiFi/examples/WiFiAccessPoint⚠️ +2080⚠️ +2040⚠️ +292⚠️ +16⚠️ +2940--⚠️ +1960
WiFi/examples/WiFiBlueToothSwitch⚠️ +2840--⚠️ +4280⚠️ +4300--⚠️ +3120
WiFi/examples/WiFiClient⚠️ +2000⚠️ +2040⚠️ +2740⚠️ +2800--⚠️ +1960
WiFi/examples/WiFiClientBasic⚠️ +2120⚠️ +2040⚠️ +298⚠️ +16⚠️ +2920--⚠️ +2040
WiFi/examples/WiFiClientConnect⚠️ +2040⚠️ +1680⚠️ +3000⚠️ +3040--⚠️ +2000
WiFi/examples/WiFiClientEnterprise⚠️ +2040⚠️ +2160⚠️ +2740⚠️ +2900--⚠️ +2080
WiFi/examples/WiFiClientEvents⚠️ +1720⚠️ +1680⚠️ +3380⚠️ +3500--⚠️ +1960
WiFi/examples/WiFiClientStaticIP⚠️ +2120⚠️ +2200⚠️ +2960⚠️ +2900--⚠️ +1960
WiFi/examples/WiFiExtender💚 -320💚 -360⚠️ +1360⚠️ +1400--⚠️ +40
WiFi/examples/WiFiIPv6⚠️ +3120⚠️ +3040⚠️ +4320⚠️ +4420--⚠️ +2640
WiFi/examples/WiFiMulti⚠️ +1760⚠️ +1720⚠️ +298⚠️ +16⚠️ +2940--⚠️ +2080
WiFi/examples/WiFiMultiAdvanced⚠️ +2080⚠️ +1960⚠️ +2780⚠️ +2920--⚠️ +1800
WiFi/examples/WiFiScan⚠️ +1720⚠️ +1840⚠️ +3040⚠️ +2980--⚠️ +1960
WiFi/examples/WiFiScanAsync⚠️ +1760⚠️ +1920⚠️ +2980⚠️ +2920--⚠️ +1960
WiFi/examples/WiFiScanDualAntenna⚠️ +1680⚠️ +1560⚠️ +2960⚠️ +3060--⚠️ +1960
WiFi/examples/WiFiScanTime⚠️ +1720⚠️ +1920⚠️ +3000⚠️ +2960--⚠️ +1960
WiFi/examples/WiFiSmartConfig⚠️ +2160⚠️ +2000⚠️ +3020⚠️ +3040--⚠️ +2040
WiFi/examples/WiFiTelnetToSerial⚠️ +2000⚠️ +1560⚠️ +2980⚠️ +3000--⚠️ +1960
WiFi/examples/WiFiUDPClient⚠️ +2960⚠️ +2920⚠️ +4180⚠️ +4280--⚠️ +2520
Ethernet/examples/ETH_LAN8720----------⚠️ +2280
Ethernet/examples/ETH_TLK110----------⚠️ +2280

@vortigont vortigont marked this pull request as draft September 26, 2024 05:33
…tions

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
@vortigont vortigont marked this pull request as ready for review September 27, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: NetworkEvents::onEvent() can't register function calbacks via lambda expressions
1 participant