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::Handle {
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    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
401        self.inner.shutdown_with_epitaph(status)
402    }
403
404    fn is_closed(&self) -> bool {
405        self.inner.channel().is_closed()
406    }
407    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
408        self.inner.channel().on_closed()
409    }
410
411    #[cfg(target_os = "fuchsia")]
412    fn signal_peer(
413        &self,
414        clear_mask: zx::Signals,
415        set_mask: zx::Signals,
416    ) -> Result<(), zx_status::Status> {
417        use fidl::Peered;
418        self.inner.channel().signal_peer(clear_mask, set_mask)
419    }
420}
421
422impl StateControlHandle {}
423
424#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
425pub struct WatcherMarker;
426
427impl fidl::endpoints::ProtocolMarker for WatcherMarker {
428    type Proxy = WatcherProxy;
429    type RequestStream = WatcherRequestStream;
430    #[cfg(target_os = "fuchsia")]
431    type SynchronousProxy = WatcherSynchronousProxy;
432
433    const DEBUG_NAME: &'static str = "(anonymous) Watcher";
434}
435
436pub trait WatcherProxyInterface: Send + Sync {
437    type WatchResponseFut: std::future::Future<Output = Result<Event, fidl::Error>> + Send;
438    fn r#watch(&self) -> Self::WatchResponseFut;
439}
440#[derive(Debug)]
441#[cfg(target_os = "fuchsia")]
442pub struct WatcherSynchronousProxy {
443    client: fidl::client::sync::Client,
444}
445
446#[cfg(target_os = "fuchsia")]
447impl fidl::endpoints::SynchronousProxy for WatcherSynchronousProxy {
448    type Proxy = WatcherProxy;
449    type Protocol = WatcherMarker;
450
451    fn from_channel(inner: fidl::Channel) -> Self {
452        Self::new(inner)
453    }
454
455    fn into_channel(self) -> fidl::Channel {
456        self.client.into_channel()
457    }
458
459    fn as_channel(&self) -> &fidl::Channel {
460        self.client.as_channel()
461    }
462}
463
464#[cfg(target_os = "fuchsia")]
465impl WatcherSynchronousProxy {
466    pub fn new(channel: fidl::Channel) -> Self {
467        let protocol_name = <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
468        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
469    }
470
471    pub fn into_channel(self) -> fidl::Channel {
472        self.client.into_channel()
473    }
474
475    /// Waits until an event arrives and returns it. It is safe for other
476    /// threads to make concurrent requests while waiting for an event.
477    pub fn wait_for_event(
478        &self,
479        deadline: zx::MonotonicInstant,
480    ) -> Result<WatcherEvent, fidl::Error> {
481        WatcherEvent::decode(self.client.wait_for_event(deadline)?)
482    }
483
484    /// Hanging get for an interface addition/deletion change.
485    ///
486    /// Clients should only have one call of this method at a time; a second
487    /// call to this method while a call is already pending will cause the
488    /// server end of the protocol to be closed.
489    ///
490    /// If there are N interfaces present at the time the server end of the
491    /// protocol is initialized, then the first N invocations of this method
492    /// will return [`Event.existing`] followed by a single [`Event.idle`]
493    /// indicating that all existing interfaces have been sent. Subsequent calls
494    /// will immediately return if there is a change to be reported, or block
495    /// until a change occurs.
496    ///
497    /// The server may choose to coalesce property change events, e.g. when
498    /// multiple independent property changes occur. As a result, clients cannot
499    /// assume that the order in which they observe the interface changes is the
500    /// order in which the changes occurred.
501    ///
502    /// - response `event` the interface change event.
503    pub fn r#watch(&self, ___deadline: zx::MonotonicInstant) -> Result<Event, fidl::Error> {
504        let _response =
505            self.client.send_query::<fidl::encoding::EmptyPayload, WatcherWatchResponse>(
506                (),
507                0x550767aa9faeeef3,
508                fidl::encoding::DynamicFlags::empty(),
509                ___deadline,
510            )?;
511        Ok(_response.event)
512    }
513}
514
515#[cfg(target_os = "fuchsia")]
516impl From<WatcherSynchronousProxy> for zx::Handle {
517    fn from(value: WatcherSynchronousProxy) -> Self {
518        value.into_channel().into()
519    }
520}
521
522#[cfg(target_os = "fuchsia")]
523impl From<fidl::Channel> for WatcherSynchronousProxy {
524    fn from(value: fidl::Channel) -> Self {
525        Self::new(value)
526    }
527}
528
529#[cfg(target_os = "fuchsia")]
530impl fidl::endpoints::FromClient for WatcherSynchronousProxy {
531    type Protocol = WatcherMarker;
532
533    fn from_client(value: fidl::endpoints::ClientEnd<WatcherMarker>) -> Self {
534        Self::new(value.into_channel())
535    }
536}
537
538#[derive(Debug, Clone)]
539pub struct WatcherProxy {
540    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
541}
542
543impl fidl::endpoints::Proxy for WatcherProxy {
544    type Protocol = WatcherMarker;
545
546    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
547        Self::new(inner)
548    }
549
550    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
551        self.client.into_channel().map_err(|client| Self { client })
552    }
553
554    fn as_channel(&self) -> &::fidl::AsyncChannel {
555        self.client.as_channel()
556    }
557}
558
559impl WatcherProxy {
560    /// Create a new Proxy for fuchsia.net.interfaces/Watcher.
561    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
562        let protocol_name = <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
563        Self { client: fidl::client::Client::new(channel, protocol_name) }
564    }
565
566    /// Get a Stream of events from the remote end of the protocol.
567    ///
568    /// # Panics
569    ///
570    /// Panics if the event stream was already taken.
571    pub fn take_event_stream(&self) -> WatcherEventStream {
572        WatcherEventStream { event_receiver: self.client.take_event_receiver() }
573    }
574
575    /// Hanging get for an interface addition/deletion change.
576    ///
577    /// Clients should only have one call of this method at a time; a second
578    /// call to this method while a call is already pending will cause the
579    /// server end of the protocol to be closed.
580    ///
581    /// If there are N interfaces present at the time the server end of the
582    /// protocol is initialized, then the first N invocations of this method
583    /// will return [`Event.existing`] followed by a single [`Event.idle`]
584    /// indicating that all existing interfaces have been sent. Subsequent calls
585    /// will immediately return if there is a change to be reported, or block
586    /// until a change occurs.
587    ///
588    /// The server may choose to coalesce property change events, e.g. when
589    /// multiple independent property changes occur. As a result, clients cannot
590    /// assume that the order in which they observe the interface changes is the
591    /// order in which the changes occurred.
592    ///
593    /// - response `event` the interface change event.
594    pub fn r#watch(
595        &self,
596    ) -> fidl::client::QueryResponseFut<Event, fidl::encoding::DefaultFuchsiaResourceDialect> {
597        WatcherProxyInterface::r#watch(self)
598    }
599}
600
601impl WatcherProxyInterface for WatcherProxy {
602    type WatchResponseFut =
603        fidl::client::QueryResponseFut<Event, fidl::encoding::DefaultFuchsiaResourceDialect>;
604    fn r#watch(&self) -> Self::WatchResponseFut {
605        fn _decode(
606            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
607        ) -> Result<Event, fidl::Error> {
608            let _response = fidl::client::decode_transaction_body::<
609                WatcherWatchResponse,
610                fidl::encoding::DefaultFuchsiaResourceDialect,
611                0x550767aa9faeeef3,
612            >(_buf?)?;
613            Ok(_response.event)
614        }
615        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Event>(
616            (),
617            0x550767aa9faeeef3,
618            fidl::encoding::DynamicFlags::empty(),
619            _decode,
620        )
621    }
622}
623
624pub struct WatcherEventStream {
625    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
626}
627
628impl std::marker::Unpin for WatcherEventStream {}
629
630impl futures::stream::FusedStream for WatcherEventStream {
631    fn is_terminated(&self) -> bool {
632        self.event_receiver.is_terminated()
633    }
634}
635
636impl futures::Stream for WatcherEventStream {
637    type Item = Result<WatcherEvent, fidl::Error>;
638
639    fn poll_next(
640        mut self: std::pin::Pin<&mut Self>,
641        cx: &mut std::task::Context<'_>,
642    ) -> std::task::Poll<Option<Self::Item>> {
643        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
644            &mut self.event_receiver,
645            cx
646        )?) {
647            Some(buf) => std::task::Poll::Ready(Some(WatcherEvent::decode(buf))),
648            None => std::task::Poll::Ready(None),
649        }
650    }
651}
652
653#[derive(Debug)]
654pub enum WatcherEvent {}
655
656impl WatcherEvent {
657    /// Decodes a message buffer as a [`WatcherEvent`].
658    fn decode(
659        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
660    ) -> Result<WatcherEvent, fidl::Error> {
661        let (bytes, _handles) = buf.split_mut();
662        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
663        debug_assert_eq!(tx_header.tx_id, 0);
664        match tx_header.ordinal {
665            _ => Err(fidl::Error::UnknownOrdinal {
666                ordinal: tx_header.ordinal,
667                protocol_name: <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
668            }),
669        }
670    }
671}
672
673/// A Stream of incoming requests for fuchsia.net.interfaces/Watcher.
674pub struct WatcherRequestStream {
675    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
676    is_terminated: bool,
677}
678
679impl std::marker::Unpin for WatcherRequestStream {}
680
681impl futures::stream::FusedStream for WatcherRequestStream {
682    fn is_terminated(&self) -> bool {
683        self.is_terminated
684    }
685}
686
687impl fidl::endpoints::RequestStream for WatcherRequestStream {
688    type Protocol = WatcherMarker;
689    type ControlHandle = WatcherControlHandle;
690
691    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
692        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
693    }
694
695    fn control_handle(&self) -> Self::ControlHandle {
696        WatcherControlHandle { inner: self.inner.clone() }
697    }
698
699    fn into_inner(
700        self,
701    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
702    {
703        (self.inner, self.is_terminated)
704    }
705
706    fn from_inner(
707        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
708        is_terminated: bool,
709    ) -> Self {
710        Self { inner, is_terminated }
711    }
712}
713
714impl futures::Stream for WatcherRequestStream {
715    type Item = Result<WatcherRequest, fidl::Error>;
716
717    fn poll_next(
718        mut self: std::pin::Pin<&mut Self>,
719        cx: &mut std::task::Context<'_>,
720    ) -> std::task::Poll<Option<Self::Item>> {
721        let this = &mut *self;
722        if this.inner.check_shutdown(cx) {
723            this.is_terminated = true;
724            return std::task::Poll::Ready(None);
725        }
726        if this.is_terminated {
727            panic!("polled WatcherRequestStream after completion");
728        }
729        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
730            |bytes, handles| {
731                match this.inner.channel().read_etc(cx, bytes, handles) {
732                    std::task::Poll::Ready(Ok(())) => {}
733                    std::task::Poll::Pending => return std::task::Poll::Pending,
734                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
735                        this.is_terminated = true;
736                        return std::task::Poll::Ready(None);
737                    }
738                    std::task::Poll::Ready(Err(e)) => {
739                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
740                            e.into(),
741                        ))))
742                    }
743                }
744
745                // A message has been received from the channel
746                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
747
748                std::task::Poll::Ready(Some(match header.ordinal {
749                    0x550767aa9faeeef3 => {
750                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
751                        let mut req = fidl::new_empty!(
752                            fidl::encoding::EmptyPayload,
753                            fidl::encoding::DefaultFuchsiaResourceDialect
754                        );
755                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
756                        let control_handle = WatcherControlHandle { inner: this.inner.clone() };
757                        Ok(WatcherRequest::Watch {
758                            responder: WatcherWatchResponder {
759                                control_handle: std::mem::ManuallyDrop::new(control_handle),
760                                tx_id: header.tx_id,
761                            },
762                        })
763                    }
764                    _ => Err(fidl::Error::UnknownOrdinal {
765                        ordinal: header.ordinal,
766                        protocol_name:
767                            <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
768                    }),
769                }))
770            },
771        )
772    }
773}
774
775/// Observer protocol for changes to network interfaces (addition, deletion, and
776/// interface property changes).
777#[derive(Debug)]
778pub enum WatcherRequest {
779    /// Hanging get for an interface addition/deletion change.
780    ///
781    /// Clients should only have one call of this method at a time; a second
782    /// call to this method while a call is already pending will cause the
783    /// server end of the protocol to be closed.
784    ///
785    /// If there are N interfaces present at the time the server end of the
786    /// protocol is initialized, then the first N invocations of this method
787    /// will return [`Event.existing`] followed by a single [`Event.idle`]
788    /// indicating that all existing interfaces have been sent. Subsequent calls
789    /// will immediately return if there is a change to be reported, or block
790    /// until a change occurs.
791    ///
792    /// The server may choose to coalesce property change events, e.g. when
793    /// multiple independent property changes occur. As a result, clients cannot
794    /// assume that the order in which they observe the interface changes is the
795    /// order in which the changes occurred.
796    ///
797    /// - response `event` the interface change event.
798    Watch { responder: WatcherWatchResponder },
799}
800
801impl WatcherRequest {
802    #[allow(irrefutable_let_patterns)]
803    pub fn into_watch(self) -> Option<(WatcherWatchResponder)> {
804        if let WatcherRequest::Watch { responder } = self {
805            Some((responder))
806        } else {
807            None
808        }
809    }
810
811    /// Name of the method defined in FIDL
812    pub fn method_name(&self) -> &'static str {
813        match *self {
814            WatcherRequest::Watch { .. } => "watch",
815        }
816    }
817}
818
819#[derive(Debug, Clone)]
820pub struct WatcherControlHandle {
821    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
822}
823
824impl fidl::endpoints::ControlHandle for WatcherControlHandle {
825    fn shutdown(&self) {
826        self.inner.shutdown()
827    }
828    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
829        self.inner.shutdown_with_epitaph(status)
830    }
831
832    fn is_closed(&self) -> bool {
833        self.inner.channel().is_closed()
834    }
835    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
836        self.inner.channel().on_closed()
837    }
838
839    #[cfg(target_os = "fuchsia")]
840    fn signal_peer(
841        &self,
842        clear_mask: zx::Signals,
843        set_mask: zx::Signals,
844    ) -> Result<(), zx_status::Status> {
845        use fidl::Peered;
846        self.inner.channel().signal_peer(clear_mask, set_mask)
847    }
848}
849
850impl WatcherControlHandle {}
851
852#[must_use = "FIDL methods require a response to be sent"]
853#[derive(Debug)]
854pub struct WatcherWatchResponder {
855    control_handle: std::mem::ManuallyDrop<WatcherControlHandle>,
856    tx_id: u32,
857}
858
859/// Set the the channel to be shutdown (see [`WatcherControlHandle::shutdown`])
860/// if the responder is dropped without sending a response, so that the client
861/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
862impl std::ops::Drop for WatcherWatchResponder {
863    fn drop(&mut self) {
864        self.control_handle.shutdown();
865        // Safety: drops once, never accessed again
866        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
867    }
868}
869
870impl fidl::endpoints::Responder for WatcherWatchResponder {
871    type ControlHandle = WatcherControlHandle;
872
873    fn control_handle(&self) -> &WatcherControlHandle {
874        &self.control_handle
875    }
876
877    fn drop_without_shutdown(mut self) {
878        // Safety: drops once, never accessed again due to mem::forget
879        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
880        // Prevent Drop from running (which would shut down the channel)
881        std::mem::forget(self);
882    }
883}
884
885impl WatcherWatchResponder {
886    /// Sends a response to the FIDL transaction.
887    ///
888    /// Sets the channel to shutdown if an error occurs.
889    pub fn send(self, mut event: &Event) -> Result<(), fidl::Error> {
890        let _result = self.send_raw(event);
891        if _result.is_err() {
892            self.control_handle.shutdown();
893        }
894        self.drop_without_shutdown();
895        _result
896    }
897
898    /// Similar to "send" but does not shutdown the channel if an error occurs.
899    pub fn send_no_shutdown_on_err(self, mut event: &Event) -> Result<(), fidl::Error> {
900        let _result = self.send_raw(event);
901        self.drop_without_shutdown();
902        _result
903    }
904
905    fn send_raw(&self, mut event: &Event) -> Result<(), fidl::Error> {
906        self.control_handle.inner.send::<WatcherWatchResponse>(
907            (event,),
908            self.tx_id,
909            0x550767aa9faeeef3,
910            fidl::encoding::DynamicFlags::empty(),
911        )
912    }
913}
914
915mod internal {
916    use super::*;
917
918    impl fidl::encoding::ResourceTypeMarker for StateGetWatcherRequest {
919        type Borrowed<'a> = &'a mut Self;
920        fn take_or_borrow<'a>(
921            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
922        ) -> Self::Borrowed<'a> {
923            value
924        }
925    }
926
927    unsafe impl fidl::encoding::TypeMarker for StateGetWatcherRequest {
928        type Owned = Self;
929
930        #[inline(always)]
931        fn inline_align(_context: fidl::encoding::Context) -> usize {
932            8
933        }
934
935        #[inline(always)]
936        fn inline_size(_context: fidl::encoding::Context) -> usize {
937            24
938        }
939    }
940
941    unsafe impl
942        fidl::encoding::Encode<
943            StateGetWatcherRequest,
944            fidl::encoding::DefaultFuchsiaResourceDialect,
945        > for &mut StateGetWatcherRequest
946    {
947        #[inline]
948        unsafe fn encode(
949            self,
950            encoder: &mut fidl::encoding::Encoder<
951                '_,
952                fidl::encoding::DefaultFuchsiaResourceDialect,
953            >,
954            offset: usize,
955            _depth: fidl::encoding::Depth,
956        ) -> fidl::Result<()> {
957            encoder.debug_check_bounds::<StateGetWatcherRequest>(offset);
958            // Delegate to tuple encoding.
959            fidl::encoding::Encode::<StateGetWatcherRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
960                (
961                    <WatcherOptions as fidl::encoding::ValueTypeMarker>::borrow(&self.options),
962                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<WatcherMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.watcher),
963                ),
964                encoder, offset, _depth
965            )
966        }
967    }
968    unsafe impl<
969            T0: fidl::encoding::Encode<WatcherOptions, fidl::encoding::DefaultFuchsiaResourceDialect>,
970            T1: fidl::encoding::Encode<
971                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<WatcherMarker>>,
972                fidl::encoding::DefaultFuchsiaResourceDialect,
973            >,
974        >
975        fidl::encoding::Encode<
976            StateGetWatcherRequest,
977            fidl::encoding::DefaultFuchsiaResourceDialect,
978        > for (T0, T1)
979    {
980        #[inline]
981        unsafe fn encode(
982            self,
983            encoder: &mut fidl::encoding::Encoder<
984                '_,
985                fidl::encoding::DefaultFuchsiaResourceDialect,
986            >,
987            offset: usize,
988            depth: fidl::encoding::Depth,
989        ) -> fidl::Result<()> {
990            encoder.debug_check_bounds::<StateGetWatcherRequest>(offset);
991            // Zero out padding regions. There's no need to apply masks
992            // because the unmasked parts will be overwritten by fields.
993            unsafe {
994                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
995                (ptr as *mut u64).write_unaligned(0);
996            }
997            // Write the fields.
998            self.0.encode(encoder, offset + 0, depth)?;
999            self.1.encode(encoder, offset + 16, depth)?;
1000            Ok(())
1001        }
1002    }
1003
1004    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1005        for StateGetWatcherRequest
1006    {
1007        #[inline(always)]
1008        fn new_empty() -> Self {
1009            Self {
1010                options: fidl::new_empty!(
1011                    WatcherOptions,
1012                    fidl::encoding::DefaultFuchsiaResourceDialect
1013                ),
1014                watcher: fidl::new_empty!(
1015                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<WatcherMarker>>,
1016                    fidl::encoding::DefaultFuchsiaResourceDialect
1017                ),
1018            }
1019        }
1020
1021        #[inline]
1022        unsafe fn decode(
1023            &mut self,
1024            decoder: &mut fidl::encoding::Decoder<
1025                '_,
1026                fidl::encoding::DefaultFuchsiaResourceDialect,
1027            >,
1028            offset: usize,
1029            _depth: fidl::encoding::Depth,
1030        ) -> fidl::Result<()> {
1031            decoder.debug_check_bounds::<Self>(offset);
1032            // Verify that padding bytes are zero.
1033            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1034            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1035            let mask = 0xffffffff00000000u64;
1036            let maskedval = padval & mask;
1037            if maskedval != 0 {
1038                return Err(fidl::Error::NonZeroPadding {
1039                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1040                });
1041            }
1042            fidl::decode!(
1043                WatcherOptions,
1044                fidl::encoding::DefaultFuchsiaResourceDialect,
1045                &mut self.options,
1046                decoder,
1047                offset + 0,
1048                _depth
1049            )?;
1050            fidl::decode!(
1051                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<WatcherMarker>>,
1052                fidl::encoding::DefaultFuchsiaResourceDialect,
1053                &mut self.watcher,
1054                decoder,
1055                offset + 16,
1056                _depth
1057            )?;
1058            Ok(())
1059        }
1060    }
1061}