Skip to main content

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