fidl_fuchsia_diagnostics_crasher/
fidl_fuchsia_diagnostics_crasher.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_diagnostics_crasher__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct CrasherMarker;
16
17impl fidl::endpoints::ProtocolMarker for CrasherMarker {
18    type Proxy = CrasherProxy;
19    type RequestStream = CrasherRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = CrasherSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.diagnostics.crasher.Crasher";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for CrasherMarker {}
26
27pub trait CrasherProxyInterface: Send + Sync {
28    type CrashResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29    fn r#crash(&self, message: &str) -> Self::CrashResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct CrasherSynchronousProxy {
34    client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for CrasherSynchronousProxy {
39    type Proxy = CrasherProxy;
40    type Protocol = CrasherMarker;
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 CrasherSynchronousProxy {
57    pub fn new(channel: fidl::Channel) -> Self {
58        let protocol_name = <CrasherMarker 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<CrasherEvent, fidl::Error> {
72        CrasherEvent::decode(self.client.wait_for_event(deadline)?)
73    }
74
75    /// Crashes the component with the specified message.
76    pub fn r#crash(
77        &self,
78        mut message: &str,
79        ___deadline: zx::MonotonicInstant,
80    ) -> Result<(), fidl::Error> {
81        let _response = self.client.send_query::<
82            CrasherCrashRequest,
83            fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
84        >(
85            (message,),
86            0x2dc9841434f9abda,
87            fidl::encoding::DynamicFlags::FLEXIBLE,
88            ___deadline,
89        )?
90        .into_result::<CrasherMarker>("crash")?;
91        Ok(_response)
92    }
93}
94
95#[cfg(target_os = "fuchsia")]
96impl From<CrasherSynchronousProxy> for zx::Handle {
97    fn from(value: CrasherSynchronousProxy) -> Self {
98        value.into_channel().into()
99    }
100}
101
102#[cfg(target_os = "fuchsia")]
103impl From<fidl::Channel> for CrasherSynchronousProxy {
104    fn from(value: fidl::Channel) -> Self {
105        Self::new(value)
106    }
107}
108
109#[cfg(target_os = "fuchsia")]
110impl fidl::endpoints::FromClient for CrasherSynchronousProxy {
111    type Protocol = CrasherMarker;
112
113    fn from_client(value: fidl::endpoints::ClientEnd<CrasherMarker>) -> Self {
114        Self::new(value.into_channel())
115    }
116}
117
118#[derive(Debug, Clone)]
119pub struct CrasherProxy {
120    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
121}
122
123impl fidl::endpoints::Proxy for CrasherProxy {
124    type Protocol = CrasherMarker;
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 CrasherProxy {
140    /// Create a new Proxy for fuchsia.diagnostics.crasher/Crasher.
141    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
142        let protocol_name = <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
143        Self { client: fidl::client::Client::new(channel, protocol_name) }
144    }
145
146    /// Get a Stream of events from the remote end of the protocol.
147    ///
148    /// # Panics
149    ///
150    /// Panics if the event stream was already taken.
151    pub fn take_event_stream(&self) -> CrasherEventStream {
152        CrasherEventStream { event_receiver: self.client.take_event_receiver() }
153    }
154
155    /// Crashes the component with the specified message.
156    pub fn r#crash(
157        &self,
158        mut message: &str,
159    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
160        CrasherProxyInterface::r#crash(self, message)
161    }
162}
163
164impl CrasherProxyInterface for CrasherProxy {
165    type CrashResponseFut =
166        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
167    fn r#crash(&self, mut message: &str) -> Self::CrashResponseFut {
168        fn _decode(
169            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
170        ) -> Result<(), fidl::Error> {
171            let _response = fidl::client::decode_transaction_body::<
172                fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
173                fidl::encoding::DefaultFuchsiaResourceDialect,
174                0x2dc9841434f9abda,
175            >(_buf?)?
176            .into_result::<CrasherMarker>("crash")?;
177            Ok(_response)
178        }
179        self.client.send_query_and_decode::<CrasherCrashRequest, ()>(
180            (message,),
181            0x2dc9841434f9abda,
182            fidl::encoding::DynamicFlags::FLEXIBLE,
183            _decode,
184        )
185    }
186}
187
188pub struct CrasherEventStream {
189    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
190}
191
192impl std::marker::Unpin for CrasherEventStream {}
193
194impl futures::stream::FusedStream for CrasherEventStream {
195    fn is_terminated(&self) -> bool {
196        self.event_receiver.is_terminated()
197    }
198}
199
200impl futures::Stream for CrasherEventStream {
201    type Item = Result<CrasherEvent, fidl::Error>;
202
203    fn poll_next(
204        mut self: std::pin::Pin<&mut Self>,
205        cx: &mut std::task::Context<'_>,
206    ) -> std::task::Poll<Option<Self::Item>> {
207        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
208            &mut self.event_receiver,
209            cx
210        )?) {
211            Some(buf) => std::task::Poll::Ready(Some(CrasherEvent::decode(buf))),
212            None => std::task::Poll::Ready(None),
213        }
214    }
215}
216
217#[derive(Debug)]
218pub enum CrasherEvent {
219    #[non_exhaustive]
220    _UnknownEvent {
221        /// Ordinal of the event that was sent.
222        ordinal: u64,
223    },
224}
225
226impl CrasherEvent {
227    /// Decodes a message buffer as a [`CrasherEvent`].
228    fn decode(
229        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
230    ) -> Result<CrasherEvent, fidl::Error> {
231        let (bytes, _handles) = buf.split_mut();
232        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
233        debug_assert_eq!(tx_header.tx_id, 0);
234        match tx_header.ordinal {
235            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
236                Ok(CrasherEvent::_UnknownEvent { ordinal: tx_header.ordinal })
237            }
238            _ => Err(fidl::Error::UnknownOrdinal {
239                ordinal: tx_header.ordinal,
240                protocol_name: <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
241            }),
242        }
243    }
244}
245
246/// A Stream of incoming requests for fuchsia.diagnostics.crasher/Crasher.
247pub struct CrasherRequestStream {
248    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
249    is_terminated: bool,
250}
251
252impl std::marker::Unpin for CrasherRequestStream {}
253
254impl futures::stream::FusedStream for CrasherRequestStream {
255    fn is_terminated(&self) -> bool {
256        self.is_terminated
257    }
258}
259
260impl fidl::endpoints::RequestStream for CrasherRequestStream {
261    type Protocol = CrasherMarker;
262    type ControlHandle = CrasherControlHandle;
263
264    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
265        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
266    }
267
268    fn control_handle(&self) -> Self::ControlHandle {
269        CrasherControlHandle { inner: self.inner.clone() }
270    }
271
272    fn into_inner(
273        self,
274    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
275    {
276        (self.inner, self.is_terminated)
277    }
278
279    fn from_inner(
280        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
281        is_terminated: bool,
282    ) -> Self {
283        Self { inner, is_terminated }
284    }
285}
286
287impl futures::Stream for CrasherRequestStream {
288    type Item = Result<CrasherRequest, fidl::Error>;
289
290    fn poll_next(
291        mut self: std::pin::Pin<&mut Self>,
292        cx: &mut std::task::Context<'_>,
293    ) -> std::task::Poll<Option<Self::Item>> {
294        let this = &mut *self;
295        if this.inner.check_shutdown(cx) {
296            this.is_terminated = true;
297            return std::task::Poll::Ready(None);
298        }
299        if this.is_terminated {
300            panic!("polled CrasherRequestStream after completion");
301        }
302        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
303            |bytes, handles| {
304                match this.inner.channel().read_etc(cx, bytes, handles) {
305                    std::task::Poll::Ready(Ok(())) => {}
306                    std::task::Poll::Pending => return std::task::Poll::Pending,
307                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
308                        this.is_terminated = true;
309                        return std::task::Poll::Ready(None);
310                    }
311                    std::task::Poll::Ready(Err(e)) => {
312                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
313                            e.into(),
314                        ))))
315                    }
316                }
317
318                // A message has been received from the channel
319                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
320
321                std::task::Poll::Ready(Some(match header.ordinal {
322                    0x2dc9841434f9abda => {
323                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
324                        let mut req = fidl::new_empty!(
325                            CrasherCrashRequest,
326                            fidl::encoding::DefaultFuchsiaResourceDialect
327                        );
328                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CrasherCrashRequest>(&header, _body_bytes, handles, &mut req)?;
329                        let control_handle = CrasherControlHandle { inner: this.inner.clone() };
330                        Ok(CrasherRequest::Crash {
331                            message: req.message,
332
333                            responder: CrasherCrashResponder {
334                                control_handle: std::mem::ManuallyDrop::new(control_handle),
335                                tx_id: header.tx_id,
336                            },
337                        })
338                    }
339                    _ if header.tx_id == 0
340                        && header
341                            .dynamic_flags()
342                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
343                    {
344                        Ok(CrasherRequest::_UnknownMethod {
345                            ordinal: header.ordinal,
346                            control_handle: CrasherControlHandle { inner: this.inner.clone() },
347                            method_type: fidl::MethodType::OneWay,
348                        })
349                    }
350                    _ if header
351                        .dynamic_flags()
352                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
353                    {
354                        this.inner.send_framework_err(
355                            fidl::encoding::FrameworkErr::UnknownMethod,
356                            header.tx_id,
357                            header.ordinal,
358                            header.dynamic_flags(),
359                            (bytes, handles),
360                        )?;
361                        Ok(CrasherRequest::_UnknownMethod {
362                            ordinal: header.ordinal,
363                            control_handle: CrasherControlHandle { inner: this.inner.clone() },
364                            method_type: fidl::MethodType::TwoWay,
365                        })
366                    }
367                    _ => Err(fidl::Error::UnknownOrdinal {
368                        ordinal: header.ordinal,
369                        protocol_name:
370                            <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
371                    }),
372                }))
373            },
374        )
375    }
376}
377
378#[derive(Debug)]
379pub enum CrasherRequest {
380    /// Crashes the component with the specified message.
381    Crash { message: String, responder: CrasherCrashResponder },
382    /// An interaction was received which does not match any known method.
383    #[non_exhaustive]
384    _UnknownMethod {
385        /// Ordinal of the method that was called.
386        ordinal: u64,
387        control_handle: CrasherControlHandle,
388        method_type: fidl::MethodType,
389    },
390}
391
392impl CrasherRequest {
393    #[allow(irrefutable_let_patterns)]
394    pub fn into_crash(self) -> Option<(String, CrasherCrashResponder)> {
395        if let CrasherRequest::Crash { message, responder } = self {
396            Some((message, responder))
397        } else {
398            None
399        }
400    }
401
402    /// Name of the method defined in FIDL
403    pub fn method_name(&self) -> &'static str {
404        match *self {
405            CrasherRequest::Crash { .. } => "crash",
406            CrasherRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
407                "unknown one-way method"
408            }
409            CrasherRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
410                "unknown two-way method"
411            }
412        }
413    }
414}
415
416#[derive(Debug, Clone)]
417pub struct CrasherControlHandle {
418    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
419}
420
421impl fidl::endpoints::ControlHandle for CrasherControlHandle {
422    fn shutdown(&self) {
423        self.inner.shutdown()
424    }
425    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
426        self.inner.shutdown_with_epitaph(status)
427    }
428
429    fn is_closed(&self) -> bool {
430        self.inner.channel().is_closed()
431    }
432    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
433        self.inner.channel().on_closed()
434    }
435
436    #[cfg(target_os = "fuchsia")]
437    fn signal_peer(
438        &self,
439        clear_mask: zx::Signals,
440        set_mask: zx::Signals,
441    ) -> Result<(), zx_status::Status> {
442        use fidl::Peered;
443        self.inner.channel().signal_peer(clear_mask, set_mask)
444    }
445}
446
447impl CrasherControlHandle {}
448
449#[must_use = "FIDL methods require a response to be sent"]
450#[derive(Debug)]
451pub struct CrasherCrashResponder {
452    control_handle: std::mem::ManuallyDrop<CrasherControlHandle>,
453    tx_id: u32,
454}
455
456/// Set the the channel to be shutdown (see [`CrasherControlHandle::shutdown`])
457/// if the responder is dropped without sending a response, so that the client
458/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
459impl std::ops::Drop for CrasherCrashResponder {
460    fn drop(&mut self) {
461        self.control_handle.shutdown();
462        // Safety: drops once, never accessed again
463        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
464    }
465}
466
467impl fidl::endpoints::Responder for CrasherCrashResponder {
468    type ControlHandle = CrasherControlHandle;
469
470    fn control_handle(&self) -> &CrasherControlHandle {
471        &self.control_handle
472    }
473
474    fn drop_without_shutdown(mut self) {
475        // Safety: drops once, never accessed again due to mem::forget
476        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
477        // Prevent Drop from running (which would shut down the channel)
478        std::mem::forget(self);
479    }
480}
481
482impl CrasherCrashResponder {
483    /// Sends a response to the FIDL transaction.
484    ///
485    /// Sets the channel to shutdown if an error occurs.
486    pub fn send(self) -> Result<(), fidl::Error> {
487        let _result = self.send_raw();
488        if _result.is_err() {
489            self.control_handle.shutdown();
490        }
491        self.drop_without_shutdown();
492        _result
493    }
494
495    /// Similar to "send" but does not shutdown the channel if an error occurs.
496    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
497        let _result = self.send_raw();
498        self.drop_without_shutdown();
499        _result
500    }
501
502    fn send_raw(&self) -> Result<(), fidl::Error> {
503        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
504            fidl::encoding::Flexible::new(()),
505            self.tx_id,
506            0x2dc9841434f9abda,
507            fidl::encoding::DynamicFlags::FLEXIBLE,
508        )
509    }
510}
511
512mod internal {
513    use super::*;
514}