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

Merged
merged 8 commits into from
Oct 24, 2024

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).

⚠️ Please consider squashing your 8 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.
- 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 ab1d55d

Copy link
Contributor

github-actions bot commented Sep 26, 2024

Test Results

 56 files   56 suites   4m 11s ⏱️
 21 tests  21 ✅ 0 💤 0 ❌
134 runs  134 ✅ 0 💤 0 ❌

Results for commit ab1d55d.

♻️ 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⚠️ +5440.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⚠️ +1160.00⚠️ +0.02000.000.00
ESP32💚 -32⚠️ +568💚 -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💚 -16💚 -40⚠️ +1040⚠️ +980⚠️ +740💚 -320
Ethernet/examples/ETH_W5500_IDF_SPI💚 -16💚 -1600⚠️ +1040⚠️ +980⚠️ +740💚 -320
Ethernet/examples/ETH_WIFI_BRIDGE⚠️ +4920⚠️ +5120⚠️ +6140⚠️ +6220--⚠️ +5000
NetworkClientSecure/examples/WiFiClientInsecure⚠️ +2000⚠️ +2000⚠️ +294⚠️ +16⚠️ +2880--⚠️ +2040
NetworkClientSecure/examples/WiFiClientPSK⚠️ +188💚 -16⚠️ +2000⚠️ +2840⚠️ +2820--⚠️ +2080
NetworkClientSecure/examples/WiFiClientSecure⚠️ +1920⚠️ +2000⚠️ +2820⚠️ +2800--⚠️ +2080
NetworkClientSecure/examples/WiFiClientSecureEnterprise⚠️ +2080⚠️ +2000⚠️ +2780⚠️ +2800--⚠️ +1920
NetworkClientSecure/examples/WiFiClientSecureProtocolUpgrade⚠️ +2040⚠️ +2040⚠️ +294⚠️ +16⚠️ +2880--⚠️ +1880
NetworkClientSecure/examples/WiFiClientShowPeerCredentials⚠️ +2080⚠️ +1960⚠️ +2840⚠️ +2980--⚠️ +1800
NetworkClientSecure/examples/WiFiClientTrustOnFirstUse⚠️ +1880⚠️ +2120⚠️ +296⚠️ +16⚠️ +288⚠️ +16--⚠️ +1960
PPP/examples/PPP_Basic⚠️ +32💚 -16⚠️ +400⚠️ +1180⚠️ +1140⚠️ +1160⚠️ +360
PPP/examples/PPP_WIFI_BRIDGE⚠️ +5560⚠️ +5440⚠️ +6240⚠️ +6240--⚠️ +5680
WebServer/examples/AdvancedWebServer⚠️ +2640⚠️ +2520⚠️ +352⚠️ +16⚠️ +3560--⚠️ +2640
WebServer/examples/FSBrowser⚠️ +2400⚠️ +2600⚠️ +3460⚠️ +3480--⚠️ +236💚 -16
WebServer/examples/Filters⚠️ +2680⚠️ +2600⚠️ +352⚠️ +16⚠️ +3560--⚠️ +2560
WebServer/examples/HelloServer⚠️ +2680⚠️ +2520⚠️ +352⚠️ +16⚠️ +3560--⚠️ +2520
WebServer/examples/HttpAdvancedAuth⚠️ +236💚 -16⚠️ +2720⚠️ +3320⚠️ +3440--⚠️ +2600
WebServer/examples/HttpAuthCallback⚠️ +2600⚠️ +2720⚠️ +3560⚠️ +3560--⚠️ +2560
WebServer/examples/HttpAuthCallbackInline⚠️ +2560⚠️ +2680⚠️ +3520⚠️ +3520--⚠️ +2600
WebServer/examples/HttpBasicAuth⚠️ +2600⚠️ +2760⚠️ +3500⚠️ +3520--⚠️ +2640
WebServer/examples/HttpBasicAuthSHA1⚠️ +2680⚠️ +2560⚠️ +3520⚠️ +3500--⚠️ +2760
WebServer/examples/HttpBasicAuthSHA1orBearerToken⚠️ +2520⚠️ +2680⚠️ +352⚠️ +16⚠️ +352⚠️ +16--⚠️ +2520
WebServer/examples/MultiHomedServers⚠️ +2480⚠️ +244💚 -16⚠️ +3520⚠️ +3540--⚠️ +2440
WebServer/examples/PathArgServer⚠️ +360⚠️ +160⚠️ +1280⚠️ +1360--⚠️ +240
WebServer/examples/SDWebServer⚠️ +248💚 -16⚠️ +2400⚠️ +3460⚠️ +3480--⚠️ +236💚 -16
WebServer/examples/SimpleAuthentification⚠️ +2440⚠️ +2480⚠️ +3540⚠️ +356⚠️ +16--⚠️ +2600
WebServer/examples/UploadHugeFile⚠️ +400⚠️ +400⚠️ +1280⚠️ +1360--⚠️ +240
WebServer/examples/WebServer⚠️ +2720⚠️ +2520⚠️ +3460⚠️ +3480--⚠️ +2520
WebServer/examples/WebUpdate⚠️ +2560⚠️ +2520⚠️ +3560⚠️ +3560--⚠️ +2480
WiFi/examples/FTM/FTM_Initiator⚠️ +480⚠️ +400⚠️ +1440⚠️ +1520--⚠️ +48💚 -16
WiFi/examples/FTM/FTM_Responder⚠️ +1760⚠️ +1600⚠️ +3040⚠️ +3080--⚠️ +1960
WiFi/examples/SimpleWiFiServer⚠️ +2040⚠️ +2000⚠️ +292⚠️ +16⚠️ +2940--⚠️ +1920
WiFi/examples/WPS💚 -160⚠️ +160⚠️ +1180⚠️ +1280--💚 -280
WiFi/examples/WiFiAccessPoint⚠️ +2040⚠️ +1800⚠️ +292⚠️ +16⚠️ +2940--⚠️ +1880
WiFi/examples/WiFiBlueToothSwitch⚠️ +2840--⚠️ +4280⚠️ +4300--⚠️ +3160
WiFi/examples/WiFiClient⚠️ +1960⚠️ +2040⚠️ +2740⚠️ +2800--⚠️ +1960
WiFi/examples/WiFiClientBasic⚠️ +2080⚠️ +2040⚠️ +298⚠️ +16⚠️ +2920--⚠️ +2120
WiFi/examples/WiFiClientConnect⚠️ +2160⚠️ +1680⚠️ +3020⚠️ +3040--⚠️ +2000
WiFi/examples/WiFiClientEnterprise⚠️ +2040⚠️ +2120⚠️ +2740⚠️ +2900--⚠️ +2080
WiFi/examples/WiFiClientEvents⚠️ +1720⚠️ +1680⚠️ +3380⚠️ +3500--⚠️ +1760
WiFi/examples/WiFiClientStaticIP⚠️ +1920⚠️ +2200⚠️ +2960⚠️ +2900--⚠️ +1960
WiFi/examples/WiFiExtender💚 -320💚 -360⚠️ +1360⚠️ +1380--💚 -120
WiFi/examples/WiFiIPv6⚠️ +3120⚠️ +3080⚠️ +4320⚠️ +4420--⚠️ +2720
WiFi/examples/WiFiMulti⚠️ +1760⚠️ +1720⚠️ +298⚠️ +16⚠️ +2920--⚠️ +2000
WiFi/examples/WiFiMultiAdvanced⚠️ +2080⚠️ +2000⚠️ +2780⚠️ +2920--⚠️ +1760
WiFi/examples/WiFiScan⚠️ +1720⚠️ +1960⚠️ +3040⚠️ +3000--⚠️ +1960
WiFi/examples/WiFiScanAsync⚠️ +1840⚠️ +1880⚠️ +2980⚠️ +2920--⚠️ +1960
WiFi/examples/WiFiScanDualAntenna⚠️ +1760⚠️ +1720⚠️ +2980⚠️ +3040--⚠️ +1960
WiFi/examples/WiFiScanTime⚠️ +1640⚠️ +1960⚠️ +3000⚠️ +2940--⚠️ +1960
WiFi/examples/WiFiSmartConfig⚠️ +2160⚠️ +2040⚠️ +3000⚠️ +3060--⚠️ +1920
WiFi/examples/WiFiTelnetToSerial⚠️ +2040⚠️ +1680⚠️ +2980⚠️ +3000--⚠️ +2000
WiFi/examples/WiFiUDPClient⚠️ +2960⚠️ +2880⚠️ +4180⚠️ +4280--⚠️ +2680
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
@VojtechBartoska VojtechBartoska added Area: WiFi Issue related to WiFi Status: Review needed Issue or PR is awaiting review labels Oct 7, 2024
@VojtechBartoska VojtechBartoska added this to the 3.1.0-RC2 milestone Oct 23, 2024
Copy link
Collaborator

@SuGlider SuGlider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
@vortigont - thanks for the good contribution!

Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@lucasssvaz lucasssvaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@me-no-dev me-no-dev added Status: Pending Merge Pull Request is ready to be merged and removed Status: Review needed Issue or PR is awaiting review labels Oct 24, 2024
@me-no-dev
Copy link
Member

@me-no-dev me-no-dev merged commit 07c510e into espressif:master Oct 24, 2024
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: WiFi Issue related to WiFi Status: Pending Merge Pull Request is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: NetworkEvents::onEvent() can't register function calbacks via lambda expressions
6 participants