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