archivist_lib/logs/servers/
log_freeze.rs1use anyhow::Error;
6use fidl_fuchsia_diagnostics_system as ftarget;
7use futures::StreamExt;
8use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender, unbounded};
9use futures::channel::oneshot;
10use log::warn;
11
12#[derive(Clone)]
13pub struct LogFreezeServer {
14 freezer: UnboundedSender<oneshot::Sender<zx::EventPair>>,
15}
16
17impl LogFreezeServer {
18 pub fn new() -> (Self, UnboundedReceiver<oneshot::Sender<zx::EventPair>>) {
19 let (freezer, rx) = unbounded();
20 (Self { freezer }, rx)
21 }
22
23 pub async fn handle_requests(
25 &self,
26 mut stream: ftarget::SerialLogControlRequestStream,
27 ) -> Result<(), Error> {
28 while let Some(request) = stream.next().await {
29 match request? {
30 fidl_fuchsia_diagnostics_system::SerialLogControlRequest::FreezeSerialForwarding { responder } => {
31 let (tx, rx) = oneshot::channel();
32 self.freezer.unbounded_send(tx)?;
33 let _ = responder.send(rx.await?);
35 },
36 ftarget::SerialLogControlRequest::_UnknownMethod {
37 ordinal,
38 method_type,
39 control_handle,
40 ..
41 } => {
42 warn!(ordinal, method_type:?; "Unknown request. Closing connection");
43 control_handle.shutdown_with_epitaph(zx::Status::UNAVAILABLE);
44 }
45 }
46 }
47 Ok(())
48 }
49}