Power policy event pass and clean-up#747
Power policy event pass and clean-up#747RobertZ2011 wants to merge 8 commits intoOpenDevicePartnership:v0.2.0from
Conversation
Rename the current `'a` lifetime to `'device` for clarity. Introduce a separate `device_storage` lifetime since a single lifetime overconstrains things and can lead to situations where borrows live too long and lead to issues with drops.
1ff2ae6 to
5b931a9
Compare
There was a problem hiding this comment.
Pull request overview
This PR reintroduces power-policy service event broadcasting and refactors naming by introducing a shared Named trait, updating PSU implementations accordingly, and adding/expanding tests to validate provider and unconstrained behavior.
Changes:
- Add
embedded_services::named::Namedand updatePsuto requireNamedinstead of definingname()directly. - Add power-policy service event broadcasting via configurable event senders, plus introduce
EventDatafor device-agnostic service events. - Add/expand power-policy service integration tests for consumer/provider/unconstrained flows.
Reviewed changes
Copilot reviewed 15 out of 22 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| type-c-service/src/wrapper/proxy.rs | Implements Named for PowerProxyDevice to satisfy updated Psu: Named bound. |
| power-policy-service/tests/unconstrained.rs | Adds unconstrained multi-device flow test using service event receiver assertions. |
| power-policy-service/tests/provider.rs | Adds provider connection/upgrade behavior tests and validates service events. |
| power-policy-service/tests/consumer.rs | Updates consumer tests to validate service-level events instead of only mock calls. |
| power-policy-service/tests/common/mod.rs | Extends test harness to provide a service event channel/receiver and adds assertion helpers. |
| power-policy-service/tests/common/mock.rs | Updates mock PSU simulation API and implements Named for the mock device. |
| power-policy-service/src/service/task.rs | Updates task generics to support event broadcasting sender types. |
| power-policy-service/src/service/provider.rs | Moves/expands provider disconnect handling into provider module and broadcasts provider events. |
| power-policy-service/src/service/mod.rs | Adds event_senders and implements broadcast_event; updates detach/disconnect flows accordingly. |
| power-policy-service/src/service/consumer.rs | Updates service impl generics and uses Named for logging. |
| power-policy-service/Cargo.toml | Comment formatting tweak. |
| power-policy-interface/src/service/event.rs | Adds EventData and From<Event> conversion; renames generics to PSU. |
| power-policy-interface/src/psu/mod.rs | Changes Psu to extend Named and removes fn name() from Psu. |
| examples/std/src/bin/type_c/unconstrained.rs | Updates power-policy service construction to pass event sender storage (currently discard). |
| examples/std/src/bin/type_c/ucsi.rs | Updates power-policy service task signature and adds discard event sender storage. |
| examples/std/src/bin/type_c/service.rs | Updates power-policy service construction to pass event sender storage (discard). |
| examples/std/src/bin/power_policy.rs | Updates example PSU to implement Named and passes discard event sender storage. |
| examples/rt685s-evk/src/bin/type_c_cfu.rs | Updates power-policy service task signature and adds discard event sender storage. |
| examples/rt685s-evk/src/bin/type_c.rs | Updates power-policy service task signature and adds discard event sender storage. |
| embedded-service/src/named.rs | Introduces Named trait. |
| embedded-service/src/lib.rs | Exposes named module. |
| embedded-service/src/event.rs | Adds DiscardSender and MapSender utilities for event sending pipelines. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
A receiver might only care that an event has happened and not what PSU generated the event. Currently, such a receiver would have to be generic over a PSU type that it never uses. Introduce `EventData` as a version of `Event` for use in these cases. Also rename `D` generic argument to `PSU` for clarity.
Rename for clarity.
Add event broadcasting based on `Sender<_>` trait, a few utility structs, and update tests to check broadcast events.
5b931a9 to
50c4c4b
Compare
50c4c4b to
44539e4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 22 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
44539e4 to
ceef927
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 22 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| async fn broadcast_event(&mut self, event: ServiceEvent<'device, PSU>) { | ||
| for sender in self.event_senders.iter_mut() { | ||
| sender.send(event).await; | ||
| } |
There was a problem hiding this comment.
Now that broadcast_event actually forwards events to listeners, existing call sites can start producing duplicate events. Concretely, process_notify_disconnect already emits ConsumerDisconnected for the current consumer, and then calls update_current_consumer() which can also emit ConsumerDisconnected (either when switching consumers or when no consumer remains). Consider de-duplicating by clearing current_consumer_state before update_current_consumer(), or by relying on update_current_consumer() to emit the disconnect event and removing the explicit broadcast in the disconnect path.
| /// Common logic for after a provider has successfully connected | ||
| async fn post_provider_connected(&mut self, requester: &'a PSU, target_power: ProviderPowerCapability) { | ||
| async fn post_provider_connected(&mut self, requester: &'device PSU, target_power: ProviderPowerCapability) { | ||
| let _ = self.state.connected_providers.insert(requester as *const PSU as usize); |
There was a problem hiding this comment.
post_provider_connected ignores the return value of connected_providers.insert(...). If the set is at capacity (currently MAX_CONNECTED_PROVIDERS = 4), insertion can fail, which would leave the service unable to later remove/broadcast disconnect for that provider and could make provider-state tracking inconsistent. Please handle insertion failure explicitly (e.g., return an error, log and refuse the connection, or increase capacity / derive it from the number of PSU devices).
| let _ = self.state.connected_providers.insert(requester as *const PSU as usize); | |
| if let Err(err) = self | |
| .state | |
| .connected_providers | |
| .insert(requester as *const PSU as usize) | |
| { | |
| error!( | |
| "Failed to track connected provider {:p} in connected_providers: {:?}", | |
| requester, err | |
| ); | |
| } |
Namedtrait