Skip to main content

fidl_fuchsia_testing_proxy/
fidl_fuchsia_testing_proxy.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_testing_proxy__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct TcpProxyControlOpenProxyRequest {
16    pub target_port: u16,
17    pub proxy_port: u16,
18    pub tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
22    for TcpProxyControlOpenProxyRequest
23{
24}
25
26#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
27pub struct TcpProxy_Marker;
28
29impl fidl::endpoints::ProtocolMarker for TcpProxy_Marker {
30    type Proxy = TcpProxy_Proxy;
31    type RequestStream = TcpProxy_RequestStream;
32    #[cfg(target_os = "fuchsia")]
33    type SynchronousProxy = TcpProxy_SynchronousProxy;
34
35    const DEBUG_NAME: &'static str = "(anonymous) TcpProxy_";
36}
37
38pub trait TcpProxy_ProxyInterface: Send + Sync {}
39#[derive(Debug)]
40#[cfg(target_os = "fuchsia")]
41pub struct TcpProxy_SynchronousProxy {
42    client: fidl::client::sync::Client,
43}
44
45#[cfg(target_os = "fuchsia")]
46impl fidl::endpoints::SynchronousProxy for TcpProxy_SynchronousProxy {
47    type Proxy = TcpProxy_Proxy;
48    type Protocol = TcpProxy_Marker;
49
50    fn from_channel(inner: fidl::Channel) -> Self {
51        Self::new(inner)
52    }
53
54    fn into_channel(self) -> fidl::Channel {
55        self.client.into_channel()
56    }
57
58    fn as_channel(&self) -> &fidl::Channel {
59        self.client.as_channel()
60    }
61}
62
63#[cfg(target_os = "fuchsia")]
64impl TcpProxy_SynchronousProxy {
65    pub fn new(channel: fidl::Channel) -> Self {
66        Self { client: fidl::client::sync::Client::new(channel) }
67    }
68
69    pub fn into_channel(self) -> fidl::Channel {
70        self.client.into_channel()
71    }
72
73    /// Waits until an event arrives and returns it. It is safe for other
74    /// threads to make concurrent requests while waiting for an event.
75    pub fn wait_for_event(
76        &self,
77        deadline: zx::MonotonicInstant,
78    ) -> Result<TcpProxy_Event, fidl::Error> {
79        TcpProxy_Event::decode(self.client.wait_for_event::<TcpProxy_Marker>(deadline)?)
80    }
81}
82
83#[cfg(target_os = "fuchsia")]
84impl From<TcpProxy_SynchronousProxy> for zx::NullableHandle {
85    fn from(value: TcpProxy_SynchronousProxy) -> Self {
86        value.into_channel().into()
87    }
88}
89
90#[cfg(target_os = "fuchsia")]
91impl From<fidl::Channel> for TcpProxy_SynchronousProxy {
92    fn from(value: fidl::Channel) -> Self {
93        Self::new(value)
94    }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl fidl::endpoints::FromClient for TcpProxy_SynchronousProxy {
99    type Protocol = TcpProxy_Marker;
100
101    fn from_client(value: fidl::endpoints::ClientEnd<TcpProxy_Marker>) -> Self {
102        Self::new(value.into_channel())
103    }
104}
105
106#[derive(Debug, Clone)]
107pub struct TcpProxy_Proxy {
108    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
109}
110
111impl fidl::endpoints::Proxy for TcpProxy_Proxy {
112    type Protocol = TcpProxy_Marker;
113
114    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
115        Self::new(inner)
116    }
117
118    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
119        self.client.into_channel().map_err(|client| Self { client })
120    }
121
122    fn as_channel(&self) -> &::fidl::AsyncChannel {
123        self.client.as_channel()
124    }
125}
126
127impl TcpProxy_Proxy {
128    /// Create a new Proxy for fuchsia.testing.proxy/TcpProxy.
129    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
130        let protocol_name = <TcpProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
131        Self { client: fidl::client::Client::new(channel, protocol_name) }
132    }
133
134    /// Get a Stream of events from the remote end of the protocol.
135    ///
136    /// # Panics
137    ///
138    /// Panics if the event stream was already taken.
139    pub fn take_event_stream(&self) -> TcpProxy_EventStream {
140        TcpProxy_EventStream { event_receiver: self.client.take_event_receiver() }
141    }
142}
143
144impl TcpProxy_ProxyInterface for TcpProxy_Proxy {}
145
146pub struct TcpProxy_EventStream {
147    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
148}
149
150impl std::marker::Unpin for TcpProxy_EventStream {}
151
152impl futures::stream::FusedStream for TcpProxy_EventStream {
153    fn is_terminated(&self) -> bool {
154        self.event_receiver.is_terminated()
155    }
156}
157
158impl futures::Stream for TcpProxy_EventStream {
159    type Item = Result<TcpProxy_Event, fidl::Error>;
160
161    fn poll_next(
162        mut self: std::pin::Pin<&mut Self>,
163        cx: &mut std::task::Context<'_>,
164    ) -> std::task::Poll<Option<Self::Item>> {
165        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
166            &mut self.event_receiver,
167            cx
168        )?) {
169            Some(buf) => std::task::Poll::Ready(Some(TcpProxy_Event::decode(buf))),
170            None => std::task::Poll::Ready(None),
171        }
172    }
173}
174
175#[derive(Debug)]
176pub enum TcpProxy_Event {}
177
178impl TcpProxy_Event {
179    /// Decodes a message buffer as a [`TcpProxy_Event`].
180    fn decode(
181        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
182    ) -> Result<TcpProxy_Event, fidl::Error> {
183        let (bytes, _handles) = buf.split_mut();
184        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
185        debug_assert_eq!(tx_header.tx_id, 0);
186        match tx_header.ordinal {
187            _ => Err(fidl::Error::UnknownOrdinal {
188                ordinal: tx_header.ordinal,
189                protocol_name: <TcpProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
190            }),
191        }
192    }
193}
194
195/// A Stream of incoming requests for fuchsia.testing.proxy/TcpProxy.
196pub struct TcpProxy_RequestStream {
197    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
198    is_terminated: bool,
199}
200
201impl std::marker::Unpin for TcpProxy_RequestStream {}
202
203impl futures::stream::FusedStream for TcpProxy_RequestStream {
204    fn is_terminated(&self) -> bool {
205        self.is_terminated
206    }
207}
208
209impl fidl::endpoints::RequestStream for TcpProxy_RequestStream {
210    type Protocol = TcpProxy_Marker;
211    type ControlHandle = TcpProxy_ControlHandle;
212
213    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
214        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
215    }
216
217    fn control_handle(&self) -> Self::ControlHandle {
218        TcpProxy_ControlHandle { inner: self.inner.clone() }
219    }
220
221    fn into_inner(
222        self,
223    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
224    {
225        (self.inner, self.is_terminated)
226    }
227
228    fn from_inner(
229        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
230        is_terminated: bool,
231    ) -> Self {
232        Self { inner, is_terminated }
233    }
234}
235
236impl futures::Stream for TcpProxy_RequestStream {
237    type Item = Result<TcpProxy_Request, fidl::Error>;
238
239    fn poll_next(
240        mut self: std::pin::Pin<&mut Self>,
241        cx: &mut std::task::Context<'_>,
242    ) -> std::task::Poll<Option<Self::Item>> {
243        let this = &mut *self;
244        if this.inner.check_shutdown(cx) {
245            this.is_terminated = true;
246            return std::task::Poll::Ready(None);
247        }
248        if this.is_terminated {
249            panic!("polled TcpProxy_RequestStream after completion");
250        }
251        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
252            |bytes, handles| {
253                match this.inner.channel().read_etc(cx, bytes, handles) {
254                    std::task::Poll::Ready(Ok(())) => {}
255                    std::task::Poll::Pending => return std::task::Poll::Pending,
256                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
257                        this.is_terminated = true;
258                        return std::task::Poll::Ready(None);
259                    }
260                    std::task::Poll::Ready(Err(e)) => {
261                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
262                            e.into(),
263                        ))));
264                    }
265                }
266
267                // A message has been received from the channel
268                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
269
270                std::task::Poll::Ready(Some(match header.ordinal {
271                    _ => Err(fidl::Error::UnknownOrdinal {
272                        ordinal: header.ordinal,
273                        protocol_name:
274                            <TcpProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
275                    }),
276                }))
277            },
278        )
279    }
280}
281
282/// An empty protocol which serves as a token for a proxy started with
283/// |TcpProxyControl.OpenProxy|. The proxy stays open as long as at least one
284/// |TcpProxy| channel corresponding to the proxy remains open. Note that the
285/// server may close the channel in the case an error is encountered.
286#[derive(Debug)]
287pub enum TcpProxy_Request {}
288
289impl TcpProxy_Request {
290    /// Name of the method defined in FIDL
291    pub fn method_name(&self) -> &'static str {
292        match *self {}
293    }
294}
295
296#[derive(Debug, Clone)]
297pub struct TcpProxy_ControlHandle {
298    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
299}
300
301impl fidl::endpoints::ControlHandle for TcpProxy_ControlHandle {
302    fn shutdown(&self) {
303        self.inner.shutdown()
304    }
305
306    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
307        self.inner.shutdown_with_epitaph(status)
308    }
309
310    fn is_closed(&self) -> bool {
311        self.inner.channel().is_closed()
312    }
313    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
314        self.inner.channel().on_closed()
315    }
316
317    #[cfg(target_os = "fuchsia")]
318    fn signal_peer(
319        &self,
320        clear_mask: zx::Signals,
321        set_mask: zx::Signals,
322    ) -> Result<(), zx_status::Status> {
323        use fidl::Peered;
324        self.inner.channel().signal_peer(clear_mask, set_mask)
325    }
326}
327
328impl TcpProxy_ControlHandle {}
329
330#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
331pub struct TcpProxyControlMarker;
332
333impl fidl::endpoints::ProtocolMarker for TcpProxyControlMarker {
334    type Proxy = TcpProxyControlProxy;
335    type RequestStream = TcpProxyControlRequestStream;
336    #[cfg(target_os = "fuchsia")]
337    type SynchronousProxy = TcpProxyControlSynchronousProxy;
338
339    const DEBUG_NAME: &'static str = "fuchsia.testing.proxy.TcpProxyControl";
340}
341impl fidl::endpoints::DiscoverableProtocolMarker for TcpProxyControlMarker {}
342
343pub trait TcpProxyControlProxyInterface: Send + Sync {
344    type OpenProxy_ResponseFut: std::future::Future<Output = Result<u16, fidl::Error>> + Send;
345    fn r#open_proxy_(
346        &self,
347        target_port: u16,
348        proxy_port: u16,
349        tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
350    ) -> Self::OpenProxy_ResponseFut;
351}
352#[derive(Debug)]
353#[cfg(target_os = "fuchsia")]
354pub struct TcpProxyControlSynchronousProxy {
355    client: fidl::client::sync::Client,
356}
357
358#[cfg(target_os = "fuchsia")]
359impl fidl::endpoints::SynchronousProxy for TcpProxyControlSynchronousProxy {
360    type Proxy = TcpProxyControlProxy;
361    type Protocol = TcpProxyControlMarker;
362
363    fn from_channel(inner: fidl::Channel) -> Self {
364        Self::new(inner)
365    }
366
367    fn into_channel(self) -> fidl::Channel {
368        self.client.into_channel()
369    }
370
371    fn as_channel(&self) -> &fidl::Channel {
372        self.client.as_channel()
373    }
374}
375
376#[cfg(target_os = "fuchsia")]
377impl TcpProxyControlSynchronousProxy {
378    pub fn new(channel: fidl::Channel) -> Self {
379        Self { client: fidl::client::sync::Client::new(channel) }
380    }
381
382    pub fn into_channel(self) -> fidl::Channel {
383        self.client.into_channel()
384    }
385
386    /// Waits until an event arrives and returns it. It is safe for other
387    /// threads to make concurrent requests while waiting for an event.
388    pub fn wait_for_event(
389        &self,
390        deadline: zx::MonotonicInstant,
391    ) -> Result<TcpProxyControlEvent, fidl::Error> {
392        TcpProxyControlEvent::decode(self.client.wait_for_event::<TcpProxyControlMarker>(deadline)?)
393    }
394
395    /// Opens a proxy to the given |target_port|. If a proxy is already open
396    /// for the specified |target_port|, the existing |open_port| is returned.
397    /// The proxy remains open as long as at least a single client keeps their
398    /// |proxy_token| handle for the specified |target_port|. Once all the
399    /// |proxy_token| handles are closed, the proxy is closed. |proxy_port| is
400    /// the source port where the proxy is opened. Except when the test running
401    /// on remote host needs to reach a local device, its value is 0. This is
402    /// only useful when the user has tunneled these ports to the local device
403    /// and specified that port number as |proxy_port|.
404    pub fn r#open_proxy_(
405        &self,
406        mut target_port: u16,
407        mut proxy_port: u16,
408        mut tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
409        ___deadline: zx::MonotonicInstant,
410    ) -> Result<u16, fidl::Error> {
411        let _response = self.client.send_query::<
412            TcpProxyControlOpenProxyRequest,
413            TcpProxyControlOpenProxyResponse,
414            TcpProxyControlMarker,
415        >(
416            (target_port, proxy_port, tcp_proxy,),
417            0x6e2c348c371061e2,
418            fidl::encoding::DynamicFlags::empty(),
419            ___deadline,
420        )?;
421        Ok(_response.open_port)
422    }
423}
424
425#[cfg(target_os = "fuchsia")]
426impl From<TcpProxyControlSynchronousProxy> for zx::NullableHandle {
427    fn from(value: TcpProxyControlSynchronousProxy) -> Self {
428        value.into_channel().into()
429    }
430}
431
432#[cfg(target_os = "fuchsia")]
433impl From<fidl::Channel> for TcpProxyControlSynchronousProxy {
434    fn from(value: fidl::Channel) -> Self {
435        Self::new(value)
436    }
437}
438
439#[cfg(target_os = "fuchsia")]
440impl fidl::endpoints::FromClient for TcpProxyControlSynchronousProxy {
441    type Protocol = TcpProxyControlMarker;
442
443    fn from_client(value: fidl::endpoints::ClientEnd<TcpProxyControlMarker>) -> Self {
444        Self::new(value.into_channel())
445    }
446}
447
448#[derive(Debug, Clone)]
449pub struct TcpProxyControlProxy {
450    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
451}
452
453impl fidl::endpoints::Proxy for TcpProxyControlProxy {
454    type Protocol = TcpProxyControlMarker;
455
456    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
457        Self::new(inner)
458    }
459
460    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
461        self.client.into_channel().map_err(|client| Self { client })
462    }
463
464    fn as_channel(&self) -> &::fidl::AsyncChannel {
465        self.client.as_channel()
466    }
467}
468
469impl TcpProxyControlProxy {
470    /// Create a new Proxy for fuchsia.testing.proxy/TcpProxyControl.
471    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
472        let protocol_name = <TcpProxyControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
473        Self { client: fidl::client::Client::new(channel, protocol_name) }
474    }
475
476    /// Get a Stream of events from the remote end of the protocol.
477    ///
478    /// # Panics
479    ///
480    /// Panics if the event stream was already taken.
481    pub fn take_event_stream(&self) -> TcpProxyControlEventStream {
482        TcpProxyControlEventStream { event_receiver: self.client.take_event_receiver() }
483    }
484
485    /// Opens a proxy to the given |target_port|. If a proxy is already open
486    /// for the specified |target_port|, the existing |open_port| is returned.
487    /// The proxy remains open as long as at least a single client keeps their
488    /// |proxy_token| handle for the specified |target_port|. Once all the
489    /// |proxy_token| handles are closed, the proxy is closed. |proxy_port| is
490    /// the source port where the proxy is opened. Except when the test running
491    /// on remote host needs to reach a local device, its value is 0. This is
492    /// only useful when the user has tunneled these ports to the local device
493    /// and specified that port number as |proxy_port|.
494    pub fn r#open_proxy_(
495        &self,
496        mut target_port: u16,
497        mut proxy_port: u16,
498        mut tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
499    ) -> fidl::client::QueryResponseFut<u16, fidl::encoding::DefaultFuchsiaResourceDialect> {
500        TcpProxyControlProxyInterface::r#open_proxy_(self, target_port, proxy_port, tcp_proxy)
501    }
502}
503
504impl TcpProxyControlProxyInterface for TcpProxyControlProxy {
505    type OpenProxy_ResponseFut =
506        fidl::client::QueryResponseFut<u16, fidl::encoding::DefaultFuchsiaResourceDialect>;
507    fn r#open_proxy_(
508        &self,
509        mut target_port: u16,
510        mut proxy_port: u16,
511        mut tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
512    ) -> Self::OpenProxy_ResponseFut {
513        fn _decode(
514            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
515        ) -> Result<u16, fidl::Error> {
516            let _response = fidl::client::decode_transaction_body::<
517                TcpProxyControlOpenProxyResponse,
518                fidl::encoding::DefaultFuchsiaResourceDialect,
519                0x6e2c348c371061e2,
520            >(_buf?)?;
521            Ok(_response.open_port)
522        }
523        self.client.send_query_and_decode::<TcpProxyControlOpenProxyRequest, u16>(
524            (target_port, proxy_port, tcp_proxy),
525            0x6e2c348c371061e2,
526            fidl::encoding::DynamicFlags::empty(),
527            _decode,
528        )
529    }
530}
531
532pub struct TcpProxyControlEventStream {
533    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
534}
535
536impl std::marker::Unpin for TcpProxyControlEventStream {}
537
538impl futures::stream::FusedStream for TcpProxyControlEventStream {
539    fn is_terminated(&self) -> bool {
540        self.event_receiver.is_terminated()
541    }
542}
543
544impl futures::Stream for TcpProxyControlEventStream {
545    type Item = Result<TcpProxyControlEvent, fidl::Error>;
546
547    fn poll_next(
548        mut self: std::pin::Pin<&mut Self>,
549        cx: &mut std::task::Context<'_>,
550    ) -> std::task::Poll<Option<Self::Item>> {
551        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
552            &mut self.event_receiver,
553            cx
554        )?) {
555            Some(buf) => std::task::Poll::Ready(Some(TcpProxyControlEvent::decode(buf))),
556            None => std::task::Poll::Ready(None),
557        }
558    }
559}
560
561#[derive(Debug)]
562pub enum TcpProxyControlEvent {}
563
564impl TcpProxyControlEvent {
565    /// Decodes a message buffer as a [`TcpProxyControlEvent`].
566    fn decode(
567        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
568    ) -> Result<TcpProxyControlEvent, fidl::Error> {
569        let (bytes, _handles) = buf.split_mut();
570        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
571        debug_assert_eq!(tx_header.tx_id, 0);
572        match tx_header.ordinal {
573            _ => Err(fidl::Error::UnknownOrdinal {
574                ordinal: tx_header.ordinal,
575                protocol_name:
576                    <TcpProxyControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
577            }),
578        }
579    }
580}
581
582/// A Stream of incoming requests for fuchsia.testing.proxy/TcpProxyControl.
583pub struct TcpProxyControlRequestStream {
584    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
585    is_terminated: bool,
586}
587
588impl std::marker::Unpin for TcpProxyControlRequestStream {}
589
590impl futures::stream::FusedStream for TcpProxyControlRequestStream {
591    fn is_terminated(&self) -> bool {
592        self.is_terminated
593    }
594}
595
596impl fidl::endpoints::RequestStream for TcpProxyControlRequestStream {
597    type Protocol = TcpProxyControlMarker;
598    type ControlHandle = TcpProxyControlControlHandle;
599
600    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
601        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
602    }
603
604    fn control_handle(&self) -> Self::ControlHandle {
605        TcpProxyControlControlHandle { inner: self.inner.clone() }
606    }
607
608    fn into_inner(
609        self,
610    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
611    {
612        (self.inner, self.is_terminated)
613    }
614
615    fn from_inner(
616        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
617        is_terminated: bool,
618    ) -> Self {
619        Self { inner, is_terminated }
620    }
621}
622
623impl futures::Stream for TcpProxyControlRequestStream {
624    type Item = Result<TcpProxyControlRequest, fidl::Error>;
625
626    fn poll_next(
627        mut self: std::pin::Pin<&mut Self>,
628        cx: &mut std::task::Context<'_>,
629    ) -> std::task::Poll<Option<Self::Item>> {
630        let this = &mut *self;
631        if this.inner.check_shutdown(cx) {
632            this.is_terminated = true;
633            return std::task::Poll::Ready(None);
634        }
635        if this.is_terminated {
636            panic!("polled TcpProxyControlRequestStream after completion");
637        }
638        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
639            |bytes, handles| {
640                match this.inner.channel().read_etc(cx, bytes, handles) {
641                    std::task::Poll::Ready(Ok(())) => {}
642                    std::task::Poll::Pending => return std::task::Poll::Pending,
643                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
644                        this.is_terminated = true;
645                        return std::task::Poll::Ready(None);
646                    }
647                    std::task::Poll::Ready(Err(e)) => {
648                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
649                            e.into(),
650                        ))));
651                    }
652                }
653
654                // A message has been received from the channel
655                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
656
657                std::task::Poll::Ready(Some(match header.ordinal {
658                    0x6e2c348c371061e2 => {
659                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
660                        let mut req = fidl::new_empty!(
661                            TcpProxyControlOpenProxyRequest,
662                            fidl::encoding::DefaultFuchsiaResourceDialect
663                        );
664                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<TcpProxyControlOpenProxyRequest>(&header, _body_bytes, handles, &mut req)?;
665                        let control_handle =
666                            TcpProxyControlControlHandle { inner: this.inner.clone() };
667                        Ok(TcpProxyControlRequest::OpenProxy_ {
668                            target_port: req.target_port,
669                            proxy_port: req.proxy_port,
670                            tcp_proxy: req.tcp_proxy,
671
672                            responder: TcpProxyControlOpenProxy_Responder {
673                                control_handle: std::mem::ManuallyDrop::new(control_handle),
674                                tx_id: header.tx_id,
675                            },
676                        })
677                    }
678                    _ => Err(fidl::Error::UnknownOrdinal {
679                        ordinal: header.ordinal,
680                        protocol_name:
681                            <TcpProxyControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
682                    }),
683                }))
684            },
685        )
686    }
687}
688
689/// A protocol that enables creating TCP proxies so that host tests may
690/// access debug services that normally accept only local connections.
691///
692/// For example, if web browser exposes a debug HTTP service listening on
693/// [::1]:9999, TcpProxyControl may listen on [::]:10000 and forward requests
694/// to port 9999. The host test then calls port 10000 to access the web browser's
695/// debug service.
696#[derive(Debug)]
697pub enum TcpProxyControlRequest {
698    /// Opens a proxy to the given |target_port|. If a proxy is already open
699    /// for the specified |target_port|, the existing |open_port| is returned.
700    /// The proxy remains open as long as at least a single client keeps their
701    /// |proxy_token| handle for the specified |target_port|. Once all the
702    /// |proxy_token| handles are closed, the proxy is closed. |proxy_port| is
703    /// the source port where the proxy is opened. Except when the test running
704    /// on remote host needs to reach a local device, its value is 0. This is
705    /// only useful when the user has tunneled these ports to the local device
706    /// and specified that port number as |proxy_port|.
707    OpenProxy_ {
708        target_port: u16,
709        proxy_port: u16,
710        tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
711        responder: TcpProxyControlOpenProxy_Responder,
712    },
713}
714
715impl TcpProxyControlRequest {
716    #[allow(irrefutable_let_patterns)]
717    pub fn into_open_proxy_(
718        self,
719    ) -> Option<(
720        u16,
721        u16,
722        fidl::endpoints::ServerEnd<TcpProxy_Marker>,
723        TcpProxyControlOpenProxy_Responder,
724    )> {
725        if let TcpProxyControlRequest::OpenProxy_ {
726            target_port,
727            proxy_port,
728            tcp_proxy,
729            responder,
730        } = self
731        {
732            Some((target_port, proxy_port, tcp_proxy, responder))
733        } else {
734            None
735        }
736    }
737
738    /// Name of the method defined in FIDL
739    pub fn method_name(&self) -> &'static str {
740        match *self {
741            TcpProxyControlRequest::OpenProxy_ { .. } => "open_proxy_",
742        }
743    }
744}
745
746#[derive(Debug, Clone)]
747pub struct TcpProxyControlControlHandle {
748    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
749}
750
751impl fidl::endpoints::ControlHandle for TcpProxyControlControlHandle {
752    fn shutdown(&self) {
753        self.inner.shutdown()
754    }
755
756    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
757        self.inner.shutdown_with_epitaph(status)
758    }
759
760    fn is_closed(&self) -> bool {
761        self.inner.channel().is_closed()
762    }
763    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
764        self.inner.channel().on_closed()
765    }
766
767    #[cfg(target_os = "fuchsia")]
768    fn signal_peer(
769        &self,
770        clear_mask: zx::Signals,
771        set_mask: zx::Signals,
772    ) -> Result<(), zx_status::Status> {
773        use fidl::Peered;
774        self.inner.channel().signal_peer(clear_mask, set_mask)
775    }
776}
777
778impl TcpProxyControlControlHandle {}
779
780#[must_use = "FIDL methods require a response to be sent"]
781#[derive(Debug)]
782pub struct TcpProxyControlOpenProxy_Responder {
783    control_handle: std::mem::ManuallyDrop<TcpProxyControlControlHandle>,
784    tx_id: u32,
785}
786
787/// Set the the channel to be shutdown (see [`TcpProxyControlControlHandle::shutdown`])
788/// if the responder is dropped without sending a response, so that the client
789/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
790impl std::ops::Drop for TcpProxyControlOpenProxy_Responder {
791    fn drop(&mut self) {
792        self.control_handle.shutdown();
793        // Safety: drops once, never accessed again
794        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
795    }
796}
797
798impl fidl::endpoints::Responder for TcpProxyControlOpenProxy_Responder {
799    type ControlHandle = TcpProxyControlControlHandle;
800
801    fn control_handle(&self) -> &TcpProxyControlControlHandle {
802        &self.control_handle
803    }
804
805    fn drop_without_shutdown(mut self) {
806        // Safety: drops once, never accessed again due to mem::forget
807        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
808        // Prevent Drop from running (which would shut down the channel)
809        std::mem::forget(self);
810    }
811}
812
813impl TcpProxyControlOpenProxy_Responder {
814    /// Sends a response to the FIDL transaction.
815    ///
816    /// Sets the channel to shutdown if an error occurs.
817    pub fn send(self, mut open_port: u16) -> Result<(), fidl::Error> {
818        let _result = self.send_raw(open_port);
819        if _result.is_err() {
820            self.control_handle.shutdown();
821        }
822        self.drop_without_shutdown();
823        _result
824    }
825
826    /// Similar to "send" but does not shutdown the channel if an error occurs.
827    pub fn send_no_shutdown_on_err(self, mut open_port: u16) -> Result<(), fidl::Error> {
828        let _result = self.send_raw(open_port);
829        self.drop_without_shutdown();
830        _result
831    }
832
833    fn send_raw(&self, mut open_port: u16) -> Result<(), fidl::Error> {
834        self.control_handle.inner.send::<TcpProxyControlOpenProxyResponse>(
835            (open_port,),
836            self.tx_id,
837            0x6e2c348c371061e2,
838            fidl::encoding::DynamicFlags::empty(),
839        )
840    }
841}
842
843mod internal {
844    use super::*;
845
846    impl fidl::encoding::ResourceTypeMarker for TcpProxyControlOpenProxyRequest {
847        type Borrowed<'a> = &'a mut Self;
848        fn take_or_borrow<'a>(
849            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
850        ) -> Self::Borrowed<'a> {
851            value
852        }
853    }
854
855    unsafe impl fidl::encoding::TypeMarker for TcpProxyControlOpenProxyRequest {
856        type Owned = Self;
857
858        #[inline(always)]
859        fn inline_align(_context: fidl::encoding::Context) -> usize {
860            4
861        }
862
863        #[inline(always)]
864        fn inline_size(_context: fidl::encoding::Context) -> usize {
865            8
866        }
867    }
868
869    unsafe impl
870        fidl::encoding::Encode<
871            TcpProxyControlOpenProxyRequest,
872            fidl::encoding::DefaultFuchsiaResourceDialect,
873        > for &mut TcpProxyControlOpenProxyRequest
874    {
875        #[inline]
876        unsafe fn encode(
877            self,
878            encoder: &mut fidl::encoding::Encoder<
879                '_,
880                fidl::encoding::DefaultFuchsiaResourceDialect,
881            >,
882            offset: usize,
883            _depth: fidl::encoding::Depth,
884        ) -> fidl::Result<()> {
885            encoder.debug_check_bounds::<TcpProxyControlOpenProxyRequest>(offset);
886            // Delegate to tuple encoding.
887            fidl::encoding::Encode::<TcpProxyControlOpenProxyRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
888                (
889                    <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.target_port),
890                    <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.proxy_port),
891                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TcpProxy_Marker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.tcp_proxy),
892                ),
893                encoder, offset, _depth
894            )
895        }
896    }
897    unsafe impl<
898        T0: fidl::encoding::Encode<u16, fidl::encoding::DefaultFuchsiaResourceDialect>,
899        T1: fidl::encoding::Encode<u16, fidl::encoding::DefaultFuchsiaResourceDialect>,
900        T2: fidl::encoding::Encode<
901                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TcpProxy_Marker>>,
902                fidl::encoding::DefaultFuchsiaResourceDialect,
903            >,
904    >
905        fidl::encoding::Encode<
906            TcpProxyControlOpenProxyRequest,
907            fidl::encoding::DefaultFuchsiaResourceDialect,
908        > for (T0, T1, T2)
909    {
910        #[inline]
911        unsafe fn encode(
912            self,
913            encoder: &mut fidl::encoding::Encoder<
914                '_,
915                fidl::encoding::DefaultFuchsiaResourceDialect,
916            >,
917            offset: usize,
918            depth: fidl::encoding::Depth,
919        ) -> fidl::Result<()> {
920            encoder.debug_check_bounds::<TcpProxyControlOpenProxyRequest>(offset);
921            // Zero out padding regions. There's no need to apply masks
922            // because the unmasked parts will be overwritten by fields.
923            // Write the fields.
924            self.0.encode(encoder, offset + 0, depth)?;
925            self.1.encode(encoder, offset + 2, depth)?;
926            self.2.encode(encoder, offset + 4, depth)?;
927            Ok(())
928        }
929    }
930
931    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
932        for TcpProxyControlOpenProxyRequest
933    {
934        #[inline(always)]
935        fn new_empty() -> Self {
936            Self {
937                target_port: fidl::new_empty!(u16, fidl::encoding::DefaultFuchsiaResourceDialect),
938                proxy_port: fidl::new_empty!(u16, fidl::encoding::DefaultFuchsiaResourceDialect),
939                tcp_proxy: fidl::new_empty!(
940                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TcpProxy_Marker>>,
941                    fidl::encoding::DefaultFuchsiaResourceDialect
942                ),
943            }
944        }
945
946        #[inline]
947        unsafe fn decode(
948            &mut self,
949            decoder: &mut fidl::encoding::Decoder<
950                '_,
951                fidl::encoding::DefaultFuchsiaResourceDialect,
952            >,
953            offset: usize,
954            _depth: fidl::encoding::Depth,
955        ) -> fidl::Result<()> {
956            decoder.debug_check_bounds::<Self>(offset);
957            // Verify that padding bytes are zero.
958            fidl::decode!(
959                u16,
960                fidl::encoding::DefaultFuchsiaResourceDialect,
961                &mut self.target_port,
962                decoder,
963                offset + 0,
964                _depth
965            )?;
966            fidl::decode!(
967                u16,
968                fidl::encoding::DefaultFuchsiaResourceDialect,
969                &mut self.proxy_port,
970                decoder,
971                offset + 2,
972                _depth
973            )?;
974            fidl::decode!(
975                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TcpProxy_Marker>>,
976                fidl::encoding::DefaultFuchsiaResourceDialect,
977                &mut self.tcp_proxy,
978                decoder,
979                offset + 4,
980                _depth
981            )?;
982            Ok(())
983        }
984    }
985}