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