Skip to main content

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