power_manager_integration_test_lib/client_connectors/
power_profile_client.rsuse crate::TestEnv;
use futures::channel::mpsc;
use futures::StreamExt;
use tracing::*;
use {fidl_fuchsia_power_profile as fprofile, fuchsia_async as fasync};
pub struct PowerProfileClient {
_watcher_task: fasync::Task<()>,
profile_receiver: mpsc::Receiver<fprofile::Profile>,
}
impl PowerProfileClient {
pub async fn new(test_env: &TestEnv) -> Self {
let (mut profile_sender, profile_receiver) = mpsc::channel(1);
let proxy = test_env.connect_to_protocol::<fprofile::WatcherMarker>();
let _watcher_task = fasync::Task::local(async move {
while let Ok(profile) = proxy.watch().await {
info!("Received power profile: {:?}", profile);
profile_sender.try_send(profile).expect("Failed to notify power profile change");
}
});
Self { _watcher_task, profile_receiver }
}
pub async fn get_power_profile(&mut self) -> fprofile::Profile {
self.profile_receiver.next().await.expect("Failed to wait for power profile")
}
}