fidl_fuchsia_test/
fidl_fuchsia_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_test__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15#[repr(C)]
16pub struct ThreadKoidReporterReportMyThreadKoidRequest {
17    pub thread_koid: u64,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for ThreadKoidReporterReportMyThreadKoidRequest
22{
23}
24
25#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
26pub struct ThreadKoidReporterMarker;
27
28impl fidl::endpoints::ProtocolMarker for ThreadKoidReporterMarker {
29    type Proxy = ThreadKoidReporterProxy;
30    type RequestStream = ThreadKoidReporterRequestStream;
31    #[cfg(target_os = "fuchsia")]
32    type SynchronousProxy = ThreadKoidReporterSynchronousProxy;
33
34    const DEBUG_NAME: &'static str = "fuchsia.test.ThreadKoidReporter";
35}
36impl fidl::endpoints::DiscoverableProtocolMarker for ThreadKoidReporterMarker {}
37
38pub trait ThreadKoidReporterProxyInterface: Send + Sync {
39    fn r#report_my_thread_koid(&self, thread_koid: u64) -> Result<(), fidl::Error>;
40}
41#[derive(Debug)]
42#[cfg(target_os = "fuchsia")]
43pub struct ThreadKoidReporterSynchronousProxy {
44    client: fidl::client::sync::Client,
45}
46
47#[cfg(target_os = "fuchsia")]
48impl fidl::endpoints::SynchronousProxy for ThreadKoidReporterSynchronousProxy {
49    type Proxy = ThreadKoidReporterProxy;
50    type Protocol = ThreadKoidReporterMarker;
51
52    fn from_channel(inner: fidl::Channel) -> Self {
53        Self::new(inner)
54    }
55
56    fn into_channel(self) -> fidl::Channel {
57        self.client.into_channel()
58    }
59
60    fn as_channel(&self) -> &fidl::Channel {
61        self.client.as_channel()
62    }
63}
64
65#[cfg(target_os = "fuchsia")]
66impl ThreadKoidReporterSynchronousProxy {
67    pub fn new(channel: fidl::Channel) -> Self {
68        let protocol_name =
69            <ThreadKoidReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
70        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
71    }
72
73    pub fn into_channel(self) -> fidl::Channel {
74        self.client.into_channel()
75    }
76
77    /// Waits until an event arrives and returns it. It is safe for other
78    /// threads to make concurrent requests while waiting for an event.
79    pub fn wait_for_event(
80        &self,
81        deadline: zx::MonotonicInstant,
82    ) -> Result<ThreadKoidReporterEvent, fidl::Error> {
83        ThreadKoidReporterEvent::decode(self.client.wait_for_event(deadline)?)
84    }
85
86    /// Reports the koid for this component's thread
87    pub fn r#report_my_thread_koid(&self, mut thread_koid: u64) -> Result<(), fidl::Error> {
88        self.client.send::<ThreadKoidReporterReportMyThreadKoidRequest>(
89            (thread_koid,),
90            0x58cb9144fdb465d0,
91            fidl::encoding::DynamicFlags::empty(),
92        )
93    }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl From<ThreadKoidReporterSynchronousProxy> for zx::NullableHandle {
98    fn from(value: ThreadKoidReporterSynchronousProxy) -> Self {
99        value.into_channel().into()
100    }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<fidl::Channel> for ThreadKoidReporterSynchronousProxy {
105    fn from(value: fidl::Channel) -> Self {
106        Self::new(value)
107    }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl fidl::endpoints::FromClient for ThreadKoidReporterSynchronousProxy {
112    type Protocol = ThreadKoidReporterMarker;
113
114    fn from_client(value: fidl::endpoints::ClientEnd<ThreadKoidReporterMarker>) -> Self {
115        Self::new(value.into_channel())
116    }
117}
118
119#[derive(Debug, Clone)]
120pub struct ThreadKoidReporterProxy {
121    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
122}
123
124impl fidl::endpoints::Proxy for ThreadKoidReporterProxy {
125    type Protocol = ThreadKoidReporterMarker;
126
127    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
128        Self::new(inner)
129    }
130
131    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
132        self.client.into_channel().map_err(|client| Self { client })
133    }
134
135    fn as_channel(&self) -> &::fidl::AsyncChannel {
136        self.client.as_channel()
137    }
138}
139
140impl ThreadKoidReporterProxy {
141    /// Create a new Proxy for fuchsia.test/ThreadKoidReporter.
142    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
143        let protocol_name =
144            <ThreadKoidReporterMarker 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) -> ThreadKoidReporterEventStream {
154        ThreadKoidReporterEventStream { event_receiver: self.client.take_event_receiver() }
155    }
156
157    /// Reports the koid for this component's thread
158    pub fn r#report_my_thread_koid(&self, mut thread_koid: u64) -> Result<(), fidl::Error> {
159        ThreadKoidReporterProxyInterface::r#report_my_thread_koid(self, thread_koid)
160    }
161}
162
163impl ThreadKoidReporterProxyInterface for ThreadKoidReporterProxy {
164    fn r#report_my_thread_koid(&self, mut thread_koid: u64) -> Result<(), fidl::Error> {
165        self.client.send::<ThreadKoidReporterReportMyThreadKoidRequest>(
166            (thread_koid,),
167            0x58cb9144fdb465d0,
168            fidl::encoding::DynamicFlags::empty(),
169        )
170    }
171}
172
173pub struct ThreadKoidReporterEventStream {
174    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
175}
176
177impl std::marker::Unpin for ThreadKoidReporterEventStream {}
178
179impl futures::stream::FusedStream for ThreadKoidReporterEventStream {
180    fn is_terminated(&self) -> bool {
181        self.event_receiver.is_terminated()
182    }
183}
184
185impl futures::Stream for ThreadKoidReporterEventStream {
186    type Item = Result<ThreadKoidReporterEvent, fidl::Error>;
187
188    fn poll_next(
189        mut self: std::pin::Pin<&mut Self>,
190        cx: &mut std::task::Context<'_>,
191    ) -> std::task::Poll<Option<Self::Item>> {
192        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
193            &mut self.event_receiver,
194            cx
195        )?) {
196            Some(buf) => std::task::Poll::Ready(Some(ThreadKoidReporterEvent::decode(buf))),
197            None => std::task::Poll::Ready(None),
198        }
199    }
200}
201
202#[derive(Debug)]
203pub enum ThreadKoidReporterEvent {}
204
205impl ThreadKoidReporterEvent {
206    /// Decodes a message buffer as a [`ThreadKoidReporterEvent`].
207    fn decode(
208        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
209    ) -> Result<ThreadKoidReporterEvent, fidl::Error> {
210        let (bytes, _handles) = buf.split_mut();
211        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
212        debug_assert_eq!(tx_header.tx_id, 0);
213        match tx_header.ordinal {
214            _ => Err(fidl::Error::UnknownOrdinal {
215                ordinal: tx_header.ordinal,
216                protocol_name:
217                    <ThreadKoidReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
218            }),
219        }
220    }
221}
222
223/// A Stream of incoming requests for fuchsia.test/ThreadKoidReporter.
224pub struct ThreadKoidReporterRequestStream {
225    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
226    is_terminated: bool,
227}
228
229impl std::marker::Unpin for ThreadKoidReporterRequestStream {}
230
231impl futures::stream::FusedStream for ThreadKoidReporterRequestStream {
232    fn is_terminated(&self) -> bool {
233        self.is_terminated
234    }
235}
236
237impl fidl::endpoints::RequestStream for ThreadKoidReporterRequestStream {
238    type Protocol = ThreadKoidReporterMarker;
239    type ControlHandle = ThreadKoidReporterControlHandle;
240
241    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
242        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
243    }
244
245    fn control_handle(&self) -> Self::ControlHandle {
246        ThreadKoidReporterControlHandle { inner: self.inner.clone() }
247    }
248
249    fn into_inner(
250        self,
251    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
252    {
253        (self.inner, self.is_terminated)
254    }
255
256    fn from_inner(
257        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
258        is_terminated: bool,
259    ) -> Self {
260        Self { inner, is_terminated }
261    }
262}
263
264impl futures::Stream for ThreadKoidReporterRequestStream {
265    type Item = Result<ThreadKoidReporterRequest, fidl::Error>;
266
267    fn poll_next(
268        mut self: std::pin::Pin<&mut Self>,
269        cx: &mut std::task::Context<'_>,
270    ) -> std::task::Poll<Option<Self::Item>> {
271        let this = &mut *self;
272        if this.inner.check_shutdown(cx) {
273            this.is_terminated = true;
274            return std::task::Poll::Ready(None);
275        }
276        if this.is_terminated {
277            panic!("polled ThreadKoidReporterRequestStream after completion");
278        }
279        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
280            |bytes, handles| {
281                match this.inner.channel().read_etc(cx, bytes, handles) {
282                    std::task::Poll::Ready(Ok(())) => {}
283                    std::task::Poll::Pending => return std::task::Poll::Pending,
284                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
285                        this.is_terminated = true;
286                        return std::task::Poll::Ready(None);
287                    }
288                    std::task::Poll::Ready(Err(e)) => {
289                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
290                            e.into(),
291                        ))));
292                    }
293                }
294
295                // A message has been received from the channel
296                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
297
298                std::task::Poll::Ready(Some(match header.ordinal {
299                0x58cb9144fdb465d0 => {
300                    header.validate_request_tx_id(fidl::MethodType::OneWay)?;
301                    let mut req = fidl::new_empty!(ThreadKoidReporterReportMyThreadKoidRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
302                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ThreadKoidReporterReportMyThreadKoidRequest>(&header, _body_bytes, handles, &mut req)?;
303                    let control_handle = ThreadKoidReporterControlHandle {
304                        inner: this.inner.clone(),
305                    };
306                    Ok(ThreadKoidReporterRequest::ReportMyThreadKoid {thread_koid: req.thread_koid,
307
308                        control_handle,
309                    })
310                }
311                _ => Err(fidl::Error::UnknownOrdinal {
312                    ordinal: header.ordinal,
313                    protocol_name: <ThreadKoidReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
314                }),
315            }))
316            },
317        )
318    }
319}
320
321/// Used by report_then_panic_on_start to report its thread koid before
322/// crashing, so that anyone using fuchsia.sys2.CrashIntrospect will know what
323/// thread koid to look for
324#[derive(Debug)]
325pub enum ThreadKoidReporterRequest {
326    /// Reports the koid for this component's thread
327    ReportMyThreadKoid { thread_koid: u64, control_handle: ThreadKoidReporterControlHandle },
328}
329
330impl ThreadKoidReporterRequest {
331    #[allow(irrefutable_let_patterns)]
332    pub fn into_report_my_thread_koid(self) -> Option<(u64, ThreadKoidReporterControlHandle)> {
333        if let ThreadKoidReporterRequest::ReportMyThreadKoid { thread_koid, control_handle } = self
334        {
335            Some((thread_koid, control_handle))
336        } else {
337            None
338        }
339    }
340
341    /// Name of the method defined in FIDL
342    pub fn method_name(&self) -> &'static str {
343        match *self {
344            ThreadKoidReporterRequest::ReportMyThreadKoid { .. } => "report_my_thread_koid",
345        }
346    }
347}
348
349#[derive(Debug, Clone)]
350pub struct ThreadKoidReporterControlHandle {
351    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
352}
353
354impl fidl::endpoints::ControlHandle for ThreadKoidReporterControlHandle {
355    fn shutdown(&self) {
356        self.inner.shutdown()
357    }
358
359    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
360        self.inner.shutdown_with_epitaph(status)
361    }
362
363    fn is_closed(&self) -> bool {
364        self.inner.channel().is_closed()
365    }
366    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
367        self.inner.channel().on_closed()
368    }
369
370    #[cfg(target_os = "fuchsia")]
371    fn signal_peer(
372        &self,
373        clear_mask: zx::Signals,
374        set_mask: zx::Signals,
375    ) -> Result<(), zx_status::Status> {
376        use fidl::Peered;
377        self.inner.channel().signal_peer(clear_mask, set_mask)
378    }
379}
380
381impl ThreadKoidReporterControlHandle {}
382
383mod internal {
384    use super::*;
385
386    impl fidl::encoding::ResourceTypeMarker for ThreadKoidReporterReportMyThreadKoidRequest {
387        type Borrowed<'a> = &'a mut Self;
388        fn take_or_borrow<'a>(
389            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
390        ) -> Self::Borrowed<'a> {
391            value
392        }
393    }
394
395    unsafe impl fidl::encoding::TypeMarker for ThreadKoidReporterReportMyThreadKoidRequest {
396        type Owned = Self;
397
398        #[inline(always)]
399        fn inline_align(_context: fidl::encoding::Context) -> usize {
400            8
401        }
402
403        #[inline(always)]
404        fn inline_size(_context: fidl::encoding::Context) -> usize {
405            8
406        }
407        #[inline(always)]
408        fn encode_is_copy() -> bool {
409            true
410        }
411
412        #[inline(always)]
413        fn decode_is_copy() -> bool {
414            true
415        }
416    }
417
418    unsafe impl
419        fidl::encoding::Encode<
420            ThreadKoidReporterReportMyThreadKoidRequest,
421            fidl::encoding::DefaultFuchsiaResourceDialect,
422        > for &mut ThreadKoidReporterReportMyThreadKoidRequest
423    {
424        #[inline]
425        unsafe fn encode(
426            self,
427            encoder: &mut fidl::encoding::Encoder<
428                '_,
429                fidl::encoding::DefaultFuchsiaResourceDialect,
430            >,
431            offset: usize,
432            _depth: fidl::encoding::Depth,
433        ) -> fidl::Result<()> {
434            encoder.debug_check_bounds::<ThreadKoidReporterReportMyThreadKoidRequest>(offset);
435            unsafe {
436                // Copy the object into the buffer.
437                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
438                (buf_ptr as *mut ThreadKoidReporterReportMyThreadKoidRequest).write_unaligned(
439                    (self as *const ThreadKoidReporterReportMyThreadKoidRequest).read(),
440                );
441                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
442                // done second because the memcpy will write garbage to these bytes.
443            }
444            Ok(())
445        }
446    }
447    unsafe impl<T0: fidl::encoding::Encode<u64, fidl::encoding::DefaultFuchsiaResourceDialect>>
448        fidl::encoding::Encode<
449            ThreadKoidReporterReportMyThreadKoidRequest,
450            fidl::encoding::DefaultFuchsiaResourceDialect,
451        > for (T0,)
452    {
453        #[inline]
454        unsafe fn encode(
455            self,
456            encoder: &mut fidl::encoding::Encoder<
457                '_,
458                fidl::encoding::DefaultFuchsiaResourceDialect,
459            >,
460            offset: usize,
461            depth: fidl::encoding::Depth,
462        ) -> fidl::Result<()> {
463            encoder.debug_check_bounds::<ThreadKoidReporterReportMyThreadKoidRequest>(offset);
464            // Zero out padding regions. There's no need to apply masks
465            // because the unmasked parts will be overwritten by fields.
466            // Write the fields.
467            self.0.encode(encoder, offset + 0, depth)?;
468            Ok(())
469        }
470    }
471
472    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
473        for ThreadKoidReporterReportMyThreadKoidRequest
474    {
475        #[inline(always)]
476        fn new_empty() -> Self {
477            Self {
478                thread_koid: fidl::new_empty!(u64, fidl::encoding::DefaultFuchsiaResourceDialect),
479            }
480        }
481
482        #[inline]
483        unsafe fn decode(
484            &mut self,
485            decoder: &mut fidl::encoding::Decoder<
486                '_,
487                fidl::encoding::DefaultFuchsiaResourceDialect,
488            >,
489            offset: usize,
490            _depth: fidl::encoding::Depth,
491        ) -> fidl::Result<()> {
492            decoder.debug_check_bounds::<Self>(offset);
493            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
494            // Verify that padding bytes are zero.
495            // Copy from the buffer into the object.
496            unsafe {
497                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
498            }
499            Ok(())
500        }
501    }
502}