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