fidl_fuchsia_powermanager_root_test/
fidl_fuchsia_powermanager_root_test.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_powermanager_root_test_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceMarker {
18 type Proxy = DeviceProxy;
19 type RequestStream = DeviceRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = DeviceSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.powermanager.root.test.Device";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
26
27pub trait DeviceProxyInterface: Send + Sync {
28 type PingResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29 fn r#ping(&self) -> Self::PingResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct DeviceSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
39 type Proxy = DeviceProxy;
40 type Protocol = DeviceMarker;
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 DeviceSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 let protocol_name = <DeviceMarker 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<DeviceEvent, fidl::Error> {
72 DeviceEvent::decode(self.client.wait_for_event(deadline)?)
73 }
74
75 pub fn r#ping(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
76 let _response =
77 self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
78 (),
79 0x224a99a6692f9caa,
80 fidl::encoding::DynamicFlags::empty(),
81 ___deadline,
82 )?;
83 Ok(_response)
84 }
85}
86
87#[derive(Debug, Clone)]
88pub struct DeviceProxy {
89 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
90}
91
92impl fidl::endpoints::Proxy for DeviceProxy {
93 type Protocol = DeviceMarker;
94
95 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
96 Self::new(inner)
97 }
98
99 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
100 self.client.into_channel().map_err(|client| Self { client })
101 }
102
103 fn as_channel(&self) -> &::fidl::AsyncChannel {
104 self.client.as_channel()
105 }
106}
107
108impl DeviceProxy {
109 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
111 let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
112 Self { client: fidl::client::Client::new(channel, protocol_name) }
113 }
114
115 pub fn take_event_stream(&self) -> DeviceEventStream {
121 DeviceEventStream { event_receiver: self.client.take_event_receiver() }
122 }
123
124 pub fn r#ping(
125 &self,
126 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
127 DeviceProxyInterface::r#ping(self)
128 }
129}
130
131impl DeviceProxyInterface for DeviceProxy {
132 type PingResponseFut =
133 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
134 fn r#ping(&self) -> Self::PingResponseFut {
135 fn _decode(
136 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
137 ) -> Result<(), fidl::Error> {
138 let _response = fidl::client::decode_transaction_body::<
139 fidl::encoding::EmptyPayload,
140 fidl::encoding::DefaultFuchsiaResourceDialect,
141 0x224a99a6692f9caa,
142 >(_buf?)?;
143 Ok(_response)
144 }
145 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
146 (),
147 0x224a99a6692f9caa,
148 fidl::encoding::DynamicFlags::empty(),
149 _decode,
150 )
151 }
152}
153
154pub struct DeviceEventStream {
155 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
156}
157
158impl std::marker::Unpin for DeviceEventStream {}
159
160impl futures::stream::FusedStream for DeviceEventStream {
161 fn is_terminated(&self) -> bool {
162 self.event_receiver.is_terminated()
163 }
164}
165
166impl futures::Stream for DeviceEventStream {
167 type Item = Result<DeviceEvent, fidl::Error>;
168
169 fn poll_next(
170 mut self: std::pin::Pin<&mut Self>,
171 cx: &mut std::task::Context<'_>,
172 ) -> std::task::Poll<Option<Self::Item>> {
173 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
174 &mut self.event_receiver,
175 cx
176 )?) {
177 Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
178 None => std::task::Poll::Ready(None),
179 }
180 }
181}
182
183#[derive(Debug)]
184pub enum DeviceEvent {}
185
186impl DeviceEvent {
187 fn decode(
189 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
190 ) -> Result<DeviceEvent, fidl::Error> {
191 let (bytes, _handles) = buf.split_mut();
192 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
193 debug_assert_eq!(tx_header.tx_id, 0);
194 match tx_header.ordinal {
195 _ => Err(fidl::Error::UnknownOrdinal {
196 ordinal: tx_header.ordinal,
197 protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
198 }),
199 }
200 }
201}
202
203pub struct DeviceRequestStream {
205 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
206 is_terminated: bool,
207}
208
209impl std::marker::Unpin for DeviceRequestStream {}
210
211impl futures::stream::FusedStream for DeviceRequestStream {
212 fn is_terminated(&self) -> bool {
213 self.is_terminated
214 }
215}
216
217impl fidl::endpoints::RequestStream for DeviceRequestStream {
218 type Protocol = DeviceMarker;
219 type ControlHandle = DeviceControlHandle;
220
221 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
222 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
223 }
224
225 fn control_handle(&self) -> Self::ControlHandle {
226 DeviceControlHandle { inner: self.inner.clone() }
227 }
228
229 fn into_inner(
230 self,
231 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
232 {
233 (self.inner, self.is_terminated)
234 }
235
236 fn from_inner(
237 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
238 is_terminated: bool,
239 ) -> Self {
240 Self { inner, is_terminated }
241 }
242}
243
244impl futures::Stream for DeviceRequestStream {
245 type Item = Result<DeviceRequest, fidl::Error>;
246
247 fn poll_next(
248 mut self: std::pin::Pin<&mut Self>,
249 cx: &mut std::task::Context<'_>,
250 ) -> std::task::Poll<Option<Self::Item>> {
251 let this = &mut *self;
252 if this.inner.check_shutdown(cx) {
253 this.is_terminated = true;
254 return std::task::Poll::Ready(None);
255 }
256 if this.is_terminated {
257 panic!("polled DeviceRequestStream after completion");
258 }
259 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
260 |bytes, handles| {
261 match this.inner.channel().read_etc(cx, bytes, handles) {
262 std::task::Poll::Ready(Ok(())) => {}
263 std::task::Poll::Pending => return std::task::Poll::Pending,
264 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
265 this.is_terminated = true;
266 return std::task::Poll::Ready(None);
267 }
268 std::task::Poll::Ready(Err(e)) => {
269 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
270 e.into(),
271 ))))
272 }
273 }
274
275 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
277
278 std::task::Poll::Ready(Some(match header.ordinal {
279 0x224a99a6692f9caa => {
280 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
281 let mut req = fidl::new_empty!(
282 fidl::encoding::EmptyPayload,
283 fidl::encoding::DefaultFuchsiaResourceDialect
284 );
285 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
286 let control_handle = DeviceControlHandle { inner: this.inner.clone() };
287 Ok(DeviceRequest::Ping {
288 responder: DevicePingResponder {
289 control_handle: std::mem::ManuallyDrop::new(control_handle),
290 tx_id: header.tx_id,
291 },
292 })
293 }
294 _ => Err(fidl::Error::UnknownOrdinal {
295 ordinal: header.ordinal,
296 protocol_name:
297 <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
298 }),
299 }))
300 },
301 )
302 }
303}
304
305#[derive(Debug)]
306pub enum DeviceRequest {
307 Ping { responder: DevicePingResponder },
308}
309
310impl DeviceRequest {
311 #[allow(irrefutable_let_patterns)]
312 pub fn into_ping(self) -> Option<(DevicePingResponder)> {
313 if let DeviceRequest::Ping { responder } = self {
314 Some((responder))
315 } else {
316 None
317 }
318 }
319
320 pub fn method_name(&self) -> &'static str {
322 match *self {
323 DeviceRequest::Ping { .. } => "ping",
324 }
325 }
326}
327
328#[derive(Debug, Clone)]
329pub struct DeviceControlHandle {
330 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
331}
332
333impl fidl::endpoints::ControlHandle for DeviceControlHandle {
334 fn shutdown(&self) {
335 self.inner.shutdown()
336 }
337 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
338 self.inner.shutdown_with_epitaph(status)
339 }
340
341 fn is_closed(&self) -> bool {
342 self.inner.channel().is_closed()
343 }
344 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
345 self.inner.channel().on_closed()
346 }
347
348 #[cfg(target_os = "fuchsia")]
349 fn signal_peer(
350 &self,
351 clear_mask: zx::Signals,
352 set_mask: zx::Signals,
353 ) -> Result<(), zx_status::Status> {
354 use fidl::Peered;
355 self.inner.channel().signal_peer(clear_mask, set_mask)
356 }
357}
358
359impl DeviceControlHandle {}
360
361#[must_use = "FIDL methods require a response to be sent"]
362#[derive(Debug)]
363pub struct DevicePingResponder {
364 control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
365 tx_id: u32,
366}
367
368impl std::ops::Drop for DevicePingResponder {
372 fn drop(&mut self) {
373 self.control_handle.shutdown();
374 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
376 }
377}
378
379impl fidl::endpoints::Responder for DevicePingResponder {
380 type ControlHandle = DeviceControlHandle;
381
382 fn control_handle(&self) -> &DeviceControlHandle {
383 &self.control_handle
384 }
385
386 fn drop_without_shutdown(mut self) {
387 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
389 std::mem::forget(self);
391 }
392}
393
394impl DevicePingResponder {
395 pub fn send(self) -> Result<(), fidl::Error> {
399 let _result = self.send_raw();
400 if _result.is_err() {
401 self.control_handle.shutdown();
402 }
403 self.drop_without_shutdown();
404 _result
405 }
406
407 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
409 let _result = self.send_raw();
410 self.drop_without_shutdown();
411 _result
412 }
413
414 fn send_raw(&self) -> Result<(), fidl::Error> {
415 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
416 (),
417 self.tx_id,
418 0x224a99a6692f9caa,
419 fidl::encoding::DynamicFlags::empty(),
420 )
421 }
422}
423
424mod internal {
425 use super::*;
426}