Skip to content

Encapsulate notifier/realtime UDP socket state behind accessors - #12

Open
netmindz wants to merge 1 commit into
refactor/split-udp-syncfrom
refactor/udp-wled-socket-state
Open

Encapsulate notifier/realtime UDP socket state behind accessors#12
netmindz wants to merge 1 commit into
refactor/split-udp-syncfrom
refactor/udp-wled-socket-state

Conversation

@netmindz

@netmindz netmindz commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Summary

Stacked on the udp.cpp sync split (targets that branch, not main, since it depends on it).

notifierUdp/notifier2Udp/rgbUdp and their udpConnected/udp2Connected/udpRgbConnected flags were WLED_GLOBAL. Once udp.cpp was split into per-protocol files (wled00/sync/), each protocol file ended up reaching into these directly — fan-out grew from a clean 2-file pair to 3-5 files each, exactly the kind of implicit cross-file coupling an accessor boundary is meant to prevent.

Moved them into a NotifierSockets struct owned by wled.cpp (where the sockets are actually opened via .begin()), exposed to every other file via six small accessors: getNotifierUdp()/getNotifier2Udp()/getRgbUdp() (returning WiFiUDP& so callers can call methods directly, no copies) and isUdpConnected()/isUdp2Connected()/isUdpRgbConnected(). Call sites that use a socket more than once alias it to a local reference at the top of the function rather than repeating the accessor call.

Found and fixed one real external consumer: usermods/udp_name_sync reached into notifierUdp/udpConnected directly. It isn't part of the default esp32dev usermod set, so this would have been a silent build break for anyone enabling it — caught by building the dedicated usermods env, which compiles every usermod.

No behavior change — purely a storage/access-pattern change.

Test plan

  • esp32dev: builds and links cleanly via pio run -e esp32dev (1,320,311 bytes flash).
  • usermods env (builds all 59 usermods, including the fixed udp_name_sync): builds and links cleanly via pio run -e usermods.
  • Repo-wide grep confirms no remaining raw references to any of the six converted identifiers outside wled.cpp's NotifierSockets struct.

🤖 Generated with Claude Code


Summary by cubic

Encapsulated notifier and realtime UDP sockets (and their connection flags) behind small accessors to reduce cross-file coupling after the UDP sync split. No behavior change; also fixes a build break in the udp_name_sync usermod.

  • Refactors

    • Moved notifierUdp, notifier2Udp, rgbUdp and their flags into NotifierSockets in wled.cpp.
    • Added accessors: getNotifierUdp(), getNotifier2Udp(), getRgbUdp(), isUdpConnected(), isUdp2Connected(), isUdpRgbConnected().
    • Updated call sites to use accessors; created local references where reused.
  • Bug Fixes

    • Updated usermods/udp_name_sync to use the new accessors to prevent a build failure when the usermod is enabled.

Written for commit a196171. Summary will update on new commits.

Review in cubic

notifierUdp/notifier2Udp/rgbUdp and their udpConnected/udp2Connected/
udpRgbConnected flags were WLED_GLOBAL. Once udp.cpp was split into
per-protocol files (wled00/sync/), each protocol file ended up
reaching into these directly - fan-out grew from a clean 2-file pair
to 3-5 files each, exactly the kind of implicit cross-file coupling
an accessor boundary is meant to prevent.

Moved them into a NotifierSockets struct owned by wled.cpp (where the
sockets are actually opened via .begin()), exposed to every other file
via six small accessors: getNotifierUdp()/getNotifier2Udp()/getRgbUdp()
(returning WiFiUDP& so callers can call methods directly, no copies)
and isUdpConnected()/isUdp2Connected()/isUdpRgbConnected(). Call sites
that use a socket more than once alias it to a local reference at the
top of the function rather than repeating the accessor call.

Found and fixed one real external consumer: usermods/udp_name_sync
reached into notifierUdp/udpConnected directly. It isn't part of the
default esp32dev usermod set, so this would have been a silent build
break for anyone enabling it - caught by building the dedicated
`usermods` env, which compiles every usermod.

No behavior change - purely a storage/access-pattern change.

Verified:
- esp32dev builds and links cleanly via `pio run -e esp32dev`
  (1,320,311 bytes flash).
- usermods env (builds all 59 usermods, including the fixed
  udp_name_sync) builds and links cleanly via `pio run -e usermods`.
- Repo-wide grep confirms no remaining raw references to any of the
  six converted identifiers outside wled.cpp's NotifierSockets struct.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (4)
  • main
  • 16_x
  • 0_15_x
  • V5

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e064ccfa-51c5-4aee-9c46-8044aaccf69c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 9 files

Re-trigger cubic

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.

1 participant