fidl_fuchsia_powermanager_driver_temperaturecontrol/
fidl_fuchsia_powermanager_driver_temperaturecontrol.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_powermanager_driver_temperaturecontrol_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceMarker {
18    type Proxy = DeviceProxy;
19    type RequestStream = DeviceRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DeviceSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "(anonymous) Device";
24}
25
26pub trait DeviceProxyInterface: Send + Sync {
27    type SetTemperatureCelsiusResponseFut: std::future::Future<Output = Result<i32, fidl::Error>>
28        + Send;
29    fn r#set_temperature_celsius(&self, temperature: f32)
30        -> Self::SetTemperatureCelsiusResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct DeviceSynchronousProxy {
35    client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
40    type Proxy = DeviceProxy;
41    type Protocol = DeviceMarker;
42
43    fn from_channel(inner: fidl::Channel) -> Self {
44        Self::new(inner)
45    }
46
47    fn into_channel(self) -> fidl::Channel {
48        self.client.into_channel()
49    }
50
51    fn as_channel(&self) -> &fidl::Channel {
52        self.client.as_channel()
53    }
54}
55
56#[cfg(target_os = "fuchsia")]
57impl DeviceSynchronousProxy {
58    pub fn new(channel: fidl::Channel) -> Self {
59        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
60        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
61    }
62
63    pub fn into_channel(self) -> fidl::Channel {
64        self.client.into_channel()
65    }
66
67    /// Waits until an event arrives and returns it. It is safe for other
68    /// threads to make concurrent requests while waiting for an event.
69    pub fn wait_for_event(
70        &self,
71        deadline: zx::MonotonicInstant,
72    ) -> Result<DeviceEvent, fidl::Error> {
73        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
74    }
75
76    /// Set the current temperature driver data in degrees Celsius.
77    pub fn r#set_temperature_celsius(
78        &self,
79        mut temperature: f32,
80        ___deadline: zx::MonotonicInstant,
81    ) -> Result<i32, fidl::Error> {
82        let _response = self
83            .client
84            .send_query::<DeviceSetTemperatureCelsiusRequest, DeviceSetTemperatureCelsiusResponse>(
85                (temperature,),
86                0x15b847f05a354b95,
87                fidl::encoding::DynamicFlags::empty(),
88                ___deadline,
89            )?;
90        Ok(_response.status)
91    }
92}
93
94#[derive(Debug, Clone)]
95pub struct DeviceProxy {
96    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
97}
98
99impl fidl::endpoints::Proxy for DeviceProxy {
100    type Protocol = DeviceMarker;
101
102    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
103        Self::new(inner)
104    }
105
106    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
107        self.client.into_channel().map_err(|client| Self { client })
108    }
109
110    fn as_channel(&self) -> &::fidl::AsyncChannel {
111        self.client.as_channel()
112    }
113}
114
115impl DeviceProxy {
116    /// Create a new Proxy for fuchsia.powermanager.driver.temperaturecontrol/Device.
117    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
118        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
119        Self { client: fidl::client::Client::new(channel, protocol_name) }
120    }
121
122    /// Get a Stream of events from the remote end of the protocol.
123    ///
124    /// # Panics
125    ///
126    /// Panics if the event stream was already taken.
127    pub fn take_event_stream(&self) -> DeviceEventStream {
128        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
129    }
130
131    /// Set the current temperature driver data in degrees Celsius.
132    pub fn r#set_temperature_celsius(
133        &self,
134        mut temperature: f32,
135    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
136        DeviceProxyInterface::r#set_temperature_celsius(self, temperature)
137    }
138}
139
140impl DeviceProxyInterface for DeviceProxy {
141    type SetTemperatureCelsiusResponseFut =
142        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
143    fn r#set_temperature_celsius(
144        &self,
145        mut temperature: f32,
146    ) -> Self::SetTemperatureCelsiusResponseFut {
147        fn _decode(
148            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
149        ) -> Result<i32, fidl::Error> {
150            let _response = fidl::client::decode_transaction_body::<
151                DeviceSetTemperatureCelsiusResponse,
152                fidl::encoding::DefaultFuchsiaResourceDialect,
153                0x15b847f05a354b95,
154            >(_buf?)?;
155            Ok(_response.status)
156        }
157        self.client.send_query_and_decode::<DeviceSetTemperatureCelsiusRequest, i32>(
158            (temperature,),
159            0x15b847f05a354b95,
160            fidl::encoding::DynamicFlags::empty(),
161            _decode,
162        )
163    }
164}
165
166pub struct DeviceEventStream {
167    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
168}
169
170impl std::marker::Unpin for DeviceEventStream {}
171
172impl futures::stream::FusedStream for DeviceEventStream {
173    fn is_terminated(&self) -> bool {
174        self.event_receiver.is_terminated()
175    }
176}
177
178impl futures::Stream for DeviceEventStream {
179    type Item = Result<DeviceEvent, fidl::Error>;
180
181    fn poll_next(
182        mut self: std::pin::Pin<&mut Self>,
183        cx: &mut std::task::Context<'_>,
184    ) -> std::task::Poll<Option<Self::Item>> {
185        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
186            &mut self.event_receiver,
187            cx
188        )?) {
189            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
190            None => std::task::Poll::Ready(None),
191        }
192    }
193}
194
195#[derive(Debug)]
196pub enum DeviceEvent {}
197
198impl DeviceEvent {
199    /// Decodes a message buffer as a [`DeviceEvent`].
200    fn decode(
201        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
202    ) -> Result<DeviceEvent, fidl::Error> {
203        let (bytes, _handles) = buf.split_mut();
204        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
205        debug_assert_eq!(tx_header.tx_id, 0);
206        match tx_header.ordinal {
207            _ => Err(fidl::Error::UnknownOrdinal {
208                ordinal: tx_header.ordinal,
209                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
210            }),
211        }
212    }
213}
214
215/// A Stream of incoming requests for fuchsia.powermanager.driver.temperaturecontrol/Device.
216pub struct DeviceRequestStream {
217    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
218    is_terminated: bool,
219}
220
221impl std::marker::Unpin for DeviceRequestStream {}
222
223impl futures::stream::FusedStream for DeviceRequestStream {
224    fn is_terminated(&self) -> bool {
225        self.is_terminated
226    }
227}
228
229impl fidl::endpoints::RequestStream for DeviceRequestStream {
230    type Protocol = DeviceMarker;
231    type ControlHandle = DeviceControlHandle;
232
233    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
234        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
235    }
236
237    fn control_handle(&self) -> Self::ControlHandle {
238        DeviceControlHandle { inner: self.inner.clone() }
239    }
240
241    fn into_inner(
242        self,
243    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
244    {
245        (self.inner, self.is_terminated)
246    }
247
248    fn from_inner(
249        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
250        is_terminated: bool,
251    ) -> Self {
252        Self { inner, is_terminated }
253    }
254}
255
256impl futures::Stream for DeviceRequestStream {
257    type Item = Result<DeviceRequest, fidl::Error>;
258
259    fn poll_next(
260        mut self: std::pin::Pin<&mut Self>,
261        cx: &mut std::task::Context<'_>,
262    ) -> std::task::Poll<Option<Self::Item>> {
263        let this = &mut *self;
264        if this.inner.check_shutdown(cx) {
265            this.is_terminated = true;
266            return std::task::Poll::Ready(None);
267        }
268        if this.is_terminated {
269            panic!("polled DeviceRequestStream after completion");
270        }
271        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
272            |bytes, handles| {
273                match this.inner.channel().read_etc(cx, bytes, handles) {
274                    std::task::Poll::Ready(Ok(())) => {}
275                    std::task::Poll::Pending => return std::task::Poll::Pending,
276                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
277                        this.is_terminated = true;
278                        return std::task::Poll::Ready(None);
279                    }
280                    std::task::Poll::Ready(Err(e)) => {
281                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
282                            e.into(),
283                        ))))
284                    }
285                }
286
287                // A message has been received from the channel
288                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
289
290                std::task::Poll::Ready(Some(match header.ordinal {
291                    0x15b847f05a354b95 => {
292                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
293                        let mut req = fidl::new_empty!(
294                            DeviceSetTemperatureCelsiusRequest,
295                            fidl::encoding::DefaultFuchsiaResourceDialect
296                        );
297                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetTemperatureCelsiusRequest>(&header, _body_bytes, handles, &mut req)?;
298                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
299                        Ok(DeviceRequest::SetTemperatureCelsius {
300                            temperature: req.temperature,
301
302                            responder: DeviceSetTemperatureCelsiusResponder {
303                                control_handle: std::mem::ManuallyDrop::new(control_handle),
304                                tx_id: header.tx_id,
305                            },
306                        })
307                    }
308                    _ => Err(fidl::Error::UnknownOrdinal {
309                        ordinal: header.ordinal,
310                        protocol_name:
311                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
312                    }),
313                }))
314            },
315        )
316    }
317}
318
319/// Device interface to allow modification of driver data.
320#[derive(Debug)]
321pub enum DeviceRequest {
322    /// Set the current temperature driver data in degrees Celsius.
323    SetTemperatureCelsius { temperature: f32, responder: DeviceSetTemperatureCelsiusResponder },
324}
325
326impl DeviceRequest {
327    #[allow(irrefutable_let_patterns)]
328    pub fn into_set_temperature_celsius(
329        self,
330    ) -> Option<(f32, DeviceSetTemperatureCelsiusResponder)> {
331        if let DeviceRequest::SetTemperatureCelsius { temperature, responder } = self {
332            Some((temperature, responder))
333        } else {
334            None
335        }
336    }
337
338    /// Name of the method defined in FIDL
339    pub fn method_name(&self) -> &'static str {
340        match *self {
341            DeviceRequest::SetTemperatureCelsius { .. } => "set_temperature_celsius",
342        }
343    }
344}
345
346#[derive(Debug, Clone)]
347pub struct DeviceControlHandle {
348    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
349}
350
351impl fidl::endpoints::ControlHandle for DeviceControlHandle {
352    fn shutdown(&self) {
353        self.inner.shutdown()
354    }
355    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
356        self.inner.shutdown_with_epitaph(status)
357    }
358
359    fn is_closed(&self) -> bool {
360        self.inner.channel().is_closed()
361    }
362    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
363        self.inner.channel().on_closed()
364    }
365
366    #[cfg(target_os = "fuchsia")]
367    fn signal_peer(
368        &self,
369        clear_mask: zx::Signals,
370        set_mask: zx::Signals,
371    ) -> Result<(), zx_status::Status> {
372        use fidl::Peered;
373        self.inner.channel().signal_peer(clear_mask, set_mask)
374    }
375}
376
377impl DeviceControlHandle {}
378
379#[must_use = "FIDL methods require a response to be sent"]
380#[derive(Debug)]
381pub struct DeviceSetTemperatureCelsiusResponder {
382    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
383    tx_id: u32,
384}
385
386/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
387/// if the responder is dropped without sending a response, so that the client
388/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
389impl std::ops::Drop for DeviceSetTemperatureCelsiusResponder {
390    fn drop(&mut self) {
391        self.control_handle.shutdown();
392        // Safety: drops once, never accessed again
393        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
394    }
395}
396
397impl fidl::endpoints::Responder for DeviceSetTemperatureCelsiusResponder {
398    type ControlHandle = DeviceControlHandle;
399
400    fn control_handle(&self) -> &DeviceControlHandle {
401        &self.control_handle
402    }
403
404    fn drop_without_shutdown(mut self) {
405        // Safety: drops once, never accessed again due to mem::forget
406        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
407        // Prevent Drop from running (which would shut down the channel)
408        std::mem::forget(self);
409    }
410}
411
412impl DeviceSetTemperatureCelsiusResponder {
413    /// Sends a response to the FIDL transaction.
414    ///
415    /// Sets the channel to shutdown if an error occurs.
416    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
417        let _result = self.send_raw(status);
418        if _result.is_err() {
419            self.control_handle.shutdown();
420        }
421        self.drop_without_shutdown();
422        _result
423    }
424
425    /// Similar to "send" but does not shutdown the channel if an error occurs.
426    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
427        let _result = self.send_raw(status);
428        self.drop_without_shutdown();
429        _result
430    }
431
432    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
433        self.control_handle.inner.send::<DeviceSetTemperatureCelsiusResponse>(
434            (status,),
435            self.tx_id,
436            0x15b847f05a354b95,
437            fidl::encoding::DynamicFlags::empty(),
438        )
439    }
440}
441
442mod internal {
443    use super::*;
444}