fidl_fuchsia_ui_observation_geometry/
fidl_fuchsia_ui_observation_geometry.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_ui_observation_geometry__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ViewTreeWatcherMarker;
16
17impl fidl::endpoints::ProtocolMarker for ViewTreeWatcherMarker {
18    type Proxy = ViewTreeWatcherProxy;
19    type RequestStream = ViewTreeWatcherRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = ViewTreeWatcherSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "(anonymous) ViewTreeWatcher";
24}
25
26pub trait ViewTreeWatcherProxyInterface: Send + Sync {
27    type WatchResponseFut: std::future::Future<Output = Result<WatchResponse, fidl::Error>> + Send;
28    fn r#watch(&self) -> Self::WatchResponseFut;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct ViewTreeWatcherSynchronousProxy {
33    client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for ViewTreeWatcherSynchronousProxy {
38    type Proxy = ViewTreeWatcherProxy;
39    type Protocol = ViewTreeWatcherMarker;
40
41    fn from_channel(inner: fidl::Channel) -> Self {
42        Self::new(inner)
43    }
44
45    fn into_channel(self) -> fidl::Channel {
46        self.client.into_channel()
47    }
48
49    fn as_channel(&self) -> &fidl::Channel {
50        self.client.as_channel()
51    }
52}
53
54#[cfg(target_os = "fuchsia")]
55impl ViewTreeWatcherSynchronousProxy {
56    pub fn new(channel: fidl::Channel) -> Self {
57        let protocol_name = <ViewTreeWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
58        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
59    }
60
61    pub fn into_channel(self) -> fidl::Channel {
62        self.client.into_channel()
63    }
64
65    /// Waits until an event arrives and returns it. It is safe for other
66    /// threads to make concurrent requests while waiting for an event.
67    pub fn wait_for_event(
68        &self,
69        deadline: zx::MonotonicInstant,
70    ) -> Result<ViewTreeWatcherEvent, fidl::Error> {
71        ViewTreeWatcherEvent::decode(self.client.wait_for_event(deadline)?)
72    }
73
74    /// A method of obtaining view tree snapshots for a particular view.
75    ///
76    /// This call is formulated as a "hanging get" pattern: the client asks for
77    /// a set of recent snapshots, and receives them via the callback. This
78    /// pull-based approach ensures that clients consume events at their own
79    /// pace; events don't clog up the channel in an unbounded manner.
80    ///
81    /// Error Handling. If Error is unset, the client may assume that the
82    /// the response contains updates with complete information over its epoch.
83    ///
84    /// Flow control. The caller is allowed at most one in-flight |Watch| call
85    /// at a time; it is a logical error to have concurrent calls to |Watch|.
86    /// Non-compliance results in channel closure.
87    ///
88    /// Client pacing. The server will dispatch snapshots to the caller on a
89    /// lossless, best-effort basis, but the caller must allocate enough time to
90    /// keep up with new snapshots.
91    pub fn r#watch(&self, ___deadline: zx::MonotonicInstant) -> Result<WatchResponse, fidl::Error> {
92        let _response = self.client.send_query::<fidl::encoding::EmptyPayload, WatchResponse>(
93            (),
94            0x3c7670983418477b,
95            fidl::encoding::DynamicFlags::empty(),
96            ___deadline,
97        )?;
98        Ok(_response)
99    }
100}
101
102#[cfg(target_os = "fuchsia")]
103impl From<ViewTreeWatcherSynchronousProxy> for zx::Handle {
104    fn from(value: ViewTreeWatcherSynchronousProxy) -> Self {
105        value.into_channel().into()
106    }
107}
108
109#[cfg(target_os = "fuchsia")]
110impl From<fidl::Channel> for ViewTreeWatcherSynchronousProxy {
111    fn from(value: fidl::Channel) -> Self {
112        Self::new(value)
113    }
114}
115
116#[cfg(target_os = "fuchsia")]
117impl fidl::endpoints::FromClient for ViewTreeWatcherSynchronousProxy {
118    type Protocol = ViewTreeWatcherMarker;
119
120    fn from_client(value: fidl::endpoints::ClientEnd<ViewTreeWatcherMarker>) -> Self {
121        Self::new(value.into_channel())
122    }
123}
124
125#[derive(Debug, Clone)]
126pub struct ViewTreeWatcherProxy {
127    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
128}
129
130impl fidl::endpoints::Proxy for ViewTreeWatcherProxy {
131    type Protocol = ViewTreeWatcherMarker;
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 ViewTreeWatcherProxy {
147    /// Create a new Proxy for fuchsia.ui.observation.geometry/ViewTreeWatcher.
148    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
149        let protocol_name = <ViewTreeWatcherMarker 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) -> ViewTreeWatcherEventStream {
159        ViewTreeWatcherEventStream { event_receiver: self.client.take_event_receiver() }
160    }
161
162    /// A method of obtaining view tree snapshots for a particular view.
163    ///
164    /// This call is formulated as a "hanging get" pattern: the client asks for
165    /// a set of recent snapshots, and receives them via the callback. This
166    /// pull-based approach ensures that clients consume events at their own
167    /// pace; events don't clog up the channel in an unbounded manner.
168    ///
169    /// Error Handling. If Error is unset, the client may assume that the
170    /// the response contains updates with complete information over its epoch.
171    ///
172    /// Flow control. The caller is allowed at most one in-flight |Watch| call
173    /// at a time; it is a logical error to have concurrent calls to |Watch|.
174    /// Non-compliance results in channel closure.
175    ///
176    /// Client pacing. The server will dispatch snapshots to the caller on a
177    /// lossless, best-effort basis, but the caller must allocate enough time to
178    /// keep up with new snapshots.
179    pub fn r#watch(
180        &self,
181    ) -> fidl::client::QueryResponseFut<WatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
182    {
183        ViewTreeWatcherProxyInterface::r#watch(self)
184    }
185}
186
187impl ViewTreeWatcherProxyInterface for ViewTreeWatcherProxy {
188    type WatchResponseFut = fidl::client::QueryResponseFut<
189        WatchResponse,
190        fidl::encoding::DefaultFuchsiaResourceDialect,
191    >;
192    fn r#watch(&self) -> Self::WatchResponseFut {
193        fn _decode(
194            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
195        ) -> Result<WatchResponse, fidl::Error> {
196            let _response = fidl::client::decode_transaction_body::<
197                WatchResponse,
198                fidl::encoding::DefaultFuchsiaResourceDialect,
199                0x3c7670983418477b,
200            >(_buf?)?;
201            Ok(_response)
202        }
203        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, WatchResponse>(
204            (),
205            0x3c7670983418477b,
206            fidl::encoding::DynamicFlags::empty(),
207            _decode,
208        )
209    }
210}
211
212pub struct ViewTreeWatcherEventStream {
213    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
214}
215
216impl std::marker::Unpin for ViewTreeWatcherEventStream {}
217
218impl futures::stream::FusedStream for ViewTreeWatcherEventStream {
219    fn is_terminated(&self) -> bool {
220        self.event_receiver.is_terminated()
221    }
222}
223
224impl futures::Stream for ViewTreeWatcherEventStream {
225    type Item = Result<ViewTreeWatcherEvent, fidl::Error>;
226
227    fn poll_next(
228        mut self: std::pin::Pin<&mut Self>,
229        cx: &mut std::task::Context<'_>,
230    ) -> std::task::Poll<Option<Self::Item>> {
231        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
232            &mut self.event_receiver,
233            cx
234        )?) {
235            Some(buf) => std::task::Poll::Ready(Some(ViewTreeWatcherEvent::decode(buf))),
236            None => std::task::Poll::Ready(None),
237        }
238    }
239}
240
241#[derive(Debug)]
242pub enum ViewTreeWatcherEvent {}
243
244impl ViewTreeWatcherEvent {
245    /// Decodes a message buffer as a [`ViewTreeWatcherEvent`].
246    fn decode(
247        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
248    ) -> Result<ViewTreeWatcherEvent, 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            _ => Err(fidl::Error::UnknownOrdinal {
254                ordinal: tx_header.ordinal,
255                protocol_name:
256                    <ViewTreeWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
257            }),
258        }
259    }
260}
261
262/// A Stream of incoming requests for fuchsia.ui.observation.geometry/ViewTreeWatcher.
263pub struct ViewTreeWatcherRequestStream {
264    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
265    is_terminated: bool,
266}
267
268impl std::marker::Unpin for ViewTreeWatcherRequestStream {}
269
270impl futures::stream::FusedStream for ViewTreeWatcherRequestStream {
271    fn is_terminated(&self) -> bool {
272        self.is_terminated
273    }
274}
275
276impl fidl::endpoints::RequestStream for ViewTreeWatcherRequestStream {
277    type Protocol = ViewTreeWatcherMarker;
278    type ControlHandle = ViewTreeWatcherControlHandle;
279
280    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
281        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
282    }
283
284    fn control_handle(&self) -> Self::ControlHandle {
285        ViewTreeWatcherControlHandle { inner: self.inner.clone() }
286    }
287
288    fn into_inner(
289        self,
290    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
291    {
292        (self.inner, self.is_terminated)
293    }
294
295    fn from_inner(
296        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
297        is_terminated: bool,
298    ) -> Self {
299        Self { inner, is_terminated }
300    }
301}
302
303impl futures::Stream for ViewTreeWatcherRequestStream {
304    type Item = Result<ViewTreeWatcherRequest, fidl::Error>;
305
306    fn poll_next(
307        mut self: std::pin::Pin<&mut Self>,
308        cx: &mut std::task::Context<'_>,
309    ) -> std::task::Poll<Option<Self::Item>> {
310        let this = &mut *self;
311        if this.inner.check_shutdown(cx) {
312            this.is_terminated = true;
313            return std::task::Poll::Ready(None);
314        }
315        if this.is_terminated {
316            panic!("polled ViewTreeWatcherRequestStream after completion");
317        }
318        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
319            |bytes, handles| {
320                match this.inner.channel().read_etc(cx, bytes, handles) {
321                    std::task::Poll::Ready(Ok(())) => {}
322                    std::task::Poll::Pending => return std::task::Poll::Pending,
323                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
324                        this.is_terminated = true;
325                        return std::task::Poll::Ready(None);
326                    }
327                    std::task::Poll::Ready(Err(e)) => {
328                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
329                            e.into(),
330                        ))))
331                    }
332                }
333
334                // A message has been received from the channel
335                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
336
337                std::task::Poll::Ready(Some(match header.ordinal {
338                    0x3c7670983418477b => {
339                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
340                        let mut req = fidl::new_empty!(
341                            fidl::encoding::EmptyPayload,
342                            fidl::encoding::DefaultFuchsiaResourceDialect
343                        );
344                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
345                        let control_handle =
346                            ViewTreeWatcherControlHandle { inner: this.inner.clone() };
347                        Ok(ViewTreeWatcherRequest::Watch {
348                            responder: ViewTreeWatcherWatchResponder {
349                                control_handle: std::mem::ManuallyDrop::new(control_handle),
350                                tx_id: header.tx_id,
351                            },
352                        })
353                    }
354                    _ => Err(fidl::Error::UnknownOrdinal {
355                        ordinal: header.ordinal,
356                        protocol_name:
357                            <ViewTreeWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
358                    }),
359                }))
360            },
361        )
362    }
363}
364
365/// A method of obtaining view tree snapshots for a particular view, the "context
366/// view", and its child views, if any. The returned data is a sequence of
367/// snapshots during the period of observation, which starts at the client's
368/// prior Watch() call's [`epoch_end`] (or zx.Time 0), and ending at the
369/// current [`epoch_end`]. The timebase is ZX_CLOCK_MONOTONIC.
370///
371/// Clients typically obtain a `ViewTreeWatcher` capability from within a test,
372/// and it is not generally possible to obtain outside of a test environment.
373/// For more information see `fuchsia.ui.observation.test.Registry` and
374/// `fuchsia.ui.test.scene.Controller`.
375///
376/// Usage note. With this protocol, a client can watch for changes to the view
377/// tree over which it has authority. For example, if a client owns view A, then
378/// A serves as the context view for A's subtree (i.e., a "root view"), where A
379/// is a parent of view B, and B is a parent of view C. The client can then
380/// observe key lifecycle events in all of A, B, and C, such as newly connected
381/// views, changes to view position and size, etc. In doing so, a client can
382/// gate its actions on changes to the view tree, in a reliable and ergonomic
383/// manner. For example, a client can wait for a descendant view C to become
384/// connected before requesting a focus transfer to C.
385///
386/// Configuration: The context view is determined outside of this protocol.
387///
388/// Frequency: A client can receive one or more snapshots per frame. Clients
389/// should not "count snapshots", as the per-frame snapshot count can be
390/// non-deterministic. Instead, clients should look for specific conditions on
391/// the snapshot state.
392///
393/// Issuance: If the context view is disconnected from a display, no
394/// frames are issued on behalf of the context view, and a Watch() call will
395/// sit quietly.
396///
397/// Lifecycle: The server endpoint is closed when the context view dies.
398#[derive(Debug)]
399pub enum ViewTreeWatcherRequest {
400    /// A method of obtaining view tree snapshots for a particular view.
401    ///
402    /// This call is formulated as a "hanging get" pattern: the client asks for
403    /// a set of recent snapshots, and receives them via the callback. This
404    /// pull-based approach ensures that clients consume events at their own
405    /// pace; events don't clog up the channel in an unbounded manner.
406    ///
407    /// Error Handling. If Error is unset, the client may assume that the
408    /// the response contains updates with complete information over its epoch.
409    ///
410    /// Flow control. The caller is allowed at most one in-flight |Watch| call
411    /// at a time; it is a logical error to have concurrent calls to |Watch|.
412    /// Non-compliance results in channel closure.
413    ///
414    /// Client pacing. The server will dispatch snapshots to the caller on a
415    /// lossless, best-effort basis, but the caller must allocate enough time to
416    /// keep up with new snapshots.
417    Watch { responder: ViewTreeWatcherWatchResponder },
418}
419
420impl ViewTreeWatcherRequest {
421    #[allow(irrefutable_let_patterns)]
422    pub fn into_watch(self) -> Option<(ViewTreeWatcherWatchResponder)> {
423        if let ViewTreeWatcherRequest::Watch { responder } = self {
424            Some((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            ViewTreeWatcherRequest::Watch { .. } => "watch",
434        }
435    }
436}
437
438#[derive(Debug, Clone)]
439pub struct ViewTreeWatcherControlHandle {
440    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
441}
442
443impl fidl::endpoints::ControlHandle for ViewTreeWatcherControlHandle {
444    fn shutdown(&self) {
445        self.inner.shutdown()
446    }
447    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
448        self.inner.shutdown_with_epitaph(status)
449    }
450
451    fn is_closed(&self) -> bool {
452        self.inner.channel().is_closed()
453    }
454    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
455        self.inner.channel().on_closed()
456    }
457
458    #[cfg(target_os = "fuchsia")]
459    fn signal_peer(
460        &self,
461        clear_mask: zx::Signals,
462        set_mask: zx::Signals,
463    ) -> Result<(), zx_status::Status> {
464        use fidl::Peered;
465        self.inner.channel().signal_peer(clear_mask, set_mask)
466    }
467}
468
469impl ViewTreeWatcherControlHandle {}
470
471#[must_use = "FIDL methods require a response to be sent"]
472#[derive(Debug)]
473pub struct ViewTreeWatcherWatchResponder {
474    control_handle: std::mem::ManuallyDrop<ViewTreeWatcherControlHandle>,
475    tx_id: u32,
476}
477
478/// Set the the channel to be shutdown (see [`ViewTreeWatcherControlHandle::shutdown`])
479/// if the responder is dropped without sending a response, so that the client
480/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
481impl std::ops::Drop for ViewTreeWatcherWatchResponder {
482    fn drop(&mut self) {
483        self.control_handle.shutdown();
484        // Safety: drops once, never accessed again
485        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
486    }
487}
488
489impl fidl::endpoints::Responder for ViewTreeWatcherWatchResponder {
490    type ControlHandle = ViewTreeWatcherControlHandle;
491
492    fn control_handle(&self) -> &ViewTreeWatcherControlHandle {
493        &self.control_handle
494    }
495
496    fn drop_without_shutdown(mut self) {
497        // Safety: drops once, never accessed again due to mem::forget
498        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
499        // Prevent Drop from running (which would shut down the channel)
500        std::mem::forget(self);
501    }
502}
503
504impl ViewTreeWatcherWatchResponder {
505    /// Sends a response to the FIDL transaction.
506    ///
507    /// Sets the channel to shutdown if an error occurs.
508    pub fn send(self, mut payload: &WatchResponse) -> Result<(), fidl::Error> {
509        let _result = self.send_raw(payload);
510        if _result.is_err() {
511            self.control_handle.shutdown();
512        }
513        self.drop_without_shutdown();
514        _result
515    }
516
517    /// Similar to "send" but does not shutdown the channel if an error occurs.
518    pub fn send_no_shutdown_on_err(self, mut payload: &WatchResponse) -> Result<(), fidl::Error> {
519        let _result = self.send_raw(payload);
520        self.drop_without_shutdown();
521        _result
522    }
523
524    fn send_raw(&self, mut payload: &WatchResponse) -> Result<(), fidl::Error> {
525        self.control_handle.inner.send::<WatchResponse>(
526            payload,
527            self.tx_id,
528            0x3c7670983418477b,
529            fidl::encoding::DynamicFlags::empty(),
530        )
531    }
532}
533
534mod internal {
535    use super::*;
536}