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