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