fidl_test_hardwarepowercontrol/
fidl_test_hardwarepowercontrol.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_test_hardwarepowercontrol_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ControlMarker;
16
17impl fidl::endpoints::ProtocolMarker for ControlMarker {
18 type Proxy = ControlProxy;
19 type RequestStream = ControlRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = ControlSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "test.hardwarepowercontrol.Control";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for ControlMarker {}
26
27pub trait ControlProxyInterface: Send + Sync {
28 type SetBatteryStatusResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29 fn r#set_battery_status(
30 &self,
31 status: &fidl_fuchsia_hardware_power_battery::Status,
32 ) -> Self::SetBatteryStatusResponseFut;
33}
34#[derive(Debug)]
35#[cfg(target_os = "fuchsia")]
36pub struct ControlSynchronousProxy {
37 client: fidl::client::sync::Client,
38}
39
40#[cfg(target_os = "fuchsia")]
41impl fidl::endpoints::SynchronousProxy for ControlSynchronousProxy {
42 type Proxy = ControlProxy;
43 type Protocol = ControlMarker;
44
45 fn from_channel(inner: fidl::Channel) -> Self {
46 Self::new(inner)
47 }
48
49 fn into_channel(self) -> fidl::Channel {
50 self.client.into_channel()
51 }
52
53 fn as_channel(&self) -> &fidl::Channel {
54 self.client.as_channel()
55 }
56}
57
58#[cfg(target_os = "fuchsia")]
59impl ControlSynchronousProxy {
60 pub fn new(channel: fidl::Channel) -> Self {
61 Self { client: fidl::client::sync::Client::new(channel) }
62 }
63
64 pub fn into_channel(self) -> fidl::Channel {
65 self.client.into_channel()
66 }
67
68 pub fn wait_for_event(
71 &self,
72 deadline: zx::MonotonicInstant,
73 ) -> Result<ControlEvent, fidl::Error> {
74 ControlEvent::decode(self.client.wait_for_event::<ControlMarker>(deadline)?)
75 }
76
77 pub fn r#set_battery_status(
79 &self,
80 mut status: &fidl_fuchsia_hardware_power_battery::Status,
81 ___deadline: zx::MonotonicInstant,
82 ) -> Result<(), fidl::Error> {
83 let _response = self.client.send_query::<
84 ControlSetBatteryStatusRequest,
85 fidl::encoding::EmptyPayload,
86 ControlMarker,
87 >(
88 (status,),
89 0x4c2c27ba4c60ea21,
90 fidl::encoding::DynamicFlags::empty(),
91 ___deadline,
92 )?;
93 Ok(_response)
94 }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl From<ControlSynchronousProxy> for zx::NullableHandle {
99 fn from(value: ControlSynchronousProxy) -> Self {
100 value.into_channel().into()
101 }
102}
103
104#[cfg(target_os = "fuchsia")]
105impl From<fidl::Channel> for ControlSynchronousProxy {
106 fn from(value: fidl::Channel) -> Self {
107 Self::new(value)
108 }
109}
110
111#[cfg(target_os = "fuchsia")]
112impl fidl::endpoints::FromClient for ControlSynchronousProxy {
113 type Protocol = ControlMarker;
114
115 fn from_client(value: fidl::endpoints::ClientEnd<ControlMarker>) -> Self {
116 Self::new(value.into_channel())
117 }
118}
119
120#[derive(Debug, Clone)]
121pub struct ControlProxy {
122 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
123}
124
125impl fidl::endpoints::Proxy for ControlProxy {
126 type Protocol = ControlMarker;
127
128 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
129 Self::new(inner)
130 }
131
132 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
133 self.client.into_channel().map_err(|client| Self { client })
134 }
135
136 fn as_channel(&self) -> &::fidl::AsyncChannel {
137 self.client.as_channel()
138 }
139}
140
141impl ControlProxy {
142 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
144 let protocol_name = <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
145 Self { client: fidl::client::Client::new(channel, protocol_name) }
146 }
147
148 pub fn take_event_stream(&self) -> ControlEventStream {
154 ControlEventStream { event_receiver: self.client.take_event_receiver() }
155 }
156
157 pub fn r#set_battery_status(
159 &self,
160 mut status: &fidl_fuchsia_hardware_power_battery::Status,
161 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
162 ControlProxyInterface::r#set_battery_status(self, status)
163 }
164}
165
166impl ControlProxyInterface for ControlProxy {
167 type SetBatteryStatusResponseFut =
168 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
169 fn r#set_battery_status(
170 &self,
171 mut status: &fidl_fuchsia_hardware_power_battery::Status,
172 ) -> Self::SetBatteryStatusResponseFut {
173 fn _decode(
174 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
175 ) -> Result<(), fidl::Error> {
176 let _response = fidl::client::decode_transaction_body::<
177 fidl::encoding::EmptyPayload,
178 fidl::encoding::DefaultFuchsiaResourceDialect,
179 0x4c2c27ba4c60ea21,
180 >(_buf?)?;
181 Ok(_response)
182 }
183 self.client.send_query_and_decode::<ControlSetBatteryStatusRequest, ()>(
184 (status,),
185 0x4c2c27ba4c60ea21,
186 fidl::encoding::DynamicFlags::empty(),
187 _decode,
188 )
189 }
190}
191
192pub struct ControlEventStream {
193 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
194}
195
196impl std::marker::Unpin for ControlEventStream {}
197
198impl futures::stream::FusedStream for ControlEventStream {
199 fn is_terminated(&self) -> bool {
200 self.event_receiver.is_terminated()
201 }
202}
203
204impl futures::Stream for ControlEventStream {
205 type Item = Result<ControlEvent, 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(ControlEvent::decode(buf))),
216 None => std::task::Poll::Ready(None),
217 }
218 }
219}
220
221#[derive(Debug)]
222pub enum ControlEvent {}
223
224impl ControlEvent {
225 fn decode(
227 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
228 ) -> Result<ControlEvent, 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: <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
236 }),
237 }
238 }
239}
240
241pub struct ControlRequestStream {
243 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
244 is_terminated: bool,
245}
246
247impl std::marker::Unpin for ControlRequestStream {}
248
249impl futures::stream::FusedStream for ControlRequestStream {
250 fn is_terminated(&self) -> bool {
251 self.is_terminated
252 }
253}
254
255impl fidl::endpoints::RequestStream for ControlRequestStream {
256 type Protocol = ControlMarker;
257 type ControlHandle = ControlControlHandle;
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 ControlControlHandle { 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 ControlRequestStream {
283 type Item = Result<ControlRequest, 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 ControlRequestStream 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 0x4c2c27ba4c60ea21 => {
318 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
319 let mut req = fidl::new_empty!(
320 ControlSetBatteryStatusRequest,
321 fidl::encoding::DefaultFuchsiaResourceDialect
322 );
323 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControlSetBatteryStatusRequest>(&header, _body_bytes, handles, &mut req)?;
324 let control_handle = ControlControlHandle { inner: this.inner.clone() };
325 Ok(ControlRequest::SetBatteryStatus {
326 status: req.status,
327
328 responder: ControlSetBatteryStatusResponder {
329 control_handle: std::mem::ManuallyDrop::new(control_handle),
330 tx_id: header.tx_id,
331 },
332 })
333 }
334 _ => Err(fidl::Error::UnknownOrdinal {
335 ordinal: header.ordinal,
336 protocol_name:
337 <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
338 }),
339 }))
340 },
341 )
342 }
343}
344
345#[derive(Debug)]
346pub enum ControlRequest {
347 SetBatteryStatus {
349 status: fidl_fuchsia_hardware_power_battery::Status,
350 responder: ControlSetBatteryStatusResponder,
351 },
352}
353
354impl ControlRequest {
355 #[allow(irrefutable_let_patterns)]
356 pub fn into_set_battery_status(
357 self,
358 ) -> Option<(fidl_fuchsia_hardware_power_battery::Status, ControlSetBatteryStatusResponder)>
359 {
360 if let ControlRequest::SetBatteryStatus { status, responder } = self {
361 Some((status, responder))
362 } else {
363 None
364 }
365 }
366
367 pub fn method_name(&self) -> &'static str {
369 match *self {
370 ControlRequest::SetBatteryStatus { .. } => "set_battery_status",
371 }
372 }
373}
374
375#[derive(Debug, Clone)]
376pub struct ControlControlHandle {
377 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
378}
379
380impl ControlControlHandle {
381 pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
382 self.inner.shutdown_with_epitaph(status.into())
383 }
384}
385
386impl fidl::endpoints::ControlHandle for ControlControlHandle {
387 fn shutdown(&self) {
388 self.inner.shutdown()
389 }
390
391 fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
392 self.inner.shutdown_with_epitaph(status)
393 }
394
395 fn is_closed(&self) -> bool {
396 self.inner.channel().is_closed()
397 }
398 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
399 self.inner.channel().on_closed()
400 }
401
402 #[cfg(target_os = "fuchsia")]
403 fn signal_peer(
404 &self,
405 clear_mask: zx::Signals,
406 set_mask: zx::Signals,
407 ) -> Result<(), zx_status::Status> {
408 use fidl::Peered;
409 self.inner.channel().signal_peer(clear_mask, set_mask)
410 }
411}
412
413impl ControlControlHandle {}
414
415#[must_use = "FIDL methods require a response to be sent"]
416#[derive(Debug)]
417pub struct ControlSetBatteryStatusResponder {
418 control_handle: std::mem::ManuallyDrop<ControlControlHandle>,
419 tx_id: u32,
420}
421
422impl std::ops::Drop for ControlSetBatteryStatusResponder {
426 fn drop(&mut self) {
427 self.control_handle.shutdown();
428 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
430 }
431}
432
433impl fidl::endpoints::Responder for ControlSetBatteryStatusResponder {
434 type ControlHandle = ControlControlHandle;
435
436 fn control_handle(&self) -> &ControlControlHandle {
437 &self.control_handle
438 }
439
440 fn drop_without_shutdown(mut self) {
441 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
443 std::mem::forget(self);
445 }
446}
447
448impl ControlSetBatteryStatusResponder {
449 pub fn send(self) -> Result<(), fidl::Error> {
453 let _result = self.send_raw();
454 if _result.is_err() {
455 self.control_handle.shutdown();
456 }
457 self.drop_without_shutdown();
458 _result
459 }
460
461 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
463 let _result = self.send_raw();
464 self.drop_without_shutdown();
465 _result
466 }
467
468 fn send_raw(&self) -> Result<(), fidl::Error> {
469 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
470 (),
471 self.tx_id,
472 0x4c2c27ba4c60ea21,
473 fidl::encoding::DynamicFlags::empty(),
474 )
475 }
476}
477
478#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
479pub struct ServiceMarker;
480
481#[cfg(target_os = "fuchsia")]
482impl fidl::endpoints::ServiceMarker for ServiceMarker {
483 type Proxy = ServiceProxy;
484 type Request = ServiceRequest;
485 const SERVICE_NAME: &'static str = "test.hardwarepowercontrol.Service";
486}
487
488#[cfg(target_os = "fuchsia")]
491pub enum ServiceRequest {
492 Control(ControlRequestStream),
493}
494
495#[cfg(target_os = "fuchsia")]
496impl fidl::endpoints::ServiceRequest for ServiceRequest {
497 type Service = ServiceMarker;
498
499 fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
500 match name {
501 "control" => Self::Control(
502 <ControlRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
503 ),
504 _ => panic!("no such member protocol name for service Service"),
505 }
506 }
507
508 fn member_names() -> &'static [&'static str] {
509 &["control"]
510 }
511}
512#[cfg(target_os = "fuchsia")]
513pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
514
515#[cfg(target_os = "fuchsia")]
516impl fidl::endpoints::ServiceProxy for ServiceProxy {
517 type Service = ServiceMarker;
518
519 fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
520 Self(opener)
521 }
522}
523
524#[cfg(target_os = "fuchsia")]
525impl ServiceProxy {
526 pub fn connect_to_control(&self) -> Result<ControlProxy, fidl::Error> {
527 let (proxy, server_end) = fidl::endpoints::create_proxy::<ControlMarker>();
528 self.connect_channel_to_control(server_end)?;
529 Ok(proxy)
530 }
531
532 pub fn connect_to_control_sync(&self) -> Result<ControlSynchronousProxy, fidl::Error> {
535 let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<ControlMarker>();
536 self.connect_channel_to_control(server_end)?;
537 Ok(proxy)
538 }
539
540 pub fn connect_channel_to_control(
543 &self,
544 server_end: fidl::endpoints::ServerEnd<ControlMarker>,
545 ) -> Result<(), fidl::Error> {
546 self.0.open_member("control", server_end.into_channel())
547 }
548
549 pub fn instance_name(&self) -> &str {
550 self.0.instance_name()
551 }
552}
553
554mod internal {
555 use super::*;
556}