fidl_fuchsia_power_suspend/
fidl_fuchsia_power_suspend.rs1#![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_suspend_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct StatsMarker;
16
17impl fidl::endpoints::ProtocolMarker for StatsMarker {
18 type Proxy = StatsProxy;
19 type RequestStream = StatsRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = StatsSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.power.suspend.Stats";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for StatsMarker {}
26
27pub trait StatsProxyInterface: Send + Sync {
28 type WatchResponseFut: std::future::Future<Output = Result<SuspendStats, fidl::Error>> + Send;
29 fn r#watch(&self) -> Self::WatchResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct StatsSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for StatsSynchronousProxy {
39 type Proxy = StatsProxy;
40 type Protocol = StatsMarker;
41
42 fn from_channel(inner: fidl::Channel) -> Self {
43 Self::new(inner)
44 }
45
46 fn into_channel(self) -> fidl::Channel {
47 self.client.into_channel()
48 }
49
50 fn as_channel(&self) -> &fidl::Channel {
51 self.client.as_channel()
52 }
53}
54
55#[cfg(target_os = "fuchsia")]
56impl StatsSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 let protocol_name = <StatsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
60 }
61
62 pub fn into_channel(self) -> fidl::Channel {
63 self.client.into_channel()
64 }
65
66 pub fn wait_for_event(
69 &self,
70 deadline: zx::MonotonicInstant,
71 ) -> Result<StatsEvent, fidl::Error> {
72 StatsEvent::decode(self.client.wait_for_event(deadline)?)
73 }
74
75 pub fn r#watch(&self, ___deadline: zx::MonotonicInstant) -> Result<SuspendStats, fidl::Error> {
81 let _response = self.client.send_query::<fidl::encoding::EmptyPayload, SuspendStats>(
82 (),
83 0x1c90507c87636a84,
84 fidl::encoding::DynamicFlags::empty(),
85 ___deadline,
86 )?;
87 Ok(_response)
88 }
89}
90
91#[derive(Debug, Clone)]
92pub struct StatsProxy {
93 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
94}
95
96impl fidl::endpoints::Proxy for StatsProxy {
97 type Protocol = StatsMarker;
98
99 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
100 Self::new(inner)
101 }
102
103 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
104 self.client.into_channel().map_err(|client| Self { client })
105 }
106
107 fn as_channel(&self) -> &::fidl::AsyncChannel {
108 self.client.as_channel()
109 }
110}
111
112impl StatsProxy {
113 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
115 let protocol_name = <StatsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
116 Self { client: fidl::client::Client::new(channel, protocol_name) }
117 }
118
119 pub fn take_event_stream(&self) -> StatsEventStream {
125 StatsEventStream { event_receiver: self.client.take_event_receiver() }
126 }
127
128 pub fn r#watch(
134 &self,
135 ) -> fidl::client::QueryResponseFut<SuspendStats, fidl::encoding::DefaultFuchsiaResourceDialect>
136 {
137 StatsProxyInterface::r#watch(self)
138 }
139}
140
141impl StatsProxyInterface for StatsProxy {
142 type WatchResponseFut =
143 fidl::client::QueryResponseFut<SuspendStats, fidl::encoding::DefaultFuchsiaResourceDialect>;
144 fn r#watch(&self) -> Self::WatchResponseFut {
145 fn _decode(
146 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
147 ) -> Result<SuspendStats, fidl::Error> {
148 let _response = fidl::client::decode_transaction_body::<
149 SuspendStats,
150 fidl::encoding::DefaultFuchsiaResourceDialect,
151 0x1c90507c87636a84,
152 >(_buf?)?;
153 Ok(_response)
154 }
155 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, SuspendStats>(
156 (),
157 0x1c90507c87636a84,
158 fidl::encoding::DynamicFlags::empty(),
159 _decode,
160 )
161 }
162}
163
164pub struct StatsEventStream {
165 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
166}
167
168impl std::marker::Unpin for StatsEventStream {}
169
170impl futures::stream::FusedStream for StatsEventStream {
171 fn is_terminated(&self) -> bool {
172 self.event_receiver.is_terminated()
173 }
174}
175
176impl futures::Stream for StatsEventStream {
177 type Item = Result<StatsEvent, fidl::Error>;
178
179 fn poll_next(
180 mut self: std::pin::Pin<&mut Self>,
181 cx: &mut std::task::Context<'_>,
182 ) -> std::task::Poll<Option<Self::Item>> {
183 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
184 &mut self.event_receiver,
185 cx
186 )?) {
187 Some(buf) => std::task::Poll::Ready(Some(StatsEvent::decode(buf))),
188 None => std::task::Poll::Ready(None),
189 }
190 }
191}
192
193#[derive(Debug)]
194pub enum StatsEvent {
195 #[non_exhaustive]
196 _UnknownEvent {
197 ordinal: u64,
199 },
200}
201
202impl StatsEvent {
203 fn decode(
205 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
206 ) -> Result<StatsEvent, fidl::Error> {
207 let (bytes, _handles) = buf.split_mut();
208 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
209 debug_assert_eq!(tx_header.tx_id, 0);
210 match tx_header.ordinal {
211 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
212 Ok(StatsEvent::_UnknownEvent { ordinal: tx_header.ordinal })
213 }
214 _ => Err(fidl::Error::UnknownOrdinal {
215 ordinal: tx_header.ordinal,
216 protocol_name: <StatsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
217 }),
218 }
219 }
220}
221
222pub struct StatsRequestStream {
224 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
225 is_terminated: bool,
226}
227
228impl std::marker::Unpin for StatsRequestStream {}
229
230impl futures::stream::FusedStream for StatsRequestStream {
231 fn is_terminated(&self) -> bool {
232 self.is_terminated
233 }
234}
235
236impl fidl::endpoints::RequestStream for StatsRequestStream {
237 type Protocol = StatsMarker;
238 type ControlHandle = StatsControlHandle;
239
240 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
241 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
242 }
243
244 fn control_handle(&self) -> Self::ControlHandle {
245 StatsControlHandle { inner: self.inner.clone() }
246 }
247
248 fn into_inner(
249 self,
250 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
251 {
252 (self.inner, self.is_terminated)
253 }
254
255 fn from_inner(
256 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
257 is_terminated: bool,
258 ) -> Self {
259 Self { inner, is_terminated }
260 }
261}
262
263impl futures::Stream for StatsRequestStream {
264 type Item = Result<StatsRequest, fidl::Error>;
265
266 fn poll_next(
267 mut self: std::pin::Pin<&mut Self>,
268 cx: &mut std::task::Context<'_>,
269 ) -> std::task::Poll<Option<Self::Item>> {
270 let this = &mut *self;
271 if this.inner.check_shutdown(cx) {
272 this.is_terminated = true;
273 return std::task::Poll::Ready(None);
274 }
275 if this.is_terminated {
276 panic!("polled StatsRequestStream after completion");
277 }
278 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
279 |bytes, handles| {
280 match this.inner.channel().read_etc(cx, bytes, handles) {
281 std::task::Poll::Ready(Ok(())) => {}
282 std::task::Poll::Pending => return std::task::Poll::Pending,
283 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
284 this.is_terminated = true;
285 return std::task::Poll::Ready(None);
286 }
287 std::task::Poll::Ready(Err(e)) => {
288 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
289 e.into(),
290 ))))
291 }
292 }
293
294 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
296
297 std::task::Poll::Ready(Some(match header.ordinal {
298 0x1c90507c87636a84 => {
299 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
300 let mut req = fidl::new_empty!(
301 fidl::encoding::EmptyPayload,
302 fidl::encoding::DefaultFuchsiaResourceDialect
303 );
304 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
305 let control_handle = StatsControlHandle { inner: this.inner.clone() };
306 Ok(StatsRequest::Watch {
307 responder: StatsWatchResponder {
308 control_handle: std::mem::ManuallyDrop::new(control_handle),
309 tx_id: header.tx_id,
310 },
311 })
312 }
313 _ if header.tx_id == 0
314 && header
315 .dynamic_flags()
316 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
317 {
318 Ok(StatsRequest::_UnknownMethod {
319 ordinal: header.ordinal,
320 control_handle: StatsControlHandle { inner: this.inner.clone() },
321 method_type: fidl::MethodType::OneWay,
322 })
323 }
324 _ if header
325 .dynamic_flags()
326 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
327 {
328 this.inner.send_framework_err(
329 fidl::encoding::FrameworkErr::UnknownMethod,
330 header.tx_id,
331 header.ordinal,
332 header.dynamic_flags(),
333 (bytes, handles),
334 )?;
335 Ok(StatsRequest::_UnknownMethod {
336 ordinal: header.ordinal,
337 control_handle: StatsControlHandle { inner: this.inner.clone() },
338 method_type: fidl::MethodType::TwoWay,
339 })
340 }
341 _ => Err(fidl::Error::UnknownOrdinal {
342 ordinal: header.ordinal,
343 protocol_name: <StatsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
344 }),
345 }))
346 },
347 )
348 }
349}
350
351#[derive(Debug)]
353pub enum StatsRequest {
354 Watch { responder: StatsWatchResponder },
360 #[non_exhaustive]
362 _UnknownMethod {
363 ordinal: u64,
365 control_handle: StatsControlHandle,
366 method_type: fidl::MethodType,
367 },
368}
369
370impl StatsRequest {
371 #[allow(irrefutable_let_patterns)]
372 pub fn into_watch(self) -> Option<(StatsWatchResponder)> {
373 if let StatsRequest::Watch { responder } = self {
374 Some((responder))
375 } else {
376 None
377 }
378 }
379
380 pub fn method_name(&self) -> &'static str {
382 match *self {
383 StatsRequest::Watch { .. } => "watch",
384 StatsRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
385 "unknown one-way method"
386 }
387 StatsRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
388 "unknown two-way method"
389 }
390 }
391 }
392}
393
394#[derive(Debug, Clone)]
395pub struct StatsControlHandle {
396 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
397}
398
399impl fidl::endpoints::ControlHandle for StatsControlHandle {
400 fn shutdown(&self) {
401 self.inner.shutdown()
402 }
403 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
404 self.inner.shutdown_with_epitaph(status)
405 }
406
407 fn is_closed(&self) -> bool {
408 self.inner.channel().is_closed()
409 }
410 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
411 self.inner.channel().on_closed()
412 }
413
414 #[cfg(target_os = "fuchsia")]
415 fn signal_peer(
416 &self,
417 clear_mask: zx::Signals,
418 set_mask: zx::Signals,
419 ) -> Result<(), zx_status::Status> {
420 use fidl::Peered;
421 self.inner.channel().signal_peer(clear_mask, set_mask)
422 }
423}
424
425impl StatsControlHandle {}
426
427#[must_use = "FIDL methods require a response to be sent"]
428#[derive(Debug)]
429pub struct StatsWatchResponder {
430 control_handle: std::mem::ManuallyDrop<StatsControlHandle>,
431 tx_id: u32,
432}
433
434impl std::ops::Drop for StatsWatchResponder {
438 fn drop(&mut self) {
439 self.control_handle.shutdown();
440 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
442 }
443}
444
445impl fidl::endpoints::Responder for StatsWatchResponder {
446 type ControlHandle = StatsControlHandle;
447
448 fn control_handle(&self) -> &StatsControlHandle {
449 &self.control_handle
450 }
451
452 fn drop_without_shutdown(mut self) {
453 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
455 std::mem::forget(self);
457 }
458}
459
460impl StatsWatchResponder {
461 pub fn send(self, mut payload: &SuspendStats) -> Result<(), fidl::Error> {
465 let _result = self.send_raw(payload);
466 if _result.is_err() {
467 self.control_handle.shutdown();
468 }
469 self.drop_without_shutdown();
470 _result
471 }
472
473 pub fn send_no_shutdown_on_err(self, mut payload: &SuspendStats) -> Result<(), fidl::Error> {
475 let _result = self.send_raw(payload);
476 self.drop_without_shutdown();
477 _result
478 }
479
480 fn send_raw(&self, mut payload: &SuspendStats) -> Result<(), fidl::Error> {
481 self.control_handle.inner.send::<SuspendStats>(
482 payload,
483 self.tx_id,
484 0x1c90507c87636a84,
485 fidl::encoding::DynamicFlags::empty(),
486 )
487 }
488}
489
490mod internal {
491 use super::*;
492}