Skip to content

power-policy-interface/psu: Introduce notification traits#916

Open
RobertZ2011 wants to merge 4 commits into
OpenDevicePartnership:mainfrom
RobertZ2011:power-policy-notifier-trait
Open

power-policy-interface/psu: Introduce notification traits#916
RobertZ2011 wants to merge 4 commits into
OpenDevicePartnership:mainfrom
RobertZ2011:power-policy-notifier-trait

Conversation

@RobertZ2011

@RobertZ2011 RobertZ2011 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Refactor the existing power policy PSU notification code to use generic notifier and handler traits instead of channel-based traits. Provide implementations of these traits for existing channel-based code.

@RobertZ2011 RobertZ2011 self-assigned this Jul 8, 2026
@RobertZ2011
RobertZ2011 force-pushed the power-policy-notifier-trait branch from cb371c3 to f063f56 Compare July 8, 2026 18:45
@RobertZ2011
RobertZ2011 requested a review from Copilot July 8, 2026 18:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces explicit “notification” traits for power-policy PSU and service events, and then migrates existing code to depend on those traits instead of directly depending on channel sender types. The net effect is that callers can choose whether notifications are delivered via non-blocking try_send-style behavior or via an async/blocking send-style behavior, without changing the service/controller logic. Type-C controller ports are updated to hold a PowerNotifier abstraction for power-policy events, and power-policy service registration is updated similarly for downstream service notifications. Tests and examples are updated to wrap existing senders using the new notifier adapter types.

Changes:

  • Add PSU/service notification traits in power-policy-interface plus adapter newtypes (NonBlockingSenderNotifier, SenderNotifier) to bridge existing sender implementations.
  • Update type-c-service controller Port to use a power-policy notifier abstraction (and update call sites accordingly).
  • Update power-policy-service registration + event fan-out to use service notification traits instead of raw senders.

Step-by-step review guide

  1. New interface surface (notification traits + adapters)

    • Review power-policy-interface/src/psu/notification.rs and power-policy-interface/src/service/notification.rs for the trait shape and error semantics (WouldBlock).
    • Review the adapter implementations in power-policy-interface/src/psu/event.rs and power-policy-interface/src/service/event.rs. These are the bridge that lets existing Sender/NonBlockingSender implementations satisfy the new notifier traits.
  2. Type-C service migration to notifier-based PSU events

    • Review type-c-service/src/controller/mod.rs and type-c-service/src/controller/power.rs where try_send(EventData::...) is replaced with power_policy_notifier.notify_*(...).await.
    • Ensure the notifier is constructed at the boundary (tests/macros/examples) via .into() from existing senders so the controller remains agnostic.
  3. Power-policy service migration to notifier-based service notifications

    • Review power-policy-service/src/service/registration.rs where Registration now exposes notifiers() instead of event_senders().
    • Review power-policy-service/src/service/mod.rs, consumer.rs, and provider.rs for the shift from “broadcast event by try_send” to “notify via trait”, and the addition of a psu::notification::NotificationHandler impl used by process_psu_event.
  4. Tests/examples plumbing

    • Review the updated test/common modules and examples to ensure they consistently wrap senders into the correct notifier adapter types (the .into() call sites are the key points).

Potential issues

