Skip to main content

fidl_fuchsia_bluetooth_deviceid/
fidl_fuchsia_bluetooth_deviceid.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_bluetooth_deviceid_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct DeviceIdentificationSetDeviceIdentificationRequest {
16    pub records: Vec<DeviceIdentificationRecord>,
17    pub token: fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for DeviceIdentificationSetDeviceIdentificationRequest
22{
23}
24
25#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
26pub struct DeviceIdentificationMarker;
27
28impl fidl::endpoints::ProtocolMarker for DeviceIdentificationMarker {
29    type Proxy = DeviceIdentificationProxy;
30    type RequestStream = DeviceIdentificationRequestStream;
31    #[cfg(target_os = "fuchsia")]
32    type SynchronousProxy = DeviceIdentificationSynchronousProxy;
33
34    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.deviceid.DeviceIdentification";
35}
36impl fidl::endpoints::DiscoverableProtocolMarker for DeviceIdentificationMarker {}
37pub type DeviceIdentificationSetDeviceIdentificationResult = Result<(), i32>;
38
39pub trait DeviceIdentificationProxyInterface: Send + Sync {
40    type SetDeviceIdentificationResponseFut: std::future::Future<
41            Output = Result<DeviceIdentificationSetDeviceIdentificationResult, fidl::Error>,
42        > + Send;
43    fn r#set_device_identification(
44        &self,
45        records: &[DeviceIdentificationRecord],
46        token: fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
47    ) -> Self::SetDeviceIdentificationResponseFut;
48}
49#[derive(Debug)]
50#[cfg(target_os = "fuchsia")]
51pub struct DeviceIdentificationSynchronousProxy {
52    client: fidl::client::sync::Client,
53}
54
55#[cfg(target_os = "fuchsia")]
56impl fidl::endpoints::SynchronousProxy for DeviceIdentificationSynchronousProxy {
57    type Proxy = DeviceIdentificationProxy;
58    type Protocol = DeviceIdentificationMarker;
59
60    fn from_channel(inner: fidl::Channel) -> Self {
61        Self::new(inner)
62    }
63
64    fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    fn as_channel(&self) -> &fidl::Channel {
69        self.client.as_channel()
70    }
71}
72
73#[cfg(target_os = "fuchsia")]
74impl DeviceIdentificationSynchronousProxy {
75    pub fn new(channel: fidl::Channel) -> Self {
76        Self { client: fidl::client::sync::Client::new(channel) }
77    }
78
79    pub fn into_channel(self) -> fidl::Channel {
80        self.client.into_channel()
81    }
82
83    /// Waits until an event arrives and returns it. It is safe for other
84    /// threads to make concurrent requests while waiting for an event.
85    pub fn wait_for_event(
86        &self,
87        deadline: zx::MonotonicInstant,
88    ) -> Result<DeviceIdentificationEvent, fidl::Error> {
89        DeviceIdentificationEvent::decode(
90            self.client.wait_for_event::<DeviceIdentificationMarker>(deadline)?,
91        )
92    }
93
94    /// Request to set the device information to be advertised over Bluetooth.
95    ///
96    /// The device information can only be set once per provided `token`. To cancel the request,
97    /// close the `token` with any epitaph.
98    ///
99    /// At most one record in `records` may be denoted as the `primary` record. If multiple records
100    /// have `primary` set, `ZX_ERR_INVALID_ARGS` will be returned.
101    /// If the server is already advertising a `primary` record, a subsequent request with `primary`
102    /// may be rejected with `ZX_ERR_ALREADY_EXISTS`.
103    ///
104    /// + request `records` is the set of device information records that identify the device.
105    /// + request `token` is used to manage the lifetime of the advertised device information.
106    ///           The `records` will remain advertised as long as the channel is open.
107    ///           The device identification advertisement will be removed when `token` is closed
108    ///           with any epitaph.
109    /// - response An empty response will be sent when the `token` has been closed and the server
110    ///            has processed the closure.
111    /// * error Returns `ZX_ERR_INVALID_ARGS` if any of the provided `records` are invalidly
112    ///         formatted.
113    /// * error Returns `ZX_ERR_NO_RESOURCES` if the server has reached the maximum number of
114    ///         device information advertisements.
115    /// * error Returns `ZX_ERR_CANCELLED` if the request was cancelled by the server for all other
116    ///         errors.
117    pub fn r#set_device_identification(
118        &self,
119        mut records: &[DeviceIdentificationRecord],
120        mut token: fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
121        ___deadline: zx::MonotonicInstant,
122    ) -> Result<DeviceIdentificationSetDeviceIdentificationResult, fidl::Error> {
123        let _response = self.client.send_query::<
124            DeviceIdentificationSetDeviceIdentificationRequest,
125            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
126            DeviceIdentificationMarker,
127        >(
128            (records, token,),
129            0x12ada3cb3fbcbd0a,
130            fidl::encoding::DynamicFlags::empty(),
131            ___deadline,
132        )?;
133        Ok(_response.map(|x| x))
134    }
135}
136
137#[cfg(target_os = "fuchsia")]
138impl From<DeviceIdentificationSynchronousProxy> for zx::NullableHandle {
139    fn from(value: DeviceIdentificationSynchronousProxy) -> Self {
140        value.into_channel().into()
141    }
142}
143
144#[cfg(target_os = "fuchsia")]
145impl From<fidl::Channel> for DeviceIdentificationSynchronousProxy {
146    fn from(value: fidl::Channel) -> Self {
147        Self::new(value)
148    }
149}
150
151#[cfg(target_os = "fuchsia")]
152impl fidl::endpoints::FromClient for DeviceIdentificationSynchronousProxy {
153    type Protocol = DeviceIdentificationMarker;
154
155    fn from_client(value: fidl::endpoints::ClientEnd<DeviceIdentificationMarker>) -> Self {
156        Self::new(value.into_channel())
157    }
158}
159
160#[derive(Debug, Clone)]
161pub struct DeviceIdentificationProxy {
162    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
163}
164
165impl fidl::endpoints::Proxy for DeviceIdentificationProxy {
166    type Protocol = DeviceIdentificationMarker;
167
168    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
169        Self::new(inner)
170    }
171
172    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
173        self.client.into_channel().map_err(|client| Self { client })
174    }
175
176    fn as_channel(&self) -> &::fidl::AsyncChannel {
177        self.client.as_channel()
178    }
179}
180
181impl DeviceIdentificationProxy {
182    /// Create a new Proxy for fuchsia.bluetooth.deviceid/DeviceIdentification.
183    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
184        let protocol_name =
185            <DeviceIdentificationMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
186        Self { client: fidl::client::Client::new(channel, protocol_name) }
187    }
188
189    /// Get a Stream of events from the remote end of the protocol.
190    ///
191    /// # Panics
192    ///
193    /// Panics if the event stream was already taken.
194    pub fn take_event_stream(&self) -> DeviceIdentificationEventStream {
195        DeviceIdentificationEventStream { event_receiver: self.client.take_event_receiver() }
196    }
197
198    /// Request to set the device information to be advertised over Bluetooth.
199    ///
200    /// The device information can only be set once per provided `token`. To cancel the request,
201    /// close the `token` with any epitaph.
202    ///
203    /// At most one record in `records` may be denoted as the `primary` record. If multiple records
204    /// have `primary` set, `ZX_ERR_INVALID_ARGS` will be returned.
205    /// If the server is already advertising a `primary` record, a subsequent request with `primary`
206    /// may be rejected with `ZX_ERR_ALREADY_EXISTS`.
207    ///
208    /// + request `records` is the set of device information records that identify the device.
209    /// + request `token` is used to manage the lifetime of the advertised device information.
210    ///           The `records` will remain advertised as long as the channel is open.
211    ///           The device identification advertisement will be removed when `token` is closed
212    ///           with any epitaph.
213    /// - response An empty response will be sent when the `token` has been closed and the server
214    ///            has processed the closure.
215    /// * error Returns `ZX_ERR_INVALID_ARGS` if any of the provided `records` are invalidly
216    ///         formatted.
217    /// * error Returns `ZX_ERR_NO_RESOURCES` if the server has reached the maximum number of
218    ///         device information advertisements.
219    /// * error Returns `ZX_ERR_CANCELLED` if the request was cancelled by the server for all other
220    ///         errors.
221    pub fn r#set_device_identification(
222        &self,
223        mut records: &[DeviceIdentificationRecord],
224        mut token: fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
225    ) -> fidl::client::QueryResponseFut<
226        DeviceIdentificationSetDeviceIdentificationResult,
227        fidl::encoding::DefaultFuchsiaResourceDialect,
228    > {
229        DeviceIdentificationProxyInterface::r#set_device_identification(self, records, token)
230    }
231}
232
233impl DeviceIdentificationProxyInterface for DeviceIdentificationProxy {
234    type SetDeviceIdentificationResponseFut = fidl::client::QueryResponseFut<
235        DeviceIdentificationSetDeviceIdentificationResult,
236        fidl::encoding::DefaultFuchsiaResourceDialect,
237    >;
238    fn r#set_device_identification(
239        &self,
240        mut records: &[DeviceIdentificationRecord],
241        mut token: fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
242    ) -> Self::SetDeviceIdentificationResponseFut {
243        fn _decode(
244            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
245        ) -> Result<DeviceIdentificationSetDeviceIdentificationResult, fidl::Error> {
246            let _response = fidl::client::decode_transaction_body::<
247                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
248                fidl::encoding::DefaultFuchsiaResourceDialect,
249                0x12ada3cb3fbcbd0a,
250            >(_buf?)?;
251            Ok(_response.map(|x| x))
252        }
253        self.client.send_query_and_decode::<
254            DeviceIdentificationSetDeviceIdentificationRequest,
255            DeviceIdentificationSetDeviceIdentificationResult,
256        >(
257            (records, token,),
258            0x12ada3cb3fbcbd0a,
259            fidl::encoding::DynamicFlags::empty(),
260            _decode,
261        )
262    }
263}
264
265pub struct DeviceIdentificationEventStream {
266    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
267}
268
269impl std::marker::Unpin for DeviceIdentificationEventStream {}
270
271impl futures::stream::FusedStream for DeviceIdentificationEventStream {
272    fn is_terminated(&self) -> bool {
273        self.event_receiver.is_terminated()
274    }
275}
276
277impl futures::Stream for DeviceIdentificationEventStream {
278    type Item = Result<DeviceIdentificationEvent, fidl::Error>;
279
280    fn poll_next(
281        mut self: std::pin::Pin<&mut Self>,
282        cx: &mut std::task::Context<'_>,
283    ) -> std::task::Poll<Option<Self::Item>> {
284        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
285            &mut self.event_receiver,
286            cx
287        )?) {
288            Some(buf) => std::task::Poll::Ready(Some(DeviceIdentificationEvent::decode(buf))),
289            None => std::task::Poll::Ready(None),
290        }
291    }
292}
293
294#[derive(Debug)]
295pub enum DeviceIdentificationEvent {}
296
297impl DeviceIdentificationEvent {
298    /// Decodes a message buffer as a [`DeviceIdentificationEvent`].
299    fn decode(
300        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
301    ) -> Result<DeviceIdentificationEvent, fidl::Error> {
302        let (bytes, _handles) = buf.split_mut();
303        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
304        debug_assert_eq!(tx_header.tx_id, 0);
305        match tx_header.ordinal {
306            _ => Err(fidl::Error::UnknownOrdinal {
307                ordinal: tx_header.ordinal,
308                protocol_name:
309                    <DeviceIdentificationMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
310            }),
311        }
312    }
313}
314
315/// A Stream of incoming requests for fuchsia.bluetooth.deviceid/DeviceIdentification.
316pub struct DeviceIdentificationRequestStream {
317    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
318    is_terminated: bool,
319}
320
321impl std::marker::Unpin for DeviceIdentificationRequestStream {}
322
323impl futures::stream::FusedStream for DeviceIdentificationRequestStream {
324    fn is_terminated(&self) -> bool {
325        self.is_terminated
326    }
327}
328
329impl fidl::endpoints::RequestStream for DeviceIdentificationRequestStream {
330    type Protocol = DeviceIdentificationMarker;
331    type ControlHandle = DeviceIdentificationControlHandle;
332
333    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
334        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
335    }
336
337    fn control_handle(&self) -> Self::ControlHandle {
338        DeviceIdentificationControlHandle { inner: self.inner.clone() }
339    }
340
341    fn into_inner(
342        self,
343    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
344    {
345        (self.inner, self.is_terminated)
346    }
347
348    fn from_inner(
349        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
350        is_terminated: bool,
351    ) -> Self {
352        Self { inner, is_terminated }
353    }
354}
355
356impl futures::Stream for DeviceIdentificationRequestStream {
357    type Item = Result<DeviceIdentificationRequest, fidl::Error>;
358
359    fn poll_next(
360        mut self: std::pin::Pin<&mut Self>,
361        cx: &mut std::task::Context<'_>,
362    ) -> std::task::Poll<Option<Self::Item>> {
363        let this = &mut *self;
364        if this.inner.check_shutdown(cx) {
365            this.is_terminated = true;
366            return std::task::Poll::Ready(None);
367        }
368        if this.is_terminated {
369            panic!("polled DeviceIdentificationRequestStream after completion");
370        }
371        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
372            |bytes, handles| {
373                match this.inner.channel().read_etc(cx, bytes, handles) {
374                    std::task::Poll::Ready(Ok(())) => {}
375                    std::task::Poll::Pending => return std::task::Poll::Pending,
376                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
377                        this.is_terminated = true;
378                        return std::task::Poll::Ready(None);
379                    }
380                    std::task::Poll::Ready(Err(e)) => {
381                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
382                            e.into(),
383                        ))));
384                    }
385                }
386
387                // A message has been received from the channel
388                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
389
390                std::task::Poll::Ready(Some(match header.ordinal {
391                0x12ada3cb3fbcbd0a => {
392                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
393                    let mut req = fidl::new_empty!(DeviceIdentificationSetDeviceIdentificationRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
394                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceIdentificationSetDeviceIdentificationRequest>(&header, _body_bytes, handles, &mut req)?;
395                    let control_handle = DeviceIdentificationControlHandle {
396                        inner: this.inner.clone(),
397                    };
398                    Ok(DeviceIdentificationRequest::SetDeviceIdentification {records: req.records,
399token: req.token,
400
401                        responder: DeviceIdentificationSetDeviceIdentificationResponder {
402                            control_handle: std::mem::ManuallyDrop::new(control_handle),
403                            tx_id: header.tx_id,
404                        },
405                    })
406                }
407                _ => Err(fidl::Error::UnknownOrdinal {
408                    ordinal: header.ordinal,
409                    protocol_name: <DeviceIdentificationMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
410                }),
411            }))
412            },
413        )
414    }
415}
416
417/// An interface for setting the identification of a Fuchsia device.
418#[derive(Debug)]
419pub enum DeviceIdentificationRequest {
420    /// Request to set the device information to be advertised over Bluetooth.
421    ///
422    /// The device information can only be set once per provided `token`. To cancel the request,
423    /// close the `token` with any epitaph.
424    ///
425    /// At most one record in `records` may be denoted as the `primary` record. If multiple records
426    /// have `primary` set, `ZX_ERR_INVALID_ARGS` will be returned.
427    /// If the server is already advertising a `primary` record, a subsequent request with `primary`
428    /// may be rejected with `ZX_ERR_ALREADY_EXISTS`.
429    ///
430    /// + request `records` is the set of device information records that identify the device.
431    /// + request `token` is used to manage the lifetime of the advertised device information.
432    ///           The `records` will remain advertised as long as the channel is open.
433    ///           The device identification advertisement will be removed when `token` is closed
434    ///           with any epitaph.
435    /// - response An empty response will be sent when the `token` has been closed and the server
436    ///            has processed the closure.
437    /// * error Returns `ZX_ERR_INVALID_ARGS` if any of the provided `records` are invalidly
438    ///         formatted.
439    /// * error Returns `ZX_ERR_NO_RESOURCES` if the server has reached the maximum number of
440    ///         device information advertisements.
441    /// * error Returns `ZX_ERR_CANCELLED` if the request was cancelled by the server for all other
442    ///         errors.
443    SetDeviceIdentification {
444        records: Vec<DeviceIdentificationRecord>,
445        token: fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
446        responder: DeviceIdentificationSetDeviceIdentificationResponder,
447    },
448}
449
450impl DeviceIdentificationRequest {
451    #[allow(irrefutable_let_patterns)]
452    pub fn into_set_device_identification(
453        self,
454    ) -> Option<(
455        Vec<DeviceIdentificationRecord>,
456        fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
457        DeviceIdentificationSetDeviceIdentificationResponder,
458    )> {
459        if let DeviceIdentificationRequest::SetDeviceIdentification { records, token, responder } =
460            self
461        {
462            Some((records, token, responder))
463        } else {
464            None
465        }
466    }
467
468    /// Name of the method defined in FIDL
469    pub fn method_name(&self) -> &'static str {
470        match *self {
471            DeviceIdentificationRequest::SetDeviceIdentification { .. } => {
472                "set_device_identification"
473            }
474        }
475    }
476}
477
478#[derive(Debug, Clone)]
479pub struct DeviceIdentificationControlHandle {
480    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
481}
482
483impl DeviceIdentificationControlHandle {
484    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
485        self.inner.shutdown_with_epitaph(status.into())
486    }
487}
488
489impl fidl::endpoints::ControlHandle for DeviceIdentificationControlHandle {
490    fn shutdown(&self) {
491        self.inner.shutdown()
492    }
493
494    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
495        self.inner.shutdown_with_epitaph(status)
496    }
497
498    fn is_closed(&self) -> bool {
499        self.inner.channel().is_closed()
500    }
501    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
502        self.inner.channel().on_closed()
503    }
504
505    #[cfg(target_os = "fuchsia")]
506    fn signal_peer(
507        &self,
508        clear_mask: zx::Signals,
509        set_mask: zx::Signals,
510    ) -> Result<(), zx_status::Status> {
511        use fidl::Peered;
512        self.inner.channel().signal_peer(clear_mask, set_mask)
513    }
514}
515
516impl DeviceIdentificationControlHandle {}
517
518#[must_use = "FIDL methods require a response to be sent"]
519#[derive(Debug)]
520pub struct DeviceIdentificationSetDeviceIdentificationResponder {
521    control_handle: std::mem::ManuallyDrop<DeviceIdentificationControlHandle>,
522    tx_id: u32,
523}
524
525/// Set the the channel to be shutdown (see [`DeviceIdentificationControlHandle::shutdown`])
526/// if the responder is dropped without sending a response, so that the client
527/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
528impl std::ops::Drop for DeviceIdentificationSetDeviceIdentificationResponder {
529    fn drop(&mut self) {
530        self.control_handle.shutdown();
531        // Safety: drops once, never accessed again
532        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
533    }
534}
535
536impl fidl::endpoints::Responder for DeviceIdentificationSetDeviceIdentificationResponder {
537    type ControlHandle = DeviceIdentificationControlHandle;
538
539    fn control_handle(&self) -> &DeviceIdentificationControlHandle {
540        &self.control_handle
541    }
542
543    fn drop_without_shutdown(mut self) {
544        // Safety: drops once, never accessed again due to mem::forget
545        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
546        // Prevent Drop from running (which would shut down the channel)
547        std::mem::forget(self);
548    }
549}
550
551impl DeviceIdentificationSetDeviceIdentificationResponder {
552    /// Sends a response to the FIDL transaction.
553    ///
554    /// Sets the channel to shutdown if an error occurs.
555    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
556        let _result = self.send_raw(result);
557        if _result.is_err() {
558            self.control_handle.shutdown();
559        }
560        self.drop_without_shutdown();
561        _result
562    }
563
564    /// Similar to "send" but does not shutdown the channel if an error occurs.
565    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
566        let _result = self.send_raw(result);
567        self.drop_without_shutdown();
568        _result
569    }
570
571    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
572        self.control_handle
573            .inner
574            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
575                result,
576                self.tx_id,
577                0x12ada3cb3fbcbd0a,
578                fidl::encoding::DynamicFlags::empty(),
579            )
580    }
581}
582
583#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
584pub struct DeviceIdentificationHandleMarker;
585
586impl fidl::endpoints::ProtocolMarker for DeviceIdentificationHandleMarker {
587    type Proxy = DeviceIdentificationHandleProxy;
588    type RequestStream = DeviceIdentificationHandleRequestStream;
589    #[cfg(target_os = "fuchsia")]
590    type SynchronousProxy = DeviceIdentificationHandleSynchronousProxy;
591
592    const DEBUG_NAME: &'static str = "(anonymous) DeviceIdentificationHandle";
593}
594
595pub trait DeviceIdentificationHandleProxyInterface: Send + Sync {}
596#[derive(Debug)]
597#[cfg(target_os = "fuchsia")]
598pub struct DeviceIdentificationHandleSynchronousProxy {
599    client: fidl::client::sync::Client,
600}
601
602#[cfg(target_os = "fuchsia")]
603impl fidl::endpoints::SynchronousProxy for DeviceIdentificationHandleSynchronousProxy {
604    type Proxy = DeviceIdentificationHandleProxy;
605    type Protocol = DeviceIdentificationHandleMarker;
606
607    fn from_channel(inner: fidl::Channel) -> Self {
608        Self::new(inner)
609    }
610
611    fn into_channel(self) -> fidl::Channel {
612        self.client.into_channel()
613    }
614
615    fn as_channel(&self) -> &fidl::Channel {
616        self.client.as_channel()
617    }
618}
619
620#[cfg(target_os = "fuchsia")]
621impl DeviceIdentificationHandleSynchronousProxy {
622    pub fn new(channel: fidl::Channel) -> Self {
623        Self { client: fidl::client::sync::Client::new(channel) }
624    }
625
626    pub fn into_channel(self) -> fidl::Channel {
627        self.client.into_channel()
628    }
629
630    /// Waits until an event arrives and returns it. It is safe for other
631    /// threads to make concurrent requests while waiting for an event.
632    pub fn wait_for_event(
633        &self,
634        deadline: zx::MonotonicInstant,
635    ) -> Result<DeviceIdentificationHandleEvent, fidl::Error> {
636        DeviceIdentificationHandleEvent::decode(
637            self.client.wait_for_event::<DeviceIdentificationHandleMarker>(deadline)?,
638        )
639    }
640}
641
642#[cfg(target_os = "fuchsia")]
643impl From<DeviceIdentificationHandleSynchronousProxy> for zx::NullableHandle {
644    fn from(value: DeviceIdentificationHandleSynchronousProxy) -> Self {
645        value.into_channel().into()
646    }
647}
648
649#[cfg(target_os = "fuchsia")]
650impl From<fidl::Channel> for DeviceIdentificationHandleSynchronousProxy {
651    fn from(value: fidl::Channel) -> Self {
652        Self::new(value)
653    }
654}
655
656#[cfg(target_os = "fuchsia")]
657impl fidl::endpoints::FromClient for DeviceIdentificationHandleSynchronousProxy {
658    type Protocol = DeviceIdentificationHandleMarker;
659
660    fn from_client(value: fidl::endpoints::ClientEnd<DeviceIdentificationHandleMarker>) -> Self {
661        Self::new(value.into_channel())
662    }
663}
664
665#[derive(Debug, Clone)]
666pub struct DeviceIdentificationHandleProxy {
667    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
668}
669
670impl fidl::endpoints::Proxy for DeviceIdentificationHandleProxy {
671    type Protocol = DeviceIdentificationHandleMarker;
672
673    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
674        Self::new(inner)
675    }
676
677    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
678        self.client.into_channel().map_err(|client| Self { client })
679    }
680
681    fn as_channel(&self) -> &::fidl::AsyncChannel {
682        self.client.as_channel()
683    }
684}
685
686impl DeviceIdentificationHandleProxy {
687    /// Create a new Proxy for fuchsia.bluetooth.deviceid/DeviceIdentificationHandle.
688    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
689        let protocol_name =
690            <DeviceIdentificationHandleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
691        Self { client: fidl::client::Client::new(channel, protocol_name) }
692    }
693
694    /// Get a Stream of events from the remote end of the protocol.
695    ///
696    /// # Panics
697    ///
698    /// Panics if the event stream was already taken.
699    pub fn take_event_stream(&self) -> DeviceIdentificationHandleEventStream {
700        DeviceIdentificationHandleEventStream { event_receiver: self.client.take_event_receiver() }
701    }
702}
703
704impl DeviceIdentificationHandleProxyInterface for DeviceIdentificationHandleProxy {}
705
706pub struct DeviceIdentificationHandleEventStream {
707    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
708}
709
710impl std::marker::Unpin for DeviceIdentificationHandleEventStream {}
711
712impl futures::stream::FusedStream for DeviceIdentificationHandleEventStream {
713    fn is_terminated(&self) -> bool {
714        self.event_receiver.is_terminated()
715    }
716}
717
718impl futures::Stream for DeviceIdentificationHandleEventStream {
719    type Item = Result<DeviceIdentificationHandleEvent, fidl::Error>;
720
721    fn poll_next(
722        mut self: std::pin::Pin<&mut Self>,
723        cx: &mut std::task::Context<'_>,
724    ) -> std::task::Poll<Option<Self::Item>> {
725        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
726            &mut self.event_receiver,
727            cx
728        )?) {
729            Some(buf) => std::task::Poll::Ready(Some(DeviceIdentificationHandleEvent::decode(buf))),
730            None => std::task::Poll::Ready(None),
731        }
732    }
733}
734
735#[derive(Debug)]
736pub enum DeviceIdentificationHandleEvent {}
737
738impl DeviceIdentificationHandleEvent {
739    /// Decodes a message buffer as a [`DeviceIdentificationHandleEvent`].
740    fn decode(
741        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
742    ) -> Result<DeviceIdentificationHandleEvent, fidl::Error> {
743        let (bytes, _handles) = buf.split_mut();
744        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
745        debug_assert_eq!(tx_header.tx_id, 0);
746        match tx_header.ordinal {
747            _ => Err(fidl::Error::UnknownOrdinal {
748                ordinal: tx_header.ordinal,
749                protocol_name: <DeviceIdentificationHandleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
750            })
751        }
752    }
753}
754
755/// A Stream of incoming requests for fuchsia.bluetooth.deviceid/DeviceIdentificationHandle.
756pub struct DeviceIdentificationHandleRequestStream {
757    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
758    is_terminated: bool,
759}
760
761impl std::marker::Unpin for DeviceIdentificationHandleRequestStream {}
762
763impl futures::stream::FusedStream for DeviceIdentificationHandleRequestStream {
764    fn is_terminated(&self) -> bool {
765        self.is_terminated
766    }
767}
768
769impl fidl::endpoints::RequestStream for DeviceIdentificationHandleRequestStream {
770    type Protocol = DeviceIdentificationHandleMarker;
771    type ControlHandle = DeviceIdentificationHandleControlHandle;
772
773    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
774        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
775    }
776
777    fn control_handle(&self) -> Self::ControlHandle {
778        DeviceIdentificationHandleControlHandle { inner: self.inner.clone() }
779    }
780
781    fn into_inner(
782        self,
783    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
784    {
785        (self.inner, self.is_terminated)
786    }
787
788    fn from_inner(
789        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
790        is_terminated: bool,
791    ) -> Self {
792        Self { inner, is_terminated }
793    }
794}
795
796impl futures::Stream for DeviceIdentificationHandleRequestStream {
797    type Item = Result<DeviceIdentificationHandleRequest, fidl::Error>;
798
799    fn poll_next(
800        mut self: std::pin::Pin<&mut Self>,
801        cx: &mut std::task::Context<'_>,
802    ) -> std::task::Poll<Option<Self::Item>> {
803        let this = &mut *self;
804        if this.inner.check_shutdown(cx) {
805            this.is_terminated = true;
806            return std::task::Poll::Ready(None);
807        }
808        if this.is_terminated {
809            panic!("polled DeviceIdentificationHandleRequestStream after completion");
810        }
811        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
812            |bytes, handles| {
813                match this.inner.channel().read_etc(cx, bytes, handles) {
814                    std::task::Poll::Ready(Ok(())) => {}
815                    std::task::Poll::Pending => return std::task::Poll::Pending,
816                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
817                        this.is_terminated = true;
818                        return std::task::Poll::Ready(None);
819                    }
820                    std::task::Poll::Ready(Err(e)) => {
821                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
822                            e.into(),
823                        ))));
824                    }
825                }
826
827                // A message has been received from the channel
828                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
829
830                std::task::Poll::Ready(Some(match header.ordinal {
831                _ => Err(fidl::Error::UnknownOrdinal {
832                    ordinal: header.ordinal,
833                    protocol_name: <DeviceIdentificationHandleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
834                }),
835            }))
836            },
837        )
838    }
839}
840
841/// Represents an active device identification advertisement. Close the handle with any epitaph to
842/// unregister the device identification request.
843#[derive(Debug)]
844pub enum DeviceIdentificationHandleRequest {}
845
846impl DeviceIdentificationHandleRequest {
847    /// Name of the method defined in FIDL
848    pub fn method_name(&self) -> &'static str {
849        match *self {}
850    }
851}
852
853#[derive(Debug, Clone)]
854pub struct DeviceIdentificationHandleControlHandle {
855    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
856}
857
858impl DeviceIdentificationHandleControlHandle {
859    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
860        self.inner.shutdown_with_epitaph(status.into())
861    }
862}
863
864impl fidl::endpoints::ControlHandle for DeviceIdentificationHandleControlHandle {
865    fn shutdown(&self) {
866        self.inner.shutdown()
867    }
868
869    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
870        self.inner.shutdown_with_epitaph(status)
871    }
872
873    fn is_closed(&self) -> bool {
874        self.inner.channel().is_closed()
875    }
876    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
877        self.inner.channel().on_closed()
878    }
879
880    #[cfg(target_os = "fuchsia")]
881    fn signal_peer(
882        &self,
883        clear_mask: zx::Signals,
884        set_mask: zx::Signals,
885    ) -> Result<(), zx_status::Status> {
886        use fidl::Peered;
887        self.inner.channel().signal_peer(clear_mask, set_mask)
888    }
889}
890
891impl DeviceIdentificationHandleControlHandle {}
892
893mod internal {
894    use super::*;
895
896    impl fidl::encoding::ResourceTypeMarker for DeviceIdentificationSetDeviceIdentificationRequest {
897        type Borrowed<'a> = &'a mut Self;
898        fn take_or_borrow<'a>(
899            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
900        ) -> Self::Borrowed<'a> {
901            value
902        }
903    }
904
905    unsafe impl fidl::encoding::TypeMarker for DeviceIdentificationSetDeviceIdentificationRequest {
906        type Owned = Self;
907
908        #[inline(always)]
909        fn inline_align(_context: fidl::encoding::Context) -> usize {
910            8
911        }
912
913        #[inline(always)]
914        fn inline_size(_context: fidl::encoding::Context) -> usize {
915            24
916        }
917    }
918
919    unsafe impl
920        fidl::encoding::Encode<
921            DeviceIdentificationSetDeviceIdentificationRequest,
922            fidl::encoding::DefaultFuchsiaResourceDialect,
923        > for &mut DeviceIdentificationSetDeviceIdentificationRequest
924    {
925        #[inline]
926        unsafe fn encode(
927            self,
928            encoder: &mut fidl::encoding::Encoder<
929                '_,
930                fidl::encoding::DefaultFuchsiaResourceDialect,
931            >,
932            offset: usize,
933            _depth: fidl::encoding::Depth,
934        ) -> fidl::Result<()> {
935            encoder
936                .debug_check_bounds::<DeviceIdentificationSetDeviceIdentificationRequest>(offset);
937            // Delegate to tuple encoding.
938            fidl::encoding::Encode::<DeviceIdentificationSetDeviceIdentificationRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
939                (
940                    <fidl::encoding::Vector<DeviceIdentificationRecord, 3> as fidl::encoding::ValueTypeMarker>::borrow(&self.records),
941                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.token),
942                ),
943                encoder, offset, _depth
944            )
945        }
946    }
947    unsafe impl<
948        T0: fidl::encoding::Encode<
949                fidl::encoding::Vector<DeviceIdentificationRecord, 3>,
950                fidl::encoding::DefaultFuchsiaResourceDialect,
951            >,
952        T1: fidl::encoding::Encode<
953                fidl::encoding::Endpoint<
954                    fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
955                >,
956                fidl::encoding::DefaultFuchsiaResourceDialect,
957            >,
958    >
959        fidl::encoding::Encode<
960            DeviceIdentificationSetDeviceIdentificationRequest,
961            fidl::encoding::DefaultFuchsiaResourceDialect,
962        > for (T0, T1)
963    {
964        #[inline]
965        unsafe fn encode(
966            self,
967            encoder: &mut fidl::encoding::Encoder<
968                '_,
969                fidl::encoding::DefaultFuchsiaResourceDialect,
970            >,
971            offset: usize,
972            depth: fidl::encoding::Depth,
973        ) -> fidl::Result<()> {
974            encoder
975                .debug_check_bounds::<DeviceIdentificationSetDeviceIdentificationRequest>(offset);
976            // Zero out padding regions. There's no need to apply masks
977            // because the unmasked parts will be overwritten by fields.
978            unsafe {
979                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
980                (ptr as *mut u64).write_unaligned(0);
981            }
982            // Write the fields.
983            self.0.encode(encoder, offset + 0, depth)?;
984            self.1.encode(encoder, offset + 16, depth)?;
985            Ok(())
986        }
987    }
988
989    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
990        for DeviceIdentificationSetDeviceIdentificationRequest
991    {
992        #[inline(always)]
993        fn new_empty() -> Self {
994            Self {
995                records: fidl::new_empty!(fidl::encoding::Vector<DeviceIdentificationRecord, 3>, fidl::encoding::DefaultFuchsiaResourceDialect),
996                token: fidl::new_empty!(
997                    fidl::encoding::Endpoint<
998                        fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
999                    >,
1000                    fidl::encoding::DefaultFuchsiaResourceDialect
1001                ),
1002            }
1003        }
1004
1005        #[inline]
1006        unsafe fn decode(
1007            &mut self,
1008            decoder: &mut fidl::encoding::Decoder<
1009                '_,
1010                fidl::encoding::DefaultFuchsiaResourceDialect,
1011            >,
1012            offset: usize,
1013            _depth: fidl::encoding::Depth,
1014        ) -> fidl::Result<()> {
1015            decoder.debug_check_bounds::<Self>(offset);
1016            // Verify that padding bytes are zero.
1017            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1018            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1019            let mask = 0xffffffff00000000u64;
1020            let maskedval = padval & mask;
1021            if maskedval != 0 {
1022                return Err(fidl::Error::NonZeroPadding {
1023                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1024                });
1025            }
1026            fidl::decode!(fidl::encoding::Vector<DeviceIdentificationRecord, 3>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.records, decoder, offset + 0, _depth)?;
1027            fidl::decode!(
1028                fidl::encoding::Endpoint<
1029                    fidl::endpoints::ServerEnd<DeviceIdentificationHandleMarker>,
1030                >,
1031                fidl::encoding::DefaultFuchsiaResourceDialect,
1032                &mut self.token,
1033                decoder,
1034                offset + 16,
1035                _depth
1036            )?;
1037            Ok(())
1038        }
1039    }
1040}