power_manager_integration_test_lib/client_connectors/
reboot_watcher_client.rsuse crate::TestEnv;
use futures::channel::mpsc;
use futures::{StreamExt, TryStreamExt};
use tracing::*;
use {fidl_fuchsia_hardware_power_statecontrol as fpower, fuchsia_async as fasync};
pub struct RebootWatcherClient {
_watcher_task: fasync::Task<()>,
reboot_reason_receiver: mpsc::Receiver<fpower::RebootReason>,
}
impl RebootWatcherClient {
pub async fn new(test_env: &TestEnv) -> Self {
let (mut reboot_reason_sender, reboot_reason_receiver) = mpsc::channel(1);
let watcher_register_proxy =
test_env.connect_to_protocol::<fpower::RebootMethodsWatcherRegisterMarker>();
let (watcher_client, mut watcher_request_stream) =
fidl::endpoints::create_request_stream::<fpower::RebootMethodsWatcherMarker>();
watcher_register_proxy
.register_with_ack(watcher_client)
.await
.expect("Failed to register reboot watcher");
let _watcher_task = fasync::Task::local(async move {
while let Some(fpower::RebootMethodsWatcherRequest::OnReboot { reason, responder }) =
watcher_request_stream.try_next().await.unwrap()
{
info!("Received reboot reason: {:?}", reason);
let _ = responder.send();
reboot_reason_sender.try_send(reason).expect("Failed to notify reboot reason");
}
});
Self { _watcher_task, reboot_reason_receiver }
}
pub async fn get_reboot_reason(&mut self) -> fpower::RebootReason {
self.reboot_reason_receiver.next().await.expect("Failed to wait for reboot reason")
}
}