Skip to main content

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