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