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