fidl_fuchsia_power_profile/
fidl_fuchsia_power_profile.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_profile__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct WatcherMarker;
16
17impl fidl::endpoints::ProtocolMarker for WatcherMarker {
18 type Proxy = WatcherProxy;
19 type RequestStream = WatcherRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = WatcherSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.power.profile.Watcher";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for WatcherMarker {}
26
27pub trait WatcherProxyInterface: Send + Sync {
28 type WatchResponseFut: std::future::Future<Output = Result<Profile, fidl::Error>> + Send;
29 fn r#watch(&self) -> Self::WatchResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct WatcherSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for WatcherSynchronousProxy {
39 type Proxy = WatcherProxy;
40 type Protocol = WatcherMarker;
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 WatcherSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 let protocol_name = <WatcherMarker 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<WatcherEvent, fidl::Error> {
72 WatcherEvent::decode(self.client.wait_for_event(deadline)?)
73 }
74
75 pub fn r#watch(&self, ___deadline: zx::MonotonicInstant) -> Result<Profile, fidl::Error> {
83 let _response =
84 self.client.send_query::<fidl::encoding::EmptyPayload, WatcherWatchResponse>(
85 (),
86 0x5f29be53ad34a947,
87 fidl::encoding::DynamicFlags::empty(),
88 ___deadline,
89 )?;
90 Ok(_response.profile)
91 }
92}
93
94#[cfg(target_os = "fuchsia")]
95impl From<WatcherSynchronousProxy> for zx::Handle {
96 fn from(value: WatcherSynchronousProxy) -> Self {
97 value.into_channel().into()
98 }
99}
100
101#[cfg(target_os = "fuchsia")]
102impl From<fidl::Channel> for WatcherSynchronousProxy {
103 fn from(value: fidl::Channel) -> Self {
104 Self::new(value)
105 }
106}
107
108#[cfg(target_os = "fuchsia")]
109impl fidl::endpoints::FromClient for WatcherSynchronousProxy {
110 type Protocol = WatcherMarker;
111
112 fn from_client(value: fidl::endpoints::ClientEnd<WatcherMarker>) -> Self {
113 Self::new(value.into_channel())
114 }
115}
116
117#[derive(Debug, Clone)]
118pub struct WatcherProxy {
119 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
120}
121
122impl fidl::endpoints::Proxy for WatcherProxy {
123 type Protocol = WatcherMarker;
124
125 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
126 Self::new(inner)
127 }
128
129 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
130 self.client.into_channel().map_err(|client| Self { client })
131 }
132
133 fn as_channel(&self) -> &::fidl::AsyncChannel {
134 self.client.as_channel()
135 }
136}
137
138impl WatcherProxy {
139 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
141 let protocol_name = <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
142 Self { client: fidl::client::Client::new(channel, protocol_name) }
143 }
144
145 pub fn take_event_stream(&self) -> WatcherEventStream {
151 WatcherEventStream { event_receiver: self.client.take_event_receiver() }
152 }
153
154 pub fn r#watch(
162 &self,
163 ) -> fidl::client::QueryResponseFut<Profile, fidl::encoding::DefaultFuchsiaResourceDialect>
164 {
165 WatcherProxyInterface::r#watch(self)
166 }
167}
168
169impl WatcherProxyInterface for WatcherProxy {
170 type WatchResponseFut =
171 fidl::client::QueryResponseFut<Profile, fidl::encoding::DefaultFuchsiaResourceDialect>;
172 fn r#watch(&self) -> Self::WatchResponseFut {
173 fn _decode(
174 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
175 ) -> Result<Profile, fidl::Error> {
176 let _response = fidl::client::decode_transaction_body::<
177 WatcherWatchResponse,
178 fidl::encoding::DefaultFuchsiaResourceDialect,
179 0x5f29be53ad34a947,
180 >(_buf?)?;
181 Ok(_response.profile)
182 }
183 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Profile>(
184 (),
185 0x5f29be53ad34a947,
186 fidl::encoding::DynamicFlags::empty(),
187 _decode,
188 )
189 }
190}
191
192pub struct WatcherEventStream {
193 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
194}
195
196impl std::marker::Unpin for WatcherEventStream {}
197
198impl futures::stream::FusedStream for WatcherEventStream {
199 fn is_terminated(&self) -> bool {
200 self.event_receiver.is_terminated()
201 }
202}
203
204impl futures::Stream for WatcherEventStream {
205 type Item = Result<WatcherEvent, fidl::Error>;
206
207 fn poll_next(
208 mut self: std::pin::Pin<&mut Self>,
209 cx: &mut std::task::Context<'_>,
210 ) -> std::task::Poll<Option<Self::Item>> {
211 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
212 &mut self.event_receiver,
213 cx
214 )?) {
215 Some(buf) => std::task::Poll::Ready(Some(WatcherEvent::decode(buf))),
216 None => std::task::Poll::Ready(None),
217 }
218 }
219}
220
221#[derive(Debug)]
222pub enum WatcherEvent {}
223
224impl WatcherEvent {
225 fn decode(
227 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
228 ) -> Result<WatcherEvent, fidl::Error> {
229 let (bytes, _handles) = buf.split_mut();
230 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
231 debug_assert_eq!(tx_header.tx_id, 0);
232 match tx_header.ordinal {
233 _ => Err(fidl::Error::UnknownOrdinal {
234 ordinal: tx_header.ordinal,
235 protocol_name: <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
236 }),
237 }
238 }
239}
240
241pub struct WatcherRequestStream {
243 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
244 is_terminated: bool,
245}
246
247impl std::marker::Unpin for WatcherRequestStream {}
248
249impl futures::stream::FusedStream for WatcherRequestStream {
250 fn is_terminated(&self) -> bool {
251 self.is_terminated
252 }
253}
254
255impl fidl::endpoints::RequestStream for WatcherRequestStream {
256 type Protocol = WatcherMarker;
257 type ControlHandle = WatcherControlHandle;
258
259 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
260 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
261 }
262
263 fn control_handle(&self) -> Self::ControlHandle {
264 WatcherControlHandle { inner: self.inner.clone() }
265 }
266
267 fn into_inner(
268 self,
269 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
270 {
271 (self.inner, self.is_terminated)
272 }
273
274 fn from_inner(
275 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
276 is_terminated: bool,
277 ) -> Self {
278 Self { inner, is_terminated }
279 }
280}
281
282impl futures::Stream for WatcherRequestStream {
283 type Item = Result<WatcherRequest, fidl::Error>;
284
285 fn poll_next(
286 mut self: std::pin::Pin<&mut Self>,
287 cx: &mut std::task::Context<'_>,
288 ) -> std::task::Poll<Option<Self::Item>> {
289 let this = &mut *self;
290 if this.inner.check_shutdown(cx) {
291 this.is_terminated = true;
292 return std::task::Poll::Ready(None);
293 }
294 if this.is_terminated {
295 panic!("polled WatcherRequestStream after completion");
296 }
297 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
298 |bytes, handles| {
299 match this.inner.channel().read_etc(cx, bytes, handles) {
300 std::task::Poll::Ready(Ok(())) => {}
301 std::task::Poll::Pending => return std::task::Poll::Pending,
302 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
303 this.is_terminated = true;
304 return std::task::Poll::Ready(None);
305 }
306 std::task::Poll::Ready(Err(e)) => {
307 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
308 e.into(),
309 ))));
310 }
311 }
312
313 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
315
316 std::task::Poll::Ready(Some(match header.ordinal {
317 0x5f29be53ad34a947 => {
318 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
319 let mut req = fidl::new_empty!(
320 fidl::encoding::EmptyPayload,
321 fidl::encoding::DefaultFuchsiaResourceDialect
322 );
323 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
324 let control_handle = WatcherControlHandle { inner: this.inner.clone() };
325 Ok(WatcherRequest::Watch {
326 responder: WatcherWatchResponder {
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:
335 <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
336 }),
337 }))
338 },
339 )
340 }
341}
342
343#[derive(Debug)]
345pub enum WatcherRequest {
346 Watch { responder: WatcherWatchResponder },
354}
355
356impl WatcherRequest {
357 #[allow(irrefutable_let_patterns)]
358 pub fn into_watch(self) -> Option<(WatcherWatchResponder)> {
359 if let WatcherRequest::Watch { responder } = self { Some((responder)) } else { None }
360 }
361
362 pub fn method_name(&self) -> &'static str {
364 match *self {
365 WatcherRequest::Watch { .. } => "watch",
366 }
367 }
368}
369
370#[derive(Debug, Clone)]
371pub struct WatcherControlHandle {
372 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
373}
374
375impl fidl::endpoints::ControlHandle for WatcherControlHandle {
376 fn shutdown(&self) {
377 self.inner.shutdown()
378 }
379 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
380 self.inner.shutdown_with_epitaph(status)
381 }
382
383 fn is_closed(&self) -> bool {
384 self.inner.channel().is_closed()
385 }
386 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
387 self.inner.channel().on_closed()
388 }
389
390 #[cfg(target_os = "fuchsia")]
391 fn signal_peer(
392 &self,
393 clear_mask: zx::Signals,
394 set_mask: zx::Signals,
395 ) -> Result<(), zx_status::Status> {
396 use fidl::Peered;
397 self.inner.channel().signal_peer(clear_mask, set_mask)
398 }
399}
400
401impl WatcherControlHandle {}
402
403#[must_use = "FIDL methods require a response to be sent"]
404#[derive(Debug)]
405pub struct WatcherWatchResponder {
406 control_handle: std::mem::ManuallyDrop<WatcherControlHandle>,
407 tx_id: u32,
408}
409
410impl std::ops::Drop for WatcherWatchResponder {
414 fn drop(&mut self) {
415 self.control_handle.shutdown();
416 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
418 }
419}
420
421impl fidl::endpoints::Responder for WatcherWatchResponder {
422 type ControlHandle = WatcherControlHandle;
423
424 fn control_handle(&self) -> &WatcherControlHandle {
425 &self.control_handle
426 }
427
428 fn drop_without_shutdown(mut self) {
429 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
431 std::mem::forget(self);
433 }
434}
435
436impl WatcherWatchResponder {
437 pub fn send(self, mut profile: Profile) -> Result<(), fidl::Error> {
441 let _result = self.send_raw(profile);
442 if _result.is_err() {
443 self.control_handle.shutdown();
444 }
445 self.drop_without_shutdown();
446 _result
447 }
448
449 pub fn send_no_shutdown_on_err(self, mut profile: Profile) -> Result<(), fidl::Error> {
451 let _result = self.send_raw(profile);
452 self.drop_without_shutdown();
453 _result
454 }
455
456 fn send_raw(&self, mut profile: Profile) -> Result<(), fidl::Error> {
457 self.control_handle.inner.send::<WatcherWatchResponse>(
458 (profile,),
459 self.tx_id,
460 0x5f29be53ad34a947,
461 fidl::encoding::DynamicFlags::empty(),
462 )
463 }
464}
465
466mod internal {
467 use super::*;
468}