fidl_fuchsia_wayland/
fidl_fuchsia_wayland.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_wayland_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct ServerConnectRequest {
16    pub channel: fidl::Channel,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for ServerConnectRequest {}
20
21#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
22pub struct Server_Marker;
23
24impl fidl::endpoints::ProtocolMarker for Server_Marker {
25    type Proxy = Server_Proxy;
26    type RequestStream = Server_RequestStream;
27    #[cfg(target_os = "fuchsia")]
28    type SynchronousProxy = Server_SynchronousProxy;
29
30    const DEBUG_NAME: &'static str = "fuchsia.wayland.Server";
31}
32impl fidl::endpoints::DiscoverableProtocolMarker for Server_Marker {}
33
34pub trait Server_ProxyInterface: Send + Sync {
35    fn r#connect(&self, channel: fidl::Channel) -> Result<(), fidl::Error>;
36}
37#[derive(Debug)]
38#[cfg(target_os = "fuchsia")]
39pub struct Server_SynchronousProxy {
40    client: fidl::client::sync::Client,
41}
42
43#[cfg(target_os = "fuchsia")]
44impl fidl::endpoints::SynchronousProxy for Server_SynchronousProxy {
45    type Proxy = Server_Proxy;
46    type Protocol = Server_Marker;
47
48    fn from_channel(inner: fidl::Channel) -> Self {
49        Self::new(inner)
50    }
51
52    fn into_channel(self) -> fidl::Channel {
53        self.client.into_channel()
54    }
55
56    fn as_channel(&self) -> &fidl::Channel {
57        self.client.as_channel()
58    }
59}
60
61#[cfg(target_os = "fuchsia")]
62impl Server_SynchronousProxy {
63    pub fn new(channel: fidl::Channel) -> Self {
64        let protocol_name = <Server_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
65        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
66    }
67
68    pub fn into_channel(self) -> fidl::Channel {
69        self.client.into_channel()
70    }
71
72    /// Waits until an event arrives and returns it. It is safe for other
73    /// threads to make concurrent requests while waiting for an event.
74    pub fn wait_for_event(
75        &self,
76        deadline: zx::MonotonicInstant,
77    ) -> Result<Server_Event, fidl::Error> {
78        Server_Event::decode(self.client.wait_for_event(deadline)?)
79    }
80
81    /// Establishes a new connection to the server.
82    ///
83    /// For a client to open a new connection, a zx::channel must be created for
84    /// that connection. The client should retain one endpoint of that channel
85    /// and the other endpoint will be provided to this method. The messages on
86    /// the channel will be Wayland protocol messages. Each channel datagram will
87    /// contain 1 or more complete Wayland messages.
88    pub fn r#connect(&self, mut channel: fidl::Channel) -> Result<(), fidl::Error> {
89        self.client.send::<ServerConnectRequest>(
90            (channel,),
91            0x52a3b4417b29e9e7,
92            fidl::encoding::DynamicFlags::empty(),
93        )
94    }
95}
96
97#[derive(Debug, Clone)]
98pub struct Server_Proxy {
99    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
100}
101
102impl fidl::endpoints::Proxy for Server_Proxy {
103    type Protocol = Server_Marker;
104
105    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
106        Self::new(inner)
107    }
108
109    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
110        self.client.into_channel().map_err(|client| Self { client })
111    }
112
113    fn as_channel(&self) -> &::fidl::AsyncChannel {
114        self.client.as_channel()
115    }
116}
117
118impl Server_Proxy {
119    /// Create a new Proxy for fuchsia.wayland/Server.
120    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
121        let protocol_name = <Server_Marker 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) -> Server_EventStream {
131        Server_EventStream { event_receiver: self.client.take_event_receiver() }
132    }
133
134    /// Establishes a new connection to the server.
135    ///
136    /// For a client to open a new connection, a zx::channel must be created for
137    /// that connection. The client should retain one endpoint of that channel
138    /// and the other endpoint will be provided to this method. The messages on
139    /// the channel will be Wayland protocol messages. Each channel datagram will
140    /// contain 1 or more complete Wayland messages.
141    pub fn r#connect(&self, mut channel: fidl::Channel) -> Result<(), fidl::Error> {
142        Server_ProxyInterface::r#connect(self, channel)
143    }
144}
145
146impl Server_ProxyInterface for Server_Proxy {
147    fn r#connect(&self, mut channel: fidl::Channel) -> Result<(), fidl::Error> {
148        self.client.send::<ServerConnectRequest>(
149            (channel,),
150            0x52a3b4417b29e9e7,
151            fidl::encoding::DynamicFlags::empty(),
152        )
153    }
154}
155
156pub struct Server_EventStream {
157    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
158}
159
160impl std::marker::Unpin for Server_EventStream {}
161
162impl futures::stream::FusedStream for Server_EventStream {
163    fn is_terminated(&self) -> bool {
164        self.event_receiver.is_terminated()
165    }
166}
167
168impl futures::Stream for Server_EventStream {
169    type Item = Result<Server_Event, fidl::Error>;
170
171    fn poll_next(
172        mut self: std::pin::Pin<&mut Self>,
173        cx: &mut std::task::Context<'_>,
174    ) -> std::task::Poll<Option<Self::Item>> {
175        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
176            &mut self.event_receiver,
177            cx
178        )?) {
179            Some(buf) => std::task::Poll::Ready(Some(Server_Event::decode(buf))),
180            None => std::task::Poll::Ready(None),
181        }
182    }
183}
184
185#[derive(Debug)]
186pub enum Server_Event {}
187
188impl Server_Event {
189    /// Decodes a message buffer as a [`Server_Event`].
190    fn decode(
191        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
192    ) -> Result<Server_Event, fidl::Error> {
193        let (bytes, _handles) = buf.split_mut();
194        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
195        debug_assert_eq!(tx_header.tx_id, 0);
196        match tx_header.ordinal {
197            _ => Err(fidl::Error::UnknownOrdinal {
198                ordinal: tx_header.ordinal,
199                protocol_name: <Server_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
200            }),
201        }
202    }
203}
204
205/// A Stream of incoming requests for fuchsia.wayland/Server.
206pub struct Server_RequestStream {
207    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
208    is_terminated: bool,
209}
210
211impl std::marker::Unpin for Server_RequestStream {}
212
213impl futures::stream::FusedStream for Server_RequestStream {
214    fn is_terminated(&self) -> bool {
215        self.is_terminated
216    }
217}
218
219impl fidl::endpoints::RequestStream for Server_RequestStream {
220    type Protocol = Server_Marker;
221    type ControlHandle = Server_ControlHandle;
222
223    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
224        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
225    }
226
227    fn control_handle(&self) -> Self::ControlHandle {
228        Server_ControlHandle { inner: self.inner.clone() }
229    }
230
231    fn into_inner(
232        self,
233    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
234    {
235        (self.inner, self.is_terminated)
236    }
237
238    fn from_inner(
239        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
240        is_terminated: bool,
241    ) -> Self {
242        Self { inner, is_terminated }
243    }
244}
245
246impl futures::Stream for Server_RequestStream {
247    type Item = Result<Server_Request, fidl::Error>;
248
249    fn poll_next(
250        mut self: std::pin::Pin<&mut Self>,
251        cx: &mut std::task::Context<'_>,
252    ) -> std::task::Poll<Option<Self::Item>> {
253        let this = &mut *self;
254        if this.inner.check_shutdown(cx) {
255            this.is_terminated = true;
256            return std::task::Poll::Ready(None);
257        }
258        if this.is_terminated {
259            panic!("polled Server_RequestStream after completion");
260        }
261        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
262            |bytes, handles| {
263                match this.inner.channel().read_etc(cx, bytes, handles) {
264                    std::task::Poll::Ready(Ok(())) => {}
265                    std::task::Poll::Pending => return std::task::Poll::Pending,
266                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
267                        this.is_terminated = true;
268                        return std::task::Poll::Ready(None);
269                    }
270                    std::task::Poll::Ready(Err(e)) => {
271                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
272                            e.into(),
273                        ))))
274                    }
275                }
276
277                // A message has been received from the channel
278                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
279
280                std::task::Poll::Ready(Some(match header.ordinal {
281                    0x52a3b4417b29e9e7 => {
282                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
283                        let mut req = fidl::new_empty!(
284                            ServerConnectRequest,
285                            fidl::encoding::DefaultFuchsiaResourceDialect
286                        );
287                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ServerConnectRequest>(&header, _body_bytes, handles, &mut req)?;
288                        let control_handle = Server_ControlHandle { inner: this.inner.clone() };
289                        Ok(Server_Request::Connect { channel: req.channel, control_handle })
290                    }
291                    _ => Err(fidl::Error::UnknownOrdinal {
292                        ordinal: header.ordinal,
293                        protocol_name:
294                            <Server_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
295                    }),
296                }))
297            },
298        )
299    }
300}
301
302/// Protocol that provides a mechanism to connect to a Wayland server
303/// and communicate with that server using Wayland protocol messages.
304///
305/// The server has to implement the minimal set of interfaces in the
306/// core protocol require by the Wayland standard. Anything beyond that
307/// is optional. Clients can discover available Wayland interfaces using
308/// Wayland messsages that are part of the core protocol. The wire format
309/// and the core protocol is described in detail here:
310///
311/// https://wayland.freedesktop.org/docs/html/ch04.html
312///
313/// The Wayland protocol makes use of file descriptors for data transfer.
314/// Each file descriptor should be replaced with a zx::handle when
315/// communicating with a server. The exact handle type depends on the
316/// interface definition. File descriptors that can be memory-mapped
317/// typically need to be replaced with zx:vmos.
318///
319/// The client can be a Fuchsia component, or a Linux program (running
320/// in a VM, or using some other type of compatibility layer).
321#[derive(Debug)]
322pub enum Server_Request {
323    /// Establishes a new connection to the server.
324    ///
325    /// For a client to open a new connection, a zx::channel must be created for
326    /// that connection. The client should retain one endpoint of that channel
327    /// and the other endpoint will be provided to this method. The messages on
328    /// the channel will be Wayland protocol messages. Each channel datagram will
329    /// contain 1 or more complete Wayland messages.
330    Connect { channel: fidl::Channel, control_handle: Server_ControlHandle },
331}
332
333impl Server_Request {
334    #[allow(irrefutable_let_patterns)]
335    pub fn into_connect(self) -> Option<(fidl::Channel, Server_ControlHandle)> {
336        if let Server_Request::Connect { channel, control_handle } = self {
337            Some((channel, control_handle))
338        } else {
339            None
340        }
341    }
342
343    /// Name of the method defined in FIDL
344    pub fn method_name(&self) -> &'static str {
345        match *self {
346            Server_Request::Connect { .. } => "connect",
347        }
348    }
349}
350
351#[derive(Debug, Clone)]
352pub struct Server_ControlHandle {
353    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
354}
355
356impl fidl::endpoints::ControlHandle for Server_ControlHandle {
357    fn shutdown(&self) {
358        self.inner.shutdown()
359    }
360    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
361        self.inner.shutdown_with_epitaph(status)
362    }
363
364    fn is_closed(&self) -> bool {
365        self.inner.channel().is_closed()
366    }
367    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
368        self.inner.channel().on_closed()
369    }
370
371    #[cfg(target_os = "fuchsia")]
372    fn signal_peer(
373        &self,
374        clear_mask: zx::Signals,
375        set_mask: zx::Signals,
376    ) -> Result<(), zx_status::Status> {
377        use fidl::Peered;
378        self.inner.channel().signal_peer(clear_mask, set_mask)
379    }
380}
381
382impl Server_ControlHandle {}
383
384mod internal {
385    use super::*;
386
387    impl fidl::encoding::ResourceTypeMarker for ServerConnectRequest {
388        type Borrowed<'a> = &'a mut Self;
389        fn take_or_borrow<'a>(
390            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
391        ) -> Self::Borrowed<'a> {
392            value
393        }
394    }
395
396    unsafe impl fidl::encoding::TypeMarker for ServerConnectRequest {
397        type Owned = Self;
398
399        #[inline(always)]
400        fn inline_align(_context: fidl::encoding::Context) -> usize {
401            4
402        }
403
404        #[inline(always)]
405        fn inline_size(_context: fidl::encoding::Context) -> usize {
406            4
407        }
408    }
409
410    unsafe impl
411        fidl::encoding::Encode<ServerConnectRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
412        for &mut ServerConnectRequest
413    {
414        #[inline]
415        unsafe fn encode(
416            self,
417            encoder: &mut fidl::encoding::Encoder<
418                '_,
419                fidl::encoding::DefaultFuchsiaResourceDialect,
420            >,
421            offset: usize,
422            _depth: fidl::encoding::Depth,
423        ) -> fidl::Result<()> {
424            encoder.debug_check_bounds::<ServerConnectRequest>(offset);
425            // Delegate to tuple encoding.
426            fidl::encoding::Encode::<
427                ServerConnectRequest,
428                fidl::encoding::DefaultFuchsiaResourceDialect,
429            >::encode(
430                (<fidl::encoding::HandleType<
431                    fidl::Channel,
432                    { fidl::ObjectType::CHANNEL.into_raw() },
433                    2147483648,
434                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
435                    &mut self.channel
436                ),),
437                encoder,
438                offset,
439                _depth,
440            )
441        }
442    }
443    unsafe impl<
444            T0: fidl::encoding::Encode<
445                fidl::encoding::HandleType<
446                    fidl::Channel,
447                    { fidl::ObjectType::CHANNEL.into_raw() },
448                    2147483648,
449                >,
450                fidl::encoding::DefaultFuchsiaResourceDialect,
451            >,
452        >
453        fidl::encoding::Encode<ServerConnectRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
454        for (T0,)
455    {
456        #[inline]
457        unsafe fn encode(
458            self,
459            encoder: &mut fidl::encoding::Encoder<
460                '_,
461                fidl::encoding::DefaultFuchsiaResourceDialect,
462            >,
463            offset: usize,
464            depth: fidl::encoding::Depth,
465        ) -> fidl::Result<()> {
466            encoder.debug_check_bounds::<ServerConnectRequest>(offset);
467            // Zero out padding regions. There's no need to apply masks
468            // because the unmasked parts will be overwritten by fields.
469            // Write the fields.
470            self.0.encode(encoder, offset + 0, depth)?;
471            Ok(())
472        }
473    }
474
475    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
476        for ServerConnectRequest
477    {
478        #[inline(always)]
479        fn new_empty() -> Self {
480            Self {
481                channel: fidl::new_empty!(fidl::encoding::HandleType<fidl::Channel, { fidl::ObjectType::CHANNEL.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
482            }
483        }
484
485        #[inline]
486        unsafe fn decode(
487            &mut self,
488            decoder: &mut fidl::encoding::Decoder<
489                '_,
490                fidl::encoding::DefaultFuchsiaResourceDialect,
491            >,
492            offset: usize,
493            _depth: fidl::encoding::Depth,
494        ) -> fidl::Result<()> {
495            decoder.debug_check_bounds::<Self>(offset);
496            // Verify that padding bytes are zero.
497            fidl::decode!(fidl::encoding::HandleType<fidl::Channel, { fidl::ObjectType::CHANNEL.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.channel, decoder, offset + 0, _depth)?;
498            Ok(())
499        }
500    }
501}