# Severity File Description Code
1 Medium power-policy-interface/src/psu/event.rs:44-46 Doc comment says NonBlockingSender<Event> but the adapter wraps NonBlockingSender<EventData>; also “chose” typo. NonBlockingSender<Event>
2 Medium power-policy-interface/src/psu/event.rs:106-108 Doc comment says Sender<Event> but the adapter wraps Sender<EventData>; also “chose” typo. Sender<Event>
3 Medium power-policy-service/src/service/registration.rs:34-35 ArrayRegistration stores notifiers but the public field remains service_senders, which is misleading for non-sender notifier implementations; renaming is a multi-file API change. pub service_senders: ...
4 Low power-policy-interface/src/service/notification.rs:21 Typo in doc comment (“disconneced”). disconneced
5 Low power-policy-interface/src/service/event.rs:89 Typo in doc comment (“chose”). chose

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
type-c-service/tests/common/mod.rs Update test harness port wiring to pass a power-policy notifier wrapper instead of a raw sender.
type-c-service/src/controller/mod.rs Port now stores a power-policy notifier and uses it for attach/detach notifications.
type-c-service/src/controller/power.rs Replace direct power-policy try_send calls with notifier notify_*().await calls.
type-c-service/src/controller/pd.rs Update generic bounds/impl headers to use the notifier abstraction.
type-c-service/src/controller/type_c.rs Update generic bounds/impl headers to use the notifier abstraction.
type-c-service/src/controller/retimer.rs Update generic bounds/impl headers to use the notifier abstraction.
type-c-service/src/controller/ucsi.rs Update generic bounds/impl headers to use the notifier abstraction.
type-c-service/src/controller/max_sink_voltage.rs Update power-policy disconnect notification to use notifier API.
type-c-service/src/controller/electrical_disconnect.rs Update generic bounds/impl headers to use the notifier abstraction.
type-c-service/src/controller/macros.rs Update controller port macro-generated types/wiring to store and pass notifier wrappers.
power-policy-service/tests/common/mod.rs Update power-policy test harness to wrap senders into PSU/service notifier adapters.
power-policy-service/src/service/registration.rs Registration now exposes service notifiers (trait) instead of service event senders.
power-policy-service/src/service/mod.rs Replace broadcast-by-sender with notifier fan-out; implement PSU notification handler trait.
power-policy-service/src/service/provider.rs Make provider post-connect/disconnect paths await notifier fan-out.
power-policy-service/src/service/consumer.rs Replace service-event broadcast calls with notifier fan-out for consumer/unconstrained events.
power-policy-interface/src/service/mod.rs Export new service::notification module.
power-policy-interface/src/service/notification.rs Add service notification trait + error type.
power-policy-interface/src/service/event.rs Add notifier adapter newtypes implementing the new service notification trait.
power-policy-interface/src/psu/mod.rs Export new psu::notification module.
power-policy-interface/src/psu/notification.rs Add PSU notifier + PSU notification handler traits.
power-policy-interface/src/psu/event.rs Add notifier adapter newtypes implementing the new PSU notification trait.
power-policy-interface-test-mocks/src/psu.rs Update PSU test mock to use notifier trait instead of raw sender.
examples/std/src/lib/type_c/mock_controller.rs Update std mock controller port type to use a PSU notifier wrapper.
examples/std/src/bin/type_c/unconstrained.rs Update example registration to pass notifier wrapper instead of sender.
examples/std/src/bin/type_c/ucsi.rs Update example registration to pass notifier wrapper instead of sender.
examples/std/src/bin/type_c/service.rs Update example registration to pass notifier wrapper instead of sender.
examples/std/src/bin/power_policy.rs Update example registration to pass notifier wrapper instead of sender.
examples/rt685s-evk/src/bin/type_c.rs Update RT685 example port/service wiring to use notifier wrappers.
examples/rt685s-evk/src/bin/type_c_cfu.rs Update RT685 CFU example port/service wiring to use notifier wrappers.

Comment thread power-policy-interface/src/service/notification.rs Outdated
Comment thread power-policy-interface/src/service/event.rs Outdated
Comment thread power-policy-interface/src/service/event.rs Outdated
Comment thread power-policy-interface/src/psu/event.rs Outdated
Comment thread power-policy-interface/src/psu/event.rs Outdated
Comment thread power-policy-service/src/service/registration.rs Outdated
Comment thread power-policy-service/src/service/registration.rs Outdated
@RobertZ2011
RobertZ2011 force-pushed the power-policy-notifier-trait branch 6 times, most recently from 3f6209a to b234ec3 Compare July 8, 2026 22:25
@RobertZ2011
RobertZ2011 force-pushed the power-policy-notifier-trait branch from b234ec3 to dda87a5 Compare July 20, 2026 15:47
@RobertZ2011
RobertZ2011 marked this pull request as ready for review July 20, 2026 15:51
@RobertZ2011
RobertZ2011 requested review from a team as code owners July 20, 2026 15:51
@RobertZ2011
RobertZ2011 enabled auto-merge (squash) July 20, 2026 15:53
@RobertZ2011
RobertZ2011 requested a review from tullom July 20, 2026 15:53
@RobertZ2011
RobertZ2011 force-pushed the power-policy-notifier-trait branch from dda87a5 to ff28bce Compare July 20, 2026 23:17
@RobertZ2011
RobertZ2011 disabled auto-merge July 20, 2026 23:17
@RobertZ2011
RobertZ2011 force-pushed the power-policy-notifier-trait branch from ff28bce to 092defa Compare July 21, 2026 15:08

@jerrysxie jerrysxie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@RobertZ2011 Can we link the issue that is tracking this effort?

Comment thread power-policy-service/src/service/mod.rs
Comment thread power-policy-interface/src/psu/event.rs
@RobertZ2011 RobertZ2011 linked an issue Jul 22, 2026 that may be closed by this pull request
@RobertZ2011 RobertZ2011 added the BREAKING CHANGE Marks breaking changes label Jul 22, 2026
@RobertZ2011
RobertZ2011 requested a review from jerrysxie July 22, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BREAKING CHANGE Marks breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Power policy: Introduce notification traits

3 participants