fidl_fuchsia_power_manager_debug/
fidl_fuchsia_power_manager_debug.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_manager_debug_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DebugMarker;
16
17impl fidl::endpoints::ProtocolMarker for DebugMarker {
18    type Proxy = DebugProxy;
19    type RequestStream = DebugRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DebugSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.power.manager.debug.Debug";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DebugMarker {}
26pub type DebugMessageResult = Result<(), MessageError>;
27
28pub trait DebugProxyInterface: Send + Sync {
29    type MessageResponseFut: std::future::Future<Output = Result<DebugMessageResult, fidl::Error>>
30        + Send;
31    fn r#message(
32        &self,
33        node_name: &str,
34        command: &str,
35        args: &[String],
36    ) -> Self::MessageResponseFut;
37}
38#[derive(Debug)]
39#[cfg(target_os = "fuchsia")]
40pub struct DebugSynchronousProxy {
41    client: fidl::client::sync::Client,
42}
43
44#[cfg(target_os = "fuchsia")]
45impl fidl::endpoints::SynchronousProxy for DebugSynchronousProxy {
46    type Proxy = DebugProxy;
47    type Protocol = DebugMarker;
48
49    fn from_channel(inner: fidl::Channel) -> Self {
50        Self::new(inner)
51    }
52
53    fn into_channel(self) -> fidl::Channel {
54        self.client.into_channel()
55    }
56
57    fn as_channel(&self) -> &fidl::Channel {
58        self.client.as_channel()
59    }
60}
61
62#[cfg(target_os = "fuchsia")]
63impl DebugSynchronousProxy {
64    pub fn new(channel: fidl::Channel) -> Self {
65        let protocol_name = <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
66        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
67    }
68
69    pub fn into_channel(self) -> fidl::Channel {
70        self.client.into_channel()
71    }
72
73    /// Waits until an event arrives and returns it. It is safe for other
74    /// threads to make concurrent requests while waiting for an event.
75    pub fn wait_for_event(
76        &self,
77        deadline: zx::MonotonicInstant,
78    ) -> Result<DebugEvent, fidl::Error> {
79        DebugEvent::decode(self.client.wait_for_event(deadline)?)
80    }
81
82    /// Sends a debug message to the specified Power Manager node.
83    ///
84    /// + `node_name` is the name of the Power Manager node to message. A list
85    ///   of node names for a given device can be found in the device-specific
86    ///   node config file [here](/src/power/power-manager/node_config/).
87    /// + `command` is the node-specific command to be sent to the specified
88    ///   node. The supported commands for a given node can be found by
89    ///   inspecting that node's source.
90    /// + `args` is a vector of arguments to be sent that may be required by the
91    ///   node to execute the command.
92    ///
93    /// For example, to override the SOC temperature to 40C on Astro (according
94    /// to the current [node
95    /// configuration](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/power/power-manager/node_config/astro_node_config.json;l=58;drc=2cd2c555e5d2f0371e36bdca70ed4ba92635cb86)
96    /// and `TemperatureHandler` [implementation](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/power/power-manager/src/temperature_handler.rs;drc=f6e405ca555f5e5ab575d421e84b721684ba41fa):
97    ///
98    ///     ```
99    ///     Message(
100    ///         "temperature_soc_pll",
101    ///         "set_temperature",
102    ///         [ "40" ]
103    ///     )
104    ///     ```
105    pub fn r#message(
106        &self,
107        mut node_name: &str,
108        mut command: &str,
109        mut args: &[String],
110        ___deadline: zx::MonotonicInstant,
111    ) -> Result<DebugMessageResult, fidl::Error> {
112        let _response = self.client.send_query::<DebugMessageRequest, fidl::encoding::ResultType<
113            fidl::encoding::EmptyStruct,
114            MessageError,
115        >>(
116            (node_name, command, args),
117            0x3a1d992128e015da,
118            fidl::encoding::DynamicFlags::empty(),
119            ___deadline,
120        )?;
121        Ok(_response.map(|x| x))
122    }
123}
124
125#[derive(Debug, Clone)]
126pub struct DebugProxy {
127    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
128}
129
130impl fidl::endpoints::Proxy for DebugProxy {
131    type Protocol = DebugMarker;
132
133    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
134        Self::new(inner)
135    }
136
137    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
138        self.client.into_channel().map_err(|client| Self { client })
139    }
140
141    fn as_channel(&self) -> &::fidl::AsyncChannel {
142        self.client.as_channel()
143    }
144}
145
146impl DebugProxy {
147    /// Create a new Proxy for fuchsia.power.manager.debug/Debug.
148    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
149        let protocol_name = <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
150        Self { client: fidl::client::Client::new(channel, protocol_name) }
151    }
152
153    /// Get a Stream of events from the remote end of the protocol.
154    ///
155    /// # Panics
156    ///
157    /// Panics if the event stream was already taken.
158    pub fn take_event_stream(&self) -> DebugEventStream {
159        DebugEventStream { event_receiver: self.client.take_event_receiver() }
160    }
161
162    /// Sends a debug message to the specified Power Manager node.
163    ///
164    /// + `node_name` is the name of the Power Manager node to message. A list
165    ///   of node names for a given device can be found in the device-specific
166    ///   node config file [here](/src/power/power-manager/node_config/).
167    /// + `command` is the node-specific command to be sent to the specified
168    ///   node. The supported commands for a given node can be found by
169    ///   inspecting that node's source.
170    /// + `args` is a vector of arguments to be sent that may be required by the
171    ///   node to execute the command.
172    ///
173    /// For example, to override the SOC temperature to 40C on Astro (according
174    /// to the current [node
175    /// configuration](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/power/power-manager/node_config/astro_node_config.json;l=58;drc=2cd2c555e5d2f0371e36bdca70ed4ba92635cb86)
176    /// and `TemperatureHandler` [implementation](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/power/power-manager/src/temperature_handler.rs;drc=f6e405ca555f5e5ab575d421e84b721684ba41fa):
177    ///
178    ///     ```
179    ///     Message(
180    ///         "temperature_soc_pll",
181    ///         "set_temperature",
182    ///         [ "40" ]
183    ///     )
184    ///     ```
185    pub fn r#message(
186        &self,
187        mut node_name: &str,
188        mut command: &str,
189        mut args: &[String],
190    ) -> fidl::client::QueryResponseFut<
191        DebugMessageResult,
192        fidl::encoding::DefaultFuchsiaResourceDialect,
193    > {
194        DebugProxyInterface::r#message(self, node_name, command, args)
195    }
196}
197
198impl DebugProxyInterface for DebugProxy {
199    type MessageResponseFut = fidl::client::QueryResponseFut<
200        DebugMessageResult,
201        fidl::encoding::DefaultFuchsiaResourceDialect,
202    >;
203    fn r#message(
204        &self,
205        mut node_name: &str,
206        mut command: &str,
207        mut args: &[String],
208    ) -> Self::MessageResponseFut {
209        fn _decode(
210            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
211        ) -> Result<DebugMessageResult, fidl::Error> {
212            let _response = fidl::client::decode_transaction_body::<
213                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, MessageError>,
214                fidl::encoding::DefaultFuchsiaResourceDialect,
215                0x3a1d992128e015da,
216            >(_buf?)?;
217            Ok(_response.map(|x| x))
218        }
219        self.client.send_query_and_decode::<DebugMessageRequest, DebugMessageResult>(
220            (node_name, command, args),
221            0x3a1d992128e015da,
222            fidl::encoding::DynamicFlags::empty(),
223            _decode,
224        )
225    }
226}
227
228pub struct DebugEventStream {
229    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
230}
231
232impl std::marker::Unpin for DebugEventStream {}
233
234impl futures::stream::FusedStream for DebugEventStream {
235    fn is_terminated(&self) -> bool {
236        self.event_receiver.is_terminated()
237    }
238}
239
240impl futures::Stream for DebugEventStream {
241    type Item = Result<DebugEvent, fidl::Error>;
242
243    fn poll_next(
244        mut self: std::pin::Pin<&mut Self>,
245        cx: &mut std::task::Context<'_>,
246    ) -> std::task::Poll<Option<Self::Item>> {
247        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
248            &mut self.event_receiver,
249            cx
250        )?) {
251            Some(buf) => std::task::Poll::Ready(Some(DebugEvent::decode(buf))),
252            None => std::task::Poll::Ready(None),
253        }
254    }
255}
256
257#[derive(Debug)]
258pub enum DebugEvent {}
259
260impl DebugEvent {
261    /// Decodes a message buffer as a [`DebugEvent`].
262    fn decode(
263        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
264    ) -> Result<DebugEvent, fidl::Error> {
265        let (bytes, _handles) = buf.split_mut();
266        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
267        debug_assert_eq!(tx_header.tx_id, 0);
268        match tx_header.ordinal {
269            _ => Err(fidl::Error::UnknownOrdinal {
270                ordinal: tx_header.ordinal,
271                protocol_name: <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
272            }),
273        }
274    }
275}
276
277/// A Stream of incoming requests for fuchsia.power.manager.debug/Debug.
278pub struct DebugRequestStream {
279    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
280    is_terminated: bool,
281}
282
283impl std::marker::Unpin for DebugRequestStream {}
284
285impl futures::stream::FusedStream for DebugRequestStream {
286    fn is_terminated(&self) -> bool {
287        self.is_terminated
288    }
289}
290
291impl fidl::endpoints::RequestStream for DebugRequestStream {
292    type Protocol = DebugMarker;
293    type ControlHandle = DebugControlHandle;
294
295    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
296        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
297    }
298
299    fn control_handle(&self) -> Self::ControlHandle {
300        DebugControlHandle { inner: self.inner.clone() }
301    }
302
303    fn into_inner(
304        self,
305    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
306    {
307        (self.inner, self.is_terminated)
308    }
309
310    fn from_inner(
311        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
312        is_terminated: bool,
313    ) -> Self {
314        Self { inner, is_terminated }
315    }
316}
317
318impl futures::Stream for DebugRequestStream {
319    type Item = Result<DebugRequest, fidl::Error>;
320
321    fn poll_next(
322        mut self: std::pin::Pin<&mut Self>,
323        cx: &mut std::task::Context<'_>,
324    ) -> std::task::Poll<Option<Self::Item>> {
325        let this = &mut *self;
326        if this.inner.check_shutdown(cx) {
327            this.is_terminated = true;
328            return std::task::Poll::Ready(None);
329        }
330        if this.is_terminated {
331            panic!("polled DebugRequestStream after completion");
332        }
333        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
334            |bytes, handles| {
335                match this.inner.channel().read_etc(cx, bytes, handles) {
336                    std::task::Poll::Ready(Ok(())) => {}
337                    std::task::Poll::Pending => return std::task::Poll::Pending,
338                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
339                        this.is_terminated = true;
340                        return std::task::Poll::Ready(None);
341                    }
342                    std::task::Poll::Ready(Err(e)) => {
343                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
344                            e.into(),
345                        ))))
346                    }
347                }
348
349                // A message has been received from the channel
350                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
351
352                std::task::Poll::Ready(Some(match header.ordinal {
353                    0x3a1d992128e015da => {
354                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
355                        let mut req = fidl::new_empty!(
356                            DebugMessageRequest,
357                            fidl::encoding::DefaultFuchsiaResourceDialect
358                        );
359                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DebugMessageRequest>(&header, _body_bytes, handles, &mut req)?;
360                        let control_handle = DebugControlHandle { inner: this.inner.clone() };
361                        Ok(DebugRequest::Message {
362                            node_name: req.node_name,
363                            command: req.command,
364                            args: req.args,
365
366                            responder: DebugMessageResponder {
367                                control_handle: std::mem::ManuallyDrop::new(control_handle),
368                                tx_id: header.tx_id,
369                            },
370                        })
371                    }
372                    _ => Err(fidl::Error::UnknownOrdinal {
373                        ordinal: header.ordinal,
374                        protocol_name: <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
375                    }),
376                }))
377            },
378        )
379    }
380}
381
382/// Exposes a debug control interface to the Power Manager.
383#[derive(Debug)]
384pub enum DebugRequest {
385    /// Sends a debug message to the specified Power Manager node.
386    ///
387    /// + `node_name` is the name of the Power Manager node to message. A list
388    ///   of node names for a given device can be found in the device-specific
389    ///   node config file [here](/src/power/power-manager/node_config/).
390    /// + `command` is the node-specific command to be sent to the specified
391    ///   node. The supported commands for a given node can be found by
392    ///   inspecting that node's source.
393    /// + `args` is a vector of arguments to be sent that may be required by the
394    ///   node to execute the command.
395    ///
396    /// For example, to override the SOC temperature to 40C on Astro (according
397    /// to the current [node
398    /// configuration](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/power/power-manager/node_config/astro_node_config.json;l=58;drc=2cd2c555e5d2f0371e36bdca70ed4ba92635cb86)
399    /// and `TemperatureHandler` [implementation](https://cs.opensource.google/fuchsia/fuchsia/+/main:src/power/power-manager/src/temperature_handler.rs;drc=f6e405ca555f5e5ab575d421e84b721684ba41fa):
400    ///
401    ///     ```
402    ///     Message(
403    ///         "temperature_soc_pll",
404    ///         "set_temperature",
405    ///         [ "40" ]
406    ///     )
407    ///     ```
408    Message {
409        node_name: String,
410        command: String,
411        args: Vec<String>,
412        responder: DebugMessageResponder,
413    },
414}
415
416impl DebugRequest {
417    #[allow(irrefutable_let_patterns)]
418    pub fn into_message(self) -> Option<(String, String, Vec<String>, DebugMessageResponder)> {
419        if let DebugRequest::Message { node_name, command, args, responder } = self {
420            Some((node_name, command, args, responder))
421        } else {
422            None
423        }
424    }
425
426    /// Name of the method defined in FIDL
427    pub fn method_name(&self) -> &'static str {
428        match *self {
429            DebugRequest::Message { .. } => "message",
430        }
431    }
432}
433
434#[derive(Debug, Clone)]
435pub struct DebugControlHandle {
436    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
437}
438
439impl fidl::endpoints::ControlHandle for DebugControlHandle {
440    fn shutdown(&self) {
441        self.inner.shutdown()
442    }
443    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
444        self.inner.shutdown_with_epitaph(status)
445    }
446
447    fn is_closed(&self) -> bool {
448        self.inner.channel().is_closed()
449    }
450    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
451        self.inner.channel().on_closed()
452    }
453
454    #[cfg(target_os = "fuchsia")]
455    fn signal_peer(
456        &self,
457        clear_mask: zx::Signals,
458        set_mask: zx::Signals,
459    ) -> Result<(), zx_status::Status> {
460        use fidl::Peered;
461        self.inner.channel().signal_peer(clear_mask, set_mask)
462    }
463}
464
465impl DebugControlHandle {}
466
467#[must_use = "FIDL methods require a response to be sent"]
468#[derive(Debug)]
469pub struct DebugMessageResponder {
470    control_handle: std::mem::ManuallyDrop<DebugControlHandle>,
471    tx_id: u32,
472}
473
474/// Set the the channel to be shutdown (see [`DebugControlHandle::shutdown`])
475/// if the responder is dropped without sending a response, so that the client
476/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
477impl std::ops::Drop for DebugMessageResponder {
478    fn drop(&mut self) {
479        self.control_handle.shutdown();
480        // Safety: drops once, never accessed again
481        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
482    }
483}
484
485impl fidl::endpoints::Responder for DebugMessageResponder {
486    type ControlHandle = DebugControlHandle;
487
488    fn control_handle(&self) -> &DebugControlHandle {
489        &self.control_handle
490    }
491
492    fn drop_without_shutdown(mut self) {
493        // Safety: drops once, never accessed again due to mem::forget
494        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
495        // Prevent Drop from running (which would shut down the channel)
496        std::mem::forget(self);
497    }
498}
499
500impl DebugMessageResponder {
501    /// Sends a response to the FIDL transaction.
502    ///
503    /// Sets the channel to shutdown if an error occurs.
504    pub fn send(self, mut result: Result<(), MessageError>) -> Result<(), fidl::Error> {
505        let _result = self.send_raw(result);
506        if _result.is_err() {
507            self.control_handle.shutdown();
508        }
509        self.drop_without_shutdown();
510        _result
511    }
512
513    /// Similar to "send" but does not shutdown the channel if an error occurs.
514    pub fn send_no_shutdown_on_err(
515        self,
516        mut result: Result<(), MessageError>,
517    ) -> Result<(), fidl::Error> {
518        let _result = self.send_raw(result);
519        self.drop_without_shutdown();
520        _result
521    }
522
523    fn send_raw(&self, mut result: Result<(), MessageError>) -> Result<(), fidl::Error> {
524        self.control_handle.inner.send::<fidl::encoding::ResultType<
525            fidl::encoding::EmptyStruct,
526            MessageError,
527        >>(
528            result,
529            self.tx_id,
530            0x3a1d992128e015da,
531            fidl::encoding::DynamicFlags::empty(),
532        )
533    }
534}
535
536mod internal {
537    use super::*;
538}