fidl_fuchsia_netemul_guest/
fidl_fuchsia_netemul_guest.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_netemul_guest__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct ControllerCreateGuestRequest {
16    pub name: String,
17    pub network: fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
18    pub mac: Option<Box<fidl_fuchsia_net::MacAddress>>,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
22    for ControllerCreateGuestRequest
23{
24}
25
26#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
27pub struct ControllerCreateGuestResponse {
28    pub s: fidl::endpoints::ClientEnd<GuestMarker>,
29}
30
31impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
32    for ControllerCreateGuestResponse
33{
34}
35
36#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
37pub struct ControllerMarker;
38
39impl fidl::endpoints::ProtocolMarker for ControllerMarker {
40    type Proxy = ControllerProxy;
41    type RequestStream = ControllerRequestStream;
42    #[cfg(target_os = "fuchsia")]
43    type SynchronousProxy = ControllerSynchronousProxy;
44
45    const DEBUG_NAME: &'static str = "fuchsia.netemul.guest.Controller";
46}
47impl fidl::endpoints::DiscoverableProtocolMarker for ControllerMarker {}
48pub type ControllerCreateGuestResult =
49    Result<fidl::endpoints::ClientEnd<GuestMarker>, ControllerCreateGuestError>;
50
51pub trait ControllerProxyInterface: Send + Sync {
52    type CreateGuestResponseFut: std::future::Future<Output = Result<ControllerCreateGuestResult, fidl::Error>>
53        + Send;
54    fn r#create_guest(
55        &self,
56        name: &str,
57        network: fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
58        mac: Option<&fidl_fuchsia_net::MacAddress>,
59    ) -> Self::CreateGuestResponseFut;
60}
61#[derive(Debug)]
62#[cfg(target_os = "fuchsia")]
63pub struct ControllerSynchronousProxy {
64    client: fidl::client::sync::Client,
65}
66
67#[cfg(target_os = "fuchsia")]
68impl fidl::endpoints::SynchronousProxy for ControllerSynchronousProxy {
69    type Proxy = ControllerProxy;
70    type Protocol = ControllerMarker;
71
72    fn from_channel(inner: fidl::Channel) -> Self {
73        Self::new(inner)
74    }
75
76    fn into_channel(self) -> fidl::Channel {
77        self.client.into_channel()
78    }
79
80    fn as_channel(&self) -> &fidl::Channel {
81        self.client.as_channel()
82    }
83}
84
85#[cfg(target_os = "fuchsia")]
86impl ControllerSynchronousProxy {
87    pub fn new(channel: fidl::Channel) -> Self {
88        let protocol_name = <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
89        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
90    }
91
92    pub fn into_channel(self) -> fidl::Channel {
93        self.client.into_channel()
94    }
95
96    /// Waits until an event arrives and returns it. It is safe for other
97    /// threads to make concurrent requests while waiting for an event.
98    pub fn wait_for_event(
99        &self,
100        deadline: zx::MonotonicInstant,
101    ) -> Result<ControllerEvent, fidl::Error> {
102        ControllerEvent::decode(self.client.wait_for_event(deadline)?)
103    }
104
105    /// Creates a new guest instance, attaches it to the provided `network`, optionally
106    /// with `mac` as its mac address, and starts serving the `Guest` protocol over
107    /// the returned client end.
108    ///
109    /// + request `name` a name to be associated with the guest, to be used in logs
110    ///   and assertions.
111    /// + request `network` the client end of a netemul network, to which the guest
112    ///   should be attached.
113    /// + request `mac` an optional mac address which is provided to the guest on
114    ///   on creation. If `mac` is not provided, the guest's mac address is picked
115    ///   by guest-manager.
116    /// + response `guest` the client end of a `Guest` protocol which can be used to
117    ///   interact with the guest.
118    pub fn r#create_guest(
119        &self,
120        mut name: &str,
121        mut network: fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
122        mut mac: Option<&fidl_fuchsia_net::MacAddress>,
123        ___deadline: zx::MonotonicInstant,
124    ) -> Result<ControllerCreateGuestResult, fidl::Error> {
125        let _response =
126            self.client.send_query::<ControllerCreateGuestRequest, fidl::encoding::ResultType<
127                ControllerCreateGuestResponse,
128                ControllerCreateGuestError,
129            >>(
130                (name, network, mac),
131                0x5c49cf5272f818c0,
132                fidl::encoding::DynamicFlags::empty(),
133                ___deadline,
134            )?;
135        Ok(_response.map(|x| x.s))
136    }
137}
138
139#[cfg(target_os = "fuchsia")]
140impl From<ControllerSynchronousProxy> for zx::Handle {
141    fn from(value: ControllerSynchronousProxy) -> Self {
142        value.into_channel().into()
143    }
144}
145
146#[cfg(target_os = "fuchsia")]
147impl From<fidl::Channel> for ControllerSynchronousProxy {
148    fn from(value: fidl::Channel) -> Self {
149        Self::new(value)
150    }
151}
152
153#[cfg(target_os = "fuchsia")]
154impl fidl::endpoints::FromClient for ControllerSynchronousProxy {
155    type Protocol = ControllerMarker;
156
157    fn from_client(value: fidl::endpoints::ClientEnd<ControllerMarker>) -> Self {
158        Self::new(value.into_channel())
159    }
160}
161
162#[derive(Debug, Clone)]
163pub struct ControllerProxy {
164    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
165}
166
167impl fidl::endpoints::Proxy for ControllerProxy {
168    type Protocol = ControllerMarker;
169
170    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
171        Self::new(inner)
172    }
173
174    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
175        self.client.into_channel().map_err(|client| Self { client })
176    }
177
178    fn as_channel(&self) -> &::fidl::AsyncChannel {
179        self.client.as_channel()
180    }
181}
182
183impl ControllerProxy {
184    /// Create a new Proxy for fuchsia.netemul.guest/Controller.
185    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
186        let protocol_name = <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
187        Self { client: fidl::client::Client::new(channel, protocol_name) }
188    }
189
190    /// Get a Stream of events from the remote end of the protocol.
191    ///
192    /// # Panics
193    ///
194    /// Panics if the event stream was already taken.
195    pub fn take_event_stream(&self) -> ControllerEventStream {
196        ControllerEventStream { event_receiver: self.client.take_event_receiver() }
197    }
198
199    /// Creates a new guest instance, attaches it to the provided `network`, optionally
200    /// with `mac` as its mac address, and starts serving the `Guest` protocol over
201    /// the returned client end.
202    ///
203    /// + request `name` a name to be associated with the guest, to be used in logs
204    ///   and assertions.
205    /// + request `network` the client end of a netemul network, to which the guest
206    ///   should be attached.
207    /// + request `mac` an optional mac address which is provided to the guest on
208    ///   on creation. If `mac` is not provided, the guest's mac address is picked
209    ///   by guest-manager.
210    /// + response `guest` the client end of a `Guest` protocol which can be used to
211    ///   interact with the guest.
212    pub fn r#create_guest(
213        &self,
214        mut name: &str,
215        mut network: fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
216        mut mac: Option<&fidl_fuchsia_net::MacAddress>,
217    ) -> fidl::client::QueryResponseFut<
218        ControllerCreateGuestResult,
219        fidl::encoding::DefaultFuchsiaResourceDialect,
220    > {
221        ControllerProxyInterface::r#create_guest(self, name, network, mac)
222    }
223}
224
225impl ControllerProxyInterface for ControllerProxy {
226    type CreateGuestResponseFut = fidl::client::QueryResponseFut<
227        ControllerCreateGuestResult,
228        fidl::encoding::DefaultFuchsiaResourceDialect,
229    >;
230    fn r#create_guest(
231        &self,
232        mut name: &str,
233        mut network: fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
234        mut mac: Option<&fidl_fuchsia_net::MacAddress>,
235    ) -> Self::CreateGuestResponseFut {
236        fn _decode(
237            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
238        ) -> Result<ControllerCreateGuestResult, fidl::Error> {
239            let _response = fidl::client::decode_transaction_body::<
240                fidl::encoding::ResultType<
241                    ControllerCreateGuestResponse,
242                    ControllerCreateGuestError,
243                >,
244                fidl::encoding::DefaultFuchsiaResourceDialect,
245                0x5c49cf5272f818c0,
246            >(_buf?)?;
247            Ok(_response.map(|x| x.s))
248        }
249        self.client
250            .send_query_and_decode::<ControllerCreateGuestRequest, ControllerCreateGuestResult>(
251                (name, network, mac),
252                0x5c49cf5272f818c0,
253                fidl::encoding::DynamicFlags::empty(),
254                _decode,
255            )
256    }
257}
258
259pub struct ControllerEventStream {
260    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
261}
262
263impl std::marker::Unpin for ControllerEventStream {}
264
265impl futures::stream::FusedStream for ControllerEventStream {
266    fn is_terminated(&self) -> bool {
267        self.event_receiver.is_terminated()
268    }
269}
270
271impl futures::Stream for ControllerEventStream {
272    type Item = Result<ControllerEvent, fidl::Error>;
273
274    fn poll_next(
275        mut self: std::pin::Pin<&mut Self>,
276        cx: &mut std::task::Context<'_>,
277    ) -> std::task::Poll<Option<Self::Item>> {
278        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
279            &mut self.event_receiver,
280            cx
281        )?) {
282            Some(buf) => std::task::Poll::Ready(Some(ControllerEvent::decode(buf))),
283            None => std::task::Poll::Ready(None),
284        }
285    }
286}
287
288#[derive(Debug)]
289pub enum ControllerEvent {}
290
291impl ControllerEvent {
292    /// Decodes a message buffer as a [`ControllerEvent`].
293    fn decode(
294        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
295    ) -> Result<ControllerEvent, fidl::Error> {
296        let (bytes, _handles) = buf.split_mut();
297        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
298        debug_assert_eq!(tx_header.tx_id, 0);
299        match tx_header.ordinal {
300            _ => Err(fidl::Error::UnknownOrdinal {
301                ordinal: tx_header.ordinal,
302                protocol_name: <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
303            }),
304        }
305    }
306}
307
308/// A Stream of incoming requests for fuchsia.netemul.guest/Controller.
309pub struct ControllerRequestStream {
310    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
311    is_terminated: bool,
312}
313
314impl std::marker::Unpin for ControllerRequestStream {}
315
316impl futures::stream::FusedStream for ControllerRequestStream {
317    fn is_terminated(&self) -> bool {
318        self.is_terminated
319    }
320}
321
322impl fidl::endpoints::RequestStream for ControllerRequestStream {
323    type Protocol = ControllerMarker;
324    type ControlHandle = ControllerControlHandle;
325
326    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
327        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
328    }
329
330    fn control_handle(&self) -> Self::ControlHandle {
331        ControllerControlHandle { inner: self.inner.clone() }
332    }
333
334    fn into_inner(
335        self,
336    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
337    {
338        (self.inner, self.is_terminated)
339    }
340
341    fn from_inner(
342        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
343        is_terminated: bool,
344    ) -> Self {
345        Self { inner, is_terminated }
346    }
347}
348
349impl futures::Stream for ControllerRequestStream {
350    type Item = Result<ControllerRequest, fidl::Error>;
351
352    fn poll_next(
353        mut self: std::pin::Pin<&mut Self>,
354        cx: &mut std::task::Context<'_>,
355    ) -> std::task::Poll<Option<Self::Item>> {
356        let this = &mut *self;
357        if this.inner.check_shutdown(cx) {
358            this.is_terminated = true;
359            return std::task::Poll::Ready(None);
360        }
361        if this.is_terminated {
362            panic!("polled ControllerRequestStream after completion");
363        }
364        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
365            |bytes, handles| {
366                match this.inner.channel().read_etc(cx, bytes, handles) {
367                    std::task::Poll::Ready(Ok(())) => {}
368                    std::task::Poll::Pending => return std::task::Poll::Pending,
369                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
370                        this.is_terminated = true;
371                        return std::task::Poll::Ready(None);
372                    }
373                    std::task::Poll::Ready(Err(e)) => {
374                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
375                            e.into(),
376                        ))))
377                    }
378                }
379
380                // A message has been received from the channel
381                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
382
383                std::task::Poll::Ready(Some(match header.ordinal {
384                    0x5c49cf5272f818c0 => {
385                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
386                        let mut req = fidl::new_empty!(
387                            ControllerCreateGuestRequest,
388                            fidl::encoding::DefaultFuchsiaResourceDialect
389                        );
390                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControllerCreateGuestRequest>(&header, _body_bytes, handles, &mut req)?;
391                        let control_handle = ControllerControlHandle { inner: this.inner.clone() };
392                        Ok(ControllerRequest::CreateGuest {
393                            name: req.name,
394                            network: req.network,
395                            mac: req.mac,
396
397                            responder: ControllerCreateGuestResponder {
398                                control_handle: std::mem::ManuallyDrop::new(control_handle),
399                                tx_id: header.tx_id,
400                            },
401                        })
402                    }
403                    _ => Err(fidl::Error::UnknownOrdinal {
404                        ordinal: header.ordinal,
405                        protocol_name:
406                            <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
407                    }),
408                }))
409            },
410        )
411    }
412}
413
414/// `Controller` exposes methods for interacting with the guest manager.
415#[derive(Debug)]
416pub enum ControllerRequest {
417    /// Creates a new guest instance, attaches it to the provided `network`, optionally
418    /// with `mac` as its mac address, and starts serving the `Guest` protocol over
419    /// the returned client end.
420    ///
421    /// + request `name` a name to be associated with the guest, to be used in logs
422    ///   and assertions.
423    /// + request `network` the client end of a netemul network, to which the guest
424    ///   should be attached.
425    /// + request `mac` an optional mac address which is provided to the guest on
426    ///   on creation. If `mac` is not provided, the guest's mac address is picked
427    ///   by guest-manager.
428    /// + response `guest` the client end of a `Guest` protocol which can be used to
429    ///   interact with the guest.
430    CreateGuest {
431        name: String,
432        network: fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
433        mac: Option<Box<fidl_fuchsia_net::MacAddress>>,
434        responder: ControllerCreateGuestResponder,
435    },
436}
437
438impl ControllerRequest {
439    #[allow(irrefutable_let_patterns)]
440    pub fn into_create_guest(
441        self,
442    ) -> Option<(
443        String,
444        fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
445        Option<Box<fidl_fuchsia_net::MacAddress>>,
446        ControllerCreateGuestResponder,
447    )> {
448        if let ControllerRequest::CreateGuest { name, network, mac, responder } = self {
449            Some((name, network, mac, responder))
450        } else {
451            None
452        }
453    }
454
455    /// Name of the method defined in FIDL
456    pub fn method_name(&self) -> &'static str {
457        match *self {
458            ControllerRequest::CreateGuest { .. } => "create_guest",
459        }
460    }
461}
462
463#[derive(Debug, Clone)]
464pub struct ControllerControlHandle {
465    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
466}
467
468impl fidl::endpoints::ControlHandle for ControllerControlHandle {
469    fn shutdown(&self) {
470        self.inner.shutdown()
471    }
472    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
473        self.inner.shutdown_with_epitaph(status)
474    }
475
476    fn is_closed(&self) -> bool {
477        self.inner.channel().is_closed()
478    }
479    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
480        self.inner.channel().on_closed()
481    }
482
483    #[cfg(target_os = "fuchsia")]
484    fn signal_peer(
485        &self,
486        clear_mask: zx::Signals,
487        set_mask: zx::Signals,
488    ) -> Result<(), zx_status::Status> {
489        use fidl::Peered;
490        self.inner.channel().signal_peer(clear_mask, set_mask)
491    }
492}
493
494impl ControllerControlHandle {}
495
496#[must_use = "FIDL methods require a response to be sent"]
497#[derive(Debug)]
498pub struct ControllerCreateGuestResponder {
499    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
500    tx_id: u32,
501}
502
503/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
504/// if the responder is dropped without sending a response, so that the client
505/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
506impl std::ops::Drop for ControllerCreateGuestResponder {
507    fn drop(&mut self) {
508        self.control_handle.shutdown();
509        // Safety: drops once, never accessed again
510        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
511    }
512}
513
514impl fidl::endpoints::Responder for ControllerCreateGuestResponder {
515    type ControlHandle = ControllerControlHandle;
516
517    fn control_handle(&self) -> &ControllerControlHandle {
518        &self.control_handle
519    }
520
521    fn drop_without_shutdown(mut self) {
522        // Safety: drops once, never accessed again due to mem::forget
523        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
524        // Prevent Drop from running (which would shut down the channel)
525        std::mem::forget(self);
526    }
527}
528
529impl ControllerCreateGuestResponder {
530    /// Sends a response to the FIDL transaction.
531    ///
532    /// Sets the channel to shutdown if an error occurs.
533    pub fn send(
534        self,
535        mut result: Result<fidl::endpoints::ClientEnd<GuestMarker>, ControllerCreateGuestError>,
536    ) -> Result<(), fidl::Error> {
537        let _result = self.send_raw(result);
538        if _result.is_err() {
539            self.control_handle.shutdown();
540        }
541        self.drop_without_shutdown();
542        _result
543    }
544
545    /// Similar to "send" but does not shutdown the channel if an error occurs.
546    pub fn send_no_shutdown_on_err(
547        self,
548        mut result: Result<fidl::endpoints::ClientEnd<GuestMarker>, ControllerCreateGuestError>,
549    ) -> Result<(), fidl::Error> {
550        let _result = self.send_raw(result);
551        self.drop_without_shutdown();
552        _result
553    }
554
555    fn send_raw(
556        &self,
557        mut result: Result<fidl::endpoints::ClientEnd<GuestMarker>, ControllerCreateGuestError>,
558    ) -> Result<(), fidl::Error> {
559        self.control_handle.inner.send::<fidl::encoding::ResultType<
560            ControllerCreateGuestResponse,
561            ControllerCreateGuestError,
562        >>(
563            result.map(|s| (s,)),
564            self.tx_id,
565            0x5c49cf5272f818c0,
566            fidl::encoding::DynamicFlags::empty(),
567        )
568    }
569}
570
571#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
572pub struct GuestMarker;
573
574impl fidl::endpoints::ProtocolMarker for GuestMarker {
575    type Proxy = GuestProxy;
576    type RequestStream = GuestRequestStream;
577    #[cfg(target_os = "fuchsia")]
578    type SynchronousProxy = GuestSynchronousProxy;
579
580    const DEBUG_NAME: &'static str = "(anonymous) Guest";
581}
582
583pub trait GuestProxyInterface: Send + Sync {
584    type PutFileResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
585    fn r#put_file(
586        &self,
587        local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
588        remote_path: &str,
589    ) -> Self::PutFileResponseFut;
590    type GetFileResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
591    fn r#get_file(
592        &self,
593        remote_path: &str,
594        local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
595    ) -> Self::GetFileResponseFut;
596    fn r#execute_command(
597        &self,
598        command: &str,
599        env: &[fidl_fuchsia_virtualization_guest_interaction::EnvironmentVariable],
600        stdin: Option<fidl::Socket>,
601        stdout: Option<fidl::Socket>,
602        stderr: Option<fidl::Socket>,
603        command_listener: fidl::endpoints::ServerEnd<
604            fidl_fuchsia_virtualization_guest_interaction::CommandListenerMarker,
605        >,
606    ) -> Result<(), fidl::Error>;
607    type ShutdownResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
608    fn r#shutdown(&self) -> Self::ShutdownResponseFut;
609}
610#[derive(Debug)]
611#[cfg(target_os = "fuchsia")]
612pub struct GuestSynchronousProxy {
613    client: fidl::client::sync::Client,
614}
615
616#[cfg(target_os = "fuchsia")]
617impl fidl::endpoints::SynchronousProxy for GuestSynchronousProxy {
618    type Proxy = GuestProxy;
619    type Protocol = GuestMarker;
620
621    fn from_channel(inner: fidl::Channel) -> Self {
622        Self::new(inner)
623    }
624
625    fn into_channel(self) -> fidl::Channel {
626        self.client.into_channel()
627    }
628
629    fn as_channel(&self) -> &fidl::Channel {
630        self.client.as_channel()
631    }
632}
633
634#[cfg(target_os = "fuchsia")]
635impl GuestSynchronousProxy {
636    pub fn new(channel: fidl::Channel) -> Self {
637        let protocol_name = <GuestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
638        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
639    }
640
641    pub fn into_channel(self) -> fidl::Channel {
642        self.client.into_channel()
643    }
644
645    /// Waits until an event arrives and returns it. It is safe for other
646    /// threads to make concurrent requests while waiting for an event.
647    pub fn wait_for_event(
648        &self,
649        deadline: zx::MonotonicInstant,
650    ) -> Result<GuestEvent, fidl::Error> {
651        GuestEvent::decode(self.client.wait_for_event(deadline)?)
652    }
653
654    /// Take a local file from the Fuchsia host and transfer it to a destination
655    /// location on the guest under test.
656    pub fn r#put_file(
657        &self,
658        mut local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
659        mut remote_path: &str,
660        ___deadline: zx::MonotonicInstant,
661    ) -> Result<i32, fidl::Error> {
662        let _response = self.client.send_query::<
663            fidl_fuchsia_virtualization_guest_interaction::InteractionPutFileRequest,
664            fidl_fuchsia_virtualization_guest_interaction::InteractionPutFileResponse,
665        >(
666            (local_file, remote_path,),
667            0x223bc20da4a7cddd,
668            fidl::encoding::DynamicFlags::empty(),
669            ___deadline,
670        )?;
671        Ok(_response.status)
672    }
673
674    /// Pull a file from the guest under test and copy it to the specified
675    /// location on the Fuchsia host.
676    pub fn r#get_file(
677        &self,
678        mut remote_path: &str,
679        mut local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
680        ___deadline: zx::MonotonicInstant,
681    ) -> Result<i32, fidl::Error> {
682        let _response = self.client.send_query::<
683            fidl_fuchsia_virtualization_guest_interaction::InteractionGetFileRequest,
684            fidl_fuchsia_virtualization_guest_interaction::InteractionGetFileResponse,
685        >(
686            (remote_path, local_file,),
687            0x7696bea472ca0f2d,
688            fidl::encoding::DynamicFlags::empty(),
689            ___deadline,
690        )?;
691        Ok(_response.status)
692    }
693
694    /// Execute command on the guest under test and return the resulting output,
695    /// error, and return code.
696    pub fn r#execute_command(
697        &self,
698        mut command: &str,
699        mut env: &[fidl_fuchsia_virtualization_guest_interaction::EnvironmentVariable],
700        mut stdin: Option<fidl::Socket>,
701        mut stdout: Option<fidl::Socket>,
702        mut stderr: Option<fidl::Socket>,
703        mut command_listener: fidl::endpoints::ServerEnd<
704            fidl_fuchsia_virtualization_guest_interaction::CommandListenerMarker,
705        >,
706    ) -> Result<(), fidl::Error> {
707        self.client.send::<fidl_fuchsia_virtualization_guest_interaction::InteractionExecuteCommandRequest>(
708            (command, env, stdin, stdout, stderr, command_listener,),
709            0x612641220a1556d8,
710            fidl::encoding::DynamicFlags::empty(),
711        )
712    }
713
714    /// Shuts down the guest and closes the channel over which `Guest` is being
715    /// served.
716    pub fn r#shutdown(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
717        let _response =
718            self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
719                (),
720                0x287e71d61642d1cc,
721                fidl::encoding::DynamicFlags::empty(),
722                ___deadline,
723            )?;
724        Ok(_response)
725    }
726}
727
728#[cfg(target_os = "fuchsia")]
729impl From<GuestSynchronousProxy> for zx::Handle {
730    fn from(value: GuestSynchronousProxy) -> Self {
731        value.into_channel().into()
732    }
733}
734
735#[cfg(target_os = "fuchsia")]
736impl From<fidl::Channel> for GuestSynchronousProxy {
737    fn from(value: fidl::Channel) -> Self {
738        Self::new(value)
739    }
740}
741
742#[cfg(target_os = "fuchsia")]
743impl fidl::endpoints::FromClient for GuestSynchronousProxy {
744    type Protocol = GuestMarker;
745
746    fn from_client(value: fidl::endpoints::ClientEnd<GuestMarker>) -> Self {
747        Self::new(value.into_channel())
748    }
749}
750
751#[derive(Debug, Clone)]
752pub struct GuestProxy {
753    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
754}
755
756impl fidl::endpoints::Proxy for GuestProxy {
757    type Protocol = GuestMarker;
758
759    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
760        Self::new(inner)
761    }
762
763    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
764        self.client.into_channel().map_err(|client| Self { client })
765    }
766
767    fn as_channel(&self) -> &::fidl::AsyncChannel {
768        self.client.as_channel()
769    }
770}
771
772impl GuestProxy {
773    /// Create a new Proxy for fuchsia.netemul.guest/Guest.
774    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
775        let protocol_name = <GuestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
776        Self { client: fidl::client::Client::new(channel, protocol_name) }
777    }
778
779    /// Get a Stream of events from the remote end of the protocol.
780    ///
781    /// # Panics
782    ///
783    /// Panics if the event stream was already taken.
784    pub fn take_event_stream(&self) -> GuestEventStream {
785        GuestEventStream { event_receiver: self.client.take_event_receiver() }
786    }
787
788    /// Take a local file from the Fuchsia host and transfer it to a destination
789    /// location on the guest under test.
790    pub fn r#put_file(
791        &self,
792        mut local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
793        mut remote_path: &str,
794    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
795        GuestProxyInterface::r#put_file(self, local_file, remote_path)
796    }
797
798    /// Pull a file from the guest under test and copy it to the specified
799    /// location on the Fuchsia host.
800    pub fn r#get_file(
801        &self,
802        mut remote_path: &str,
803        mut local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
804    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
805        GuestProxyInterface::r#get_file(self, remote_path, local_file)
806    }
807
808    /// Execute command on the guest under test and return the resulting output,
809    /// error, and return code.
810    pub fn r#execute_command(
811        &self,
812        mut command: &str,
813        mut env: &[fidl_fuchsia_virtualization_guest_interaction::EnvironmentVariable],
814        mut stdin: Option<fidl::Socket>,
815        mut stdout: Option<fidl::Socket>,
816        mut stderr: Option<fidl::Socket>,
817        mut command_listener: fidl::endpoints::ServerEnd<
818            fidl_fuchsia_virtualization_guest_interaction::CommandListenerMarker,
819        >,
820    ) -> Result<(), fidl::Error> {
821        GuestProxyInterface::r#execute_command(
822            self,
823            command,
824            env,
825            stdin,
826            stdout,
827            stderr,
828            command_listener,
829        )
830    }
831
832    /// Shuts down the guest and closes the channel over which `Guest` is being
833    /// served.
834    pub fn r#shutdown(
835        &self,
836    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
837        GuestProxyInterface::r#shutdown(self)
838    }
839}
840
841impl GuestProxyInterface for GuestProxy {
842    type PutFileResponseFut =
843        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
844    fn r#put_file(
845        &self,
846        mut local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
847        mut remote_path: &str,
848    ) -> Self::PutFileResponseFut {
849        fn _decode(
850            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
851        ) -> Result<i32, fidl::Error> {
852            let _response = fidl::client::decode_transaction_body::<
853                fidl_fuchsia_virtualization_guest_interaction::InteractionPutFileResponse,
854                fidl::encoding::DefaultFuchsiaResourceDialect,
855                0x223bc20da4a7cddd,
856            >(_buf?)?;
857            Ok(_response.status)
858        }
859        self.client.send_query_and_decode::<
860            fidl_fuchsia_virtualization_guest_interaction::InteractionPutFileRequest,
861            i32,
862        >(
863            (local_file, remote_path,),
864            0x223bc20da4a7cddd,
865            fidl::encoding::DynamicFlags::empty(),
866            _decode,
867        )
868    }
869
870    type GetFileResponseFut =
871        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
872    fn r#get_file(
873        &self,
874        mut remote_path: &str,
875        mut local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
876    ) -> Self::GetFileResponseFut {
877        fn _decode(
878            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
879        ) -> Result<i32, fidl::Error> {
880            let _response = fidl::client::decode_transaction_body::<
881                fidl_fuchsia_virtualization_guest_interaction::InteractionGetFileResponse,
882                fidl::encoding::DefaultFuchsiaResourceDialect,
883                0x7696bea472ca0f2d,
884            >(_buf?)?;
885            Ok(_response.status)
886        }
887        self.client.send_query_and_decode::<
888            fidl_fuchsia_virtualization_guest_interaction::InteractionGetFileRequest,
889            i32,
890        >(
891            (remote_path, local_file,),
892            0x7696bea472ca0f2d,
893            fidl::encoding::DynamicFlags::empty(),
894            _decode,
895        )
896    }
897
898    fn r#execute_command(
899        &self,
900        mut command: &str,
901        mut env: &[fidl_fuchsia_virtualization_guest_interaction::EnvironmentVariable],
902        mut stdin: Option<fidl::Socket>,
903        mut stdout: Option<fidl::Socket>,
904        mut stderr: Option<fidl::Socket>,
905        mut command_listener: fidl::endpoints::ServerEnd<
906            fidl_fuchsia_virtualization_guest_interaction::CommandListenerMarker,
907        >,
908    ) -> Result<(), fidl::Error> {
909        self.client.send::<fidl_fuchsia_virtualization_guest_interaction::InteractionExecuteCommandRequest>(
910            (command, env, stdin, stdout, stderr, command_listener,),
911            0x612641220a1556d8,
912            fidl::encoding::DynamicFlags::empty(),
913        )
914    }
915
916    type ShutdownResponseFut =
917        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
918    fn r#shutdown(&self) -> Self::ShutdownResponseFut {
919        fn _decode(
920            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
921        ) -> Result<(), fidl::Error> {
922            let _response = fidl::client::decode_transaction_body::<
923                fidl::encoding::EmptyPayload,
924                fidl::encoding::DefaultFuchsiaResourceDialect,
925                0x287e71d61642d1cc,
926            >(_buf?)?;
927            Ok(_response)
928        }
929        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
930            (),
931            0x287e71d61642d1cc,
932            fidl::encoding::DynamicFlags::empty(),
933            _decode,
934        )
935    }
936}
937
938pub struct GuestEventStream {
939    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
940}
941
942impl std::marker::Unpin for GuestEventStream {}
943
944impl futures::stream::FusedStream for GuestEventStream {
945    fn is_terminated(&self) -> bool {
946        self.event_receiver.is_terminated()
947    }
948}
949
950impl futures::Stream for GuestEventStream {
951    type Item = Result<GuestEvent, fidl::Error>;
952
953    fn poll_next(
954        mut self: std::pin::Pin<&mut Self>,
955        cx: &mut std::task::Context<'_>,
956    ) -> std::task::Poll<Option<Self::Item>> {
957        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
958            &mut self.event_receiver,
959            cx
960        )?) {
961            Some(buf) => std::task::Poll::Ready(Some(GuestEvent::decode(buf))),
962            None => std::task::Poll::Ready(None),
963        }
964    }
965}
966
967#[derive(Debug)]
968pub enum GuestEvent {}
969
970impl GuestEvent {
971    /// Decodes a message buffer as a [`GuestEvent`].
972    fn decode(
973        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
974    ) -> Result<GuestEvent, fidl::Error> {
975        let (bytes, _handles) = buf.split_mut();
976        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
977        debug_assert_eq!(tx_header.tx_id, 0);
978        match tx_header.ordinal {
979            _ => Err(fidl::Error::UnknownOrdinal {
980                ordinal: tx_header.ordinal,
981                protocol_name: <GuestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
982            }),
983        }
984    }
985}
986
987/// A Stream of incoming requests for fuchsia.netemul.guest/Guest.
988pub struct GuestRequestStream {
989    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
990    is_terminated: bool,
991}
992
993impl std::marker::Unpin for GuestRequestStream {}
994
995impl futures::stream::FusedStream for GuestRequestStream {
996    fn is_terminated(&self) -> bool {
997        self.is_terminated
998    }
999}
1000
1001impl fidl::endpoints::RequestStream for GuestRequestStream {
1002    type Protocol = GuestMarker;
1003    type ControlHandle = GuestControlHandle;
1004
1005    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1006        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1007    }
1008
1009    fn control_handle(&self) -> Self::ControlHandle {
1010        GuestControlHandle { inner: self.inner.clone() }
1011    }
1012
1013    fn into_inner(
1014        self,
1015    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1016    {
1017        (self.inner, self.is_terminated)
1018    }
1019
1020    fn from_inner(
1021        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1022        is_terminated: bool,
1023    ) -> Self {
1024        Self { inner, is_terminated }
1025    }
1026}
1027
1028impl futures::Stream for GuestRequestStream {
1029    type Item = Result<GuestRequest, fidl::Error>;
1030
1031    fn poll_next(
1032        mut self: std::pin::Pin<&mut Self>,
1033        cx: &mut std::task::Context<'_>,
1034    ) -> std::task::Poll<Option<Self::Item>> {
1035        let this = &mut *self;
1036        if this.inner.check_shutdown(cx) {
1037            this.is_terminated = true;
1038            return std::task::Poll::Ready(None);
1039        }
1040        if this.is_terminated {
1041            panic!("polled GuestRequestStream after completion");
1042        }
1043        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1044            |bytes, handles| {
1045                match this.inner.channel().read_etc(cx, bytes, handles) {
1046                    std::task::Poll::Ready(Ok(())) => {}
1047                    std::task::Poll::Pending => return std::task::Poll::Pending,
1048                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1049                        this.is_terminated = true;
1050                        return std::task::Poll::Ready(None);
1051                    }
1052                    std::task::Poll::Ready(Err(e)) => {
1053                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1054                            e.into(),
1055                        ))))
1056                    }
1057                }
1058
1059                // A message has been received from the channel
1060                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1061
1062                std::task::Poll::Ready(Some(match header.ordinal {
1063                    0x223bc20da4a7cddd => {
1064                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1065                        let mut req = fidl::new_empty!(fidl_fuchsia_virtualization_guest_interaction::InteractionPutFileRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
1066                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl_fuchsia_virtualization_guest_interaction::InteractionPutFileRequest>(&header, _body_bytes, handles, &mut req)?;
1067                        let control_handle = GuestControlHandle { inner: this.inner.clone() };
1068                        Ok(GuestRequest::PutFile {
1069                            local_file: req.local_file,
1070                            remote_path: req.remote_path,
1071
1072                            responder: GuestPutFileResponder {
1073                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1074                                tx_id: header.tx_id,
1075                            },
1076                        })
1077                    }
1078                    0x7696bea472ca0f2d => {
1079                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1080                        let mut req = fidl::new_empty!(fidl_fuchsia_virtualization_guest_interaction::InteractionGetFileRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
1081                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl_fuchsia_virtualization_guest_interaction::InteractionGetFileRequest>(&header, _body_bytes, handles, &mut req)?;
1082                        let control_handle = GuestControlHandle { inner: this.inner.clone() };
1083                        Ok(GuestRequest::GetFile {
1084                            remote_path: req.remote_path,
1085                            local_file: req.local_file,
1086
1087                            responder: GuestGetFileResponder {
1088                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1089                                tx_id: header.tx_id,
1090                            },
1091                        })
1092                    }
1093                    0x612641220a1556d8 => {
1094                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1095                        let mut req = fidl::new_empty!(fidl_fuchsia_virtualization_guest_interaction::InteractionExecuteCommandRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
1096                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl_fuchsia_virtualization_guest_interaction::InteractionExecuteCommandRequest>(&header, _body_bytes, handles, &mut req)?;
1097                        let control_handle = GuestControlHandle { inner: this.inner.clone() };
1098                        Ok(GuestRequest::ExecuteCommand {
1099                            command: req.command,
1100                            env: req.env,
1101                            stdin: req.stdin,
1102                            stdout: req.stdout,
1103                            stderr: req.stderr,
1104                            command_listener: req.command_listener,
1105
1106                            control_handle,
1107                        })
1108                    }
1109                    0x287e71d61642d1cc => {
1110                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1111                        let mut req = fidl::new_empty!(
1112                            fidl::encoding::EmptyPayload,
1113                            fidl::encoding::DefaultFuchsiaResourceDialect
1114                        );
1115                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1116                        let control_handle = GuestControlHandle { inner: this.inner.clone() };
1117                        Ok(GuestRequest::Shutdown {
1118                            responder: GuestShutdownResponder {
1119                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1120                                tx_id: header.tx_id,
1121                            },
1122                        })
1123                    }
1124                    _ => Err(fidl::Error::UnknownOrdinal {
1125                        ordinal: header.ordinal,
1126                        protocol_name: <GuestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1127                    }),
1128                }))
1129            },
1130        )
1131    }
1132}
1133
1134/// `Guest` exposes methods for interacting with a virtualized guest.
1135///
1136/// A connection to `Guest` provides access to a single virtualized guest.
1137/// The guest lifetime is bound to the connection; when the client handle
1138/// is dropped, the guest will be shutdown. NOTE however that this
1139/// shutdown-on-drop happens asynchronously; clients should always use
1140/// the synchronous method below to avoid flakes when running multiple
1141/// tests.
1142#[derive(Debug)]
1143pub enum GuestRequest {
1144    /// Take a local file from the Fuchsia host and transfer it to a destination
1145    /// location on the guest under test.
1146    PutFile {
1147        local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
1148        remote_path: String,
1149        responder: GuestPutFileResponder,
1150    },
1151    /// Pull a file from the guest under test and copy it to the specified
1152    /// location on the Fuchsia host.
1153    GetFile {
1154        remote_path: String,
1155        local_file: fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
1156        responder: GuestGetFileResponder,
1157    },
1158    /// Execute command on the guest under test and return the resulting output,
1159    /// error, and return code.
1160    ExecuteCommand {
1161        command: String,
1162        env: Vec<fidl_fuchsia_virtualization_guest_interaction::EnvironmentVariable>,
1163        stdin: Option<fidl::Socket>,
1164        stdout: Option<fidl::Socket>,
1165        stderr: Option<fidl::Socket>,
1166        command_listener: fidl::endpoints::ServerEnd<
1167            fidl_fuchsia_virtualization_guest_interaction::CommandListenerMarker,
1168        >,
1169        control_handle: GuestControlHandle,
1170    },
1171    /// Shuts down the guest and closes the channel over which `Guest` is being
1172    /// served.
1173    Shutdown { responder: GuestShutdownResponder },
1174}
1175
1176impl GuestRequest {
1177    #[allow(irrefutable_let_patterns)]
1178    pub fn into_put_file(
1179        self,
1180    ) -> Option<(
1181        fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
1182        String,
1183        GuestPutFileResponder,
1184    )> {
1185        if let GuestRequest::PutFile { local_file, remote_path, responder } = self {
1186            Some((local_file, remote_path, responder))
1187        } else {
1188            None
1189        }
1190    }
1191
1192    #[allow(irrefutable_let_patterns)]
1193    pub fn into_get_file(
1194        self,
1195    ) -> Option<(
1196        String,
1197        fidl::endpoints::ClientEnd<fidl_fuchsia_io::FileMarker>,
1198        GuestGetFileResponder,
1199    )> {
1200        if let GuestRequest::GetFile { remote_path, local_file, responder } = self {
1201            Some((remote_path, local_file, responder))
1202        } else {
1203            None
1204        }
1205    }
1206
1207    #[allow(irrefutable_let_patterns)]
1208    pub fn into_execute_command(
1209        self,
1210    ) -> Option<(
1211        String,
1212        Vec<fidl_fuchsia_virtualization_guest_interaction::EnvironmentVariable>,
1213        Option<fidl::Socket>,
1214        Option<fidl::Socket>,
1215        Option<fidl::Socket>,
1216        fidl::endpoints::ServerEnd<
1217            fidl_fuchsia_virtualization_guest_interaction::CommandListenerMarker,
1218        >,
1219        GuestControlHandle,
1220    )> {
1221        if let GuestRequest::ExecuteCommand {
1222            command,
1223            env,
1224            stdin,
1225            stdout,
1226            stderr,
1227            command_listener,
1228            control_handle,
1229        } = self
1230        {
1231            Some((command, env, stdin, stdout, stderr, command_listener, control_handle))
1232        } else {
1233            None
1234        }
1235    }
1236
1237    #[allow(irrefutable_let_patterns)]
1238    pub fn into_shutdown(self) -> Option<(GuestShutdownResponder)> {
1239        if let GuestRequest::Shutdown { responder } = self {
1240            Some((responder))
1241        } else {
1242            None
1243        }
1244    }
1245
1246    /// Name of the method defined in FIDL
1247    pub fn method_name(&self) -> &'static str {
1248        match *self {
1249            GuestRequest::PutFile { .. } => "put_file",
1250            GuestRequest::GetFile { .. } => "get_file",
1251            GuestRequest::ExecuteCommand { .. } => "execute_command",
1252            GuestRequest::Shutdown { .. } => "shutdown",
1253        }
1254    }
1255}
1256
1257#[derive(Debug, Clone)]
1258pub struct GuestControlHandle {
1259    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1260}
1261
1262impl fidl::endpoints::ControlHandle for GuestControlHandle {
1263    fn shutdown(&self) {
1264        self.inner.shutdown()
1265    }
1266    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1267        self.inner.shutdown_with_epitaph(status)
1268    }
1269
1270    fn is_closed(&self) -> bool {
1271        self.inner.channel().is_closed()
1272    }
1273    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1274        self.inner.channel().on_closed()
1275    }
1276
1277    #[cfg(target_os = "fuchsia")]
1278    fn signal_peer(
1279        &self,
1280        clear_mask: zx::Signals,
1281        set_mask: zx::Signals,
1282    ) -> Result<(), zx_status::Status> {
1283        use fidl::Peered;
1284        self.inner.channel().signal_peer(clear_mask, set_mask)
1285    }
1286}
1287
1288impl GuestControlHandle {}
1289
1290#[must_use = "FIDL methods require a response to be sent"]
1291#[derive(Debug)]
1292pub struct GuestPutFileResponder {
1293    control_handle: std::mem::ManuallyDrop<GuestControlHandle>,
1294    tx_id: u32,
1295}
1296
1297/// Set the the channel to be shutdown (see [`GuestControlHandle::shutdown`])
1298/// if the responder is dropped without sending a response, so that the client
1299/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1300impl std::ops::Drop for GuestPutFileResponder {
1301    fn drop(&mut self) {
1302        self.control_handle.shutdown();
1303        // Safety: drops once, never accessed again
1304        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1305    }
1306}
1307
1308impl fidl::endpoints::Responder for GuestPutFileResponder {
1309    type ControlHandle = GuestControlHandle;
1310
1311    fn control_handle(&self) -> &GuestControlHandle {
1312        &self.control_handle
1313    }
1314
1315    fn drop_without_shutdown(mut self) {
1316        // Safety: drops once, never accessed again due to mem::forget
1317        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1318        // Prevent Drop from running (which would shut down the channel)
1319        std::mem::forget(self);
1320    }
1321}
1322
1323impl GuestPutFileResponder {
1324    /// Sends a response to the FIDL transaction.
1325    ///
1326    /// Sets the channel to shutdown if an error occurs.
1327    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
1328        let _result = self.send_raw(status);
1329        if _result.is_err() {
1330            self.control_handle.shutdown();
1331        }
1332        self.drop_without_shutdown();
1333        _result
1334    }
1335
1336    /// Similar to "send" but does not shutdown the channel if an error occurs.
1337    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
1338        let _result = self.send_raw(status);
1339        self.drop_without_shutdown();
1340        _result
1341    }
1342
1343    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
1344        self.control_handle
1345            .inner
1346            .send::<fidl_fuchsia_virtualization_guest_interaction::InteractionPutFileResponse>(
1347            (status,),
1348            self.tx_id,
1349            0x223bc20da4a7cddd,
1350            fidl::encoding::DynamicFlags::empty(),
1351        )
1352    }
1353}
1354
1355#[must_use = "FIDL methods require a response to be sent"]
1356#[derive(Debug)]
1357pub struct GuestGetFileResponder {
1358    control_handle: std::mem::ManuallyDrop<GuestControlHandle>,
1359    tx_id: u32,
1360}
1361
1362/// Set the the channel to be shutdown (see [`GuestControlHandle::shutdown`])
1363/// if the responder is dropped without sending a response, so that the client
1364/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1365impl std::ops::Drop for GuestGetFileResponder {
1366    fn drop(&mut self) {
1367        self.control_handle.shutdown();
1368        // Safety: drops once, never accessed again
1369        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1370    }
1371}
1372
1373impl fidl::endpoints::Responder for GuestGetFileResponder {
1374    type ControlHandle = GuestControlHandle;
1375
1376    fn control_handle(&self) -> &GuestControlHandle {
1377        &self.control_handle
1378    }
1379
1380    fn drop_without_shutdown(mut self) {
1381        // Safety: drops once, never accessed again due to mem::forget
1382        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1383        // Prevent Drop from running (which would shut down the channel)
1384        std::mem::forget(self);
1385    }
1386}
1387
1388impl GuestGetFileResponder {
1389    /// Sends a response to the FIDL transaction.
1390    ///
1391    /// Sets the channel to shutdown if an error occurs.
1392    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
1393        let _result = self.send_raw(status);
1394        if _result.is_err() {
1395            self.control_handle.shutdown();
1396        }
1397        self.drop_without_shutdown();
1398        _result
1399    }
1400
1401    /// Similar to "send" but does not shutdown the channel if an error occurs.
1402    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
1403        let _result = self.send_raw(status);
1404        self.drop_without_shutdown();
1405        _result
1406    }
1407
1408    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
1409        self.control_handle
1410            .inner
1411            .send::<fidl_fuchsia_virtualization_guest_interaction::InteractionGetFileResponse>(
1412            (status,),
1413            self.tx_id,
1414            0x7696bea472ca0f2d,
1415            fidl::encoding::DynamicFlags::empty(),
1416        )
1417    }
1418}
1419
1420#[must_use = "FIDL methods require a response to be sent"]
1421#[derive(Debug)]
1422pub struct GuestShutdownResponder {
1423    control_handle: std::mem::ManuallyDrop<GuestControlHandle>,
1424    tx_id: u32,
1425}
1426
1427/// Set the the channel to be shutdown (see [`GuestControlHandle::shutdown`])
1428/// if the responder is dropped without sending a response, so that the client
1429/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1430impl std::ops::Drop for GuestShutdownResponder {
1431    fn drop(&mut self) {
1432        self.control_handle.shutdown();
1433        // Safety: drops once, never accessed again
1434        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1435    }
1436}
1437
1438impl fidl::endpoints::Responder for GuestShutdownResponder {
1439    type ControlHandle = GuestControlHandle;
1440
1441    fn control_handle(&self) -> &GuestControlHandle {
1442        &self.control_handle
1443    }
1444
1445    fn drop_without_shutdown(mut self) {
1446        // Safety: drops once, never accessed again due to mem::forget
1447        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1448        // Prevent Drop from running (which would shut down the channel)
1449        std::mem::forget(self);
1450    }
1451}
1452
1453impl GuestShutdownResponder {
1454    /// Sends a response to the FIDL transaction.
1455    ///
1456    /// Sets the channel to shutdown if an error occurs.
1457    pub fn send(self) -> Result<(), fidl::Error> {
1458        let _result = self.send_raw();
1459        if _result.is_err() {
1460            self.control_handle.shutdown();
1461        }
1462        self.drop_without_shutdown();
1463        _result
1464    }
1465
1466    /// Similar to "send" but does not shutdown the channel if an error occurs.
1467    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1468        let _result = self.send_raw();
1469        self.drop_without_shutdown();
1470        _result
1471    }
1472
1473    fn send_raw(&self) -> Result<(), fidl::Error> {
1474        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1475            (),
1476            self.tx_id,
1477            0x287e71d61642d1cc,
1478            fidl::encoding::DynamicFlags::empty(),
1479        )
1480    }
1481}
1482
1483mod internal {
1484    use super::*;
1485
1486    impl fidl::encoding::ResourceTypeMarker for ControllerCreateGuestRequest {
1487        type Borrowed<'a> = &'a mut Self;
1488        fn take_or_borrow<'a>(
1489            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1490        ) -> Self::Borrowed<'a> {
1491            value
1492        }
1493    }
1494
1495    unsafe impl fidl::encoding::TypeMarker for ControllerCreateGuestRequest {
1496        type Owned = Self;
1497
1498        #[inline(always)]
1499        fn inline_align(_context: fidl::encoding::Context) -> usize {
1500            8
1501        }
1502
1503        #[inline(always)]
1504        fn inline_size(_context: fidl::encoding::Context) -> usize {
1505            32
1506        }
1507    }
1508
1509    unsafe impl
1510        fidl::encoding::Encode<
1511            ControllerCreateGuestRequest,
1512            fidl::encoding::DefaultFuchsiaResourceDialect,
1513        > for &mut ControllerCreateGuestRequest
1514    {
1515        #[inline]
1516        unsafe fn encode(
1517            self,
1518            encoder: &mut fidl::encoding::Encoder<
1519                '_,
1520                fidl::encoding::DefaultFuchsiaResourceDialect,
1521            >,
1522            offset: usize,
1523            _depth: fidl::encoding::Depth,
1524        ) -> fidl::Result<()> {
1525            encoder.debug_check_bounds::<ControllerCreateGuestRequest>(offset);
1526            // Delegate to tuple encoding.
1527            fidl::encoding::Encode::<ControllerCreateGuestRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1528                (
1529                    <fidl::encoding::BoundedString<32> as fidl::encoding::ValueTypeMarker>::borrow(&self.name),
1530                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.network),
1531                    <fidl::encoding::Boxed<fidl_fuchsia_net::MacAddress> as fidl::encoding::ValueTypeMarker>::borrow(&self.mac),
1532                ),
1533                encoder, offset, _depth
1534            )
1535        }
1536    }
1537    unsafe impl<
1538            T0: fidl::encoding::Encode<
1539                fidl::encoding::BoundedString<32>,
1540                fidl::encoding::DefaultFuchsiaResourceDialect,
1541            >,
1542            T1: fidl::encoding::Encode<
1543                fidl::encoding::Endpoint<
1544                    fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
1545                >,
1546                fidl::encoding::DefaultFuchsiaResourceDialect,
1547            >,
1548            T2: fidl::encoding::Encode<
1549                fidl::encoding::Boxed<fidl_fuchsia_net::MacAddress>,
1550                fidl::encoding::DefaultFuchsiaResourceDialect,
1551            >,
1552        >
1553        fidl::encoding::Encode<
1554            ControllerCreateGuestRequest,
1555            fidl::encoding::DefaultFuchsiaResourceDialect,
1556        > for (T0, T1, T2)
1557    {
1558        #[inline]
1559        unsafe fn encode(
1560            self,
1561            encoder: &mut fidl::encoding::Encoder<
1562                '_,
1563                fidl::encoding::DefaultFuchsiaResourceDialect,
1564            >,
1565            offset: usize,
1566            depth: fidl::encoding::Depth,
1567        ) -> fidl::Result<()> {
1568            encoder.debug_check_bounds::<ControllerCreateGuestRequest>(offset);
1569            // Zero out padding regions. There's no need to apply masks
1570            // because the unmasked parts will be overwritten by fields.
1571            unsafe {
1572                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1573                (ptr as *mut u64).write_unaligned(0);
1574            }
1575            // Write the fields.
1576            self.0.encode(encoder, offset + 0, depth)?;
1577            self.1.encode(encoder, offset + 16, depth)?;
1578            self.2.encode(encoder, offset + 24, depth)?;
1579            Ok(())
1580        }
1581    }
1582
1583    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1584        for ControllerCreateGuestRequest
1585    {
1586        #[inline(always)]
1587        fn new_empty() -> Self {
1588            Self {
1589                name: fidl::new_empty!(
1590                    fidl::encoding::BoundedString<32>,
1591                    fidl::encoding::DefaultFuchsiaResourceDialect
1592                ),
1593                network: fidl::new_empty!(
1594                    fidl::encoding::Endpoint<
1595                        fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
1596                    >,
1597                    fidl::encoding::DefaultFuchsiaResourceDialect
1598                ),
1599                mac: fidl::new_empty!(
1600                    fidl::encoding::Boxed<fidl_fuchsia_net::MacAddress>,
1601                    fidl::encoding::DefaultFuchsiaResourceDialect
1602                ),
1603            }
1604        }
1605
1606        #[inline]
1607        unsafe fn decode(
1608            &mut self,
1609            decoder: &mut fidl::encoding::Decoder<
1610                '_,
1611                fidl::encoding::DefaultFuchsiaResourceDialect,
1612            >,
1613            offset: usize,
1614            _depth: fidl::encoding::Depth,
1615        ) -> fidl::Result<()> {
1616            decoder.debug_check_bounds::<Self>(offset);
1617            // Verify that padding bytes are zero.
1618            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1619            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1620            let mask = 0xffffffff00000000u64;
1621            let maskedval = padval & mask;
1622            if maskedval != 0 {
1623                return Err(fidl::Error::NonZeroPadding {
1624                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1625                });
1626            }
1627            fidl::decode!(
1628                fidl::encoding::BoundedString<32>,
1629                fidl::encoding::DefaultFuchsiaResourceDialect,
1630                &mut self.name,
1631                decoder,
1632                offset + 0,
1633                _depth
1634            )?;
1635            fidl::decode!(
1636                fidl::encoding::Endpoint<
1637                    fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
1638                >,
1639                fidl::encoding::DefaultFuchsiaResourceDialect,
1640                &mut self.network,
1641                decoder,
1642                offset + 16,
1643                _depth
1644            )?;
1645            fidl::decode!(
1646                fidl::encoding::Boxed<fidl_fuchsia_net::MacAddress>,
1647                fidl::encoding::DefaultFuchsiaResourceDialect,
1648                &mut self.mac,
1649                decoder,
1650                offset + 24,
1651                _depth
1652            )?;
1653            Ok(())
1654        }
1655    }
1656
1657    impl fidl::encoding::ResourceTypeMarker for ControllerCreateGuestResponse {
1658        type Borrowed<'a> = &'a mut Self;
1659        fn take_or_borrow<'a>(
1660            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1661        ) -> Self::Borrowed<'a> {
1662            value
1663        }
1664    }
1665
1666    unsafe impl fidl::encoding::TypeMarker for ControllerCreateGuestResponse {
1667        type Owned = Self;
1668
1669        #[inline(always)]
1670        fn inline_align(_context: fidl::encoding::Context) -> usize {
1671            4
1672        }
1673
1674        #[inline(always)]
1675        fn inline_size(_context: fidl::encoding::Context) -> usize {
1676            4
1677        }
1678    }
1679
1680    unsafe impl
1681        fidl::encoding::Encode<
1682            ControllerCreateGuestResponse,
1683            fidl::encoding::DefaultFuchsiaResourceDialect,
1684        > for &mut ControllerCreateGuestResponse
1685    {
1686        #[inline]
1687        unsafe fn encode(
1688            self,
1689            encoder: &mut fidl::encoding::Encoder<
1690                '_,
1691                fidl::encoding::DefaultFuchsiaResourceDialect,
1692            >,
1693            offset: usize,
1694            _depth: fidl::encoding::Depth,
1695        ) -> fidl::Result<()> {
1696            encoder.debug_check_bounds::<ControllerCreateGuestResponse>(offset);
1697            // Delegate to tuple encoding.
1698            fidl::encoding::Encode::<ControllerCreateGuestResponse, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1699                (
1700                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<GuestMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.s),
1701                ),
1702                encoder, offset, _depth
1703            )
1704        }
1705    }
1706    unsafe impl<
1707            T0: fidl::encoding::Encode<
1708                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<GuestMarker>>,
1709                fidl::encoding::DefaultFuchsiaResourceDialect,
1710            >,
1711        >
1712        fidl::encoding::Encode<
1713            ControllerCreateGuestResponse,
1714            fidl::encoding::DefaultFuchsiaResourceDialect,
1715        > for (T0,)
1716    {
1717        #[inline]
1718        unsafe fn encode(
1719            self,
1720            encoder: &mut fidl::encoding::Encoder<
1721                '_,
1722                fidl::encoding::DefaultFuchsiaResourceDialect,
1723            >,
1724            offset: usize,
1725            depth: fidl::encoding::Depth,
1726        ) -> fidl::Result<()> {
1727            encoder.debug_check_bounds::<ControllerCreateGuestResponse>(offset);
1728            // Zero out padding regions. There's no need to apply masks
1729            // because the unmasked parts will be overwritten by fields.
1730            // Write the fields.
1731            self.0.encode(encoder, offset + 0, depth)?;
1732            Ok(())
1733        }
1734    }
1735
1736    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1737        for ControllerCreateGuestResponse
1738    {
1739        #[inline(always)]
1740        fn new_empty() -> Self {
1741            Self {
1742                s: fidl::new_empty!(
1743                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<GuestMarker>>,
1744                    fidl::encoding::DefaultFuchsiaResourceDialect
1745                ),
1746            }
1747        }
1748
1749        #[inline]
1750        unsafe fn decode(
1751            &mut self,
1752            decoder: &mut fidl::encoding::Decoder<
1753                '_,
1754                fidl::encoding::DefaultFuchsiaResourceDialect,
1755            >,
1756            offset: usize,
1757            _depth: fidl::encoding::Depth,
1758        ) -> fidl::Result<()> {
1759            decoder.debug_check_bounds::<Self>(offset);
1760            // Verify that padding bytes are zero.
1761            fidl::decode!(
1762                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<GuestMarker>>,
1763                fidl::encoding::DefaultFuchsiaResourceDialect,
1764                &mut self.s,
1765                decoder,
1766                offset + 0,
1767                _depth
1768            )?;
1769            Ok(())
1770        }
1771    }
1772}