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