fidl_fuchsia_crashdriver_test/
fidl_fuchsia_crashdriver_test.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_crashdriver_test_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 = "(anonymous) Crasher";
24}
25
26pub trait CrasherProxyInterface: Send + Sync {
27    type PingResponseFut: std::future::Future<Output = Result<u64, fidl::Error>> + Send;
28    fn r#ping(&self) -> Self::PingResponseFut;
29    fn r#crash(&self) -> Result<(), fidl::Error>;
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    /// Returns a number that is unique per instance of the driver.
76    pub fn r#ping(&self, ___deadline: zx::MonotonicInstant) -> Result<u64, fidl::Error> {
77        let _response =
78            self.client.send_query::<fidl::encoding::EmptyPayload, CrasherPingResponse>(
79                (),
80                0x63e0c4d973e4b1f9,
81                fidl::encoding::DynamicFlags::empty(),
82                ___deadline,
83            )?;
84        Ok(_response.pong)
85    }
86
87    /// One way call that will assert false and kill the host process.
88    pub fn r#crash(&self) -> Result<(), fidl::Error> {
89        self.client.send::<fidl::encoding::EmptyPayload>(
90            (),
91            0x15290e84d9b74bd2,
92            fidl::encoding::DynamicFlags::empty(),
93        )
94    }
95}
96
97#[derive(Debug, Clone)]
98pub struct CrasherProxy {
99    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
100}
101
102impl fidl::endpoints::Proxy for CrasherProxy {
103    type Protocol = CrasherMarker;
104
105    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
106        Self::new(inner)
107    }
108
109    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
110        self.client.into_channel().map_err(|client| Self { client })
111    }
112
113    fn as_channel(&self) -> &::fidl::AsyncChannel {
114        self.client.as_channel()
115    }
116}
117
118impl CrasherProxy {
119    /// Create a new Proxy for fuchsia.crashdriver.test/Crasher.
120    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
121        let protocol_name = <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
122        Self { client: fidl::client::Client::new(channel, protocol_name) }
123    }
124
125    /// Get a Stream of events from the remote end of the protocol.
126    ///
127    /// # Panics
128    ///
129    /// Panics if the event stream was already taken.
130    pub fn take_event_stream(&self) -> CrasherEventStream {
131        CrasherEventStream { event_receiver: self.client.take_event_receiver() }
132    }
133
134    /// Returns a number that is unique per instance of the driver.
135    pub fn r#ping(
136        &self,
137    ) -> fidl::client::QueryResponseFut<u64, fidl::encoding::DefaultFuchsiaResourceDialect> {
138        CrasherProxyInterface::r#ping(self)
139    }
140
141    /// One way call that will assert false and kill the host process.
142    pub fn r#crash(&self) -> Result<(), fidl::Error> {
143        CrasherProxyInterface::r#crash(self)
144    }
145}
146
147impl CrasherProxyInterface for CrasherProxy {
148    type PingResponseFut =
149        fidl::client::QueryResponseFut<u64, fidl::encoding::DefaultFuchsiaResourceDialect>;
150    fn r#ping(&self) -> Self::PingResponseFut {
151        fn _decode(
152            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
153        ) -> Result<u64, fidl::Error> {
154            let _response = fidl::client::decode_transaction_body::<
155                CrasherPingResponse,
156                fidl::encoding::DefaultFuchsiaResourceDialect,
157                0x63e0c4d973e4b1f9,
158            >(_buf?)?;
159            Ok(_response.pong)
160        }
161        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, u64>(
162            (),
163            0x63e0c4d973e4b1f9,
164            fidl::encoding::DynamicFlags::empty(),
165            _decode,
166        )
167    }
168
169    fn r#crash(&self) -> Result<(), fidl::Error> {
170        self.client.send::<fidl::encoding::EmptyPayload>(
171            (),
172            0x15290e84d9b74bd2,
173            fidl::encoding::DynamicFlags::empty(),
174        )
175    }
176}
177
178pub struct CrasherEventStream {
179    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
180}
181
182impl std::marker::Unpin for CrasherEventStream {}
183
184impl futures::stream::FusedStream for CrasherEventStream {
185    fn is_terminated(&self) -> bool {
186        self.event_receiver.is_terminated()
187    }
188}
189
190impl futures::Stream for CrasherEventStream {
191    type Item = Result<CrasherEvent, fidl::Error>;
192
193    fn poll_next(
194        mut self: std::pin::Pin<&mut Self>,
195        cx: &mut std::task::Context<'_>,
196    ) -> std::task::Poll<Option<Self::Item>> {
197        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
198            &mut self.event_receiver,
199            cx
200        )?) {
201            Some(buf) => std::task::Poll::Ready(Some(CrasherEvent::decode(buf))),
202            None => std::task::Poll::Ready(None),
203        }
204    }
205}
206
207#[derive(Debug)]
208pub enum CrasherEvent {}
209
210impl CrasherEvent {
211    /// Decodes a message buffer as a [`CrasherEvent`].
212    fn decode(
213        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
214    ) -> Result<CrasherEvent, fidl::Error> {
215        let (bytes, _handles) = buf.split_mut();
216        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
217        debug_assert_eq!(tx_header.tx_id, 0);
218        match tx_header.ordinal {
219            _ => Err(fidl::Error::UnknownOrdinal {
220                ordinal: tx_header.ordinal,
221                protocol_name: <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
222            }),
223        }
224    }
225}
226
227/// A Stream of incoming requests for fuchsia.crashdriver.test/Crasher.
228pub struct CrasherRequestStream {
229    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
230    is_terminated: bool,
231}
232
233impl std::marker::Unpin for CrasherRequestStream {}
234
235impl futures::stream::FusedStream for CrasherRequestStream {
236    fn is_terminated(&self) -> bool {
237        self.is_terminated
238    }
239}
240
241impl fidl::endpoints::RequestStream for CrasherRequestStream {
242    type Protocol = CrasherMarker;
243    type ControlHandle = CrasherControlHandle;
244
245    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
246        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
247    }
248
249    fn control_handle(&self) -> Self::ControlHandle {
250        CrasherControlHandle { inner: self.inner.clone() }
251    }
252
253    fn into_inner(
254        self,
255    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
256    {
257        (self.inner, self.is_terminated)
258    }
259
260    fn from_inner(
261        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
262        is_terminated: bool,
263    ) -> Self {
264        Self { inner, is_terminated }
265    }
266}
267
268impl futures::Stream for CrasherRequestStream {
269    type Item = Result<CrasherRequest, fidl::Error>;
270
271    fn poll_next(
272        mut self: std::pin::Pin<&mut Self>,
273        cx: &mut std::task::Context<'_>,
274    ) -> std::task::Poll<Option<Self::Item>> {
275        let this = &mut *self;
276        if this.inner.check_shutdown(cx) {
277            this.is_terminated = true;
278            return std::task::Poll::Ready(None);
279        }
280        if this.is_terminated {
281            panic!("polled CrasherRequestStream after completion");
282        }
283        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
284            |bytes, handles| {
285                match this.inner.channel().read_etc(cx, bytes, handles) {
286                    std::task::Poll::Ready(Ok(())) => {}
287                    std::task::Poll::Pending => return std::task::Poll::Pending,
288                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
289                        this.is_terminated = true;
290                        return std::task::Poll::Ready(None);
291                    }
292                    std::task::Poll::Ready(Err(e)) => {
293                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
294                            e.into(),
295                        ))))
296                    }
297                }
298
299                // A message has been received from the channel
300                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
301
302                std::task::Poll::Ready(Some(match header.ordinal {
303                    0x63e0c4d973e4b1f9 => {
304                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
305                        let mut req = fidl::new_empty!(
306                            fidl::encoding::EmptyPayload,
307                            fidl::encoding::DefaultFuchsiaResourceDialect
308                        );
309                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
310                        let control_handle = CrasherControlHandle { inner: this.inner.clone() };
311                        Ok(CrasherRequest::Ping {
312                            responder: CrasherPingResponder {
313                                control_handle: std::mem::ManuallyDrop::new(control_handle),
314                                tx_id: header.tx_id,
315                            },
316                        })
317                    }
318                    0x15290e84d9b74bd2 => {
319                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
320                        let mut req = fidl::new_empty!(
321                            fidl::encoding::EmptyPayload,
322                            fidl::encoding::DefaultFuchsiaResourceDialect
323                        );
324                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
325                        let control_handle = CrasherControlHandle { inner: this.inner.clone() };
326                        Ok(CrasherRequest::Crash { control_handle })
327                    }
328                    _ => Err(fidl::Error::UnknownOrdinal {
329                        ordinal: header.ordinal,
330                        protocol_name:
331                            <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
332                    }),
333                }))
334            },
335        )
336    }
337}
338
339#[derive(Debug)]
340pub enum CrasherRequest {
341    /// Returns a number that is unique per instance of the driver.
342    Ping { responder: CrasherPingResponder },
343    /// One way call that will assert false and kill the host process.
344    Crash { control_handle: CrasherControlHandle },
345}
346
347impl CrasherRequest {
348    #[allow(irrefutable_let_patterns)]
349    pub fn into_ping(self) -> Option<(CrasherPingResponder)> {
350        if let CrasherRequest::Ping { responder } = self {
351            Some((responder))
352        } else {
353            None
354        }
355    }
356
357    #[allow(irrefutable_let_patterns)]
358    pub fn into_crash(self) -> Option<(CrasherControlHandle)> {
359        if let CrasherRequest::Crash { control_handle } = self {
360            Some((control_handle))
361        } else {
362            None
363        }
364    }
365
366    /// Name of the method defined in FIDL
367    pub fn method_name(&self) -> &'static str {
368        match *self {
369            CrasherRequest::Ping { .. } => "ping",
370            CrasherRequest::Crash { .. } => "crash",
371        }
372    }
373}
374
375#[derive(Debug, Clone)]
376pub struct CrasherControlHandle {
377    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
378}
379
380impl fidl::endpoints::ControlHandle for CrasherControlHandle {
381    fn shutdown(&self) {
382        self.inner.shutdown()
383    }
384    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
385        self.inner.shutdown_with_epitaph(status)
386    }
387
388    fn is_closed(&self) -> bool {
389        self.inner.channel().is_closed()
390    }
391    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
392        self.inner.channel().on_closed()
393    }
394
395    #[cfg(target_os = "fuchsia")]
396    fn signal_peer(
397        &self,
398        clear_mask: zx::Signals,
399        set_mask: zx::Signals,
400    ) -> Result<(), zx_status::Status> {
401        use fidl::Peered;
402        self.inner.channel().signal_peer(clear_mask, set_mask)
403    }
404}
405
406impl CrasherControlHandle {}
407
408#[must_use = "FIDL methods require a response to be sent"]
409#[derive(Debug)]
410pub struct CrasherPingResponder {
411    control_handle: std::mem::ManuallyDrop<CrasherControlHandle>,
412    tx_id: u32,
413}
414
415/// Set the the channel to be shutdown (see [`CrasherControlHandle::shutdown`])
416/// if the responder is dropped without sending a response, so that the client
417/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
418impl std::ops::Drop for CrasherPingResponder {
419    fn drop(&mut self) {
420        self.control_handle.shutdown();
421        // Safety: drops once, never accessed again
422        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
423    }
424}
425
426impl fidl::endpoints::Responder for CrasherPingResponder {
427    type ControlHandle = CrasherControlHandle;
428
429    fn control_handle(&self) -> &CrasherControlHandle {
430        &self.control_handle
431    }
432
433    fn drop_without_shutdown(mut self) {
434        // Safety: drops once, never accessed again due to mem::forget
435        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
436        // Prevent Drop from running (which would shut down the channel)
437        std::mem::forget(self);
438    }
439}
440
441impl CrasherPingResponder {
442    /// Sends a response to the FIDL transaction.
443    ///
444    /// Sets the channel to shutdown if an error occurs.
445    pub fn send(self, mut pong: u64) -> Result<(), fidl::Error> {
446        let _result = self.send_raw(pong);
447        if _result.is_err() {
448            self.control_handle.shutdown();
449        }
450        self.drop_without_shutdown();
451        _result
452    }
453
454    /// Similar to "send" but does not shutdown the channel if an error occurs.
455    pub fn send_no_shutdown_on_err(self, mut pong: u64) -> Result<(), fidl::Error> {
456        let _result = self.send_raw(pong);
457        self.drop_without_shutdown();
458        _result
459    }
460
461    fn send_raw(&self, mut pong: u64) -> Result<(), fidl::Error> {
462        self.control_handle.inner.send::<CrasherPingResponse>(
463            (pong,),
464            self.tx_id,
465            0x63e0c4d973e4b1f9,
466            fidl::encoding::DynamicFlags::empty(),
467        )
468    }
469}
470
471#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
472pub struct DeviceMarker;
473
474#[cfg(target_os = "fuchsia")]
475impl fidl::endpoints::ServiceMarker for DeviceMarker {
476    type Proxy = DeviceProxy;
477    type Request = DeviceRequest;
478    const SERVICE_NAME: &'static str = "fuchsia.crashdriver.test.Device";
479}
480
481/// A request for one of the member protocols of Device.
482///
483#[cfg(target_os = "fuchsia")]
484pub enum DeviceRequest {
485    Crasher(CrasherRequestStream),
486}
487
488#[cfg(target_os = "fuchsia")]
489impl fidl::endpoints::ServiceRequest for DeviceRequest {
490    type Service = DeviceMarker;
491
492    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
493        match name {
494            "crasher" => Self::Crasher(
495                <CrasherRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
496            ),
497            _ => panic!("no such member protocol name for service Device"),
498        }
499    }
500
501    fn member_names() -> &'static [&'static str] {
502        &["crasher"]
503    }
504}
505#[cfg(target_os = "fuchsia")]
506pub struct DeviceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
507
508#[cfg(target_os = "fuchsia")]
509impl fidl::endpoints::ServiceProxy for DeviceProxy {
510    type Service = DeviceMarker;
511
512    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
513        Self(opener)
514    }
515}
516
517#[cfg(target_os = "fuchsia")]
518impl DeviceProxy {
519    pub fn connect_to_crasher(&self) -> Result<CrasherProxy, fidl::Error> {
520        let (proxy, server_end) = fidl::endpoints::create_proxy::<CrasherMarker>();
521        self.connect_channel_to_crasher(server_end)?;
522        Ok(proxy)
523    }
524
525    /// Like `connect_to_crasher`, but returns a sync proxy.
526    /// See [`Self::connect_to_crasher`] for more details.
527    pub fn connect_to_crasher_sync(&self) -> Result<CrasherSynchronousProxy, fidl::Error> {
528        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<CrasherMarker>();
529        self.connect_channel_to_crasher(server_end)?;
530        Ok(proxy)
531    }
532
533    /// Like `connect_to_crasher`, but accepts a server end.
534    /// See [`Self::connect_to_crasher`] for more details.
535    pub fn connect_channel_to_crasher(
536        &self,
537        server_end: fidl::endpoints::ServerEnd<CrasherMarker>,
538    ) -> Result<(), fidl::Error> {
539        self.0.open_member("crasher", server_end.into_channel())
540    }
541
542    pub fn instance_name(&self) -> &str {
543        self.0.instance_name()
544    }
545}
546
547mod internal {
548    use super::*;
549}