fidl_fuchsia_starnix_gralloc/
fidl_fuchsia_starnix_gralloc.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_starnix_gralloc__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct VulkanModeSetterMarker;
16
17impl fidl::endpoints::ProtocolMarker for VulkanModeSetterMarker {
18    type Proxy = VulkanModeSetterProxy;
19    type RequestStream = VulkanModeSetterRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = VulkanModeSetterSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.starnix.gralloc.VulkanModeSetter";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for VulkanModeSetterMarker {}
26pub type VulkanModeSetterSetVulkanModeResult = Result<(), VulkanModeSetterError>;
27
28pub trait VulkanModeSetterProxyInterface: Send + Sync {
29    type SetVulkanModeResponseFut: std::future::Future<Output = Result<VulkanModeSetterSetVulkanModeResult, fidl::Error>>
30        + Send;
31    fn r#set_vulkan_mode(
32        &self,
33        payload: &VulkanModeSetterSetVulkanModeRequest,
34    ) -> Self::SetVulkanModeResponseFut;
35}
36#[derive(Debug)]
37#[cfg(target_os = "fuchsia")]
38pub struct VulkanModeSetterSynchronousProxy {
39    client: fidl::client::sync::Client,
40}
41
42#[cfg(target_os = "fuchsia")]
43impl fidl::endpoints::SynchronousProxy for VulkanModeSetterSynchronousProxy {
44    type Proxy = VulkanModeSetterProxy;
45    type Protocol = VulkanModeSetterMarker;
46
47    fn from_channel(inner: fidl::Channel) -> Self {
48        Self::new(inner)
49    }
50
51    fn into_channel(self) -> fidl::Channel {
52        self.client.into_channel()
53    }
54
55    fn as_channel(&self) -> &fidl::Channel {
56        self.client.as_channel()
57    }
58}
59
60#[cfg(target_os = "fuchsia")]
61impl VulkanModeSetterSynchronousProxy {
62    pub fn new(channel: fidl::Channel) -> Self {
63        let protocol_name = <VulkanModeSetterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
64        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
65    }
66
67    pub fn into_channel(self) -> fidl::Channel {
68        self.client.into_channel()
69    }
70
71    /// Waits until an event arrives and returns it. It is safe for other
72    /// threads to make concurrent requests while waiting for an event.
73    pub fn wait_for_event(
74        &self,
75        deadline: zx::MonotonicInstant,
76    ) -> Result<VulkanModeSetterEvent, fidl::Error> {
77        VulkanModeSetterEvent::decode(self.client.wait_for_event(deadline)?)
78    }
79
80    /// Inform gralloc of the vulkan mode. In normal operation this is called
81    /// once per container lifetime.
82    pub fn r#set_vulkan_mode(
83        &self,
84        mut payload: &VulkanModeSetterSetVulkanModeRequest,
85        ___deadline: zx::MonotonicInstant,
86    ) -> Result<VulkanModeSetterSetVulkanModeResult, fidl::Error> {
87        let _response = self.client.send_query::<
88            VulkanModeSetterSetVulkanModeRequest,
89            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, VulkanModeSetterError>,
90        >(
91            payload,
92            0x71ffe16858e9e7eb,
93            fidl::encoding::DynamicFlags::empty(),
94            ___deadline,
95        )?;
96        Ok(_response.map(|x| x))
97    }
98}
99
100#[cfg(target_os = "fuchsia")]
101impl From<VulkanModeSetterSynchronousProxy> for zx::Handle {
102    fn from(value: VulkanModeSetterSynchronousProxy) -> Self {
103        value.into_channel().into()
104    }
105}
106
107#[cfg(target_os = "fuchsia")]
108impl From<fidl::Channel> for VulkanModeSetterSynchronousProxy {
109    fn from(value: fidl::Channel) -> Self {
110        Self::new(value)
111    }
112}
113
114#[cfg(target_os = "fuchsia")]
115impl fidl::endpoints::FromClient for VulkanModeSetterSynchronousProxy {
116    type Protocol = VulkanModeSetterMarker;
117
118    fn from_client(value: fidl::endpoints::ClientEnd<VulkanModeSetterMarker>) -> Self {
119        Self::new(value.into_channel())
120    }
121}
122
123#[derive(Debug, Clone)]
124pub struct VulkanModeSetterProxy {
125    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
126}
127
128impl fidl::endpoints::Proxy for VulkanModeSetterProxy {
129    type Protocol = VulkanModeSetterMarker;
130
131    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
132        Self::new(inner)
133    }
134
135    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
136        self.client.into_channel().map_err(|client| Self { client })
137    }
138
139    fn as_channel(&self) -> &::fidl::AsyncChannel {
140        self.client.as_channel()
141    }
142}
143
144impl VulkanModeSetterProxy {
145    /// Create a new Proxy for fuchsia.starnix.gralloc/VulkanModeSetter.
146    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
147        let protocol_name = <VulkanModeSetterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
148        Self { client: fidl::client::Client::new(channel, protocol_name) }
149    }
150
151    /// Get a Stream of events from the remote end of the protocol.
152    ///
153    /// # Panics
154    ///
155    /// Panics if the event stream was already taken.
156    pub fn take_event_stream(&self) -> VulkanModeSetterEventStream {
157        VulkanModeSetterEventStream { event_receiver: self.client.take_event_receiver() }
158    }
159
160    /// Inform gralloc of the vulkan mode. In normal operation this is called
161    /// once per container lifetime.
162    pub fn r#set_vulkan_mode(
163        &self,
164        mut payload: &VulkanModeSetterSetVulkanModeRequest,
165    ) -> fidl::client::QueryResponseFut<
166        VulkanModeSetterSetVulkanModeResult,
167        fidl::encoding::DefaultFuchsiaResourceDialect,
168    > {
169        VulkanModeSetterProxyInterface::r#set_vulkan_mode(self, payload)
170    }
171}
172
173impl VulkanModeSetterProxyInterface for VulkanModeSetterProxy {
174    type SetVulkanModeResponseFut = fidl::client::QueryResponseFut<
175        VulkanModeSetterSetVulkanModeResult,
176        fidl::encoding::DefaultFuchsiaResourceDialect,
177    >;
178    fn r#set_vulkan_mode(
179        &self,
180        mut payload: &VulkanModeSetterSetVulkanModeRequest,
181    ) -> Self::SetVulkanModeResponseFut {
182        fn _decode(
183            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
184        ) -> Result<VulkanModeSetterSetVulkanModeResult, fidl::Error> {
185            let _response = fidl::client::decode_transaction_body::<
186                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, VulkanModeSetterError>,
187                fidl::encoding::DefaultFuchsiaResourceDialect,
188                0x71ffe16858e9e7eb,
189            >(_buf?)?;
190            Ok(_response.map(|x| x))
191        }
192        self.client.send_query_and_decode::<
193            VulkanModeSetterSetVulkanModeRequest,
194            VulkanModeSetterSetVulkanModeResult,
195        >(
196            payload,
197            0x71ffe16858e9e7eb,
198            fidl::encoding::DynamicFlags::empty(),
199            _decode,
200        )
201    }
202}
203
204pub struct VulkanModeSetterEventStream {
205    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
206}
207
208impl std::marker::Unpin for VulkanModeSetterEventStream {}
209
210impl futures::stream::FusedStream for VulkanModeSetterEventStream {
211    fn is_terminated(&self) -> bool {
212        self.event_receiver.is_terminated()
213    }
214}
215
216impl futures::Stream for VulkanModeSetterEventStream {
217    type Item = Result<VulkanModeSetterEvent, fidl::Error>;
218
219    fn poll_next(
220        mut self: std::pin::Pin<&mut Self>,
221        cx: &mut std::task::Context<'_>,
222    ) -> std::task::Poll<Option<Self::Item>> {
223        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
224            &mut self.event_receiver,
225            cx
226        )?) {
227            Some(buf) => std::task::Poll::Ready(Some(VulkanModeSetterEvent::decode(buf))),
228            None => std::task::Poll::Ready(None),
229        }
230    }
231}
232
233#[derive(Debug)]
234pub enum VulkanModeSetterEvent {
235    #[non_exhaustive]
236    _UnknownEvent {
237        /// Ordinal of the event that was sent.
238        ordinal: u64,
239    },
240}
241
242impl VulkanModeSetterEvent {
243    /// Decodes a message buffer as a [`VulkanModeSetterEvent`].
244    fn decode(
245        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
246    ) -> Result<VulkanModeSetterEvent, fidl::Error> {
247        let (bytes, _handles) = buf.split_mut();
248        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
249        debug_assert_eq!(tx_header.tx_id, 0);
250        match tx_header.ordinal {
251            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
252                Ok(VulkanModeSetterEvent::_UnknownEvent { ordinal: tx_header.ordinal })
253            }
254            _ => Err(fidl::Error::UnknownOrdinal {
255                ordinal: tx_header.ordinal,
256                protocol_name:
257                    <VulkanModeSetterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
258            }),
259        }
260    }
261}
262
263/// A Stream of incoming requests for fuchsia.starnix.gralloc/VulkanModeSetter.
264pub struct VulkanModeSetterRequestStream {
265    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
266    is_terminated: bool,
267}
268
269impl std::marker::Unpin for VulkanModeSetterRequestStream {}
270
271impl futures::stream::FusedStream for VulkanModeSetterRequestStream {
272    fn is_terminated(&self) -> bool {
273        self.is_terminated
274    }
275}
276
277impl fidl::endpoints::RequestStream for VulkanModeSetterRequestStream {
278    type Protocol = VulkanModeSetterMarker;
279    type ControlHandle = VulkanModeSetterControlHandle;
280
281    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
282        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
283    }
284
285    fn control_handle(&self) -> Self::ControlHandle {
286        VulkanModeSetterControlHandle { inner: self.inner.clone() }
287    }
288
289    fn into_inner(
290        self,
291    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
292    {
293        (self.inner, self.is_terminated)
294    }
295
296    fn from_inner(
297        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
298        is_terminated: bool,
299    ) -> Self {
300        Self { inner, is_terminated }
301    }
302}
303
304impl futures::Stream for VulkanModeSetterRequestStream {
305    type Item = Result<VulkanModeSetterRequest, fidl::Error>;
306
307    fn poll_next(
308        mut self: std::pin::Pin<&mut Self>,
309        cx: &mut std::task::Context<'_>,
310    ) -> std::task::Poll<Option<Self::Item>> {
311        let this = &mut *self;
312        if this.inner.check_shutdown(cx) {
313            this.is_terminated = true;
314            return std::task::Poll::Ready(None);
315        }
316        if this.is_terminated {
317            panic!("polled VulkanModeSetterRequestStream after completion");
318        }
319        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
320            |bytes, handles| {
321                match this.inner.channel().read_etc(cx, bytes, handles) {
322                    std::task::Poll::Ready(Ok(())) => {}
323                    std::task::Poll::Pending => return std::task::Poll::Pending,
324                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
325                        this.is_terminated = true;
326                        return std::task::Poll::Ready(None);
327                    }
328                    std::task::Poll::Ready(Err(e)) => {
329                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
330                            e.into(),
331                        ))))
332                    }
333                }
334
335                // A message has been received from the channel
336                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
337
338                std::task::Poll::Ready(Some(match header.ordinal {
339                    0x71ffe16858e9e7eb => {
340                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
341                        let mut req = fidl::new_empty!(
342                            VulkanModeSetterSetVulkanModeRequest,
343                            fidl::encoding::DefaultFuchsiaResourceDialect
344                        );
345                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VulkanModeSetterSetVulkanModeRequest>(&header, _body_bytes, handles, &mut req)?;
346                        let control_handle =
347                            VulkanModeSetterControlHandle { inner: this.inner.clone() };
348                        Ok(VulkanModeSetterRequest::SetVulkanMode {
349                            payload: req,
350                            responder: VulkanModeSetterSetVulkanModeResponder {
351                                control_handle: std::mem::ManuallyDrop::new(control_handle),
352                                tx_id: header.tx_id,
353                            },
354                        })
355                    }
356                    _ if header.tx_id == 0
357                        && header
358                            .dynamic_flags()
359                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
360                    {
361                        Ok(VulkanModeSetterRequest::_UnknownMethod {
362                            ordinal: header.ordinal,
363                            control_handle: VulkanModeSetterControlHandle {
364                                inner: this.inner.clone(),
365                            },
366                            method_type: fidl::MethodType::OneWay,
367                        })
368                    }
369                    _ if header
370                        .dynamic_flags()
371                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
372                    {
373                        this.inner.send_framework_err(
374                            fidl::encoding::FrameworkErr::UnknownMethod,
375                            header.tx_id,
376                            header.ordinal,
377                            header.dynamic_flags(),
378                            (bytes, handles),
379                        )?;
380                        Ok(VulkanModeSetterRequest::_UnknownMethod {
381                            ordinal: header.ordinal,
382                            control_handle: VulkanModeSetterControlHandle {
383                                inner: this.inner.clone(),
384                            },
385                            method_type: fidl::MethodType::TwoWay,
386                        })
387                    }
388                    _ => Err(fidl::Error::UnknownOrdinal {
389                        ordinal: header.ordinal,
390                        protocol_name:
391                            <VulkanModeSetterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
392                    }),
393                }))
394            },
395        )
396    }
397}
398
399#[derive(Debug)]
400pub enum VulkanModeSetterRequest {
401    /// Inform gralloc of the vulkan mode. In normal operation this is called
402    /// once per container lifetime.
403    SetVulkanMode {
404        payload: VulkanModeSetterSetVulkanModeRequest,
405        responder: VulkanModeSetterSetVulkanModeResponder,
406    },
407    /// An interaction was received which does not match any known method.
408    #[non_exhaustive]
409    _UnknownMethod {
410        /// Ordinal of the method that was called.
411        ordinal: u64,
412        control_handle: VulkanModeSetterControlHandle,
413        method_type: fidl::MethodType,
414    },
415}
416
417impl VulkanModeSetterRequest {
418    #[allow(irrefutable_let_patterns)]
419    pub fn into_set_vulkan_mode(
420        self,
421    ) -> Option<(VulkanModeSetterSetVulkanModeRequest, VulkanModeSetterSetVulkanModeResponder)>
422    {
423        if let VulkanModeSetterRequest::SetVulkanMode { payload, responder } = self {
424            Some((payload, responder))
425        } else {
426            None
427        }
428    }
429
430    /// Name of the method defined in FIDL
431    pub fn method_name(&self) -> &'static str {
432        match *self {
433            VulkanModeSetterRequest::SetVulkanMode { .. } => "set_vulkan_mode",
434            VulkanModeSetterRequest::_UnknownMethod {
435                method_type: fidl::MethodType::OneWay,
436                ..
437            } => "unknown one-way method",
438            VulkanModeSetterRequest::_UnknownMethod {
439                method_type: fidl::MethodType::TwoWay,
440                ..
441            } => "unknown two-way method",
442        }
443    }
444}
445
446#[derive(Debug, Clone)]
447pub struct VulkanModeSetterControlHandle {
448    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
449}
450
451impl fidl::endpoints::ControlHandle for VulkanModeSetterControlHandle {
452    fn shutdown(&self) {
453        self.inner.shutdown()
454    }
455    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
456        self.inner.shutdown_with_epitaph(status)
457    }
458
459    fn is_closed(&self) -> bool {
460        self.inner.channel().is_closed()
461    }
462    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
463        self.inner.channel().on_closed()
464    }
465
466    #[cfg(target_os = "fuchsia")]
467    fn signal_peer(
468        &self,
469        clear_mask: zx::Signals,
470        set_mask: zx::Signals,
471    ) -> Result<(), zx_status::Status> {
472        use fidl::Peered;
473        self.inner.channel().signal_peer(clear_mask, set_mask)
474    }
475}
476
477impl VulkanModeSetterControlHandle {}
478
479#[must_use = "FIDL methods require a response to be sent"]
480#[derive(Debug)]
481pub struct VulkanModeSetterSetVulkanModeResponder {
482    control_handle: std::mem::ManuallyDrop<VulkanModeSetterControlHandle>,
483    tx_id: u32,
484}
485
486/// Set the the channel to be shutdown (see [`VulkanModeSetterControlHandle::shutdown`])
487/// if the responder is dropped without sending a response, so that the client
488/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
489impl std::ops::Drop for VulkanModeSetterSetVulkanModeResponder {
490    fn drop(&mut self) {
491        self.control_handle.shutdown();
492        // Safety: drops once, never accessed again
493        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
494    }
495}
496
497impl fidl::endpoints::Responder for VulkanModeSetterSetVulkanModeResponder {
498    type ControlHandle = VulkanModeSetterControlHandle;
499
500    fn control_handle(&self) -> &VulkanModeSetterControlHandle {
501        &self.control_handle
502    }
503
504    fn drop_without_shutdown(mut self) {
505        // Safety: drops once, never accessed again due to mem::forget
506        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
507        // Prevent Drop from running (which would shut down the channel)
508        std::mem::forget(self);
509    }
510}
511
512impl VulkanModeSetterSetVulkanModeResponder {
513    /// Sends a response to the FIDL transaction.
514    ///
515    /// Sets the channel to shutdown if an error occurs.
516    pub fn send(self, mut result: Result<(), VulkanModeSetterError>) -> Result<(), fidl::Error> {
517        let _result = self.send_raw(result);
518        if _result.is_err() {
519            self.control_handle.shutdown();
520        }
521        self.drop_without_shutdown();
522        _result
523    }
524
525    /// Similar to "send" but does not shutdown the channel if an error occurs.
526    pub fn send_no_shutdown_on_err(
527        self,
528        mut result: Result<(), VulkanModeSetterError>,
529    ) -> Result<(), fidl::Error> {
530        let _result = self.send_raw(result);
531        self.drop_without_shutdown();
532        _result
533    }
534
535    fn send_raw(&self, mut result: Result<(), VulkanModeSetterError>) -> Result<(), fidl::Error> {
536        self.control_handle.inner.send::<fidl::encoding::ResultType<
537            fidl::encoding::EmptyStruct,
538            VulkanModeSetterError,
539        >>(
540            result,
541            self.tx_id,
542            0x71ffe16858e9e7eb,
543            fidl::encoding::DynamicFlags::empty(),
544        )
545    }
546}
547
548mod internal {
549    use super::*;
550}