Skip to main content

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