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