fidl_test_config_parentoverrides/
fidl_test_config_parentoverrides.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_test_config_parentoverrides__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ReporterMarker;
16
17impl fidl::endpoints::ProtocolMarker for ReporterMarker {
18    type Proxy = ReporterProxy;
19    type RequestStream = ReporterRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = ReporterSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "test.config.parentoverrides.Reporter";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for ReporterMarker {}
26
27pub trait ReporterProxyInterface: Send + Sync {
28    type GetParentProvidedConfigStringResponseFut: std::future::Future<Output = Result<String, fidl::Error>>
29        + Send;
30    fn r#get_parent_provided_config_string(&self)
31        -> Self::GetParentProvidedConfigStringResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct ReporterSynchronousProxy {
36    client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for ReporterSynchronousProxy {
41    type Proxy = ReporterProxy;
42    type Protocol = ReporterMarker;
43
44    fn from_channel(inner: fidl::Channel) -> Self {
45        Self::new(inner)
46    }
47
48    fn into_channel(self) -> fidl::Channel {
49        self.client.into_channel()
50    }
51
52    fn as_channel(&self) -> &fidl::Channel {
53        self.client.as_channel()
54    }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl ReporterSynchronousProxy {
59    pub fn new(channel: fidl::Channel) -> Self {
60        let protocol_name = <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62    }
63
64    pub fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    /// Waits until an event arrives and returns it. It is safe for other
69    /// threads to make concurrent requests while waiting for an event.
70    pub fn wait_for_event(
71        &self,
72        deadline: zx::MonotonicInstant,
73    ) -> Result<ReporterEvent, fidl::Error> {
74        ReporterEvent::decode(self.client.wait_for_event(deadline)?)
75    }
76
77    pub fn r#get_parent_provided_config_string(
78        &self,
79        ___deadline: zx::MonotonicInstant,
80    ) -> Result<String, fidl::Error> {
81        let _response = self.client.send_query::<
82            fidl::encoding::EmptyPayload,
83            ReporterGetParentProvidedConfigStringResponse,
84        >(
85            (),
86            0x5fd767f67a6dd786,
87            fidl::encoding::DynamicFlags::empty(),
88            ___deadline,
89        )?;
90        Ok(_response.value)
91    }
92}
93
94#[cfg(target_os = "fuchsia")]
95impl From<ReporterSynchronousProxy> for zx::Handle {
96    fn from(value: ReporterSynchronousProxy) -> Self {
97        value.into_channel().into()
98    }
99}
100
101#[cfg(target_os = "fuchsia")]
102impl From<fidl::Channel> for ReporterSynchronousProxy {
103    fn from(value: fidl::Channel) -> Self {
104        Self::new(value)
105    }
106}
107
108#[cfg(target_os = "fuchsia")]
109impl fidl::endpoints::FromClient for ReporterSynchronousProxy {
110    type Protocol = ReporterMarker;
111
112    fn from_client(value: fidl::endpoints::ClientEnd<ReporterMarker>) -> Self {
113        Self::new(value.into_channel())
114    }
115}
116
117#[derive(Debug, Clone)]
118pub struct ReporterProxy {
119    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
120}
121
122impl fidl::endpoints::Proxy for ReporterProxy {
123    type Protocol = ReporterMarker;
124
125    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
126        Self::new(inner)
127    }
128
129    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
130        self.client.into_channel().map_err(|client| Self { client })
131    }
132
133    fn as_channel(&self) -> &::fidl::AsyncChannel {
134        self.client.as_channel()
135    }
136}
137
138impl ReporterProxy {
139    /// Create a new Proxy for test.config.parentoverrides/Reporter.
140    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
141        let protocol_name = <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
142        Self { client: fidl::client::Client::new(channel, protocol_name) }
143    }
144
145    /// Get a Stream of events from the remote end of the protocol.
146    ///
147    /// # Panics
148    ///
149    /// Panics if the event stream was already taken.
150    pub fn take_event_stream(&self) -> ReporterEventStream {
151        ReporterEventStream { event_receiver: self.client.take_event_receiver() }
152    }
153
154    pub fn r#get_parent_provided_config_string(
155        &self,
156    ) -> fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect> {
157        ReporterProxyInterface::r#get_parent_provided_config_string(self)
158    }
159}
160
161impl ReporterProxyInterface for ReporterProxy {
162    type GetParentProvidedConfigStringResponseFut =
163        fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect>;
164    fn r#get_parent_provided_config_string(
165        &self,
166    ) -> Self::GetParentProvidedConfigStringResponseFut {
167        fn _decode(
168            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
169        ) -> Result<String, fidl::Error> {
170            let _response = fidl::client::decode_transaction_body::<
171                ReporterGetParentProvidedConfigStringResponse,
172                fidl::encoding::DefaultFuchsiaResourceDialect,
173                0x5fd767f67a6dd786,
174            >(_buf?)?;
175            Ok(_response.value)
176        }
177        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, String>(
178            (),
179            0x5fd767f67a6dd786,
180            fidl::encoding::DynamicFlags::empty(),
181            _decode,
182        )
183    }
184}
185
186pub struct ReporterEventStream {
187    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
188}
189
190impl std::marker::Unpin for ReporterEventStream {}
191
192impl futures::stream::FusedStream for ReporterEventStream {
193    fn is_terminated(&self) -> bool {
194        self.event_receiver.is_terminated()
195    }
196}
197
198impl futures::Stream for ReporterEventStream {
199    type Item = Result<ReporterEvent, fidl::Error>;
200
201    fn poll_next(
202        mut self: std::pin::Pin<&mut Self>,
203        cx: &mut std::task::Context<'_>,
204    ) -> std::task::Poll<Option<Self::Item>> {
205        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
206            &mut self.event_receiver,
207            cx
208        )?) {
209            Some(buf) => std::task::Poll::Ready(Some(ReporterEvent::decode(buf))),
210            None => std::task::Poll::Ready(None),
211        }
212    }
213}
214
215#[derive(Debug)]
216pub enum ReporterEvent {}
217
218impl ReporterEvent {
219    /// Decodes a message buffer as a [`ReporterEvent`].
220    fn decode(
221        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
222    ) -> Result<ReporterEvent, fidl::Error> {
223        let (bytes, _handles) = buf.split_mut();
224        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
225        debug_assert_eq!(tx_header.tx_id, 0);
226        match tx_header.ordinal {
227            _ => Err(fidl::Error::UnknownOrdinal {
228                ordinal: tx_header.ordinal,
229                protocol_name: <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
230            }),
231        }
232    }
233}
234
235/// A Stream of incoming requests for test.config.parentoverrides/Reporter.
236pub struct ReporterRequestStream {
237    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
238    is_terminated: bool,
239}
240
241impl std::marker::Unpin for ReporterRequestStream {}
242
243impl futures::stream::FusedStream for ReporterRequestStream {
244    fn is_terminated(&self) -> bool {
245        self.is_terminated
246    }
247}
248
249impl fidl::endpoints::RequestStream for ReporterRequestStream {
250    type Protocol = ReporterMarker;
251    type ControlHandle = ReporterControlHandle;
252
253    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
254        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
255    }
256
257    fn control_handle(&self) -> Self::ControlHandle {
258        ReporterControlHandle { inner: self.inner.clone() }
259    }
260
261    fn into_inner(
262        self,
263    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
264    {
265        (self.inner, self.is_terminated)
266    }
267
268    fn from_inner(
269        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
270        is_terminated: bool,
271    ) -> Self {
272        Self { inner, is_terminated }
273    }
274}
275
276impl futures::Stream for ReporterRequestStream {
277    type Item = Result<ReporterRequest, fidl::Error>;
278
279    fn poll_next(
280        mut self: std::pin::Pin<&mut Self>,
281        cx: &mut std::task::Context<'_>,
282    ) -> std::task::Poll<Option<Self::Item>> {
283        let this = &mut *self;
284        if this.inner.check_shutdown(cx) {
285            this.is_terminated = true;
286            return std::task::Poll::Ready(None);
287        }
288        if this.is_terminated {
289            panic!("polled ReporterRequestStream after completion");
290        }
291        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
292            |bytes, handles| {
293                match this.inner.channel().read_etc(cx, bytes, handles) {
294                    std::task::Poll::Ready(Ok(())) => {}
295                    std::task::Poll::Pending => return std::task::Poll::Pending,
296                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
297                        this.is_terminated = true;
298                        return std::task::Poll::Ready(None);
299                    }
300                    std::task::Poll::Ready(Err(e)) => {
301                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
302                            e.into(),
303                        ))))
304                    }
305                }
306
307                // A message has been received from the channel
308                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
309
310                std::task::Poll::Ready(Some(match header.ordinal {
311                    0x5fd767f67a6dd786 => {
312                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
313                        let mut req = fidl::new_empty!(
314                            fidl::encoding::EmptyPayload,
315                            fidl::encoding::DefaultFuchsiaResourceDialect
316                        );
317                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
318                        let control_handle = ReporterControlHandle { inner: this.inner.clone() };
319                        Ok(ReporterRequest::GetParentProvidedConfigString {
320                            responder: ReporterGetParentProvidedConfigStringResponder {
321                                control_handle: std::mem::ManuallyDrop::new(control_handle),
322                                tx_id: header.tx_id,
323                            },
324                        })
325                    }
326                    _ => Err(fidl::Error::UnknownOrdinal {
327                        ordinal: header.ordinal,
328                        protocol_name:
329                            <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
330                    }),
331                }))
332            },
333        )
334    }
335}
336
337#[derive(Debug)]
338pub enum ReporterRequest {
339    GetParentProvidedConfigString { responder: ReporterGetParentProvidedConfigStringResponder },
340}
341
342impl ReporterRequest {
343    #[allow(irrefutable_let_patterns)]
344    pub fn into_get_parent_provided_config_string(
345        self,
346    ) -> Option<(ReporterGetParentProvidedConfigStringResponder)> {
347        if let ReporterRequest::GetParentProvidedConfigString { responder } = self {
348            Some((responder))
349        } else {
350            None
351        }
352    }
353
354    /// Name of the method defined in FIDL
355    pub fn method_name(&self) -> &'static str {
356        match *self {
357            ReporterRequest::GetParentProvidedConfigString { .. } => {
358                "get_parent_provided_config_string"
359            }
360        }
361    }
362}
363
364#[derive(Debug, Clone)]
365pub struct ReporterControlHandle {
366    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
367}
368
369impl fidl::endpoints::ControlHandle for ReporterControlHandle {
370    fn shutdown(&self) {
371        self.inner.shutdown()
372    }
373    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
374        self.inner.shutdown_with_epitaph(status)
375    }
376
377    fn is_closed(&self) -> bool {
378        self.inner.channel().is_closed()
379    }
380    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
381        self.inner.channel().on_closed()
382    }
383
384    #[cfg(target_os = "fuchsia")]
385    fn signal_peer(
386        &self,
387        clear_mask: zx::Signals,
388        set_mask: zx::Signals,
389    ) -> Result<(), zx_status::Status> {
390        use fidl::Peered;
391        self.inner.channel().signal_peer(clear_mask, set_mask)
392    }
393}
394
395impl ReporterControlHandle {}
396
397#[must_use = "FIDL methods require a response to be sent"]
398#[derive(Debug)]
399pub struct ReporterGetParentProvidedConfigStringResponder {
400    control_handle: std::mem::ManuallyDrop<ReporterControlHandle>,
401    tx_id: u32,
402}
403
404/// Set the the channel to be shutdown (see [`ReporterControlHandle::shutdown`])
405/// if the responder is dropped without sending a response, so that the client
406/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
407impl std::ops::Drop for ReporterGetParentProvidedConfigStringResponder {
408    fn drop(&mut self) {
409        self.control_handle.shutdown();
410        // Safety: drops once, never accessed again
411        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
412    }
413}
414
415impl fidl::endpoints::Responder for ReporterGetParentProvidedConfigStringResponder {
416    type ControlHandle = ReporterControlHandle;
417
418    fn control_handle(&self) -> &ReporterControlHandle {
419        &self.control_handle
420    }
421
422    fn drop_without_shutdown(mut self) {
423        // Safety: drops once, never accessed again due to mem::forget
424        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
425        // Prevent Drop from running (which would shut down the channel)
426        std::mem::forget(self);
427    }
428}
429
430impl ReporterGetParentProvidedConfigStringResponder {
431    /// Sends a response to the FIDL transaction.
432    ///
433    /// Sets the channel to shutdown if an error occurs.
434    pub fn send(self, mut value: &str) -> Result<(), fidl::Error> {
435        let _result = self.send_raw(value);
436        if _result.is_err() {
437            self.control_handle.shutdown();
438        }
439        self.drop_without_shutdown();
440        _result
441    }
442
443    /// Similar to "send" but does not shutdown the channel if an error occurs.
444    pub fn send_no_shutdown_on_err(self, mut value: &str) -> Result<(), fidl::Error> {
445        let _result = self.send_raw(value);
446        self.drop_without_shutdown();
447        _result
448    }
449
450    fn send_raw(&self, mut value: &str) -> Result<(), fidl::Error> {
451        self.control_handle.inner.send::<ReporterGetParentProvidedConfigStringResponse>(
452            (value,),
453            self.tx_id,
454            0x5fd767f67a6dd786,
455            fidl::encoding::DynamicFlags::empty(),
456        )
457    }
458}
459
460mod internal {
461    use super::*;
462}