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