Skip to main content

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