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