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