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::Handle {
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    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
359        self.inner.shutdown_with_epitaph(status)
360    }
361
362    fn is_closed(&self) -> bool {
363        self.inner.channel().is_closed()
364    }
365    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
366        self.inner.channel().on_closed()
367    }
368
369    #[cfg(target_os = "fuchsia")]
370    fn signal_peer(
371        &self,
372        clear_mask: zx::Signals,
373        set_mask: zx::Signals,
374    ) -> Result<(), zx_status::Status> {
375        use fidl::Peered;
376        self.inner.channel().signal_peer(clear_mask, set_mask)
377    }
378}
379
380impl ThreadKoidReporterControlHandle {}
381
382mod internal {
383    use super::*;
384
385    impl fidl::encoding::ResourceTypeMarker for ThreadKoidReporterReportMyThreadKoidRequest {
386        type Borrowed<'a> = &'a mut Self;
387        fn take_or_borrow<'a>(
388            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
389        ) -> Self::Borrowed<'a> {
390            value
391        }
392    }
393
394    unsafe impl fidl::encoding::TypeMarker for ThreadKoidReporterReportMyThreadKoidRequest {
395        type Owned = Self;
396
397        #[inline(always)]
398        fn inline_align(_context: fidl::encoding::Context) -> usize {
399            8
400        }
401
402        #[inline(always)]
403        fn inline_size(_context: fidl::encoding::Context) -> usize {
404            8
405        }
406        #[inline(always)]
407        fn encode_is_copy() -> bool {
408            true
409        }
410
411        #[inline(always)]
412        fn decode_is_copy() -> bool {
413            true
414        }
415    }
416
417    unsafe impl
418        fidl::encoding::Encode<
419            ThreadKoidReporterReportMyThreadKoidRequest,
420            fidl::encoding::DefaultFuchsiaResourceDialect,
421        > for &mut ThreadKoidReporterReportMyThreadKoidRequest
422    {
423        #[inline]
424        unsafe fn encode(
425            self,
426            encoder: &mut fidl::encoding::Encoder<
427                '_,
428                fidl::encoding::DefaultFuchsiaResourceDialect,
429            >,
430            offset: usize,
431            _depth: fidl::encoding::Depth,
432        ) -> fidl::Result<()> {
433            encoder.debug_check_bounds::<ThreadKoidReporterReportMyThreadKoidRequest>(offset);
434            unsafe {
435                // Copy the object into the buffer.
436                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
437                (buf_ptr as *mut ThreadKoidReporterReportMyThreadKoidRequest).write_unaligned(
438                    (self as *const ThreadKoidReporterReportMyThreadKoidRequest).read(),
439                );
440                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
441                // done second because the memcpy will write garbage to these bytes.
442            }
443            Ok(())
444        }
445    }
446    unsafe impl<T0: fidl::encoding::Encode<u64, fidl::encoding::DefaultFuchsiaResourceDialect>>
447        fidl::encoding::Encode<
448            ThreadKoidReporterReportMyThreadKoidRequest,
449            fidl::encoding::DefaultFuchsiaResourceDialect,
450        > for (T0,)
451    {
452        #[inline]
453        unsafe fn encode(
454            self,
455            encoder: &mut fidl::encoding::Encoder<
456                '_,
457                fidl::encoding::DefaultFuchsiaResourceDialect,
458            >,
459            offset: usize,
460            depth: fidl::encoding::Depth,
461        ) -> fidl::Result<()> {
462            encoder.debug_check_bounds::<ThreadKoidReporterReportMyThreadKoidRequest>(offset);
463            // Zero out padding regions. There's no need to apply masks
464            // because the unmasked parts will be overwritten by fields.
465            // Write the fields.
466            self.0.encode(encoder, offset + 0, depth)?;
467            Ok(())
468        }
469    }
470
471    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
472        for ThreadKoidReporterReportMyThreadKoidRequest
473    {
474        #[inline(always)]
475        fn new_empty() -> Self {
476            Self {
477                thread_koid: fidl::new_empty!(u64, fidl::encoding::DefaultFuchsiaResourceDialect),
478            }
479        }
480
481        #[inline]
482        unsafe fn decode(
483            &mut self,
484            decoder: &mut fidl::encoding::Decoder<
485                '_,
486                fidl::encoding::DefaultFuchsiaResourceDialect,
487            >,
488            offset: usize,
489            _depth: fidl::encoding::Depth,
490        ) -> fidl::Result<()> {
491            decoder.debug_check_bounds::<Self>(offset);
492            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
493            // Verify that padding bytes are zero.
494            // Copy from the buffer into the object.
495            unsafe {
496                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
497            }
498            Ok(())
499        }
500    }
501}