Skip to main content

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