Skip to main content

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