power-policy-interface/psu: Introduce notification traits#916
power-policy-interface/psu: Introduce notification traits#916RobertZ2011 wants to merge 4 commits into
Conversation
cb371c3 to
f063f56
Compare
There was a problem hiding this comment.
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-interfaceplus adapter newtypes (NonBlockingSenderNotifier,SenderNotifier) to bridge existing sender implementations. - Update
type-c-servicecontrollerPortto use a power-policy notifier abstraction (and update call sites accordingly). - Update
power-policy-serviceregistration + event fan-out to use service notification traits instead of raw senders.
Step-by-step review guide
-
New interface surface (notification traits + adapters)
- Review
power-policy-interface/src/psu/notification.rsandpower-policy-interface/src/service/notification.rsfor the trait shape and error semantics (WouldBlock). - Review the adapter implementations in
power-policy-interface/src/psu/event.rsandpower-policy-interface/src/service/event.rs. These are the bridge that lets existingSender/NonBlockingSenderimplementations satisfy the new notifier traits.
- Review
-
Type-C service migration to notifier-based PSU events
- Review
type-c-service/src/controller/mod.rsandtype-c-service/src/controller/power.rswheretry_send(EventData::...)is replaced withpower_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.
- Review
-
Power-policy service migration to notifier-based service notifications
- Review
power-policy-service/src/service/registration.rswhereRegistrationnow exposesnotifiers()instead ofevent_senders(). - Review
power-policy-service/src/service/mod.rs,consumer.rs, andprovider.rsfor the shift from “broadcast event by try_send” to “notify via trait”, and the addition of apsu::notification::NotificationHandlerimpl used byprocess_psu_event.
- Review
-
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).
- Review the updated test/common modules and examples to ensure they consistently wrap senders into the correct notifier adapter types (the
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. |
c6841e4 to
9644dee
Compare
9644dee to
88d666a
Compare
3f6209a to
b234ec3
Compare
No description provided.