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#[derive(Debug, Clone)]
97pub struct ThreadKoidReporterProxy {
98    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
99}
100
101impl fidl::endpoints::Proxy for ThreadKoidReporterProxy {
102    type Protocol = ThreadKoidReporterMarker;
103
104    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
105        Self::new(inner)
106    }
107
108    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
109        self.client.into_channel().map_err(|client| Self { client })
110    }
111
112    fn as_channel(&self) -> &::fidl::AsyncChannel {
113        self.client.as_channel()
114    }
115}
116
117impl ThreadKoidReporterProxy {
118    /// Create a new Proxy for fuchsia.test/ThreadKoidReporter.
119    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
120        let protocol_name =
121            <ThreadKoidReporterMarker 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) -> ThreadKoidReporterEventStream {
131        ThreadKoidReporterEventStream { event_receiver: self.client.take_event_receiver() }
132    }
133
134    /// Reports the koid for this component's thread
135    pub fn r#report_my_thread_koid(&self, mut thread_koid: u64) -> Result<(), fidl::Error> {
136        ThreadKoidReporterProxyInterface::r#report_my_thread_koid(self, thread_koid)
137    }
138}
139
140impl ThreadKoidReporterProxyInterface for ThreadKoidReporterProxy {
141    fn r#report_my_thread_koid(&self, mut thread_koid: u64) -> Result<(), fidl::Error> {
142        self.client.send::<ThreadKoidReporterReportMyThreadKoidRequest>(
143            (thread_koid,),
144            0x58cb9144fdb465d0,
145            fidl::encoding::DynamicFlags::empty(),
146        )
147    }
148}
149
150pub struct ThreadKoidReporterEventStream {
151    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
152}
153
154impl std::marker::Unpin for ThreadKoidReporterEventStream {}
155
156impl futures::stream::FusedStream for ThreadKoidReporterEventStream {
157    fn is_terminated(&self) -> bool {
158        self.event_receiver.is_terminated()
159    }
160}
161
162impl futures::Stream for ThreadKoidReporterEventStream {
163    type Item = Result<ThreadKoidReporterEvent, fidl::Error>;
164
165    fn poll_next(
166        mut self: std::pin::Pin<&mut Self>,
167        cx: &mut std::task::Context<'_>,
168    ) -> std::task::Poll<Option<Self::Item>> {
169        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
170            &mut self.event_receiver,
171            cx
172        )?) {
173            Some(buf) => std::task::Poll::Ready(Some(ThreadKoidReporterEvent::decode(buf))),
174            None => std::task::Poll::Ready(None),
175        }
176    }
177}
178
179#[derive(Debug)]
180pub enum ThreadKoidReporterEvent {}
181
182impl ThreadKoidReporterEvent {
183    /// Decodes a message buffer as a [`ThreadKoidReporterEvent`].
184    fn decode(
185        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
186    ) -> Result<ThreadKoidReporterEvent, fidl::Error> {
187        let (bytes, _handles) = buf.split_mut();
188        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
189        debug_assert_eq!(tx_header.tx_id, 0);
190        match tx_header.ordinal {
191            _ => Err(fidl::Error::UnknownOrdinal {
192                ordinal: tx_header.ordinal,
193                protocol_name:
194                    <ThreadKoidReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
195            }),
196        }
197    }
198}
199
200/// A Stream of incoming requests for fuchsia.test/ThreadKoidReporter.
201pub struct ThreadKoidReporterRequestStream {
202    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
203    is_terminated: bool,
204}
205
206impl std::marker::Unpin for ThreadKoidReporterRequestStream {}
207
208impl futures::stream::FusedStream for ThreadKoidReporterRequestStream {
209    fn is_terminated(&self) -> bool {
210        self.is_terminated
211    }
212}
213
214impl fidl::endpoints::RequestStream for ThreadKoidReporterRequestStream {
215    type Protocol = ThreadKoidReporterMarker;
216    type ControlHandle = ThreadKoidReporterControlHandle;
217
218    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
219        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
220    }
221
222    fn control_handle(&self) -> Self::ControlHandle {
223        ThreadKoidReporterControlHandle { inner: self.inner.clone() }
224    }
225
226    fn into_inner(
227        self,
228    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
229    {
230        (self.inner, self.is_terminated)
231    }
232
233    fn from_inner(
234        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
235        is_terminated: bool,
236    ) -> Self {
237        Self { inner, is_terminated }
238    }
239}
240
241impl futures::Stream for ThreadKoidReporterRequestStream {
242    type Item = Result<ThreadKoidReporterRequest, fidl::Error>;
243
244    fn poll_next(
245        mut self: std::pin::Pin<&mut Self>,
246        cx: &mut std::task::Context<'_>,
247    ) -> std::task::Poll<Option<Self::Item>> {
248        let this = &mut *self;
249        if this.inner.check_shutdown(cx) {
250            this.is_terminated = true;
251            return std::task::Poll::Ready(None);
252        }
253        if this.is_terminated {
254            panic!("polled ThreadKoidReporterRequestStream after completion");
255        }
256        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
257            |bytes, handles| {
258                match this.inner.channel().read_etc(cx, bytes, handles) {
259                    std::task::Poll::Ready(Ok(())) => {}
260                    std::task::Poll::Pending => return std::task::Poll::Pending,
261                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
262                        this.is_terminated = true;
263                        return std::task::Poll::Ready(None);
264                    }
265                    std::task::Poll::Ready(Err(e)) => {
266                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
267                            e.into(),
268                        ))))
269                    }
270                }
271
272                // A message has been received from the channel
273                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
274
275                std::task::Poll::Ready(Some(match header.ordinal {
276                0x58cb9144fdb465d0 => {
277                    header.validate_request_tx_id(fidl::MethodType::OneWay)?;
278                    let mut req = fidl::new_empty!(ThreadKoidReporterReportMyThreadKoidRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
279                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ThreadKoidReporterReportMyThreadKoidRequest>(&header, _body_bytes, handles, &mut req)?;
280                    let control_handle = ThreadKoidReporterControlHandle {
281                        inner: this.inner.clone(),
282                    };
283                    Ok(ThreadKoidReporterRequest::ReportMyThreadKoid {thread_koid: req.thread_koid,
284
285                        control_handle,
286                    })
287                }
288                _ => Err(fidl::Error::UnknownOrdinal {
289                    ordinal: header.ordinal,
290                    protocol_name: <ThreadKoidReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
291                }),
292            }))
293            },
294        )
295    }
296}
297
298/// Used by report_then_panic_on_start to report its thread koid before
299/// crashing, so that anyone using fuchsia.sys2.CrashIntrospect will know what
300/// thread koid to look for
301#[derive(Debug)]
302pub enum ThreadKoidReporterRequest {
303    /// Reports the koid for this component's thread
304    ReportMyThreadKoid { thread_koid: u64, control_handle: ThreadKoidReporterControlHandle },
305}
306
307impl ThreadKoidReporterRequest {
308    #[allow(irrefutable_let_patterns)]
309    pub fn into_report_my_thread_koid(self) -> Option<(u64, ThreadKoidReporterControlHandle)> {
310        if let ThreadKoidReporterRequest::ReportMyThreadKoid { thread_koid, control_handle } = self
311        {
312            Some((thread_koid, control_handle))
313        } else {
314            None
315        }
316    }
317
318    /// Name of the method defined in FIDL
319    pub fn method_name(&self) -> &'static str {
320        match *self {
321            ThreadKoidReporterRequest::ReportMyThreadKoid { .. } => "report_my_thread_koid",
322        }
323    }
324}
325
326#[derive(Debug, Clone)]
327pub struct ThreadKoidReporterControlHandle {
328    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
329}
330
331impl fidl::endpoints::ControlHandle for ThreadKoidReporterControlHandle {
332    fn shutdown(&self) {
333        self.inner.shutdown()
334    }
335    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
336        self.inner.shutdown_with_epitaph(status)
337    }
338
339    fn is_closed(&self) -> bool {
340        self.inner.channel().is_closed()
341    }
342    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
343        self.inner.channel().on_closed()
344    }
345
346    #[cfg(target_os = "fuchsia")]
347    fn signal_peer(
348        &self,
349        clear_mask: zx::Signals,
350        set_mask: zx::Signals,
351    ) -> Result<(), zx_status::Status> {
352        use fidl::Peered;
353        self.inner.channel().signal_peer(clear_mask, set_mask)
354    }
355}
356
357impl ThreadKoidReporterControlHandle {}
358
359mod internal {
360    use super::*;
361
362    impl fidl::encoding::ResourceTypeMarker for ThreadKoidReporterReportMyThreadKoidRequest {
363        type Borrowed<'a> = &'a mut Self;
364        fn take_or_borrow<'a>(
365            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
366        ) -> Self::Borrowed<'a> {
367            value
368        }
369    }
370
371    unsafe impl fidl::encoding::TypeMarker for ThreadKoidReporterReportMyThreadKoidRequest {
372        type Owned = Self;
373
374        #[inline(always)]
375        fn inline_align(_context: fidl::encoding::Context) -> usize {
376            8
377        }
378
379        #[inline(always)]
380        fn inline_size(_context: fidl::encoding::Context) -> usize {
381            8
382        }
383        #[inline(always)]
384        fn encode_is_copy() -> bool {
385            true
386        }
387
388        #[inline(always)]
389        fn decode_is_copy() -> bool {
390            true
391        }
392    }
393
394    unsafe impl
395        fidl::encoding::Encode<
396            ThreadKoidReporterReportMyThreadKoidRequest,
397            fidl::encoding::DefaultFuchsiaResourceDialect,
398        > for &mut ThreadKoidReporterReportMyThreadKoidRequest
399    {
400        #[inline]
401        unsafe fn encode(
402            self,
403            encoder: &mut fidl::encoding::Encoder<
404                '_,
405                fidl::encoding::DefaultFuchsiaResourceDialect,
406            >,
407            offset: usize,
408            _depth: fidl::encoding::Depth,
409        ) -> fidl::Result<()> {
410            encoder.debug_check_bounds::<ThreadKoidReporterReportMyThreadKoidRequest>(offset);
411            unsafe {
412                // Copy the object into the buffer.
413                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
414                (buf_ptr as *mut ThreadKoidReporterReportMyThreadKoidRequest).write_unaligned(
415                    (self as *const ThreadKoidReporterReportMyThreadKoidRequest).read(),
416                );
417                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
418                // done second because the memcpy will write garbage to these bytes.
419            }
420            Ok(())
421        }
422    }
423    unsafe impl<T0: fidl::encoding::Encode<u64, fidl::encoding::DefaultFuchsiaResourceDialect>>
424        fidl::encoding::Encode<
425            ThreadKoidReporterReportMyThreadKoidRequest,
426            fidl::encoding::DefaultFuchsiaResourceDialect,
427        > for (T0,)
428    {
429        #[inline]
430        unsafe fn encode(
431            self,
432            encoder: &mut fidl::encoding::Encoder<
433                '_,
434                fidl::encoding::DefaultFuchsiaResourceDialect,
435            >,
436            offset: usize,
437            depth: fidl::encoding::Depth,
438        ) -> fidl::Result<()> {
439            encoder.debug_check_bounds::<ThreadKoidReporterReportMyThreadKoidRequest>(offset);
440            // Zero out padding regions. There's no need to apply masks
441            // because the unmasked parts will be overwritten by fields.
442            // Write the fields.
443            self.0.encode(encoder, offset + 0, depth)?;
444            Ok(())
445        }
446    }
447
448    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
449        for ThreadKoidReporterReportMyThreadKoidRequest
450    {
451        #[inline(always)]
452        fn new_empty() -> Self {
453            Self {
454                thread_koid: fidl::new_empty!(u64, fidl::encoding::DefaultFuchsiaResourceDialect),
455            }
456        }
457
458        #[inline]
459        unsafe fn decode(
460            &mut self,
461            decoder: &mut fidl::encoding::Decoder<
462                '_,
463                fidl::encoding::DefaultFuchsiaResourceDialect,
464            >,
465            offset: usize,
466            _depth: fidl::encoding::Depth,
467        ) -> fidl::Result<()> {
468            decoder.debug_check_bounds::<Self>(offset);
469            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
470            // Verify that padding bytes are zero.
471            // Copy from the buffer into the object.
472            unsafe {
473                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
474            }
475            Ok(())
476        }
477    }
478}