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 { Some((responder)) } else { None }
1240    }
1241
1242    /// Name of the method defined in FIDL
1243    pub fn method_name(&self) -> &'static str {
1244        match *self {
1245            GuestRequest::PutFile { .. } => "put_file",
1246            GuestRequest::GetFile { .. } => "get_file",
1247            GuestRequest::ExecuteCommand { .. } => "execute_command",
1248            GuestRequest::Shutdown { .. } => "shutdown",
1249        }
1250    }
1251}
1252
1253#[derive(Debug, Clone)]
1254pub struct GuestControlHandle {
1255    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1256}
1257
1258impl fidl::endpoints::ControlHandle for GuestControlHandle {
1259    fn shutdown(&self) {
1260        self.inner.shutdown()
1261    }
1262    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1263        self.inner.shutdown_with_epitaph(status)
1264    }
1265
1266    fn is_closed(&self) -> bool {
1267        self.inner.channel().is_closed()
1268    }
1269    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1270        self.inner.channel().on_closed()
1271    }
1272
1273    #[cfg(target_os = "fuchsia")]
1274    fn signal_peer(
1275        &self,
1276        clear_mask: zx::Signals,
1277        set_mask: zx::Signals,
1278    ) -> Result<(), zx_status::Status> {
1279        use fidl::Peered;
1280        self.inner.channel().signal_peer(clear_mask, set_mask)
1281    }
1282}
1283
1284impl GuestControlHandle {}
1285
1286#[must_use = "FIDL methods require a response to be sent"]
1287#[derive(Debug)]
1288pub struct GuestPutFileResponder {
1289    control_handle: std::mem::ManuallyDrop<GuestControlHandle>,
1290    tx_id: u32,
1291}
1292
1293/// Set the the channel to be shutdown (see [`GuestControlHandle::shutdown`])
1294/// if the responder is dropped without sending a response, so that the client
1295/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1296impl std::ops::Drop for GuestPutFileResponder {
1297    fn drop(&mut self) {
1298        self.control_handle.shutdown();
1299        // Safety: drops once, never accessed again
1300        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1301    }
1302}
1303
1304impl fidl::endpoints::Responder for GuestPutFileResponder {
1305    type ControlHandle = GuestControlHandle;
1306
1307    fn control_handle(&self) -> &GuestControlHandle {
1308        &self.control_handle
1309    }
1310
1311    fn drop_without_shutdown(mut self) {
1312        // Safety: drops once, never accessed again due to mem::forget
1313        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1314        // Prevent Drop from running (which would shut down the channel)
1315        std::mem::forget(self);
1316    }
1317}
1318
1319impl GuestPutFileResponder {
1320    /// Sends a response to the FIDL transaction.
1321    ///
1322    /// Sets the channel to shutdown if an error occurs.
1323    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
1324        let _result = self.send_raw(status);
1325        if _result.is_err() {
1326            self.control_handle.shutdown();
1327        }
1328        self.drop_without_shutdown();
1329        _result
1330    }
1331
1332    /// Similar to "send" but does not shutdown the channel if an error occurs.
1333    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
1334        let _result = self.send_raw(status);
1335        self.drop_without_shutdown();
1336        _result
1337    }
1338
1339    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
1340        self.control_handle
1341            .inner
1342            .send::<fidl_fuchsia_virtualization_guest_interaction::InteractionPutFileResponse>(
1343            (status,),
1344            self.tx_id,
1345            0x223bc20da4a7cddd,
1346            fidl::encoding::DynamicFlags::empty(),
1347        )
1348    }
1349}
1350
1351#[must_use = "FIDL methods require a response to be sent"]
1352#[derive(Debug)]
1353pub struct GuestGetFileResponder {
1354    control_handle: std::mem::ManuallyDrop<GuestControlHandle>,
1355    tx_id: u32,
1356}
1357
1358/// Set the the channel to be shutdown (see [`GuestControlHandle::shutdown`])
1359/// if the responder is dropped without sending a response, so that the client
1360/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1361impl std::ops::Drop for GuestGetFileResponder {
1362    fn drop(&mut self) {
1363        self.control_handle.shutdown();
1364        // Safety: drops once, never accessed again
1365        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1366    }
1367}
1368
1369impl fidl::endpoints::Responder for GuestGetFileResponder {
1370    type ControlHandle = GuestControlHandle;
1371
1372    fn control_handle(&self) -> &GuestControlHandle {
1373        &self.control_handle
1374    }
1375
1376    fn drop_without_shutdown(mut self) {
1377        // Safety: drops once, never accessed again due to mem::forget
1378        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1379        // Prevent Drop from running (which would shut down the channel)
1380        std::mem::forget(self);
1381    }
1382}
1383
1384impl GuestGetFileResponder {
1385    /// Sends a response to the FIDL transaction.
1386    ///
1387    /// Sets the channel to shutdown if an error occurs.
1388    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
1389        let _result = self.send_raw(status);
1390        if _result.is_err() {
1391            self.control_handle.shutdown();
1392        }
1393        self.drop_without_shutdown();
1394        _result
1395    }
1396
1397    /// Similar to "send" but does not shutdown the channel if an error occurs.
1398    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
1399        let _result = self.send_raw(status);
1400        self.drop_without_shutdown();
1401        _result
1402    }
1403
1404    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
1405        self.control_handle
1406            .inner
1407            .send::<fidl_fuchsia_virtualization_guest_interaction::InteractionGetFileResponse>(
1408            (status,),
1409            self.tx_id,
1410            0x7696bea472ca0f2d,
1411            fidl::encoding::DynamicFlags::empty(),
1412        )
1413    }
1414}
1415
1416#[must_use = "FIDL methods require a response to be sent"]
1417#[derive(Debug)]
1418pub struct GuestShutdownResponder {
1419    control_handle: std::mem::ManuallyDrop<GuestControlHandle>,
1420    tx_id: u32,
1421}
1422
1423/// Set the the channel to be shutdown (see [`GuestControlHandle::shutdown`])
1424/// if the responder is dropped without sending a response, so that the client
1425/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1426impl std::ops::Drop for GuestShutdownResponder {
1427    fn drop(&mut self) {
1428        self.control_handle.shutdown();
1429        // Safety: drops once, never accessed again
1430        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1431    }
1432}
1433
1434impl fidl::endpoints::Responder for GuestShutdownResponder {
1435    type ControlHandle = GuestControlHandle;
1436
1437    fn control_handle(&self) -> &GuestControlHandle {
1438        &self.control_handle
1439    }
1440
1441    fn drop_without_shutdown(mut self) {
1442        // Safety: drops once, never accessed again due to mem::forget
1443        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1444        // Prevent Drop from running (which would shut down the channel)
1445        std::mem::forget(self);
1446    }
1447}
1448
1449impl GuestShutdownResponder {
1450    /// Sends a response to the FIDL transaction.
1451    ///
1452    /// Sets the channel to shutdown if an error occurs.
1453    pub fn send(self) -> Result<(), fidl::Error> {
1454        let _result = self.send_raw();
1455        if _result.is_err() {
1456            self.control_handle.shutdown();
1457        }
1458        self.drop_without_shutdown();
1459        _result
1460    }
1461
1462    /// Similar to "send" but does not shutdown the channel if an error occurs.
1463    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1464        let _result = self.send_raw();
1465        self.drop_without_shutdown();
1466        _result
1467    }
1468
1469    fn send_raw(&self) -> Result<(), fidl::Error> {
1470        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1471            (),
1472            self.tx_id,
1473            0x287e71d61642d1cc,
1474            fidl::encoding::DynamicFlags::empty(),
1475        )
1476    }
1477}
1478
1479mod internal {
1480    use super::*;
1481
1482    impl fidl::encoding::ResourceTypeMarker for ControllerCreateGuestRequest {
1483        type Borrowed<'a> = &'a mut Self;
1484        fn take_or_borrow<'a>(
1485            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1486        ) -> Self::Borrowed<'a> {
1487            value
1488        }
1489    }
1490
1491    unsafe impl fidl::encoding::TypeMarker for ControllerCreateGuestRequest {
1492        type Owned = Self;
1493
1494        #[inline(always)]
1495        fn inline_align(_context: fidl::encoding::Context) -> usize {
1496            8
1497        }
1498
1499        #[inline(always)]
1500        fn inline_size(_context: fidl::encoding::Context) -> usize {
1501            32
1502        }
1503    }
1504
1505    unsafe impl
1506        fidl::encoding::Encode<
1507            ControllerCreateGuestRequest,
1508            fidl::encoding::DefaultFuchsiaResourceDialect,
1509        > for &mut ControllerCreateGuestRequest
1510    {
1511        #[inline]
1512        unsafe fn encode(
1513            self,
1514            encoder: &mut fidl::encoding::Encoder<
1515                '_,
1516                fidl::encoding::DefaultFuchsiaResourceDialect,
1517            >,
1518            offset: usize,
1519            _depth: fidl::encoding::Depth,
1520        ) -> fidl::Result<()> {
1521            encoder.debug_check_bounds::<ControllerCreateGuestRequest>(offset);
1522            // Delegate to tuple encoding.
1523            fidl::encoding::Encode::<ControllerCreateGuestRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1524                (
1525                    <fidl::encoding::BoundedString<32> as fidl::encoding::ValueTypeMarker>::borrow(&self.name),
1526                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.network),
1527                    <fidl::encoding::Boxed<fidl_fuchsia_net::MacAddress> as fidl::encoding::ValueTypeMarker>::borrow(&self.mac),
1528                ),
1529                encoder, offset, _depth
1530            )
1531        }
1532    }
1533    unsafe impl<
1534        T0: fidl::encoding::Encode<
1535                fidl::encoding::BoundedString<32>,
1536                fidl::encoding::DefaultFuchsiaResourceDialect,
1537            >,
1538        T1: fidl::encoding::Encode<
1539                fidl::encoding::Endpoint<
1540                    fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
1541                >,
1542                fidl::encoding::DefaultFuchsiaResourceDialect,
1543            >,
1544        T2: fidl::encoding::Encode<
1545                fidl::encoding::Boxed<fidl_fuchsia_net::MacAddress>,
1546                fidl::encoding::DefaultFuchsiaResourceDialect,
1547            >,
1548    >
1549        fidl::encoding::Encode<
1550            ControllerCreateGuestRequest,
1551            fidl::encoding::DefaultFuchsiaResourceDialect,
1552        > for (T0, T1, T2)
1553    {
1554        #[inline]
1555        unsafe fn encode(
1556            self,
1557            encoder: &mut fidl::encoding::Encoder<
1558                '_,
1559                fidl::encoding::DefaultFuchsiaResourceDialect,
1560            >,
1561            offset: usize,
1562            depth: fidl::encoding::Depth,
1563        ) -> fidl::Result<()> {
1564            encoder.debug_check_bounds::<ControllerCreateGuestRequest>(offset);
1565            // Zero out padding regions. There's no need to apply masks
1566            // because the unmasked parts will be overwritten by fields.
1567            unsafe {
1568                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1569                (ptr as *mut u64).write_unaligned(0);
1570            }
1571            // Write the fields.
1572            self.0.encode(encoder, offset + 0, depth)?;
1573            self.1.encode(encoder, offset + 16, depth)?;
1574            self.2.encode(encoder, offset + 24, depth)?;
1575            Ok(())
1576        }
1577    }
1578
1579    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1580        for ControllerCreateGuestRequest
1581    {
1582        #[inline(always)]
1583        fn new_empty() -> Self {
1584            Self {
1585                name: fidl::new_empty!(
1586                    fidl::encoding::BoundedString<32>,
1587                    fidl::encoding::DefaultFuchsiaResourceDialect
1588                ),
1589                network: fidl::new_empty!(
1590                    fidl::encoding::Endpoint<
1591                        fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
1592                    >,
1593                    fidl::encoding::DefaultFuchsiaResourceDialect
1594                ),
1595                mac: fidl::new_empty!(
1596                    fidl::encoding::Boxed<fidl_fuchsia_net::MacAddress>,
1597                    fidl::encoding::DefaultFuchsiaResourceDialect
1598                ),
1599            }
1600        }
1601
1602        #[inline]
1603        unsafe fn decode(
1604            &mut self,
1605            decoder: &mut fidl::encoding::Decoder<
1606                '_,
1607                fidl::encoding::DefaultFuchsiaResourceDialect,
1608            >,
1609            offset: usize,
1610            _depth: fidl::encoding::Depth,
1611        ) -> fidl::Result<()> {
1612            decoder.debug_check_bounds::<Self>(offset);
1613            // Verify that padding bytes are zero.
1614            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1615            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1616            let mask = 0xffffffff00000000u64;
1617            let maskedval = padval & mask;
1618            if maskedval != 0 {
1619                return Err(fidl::Error::NonZeroPadding {
1620                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1621                });
1622            }
1623            fidl::decode!(
1624                fidl::encoding::BoundedString<32>,
1625                fidl::encoding::DefaultFuchsiaResourceDialect,
1626                &mut self.name,
1627                decoder,
1628                offset + 0,
1629                _depth
1630            )?;
1631            fidl::decode!(
1632                fidl::encoding::Endpoint<
1633                    fidl::endpoints::ClientEnd<fidl_fuchsia_netemul_network::NetworkMarker>,
1634                >,
1635                fidl::encoding::DefaultFuchsiaResourceDialect,
1636                &mut self.network,
1637                decoder,
1638                offset + 16,
1639                _depth
1640            )?;
1641            fidl::decode!(
1642                fidl::encoding::Boxed<fidl_fuchsia_net::MacAddress>,
1643                fidl::encoding::DefaultFuchsiaResourceDialect,
1644                &mut self.mac,
1645                decoder,
1646                offset + 24,
1647                _depth
1648            )?;
1649            Ok(())
1650        }
1651    }
1652
1653    impl fidl::encoding::ResourceTypeMarker for ControllerCreateGuestResponse {
1654        type Borrowed<'a> = &'a mut Self;
1655        fn take_or_borrow<'a>(
1656            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1657        ) -> Self::Borrowed<'a> {
1658            value
1659        }
1660    }
1661
1662    unsafe impl fidl::encoding::TypeMarker for ControllerCreateGuestResponse {
1663        type Owned = Self;
1664
1665        #[inline(always)]
1666        fn inline_align(_context: fidl::encoding::Context) -> usize {
1667            4
1668        }
1669
1670        #[inline(always)]
1671        fn inline_size(_context: fidl::encoding::Context) -> usize {
1672            4
1673        }
1674    }
1675
1676    unsafe impl
1677        fidl::encoding::Encode<
1678            ControllerCreateGuestResponse,
1679            fidl::encoding::DefaultFuchsiaResourceDialect,
1680        > for &mut ControllerCreateGuestResponse
1681    {
1682        #[inline]
1683        unsafe fn encode(
1684            self,
1685            encoder: &mut fidl::encoding::Encoder<
1686                '_,
1687                fidl::encoding::DefaultFuchsiaResourceDialect,
1688            >,
1689            offset: usize,
1690            _depth: fidl::encoding::Depth,
1691        ) -> fidl::Result<()> {
1692            encoder.debug_check_bounds::<ControllerCreateGuestResponse>(offset);
1693            // Delegate to tuple encoding.
1694            fidl::encoding::Encode::<ControllerCreateGuestResponse, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1695                (
1696                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<GuestMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.s),
1697                ),
1698                encoder, offset, _depth
1699            )
1700        }
1701    }
1702    unsafe impl<
1703        T0: fidl::encoding::Encode<
1704                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<GuestMarker>>,
1705                fidl::encoding::DefaultFuchsiaResourceDialect,
1706            >,
1707    >
1708        fidl::encoding::Encode<
1709            ControllerCreateGuestResponse,
1710            fidl::encoding::DefaultFuchsiaResourceDialect,
1711        > for (T0,)
1712    {
1713        #[inline]
1714        unsafe fn encode(
1715            self,
1716            encoder: &mut fidl::encoding::Encoder<
1717                '_,
1718                fidl::encoding::DefaultFuchsiaResourceDialect,
1719            >,
1720            offset: usize,
1721            depth: fidl::encoding::Depth,
1722        ) -> fidl::Result<()> {
1723            encoder.debug_check_bounds::<ControllerCreateGuestResponse>(offset);
1724            // Zero out padding regions. There's no need to apply masks
1725            // because the unmasked parts will be overwritten by fields.
1726            // Write the fields.
1727            self.0.encode(encoder, offset + 0, depth)?;
1728            Ok(())
1729        }
1730    }
1731
1732    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1733        for ControllerCreateGuestResponse
1734    {
1735        #[inline(always)]
1736        fn new_empty() -> Self {
1737            Self {
1738                s: fidl::new_empty!(
1739                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<GuestMarker>>,
1740                    fidl::encoding::DefaultFuchsiaResourceDialect
1741                ),
1742            }
1743        }
1744
1745        #[inline]
1746        unsafe fn decode(
1747            &mut self,
1748            decoder: &mut fidl::encoding::Decoder<
1749                '_,
1750                fidl::encoding::DefaultFuchsiaResourceDialect,
1751            >,
1752            offset: usize,
1753            _depth: fidl::encoding::Depth,
1754        ) -> fidl::Result<()> {
1755            decoder.debug_check_bounds::<Self>(offset);
1756            // Verify that padding bytes are zero.
1757            fidl::decode!(
1758                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<GuestMarker>>,
1759                fidl::encoding::DefaultFuchsiaResourceDialect,
1760                &mut self.s,
1761                decoder,
1762                offset + 0,
1763                _depth
1764            )?;
1765            Ok(())
1766        }
1767    }
1768}