Skip to main content

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