1#![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 type SetSourceStatusResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
34 fn r#set_source_status(
35 &self,
36 status: &fidl_fuchsia_hardware_power_source::Status,
37 ) -> Self::SetSourceStatusResponseFut;
38}
39#[derive(Debug)]
40#[cfg(target_os = "fuchsia")]
41pub struct ControlSynchronousProxy {
42 client: fidl::client::sync::Client,
43}
44
45#[cfg(target_os = "fuchsia")]
46impl fidl::endpoints::SynchronousProxy for ControlSynchronousProxy {
47 type Proxy = ControlProxy;
48 type Protocol = ControlMarker;
49
50 fn from_channel(inner: fidl::Channel) -> Self {
51 Self::new(inner)
52 }
53
54 fn into_channel(self) -> fidl::Channel {
55 self.client.into_channel()
56 }
57
58 fn as_channel(&self) -> &fidl::Channel {
59 self.client.as_channel()
60 }
61}
62
63#[cfg(target_os = "fuchsia")]
64impl ControlSynchronousProxy {
65 pub fn new(channel: fidl::Channel) -> Self {
66 Self { client: fidl::client::sync::Client::new(channel) }
67 }
68
69 pub fn into_channel(self) -> fidl::Channel {
70 self.client.into_channel()
71 }
72
73 pub fn wait_for_event(
76 &self,
77 deadline: zx::MonotonicInstant,
78 ) -> Result<ControlEvent, fidl::Error> {
79 ControlEvent::decode(self.client.wait_for_event::<ControlMarker>(deadline)?)
80 }
81
82 pub fn r#set_battery_status(
86 &self,
87 mut status: &fidl_fuchsia_hardware_power_battery::Status,
88 ___deadline: zx::MonotonicInstant,
89 ) -> Result<(), fidl::Error> {
90 let _response = self.client.send_query::<
91 ControlSetBatteryStatusRequest,
92 fidl::encoding::EmptyPayload,
93 ControlMarker,
94 >(
95 (status,),
96 0x4c2c27ba4c60ea21,
97 fidl::encoding::DynamicFlags::empty(),
98 ___deadline,
99 )?;
100 Ok(_response)
101 }
102
103 pub fn r#set_source_status(
105 &self,
106 mut status: &fidl_fuchsia_hardware_power_source::Status,
107 ___deadline: zx::MonotonicInstant,
108 ) -> Result<(), fidl::Error> {
109 let _response = self.client.send_query::<
110 ControlSetSourceStatusRequest,
111 fidl::encoding::EmptyPayload,
112 ControlMarker,
113 >(
114 (status,),
115 0x3d3137802b73710f,
116 fidl::encoding::DynamicFlags::empty(),
117 ___deadline,
118 )?;
119 Ok(_response)
120 }
121}
122
123#[cfg(target_os = "fuchsia")]
124impl From<ControlSynchronousProxy> for zx::NullableHandle {
125 fn from(value: ControlSynchronousProxy) -> Self {
126 value.into_channel().into()
127 }
128}
129
130#[cfg(target_os = "fuchsia")]
131impl From<fidl::Channel> for ControlSynchronousProxy {
132 fn from(value: fidl::Channel) -> Self {
133 Self::new(value)
134 }
135}
136
137#[cfg(target_os = "fuchsia")]
138impl fidl::endpoints::FromClient for ControlSynchronousProxy {
139 type Protocol = ControlMarker;
140
141 fn from_client(value: fidl::endpoints::ClientEnd<ControlMarker>) -> Self {
142 Self::new(value.into_channel())
143 }
144}
145
146#[derive(Debug, Clone)]
147pub struct ControlProxy {
148 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
149}
150
151impl fidl::endpoints::Proxy for ControlProxy {
152 type Protocol = ControlMarker;
153
154 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
155 Self::new(inner)
156 }
157
158 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
159 self.client.into_channel().map_err(|client| Self { client })
160 }
161
162 fn as_channel(&self) -> &::fidl::AsyncChannel {
163 self.client.as_channel()
164 }
165}
166
167impl ControlProxy {
168 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
170 let protocol_name = <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
171 Self { client: fidl::client::Client::new(channel, protocol_name) }
172 }
173
174 pub fn take_event_stream(&self) -> ControlEventStream {
180 ControlEventStream { event_receiver: self.client.take_event_receiver() }
181 }
182
183 pub fn r#set_battery_status(
187 &self,
188 mut status: &fidl_fuchsia_hardware_power_battery::Status,
189 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
190 ControlProxyInterface::r#set_battery_status(self, status)
191 }
192
193 pub fn r#set_source_status(
195 &self,
196 mut status: &fidl_fuchsia_hardware_power_source::Status,
197 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
198 ControlProxyInterface::r#set_source_status(self, status)
199 }
200}
201
202impl ControlProxyInterface for ControlProxy {
203 type SetBatteryStatusResponseFut =
204 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
205 fn r#set_battery_status(
206 &self,
207 mut status: &fidl_fuchsia_hardware_power_battery::Status,
208 ) -> Self::SetBatteryStatusResponseFut {
209 fn _decode(
210 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
211 ) -> Result<(), fidl::Error> {
212 let _response = fidl::client::decode_transaction_body::<
213 fidl::encoding::EmptyPayload,
214 fidl::encoding::DefaultFuchsiaResourceDialect,
215 0x4c2c27ba4c60ea21,
216 >(_buf?)?;
217 Ok(_response)
218 }
219 self.client.send_query_and_decode::<ControlSetBatteryStatusRequest, ()>(
220 (status,),
221 0x4c2c27ba4c60ea21,
222 fidl::encoding::DynamicFlags::empty(),
223 _decode,
224 )
225 }
226
227 type SetSourceStatusResponseFut =
228 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
229 fn r#set_source_status(
230 &self,
231 mut status: &fidl_fuchsia_hardware_power_source::Status,
232 ) -> Self::SetSourceStatusResponseFut {
233 fn _decode(
234 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
235 ) -> Result<(), fidl::Error> {
236 let _response = fidl::client::decode_transaction_body::<
237 fidl::encoding::EmptyPayload,
238 fidl::encoding::DefaultFuchsiaResourceDialect,
239 0x3d3137802b73710f,
240 >(_buf?)?;
241 Ok(_response)
242 }
243 self.client.send_query_and_decode::<ControlSetSourceStatusRequest, ()>(
244 (status,),
245 0x3d3137802b73710f,
246 fidl::encoding::DynamicFlags::empty(),
247 _decode,
248 )
249 }
250}
251
252pub struct ControlEventStream {
253 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
254}
255
256impl std::marker::Unpin for ControlEventStream {}
257
258impl futures::stream::FusedStream for ControlEventStream {
259 fn is_terminated(&self) -> bool {
260 self.event_receiver.is_terminated()
261 }
262}
263
264impl futures::Stream for ControlEventStream {
265 type Item = Result<ControlEvent, fidl::Error>;
266
267 fn poll_next(
268 mut self: std::pin::Pin<&mut Self>,
269 cx: &mut std::task::Context<'_>,
270 ) -> std::task::Poll<Option<Self::Item>> {
271 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
272 &mut self.event_receiver,
273 cx
274 )?) {
275 Some(buf) => std::task::Poll::Ready(Some(ControlEvent::decode(buf))),
276 None => std::task::Poll::Ready(None),
277 }
278 }
279}
280
281#[derive(Debug)]
282pub enum ControlEvent {}
283
284impl ControlEvent {
285 fn decode(
287 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
288 ) -> Result<ControlEvent, fidl::Error> {
289 let (bytes, _handles) = buf.split_mut();
290 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
291 debug_assert_eq!(tx_header.tx_id, 0);
292 match tx_header.ordinal {
293 _ => Err(fidl::Error::UnknownOrdinal {
294 ordinal: tx_header.ordinal,
295 protocol_name: <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
296 }),
297 }
298 }
299}
300
301pub struct ControlRequestStream {
303 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
304 is_terminated: bool,
305}
306
307impl std::marker::Unpin for ControlRequestStream {}
308
309impl futures::stream::FusedStream for ControlRequestStream {
310 fn is_terminated(&self) -> bool {
311 self.is_terminated
312 }
313}
314
315impl fidl::endpoints::RequestStream for ControlRequestStream {
316 type Protocol = ControlMarker;
317 type ControlHandle = ControlControlHandle;
318
319 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
320 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
321 }
322
323 fn control_handle(&self) -> Self::ControlHandle {
324 ControlControlHandle { inner: self.inner.clone() }
325 }
326
327 fn into_inner(
328 self,
329 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
330 {
331 (self.inner, self.is_terminated)
332 }
333
334 fn from_inner(
335 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
336 is_terminated: bool,
337 ) -> Self {
338 Self { inner, is_terminated }
339 }
340}
341
342impl futures::Stream for ControlRequestStream {
343 type Item = Result<ControlRequest, fidl::Error>;
344
345 fn poll_next(
346 mut self: std::pin::Pin<&mut Self>,
347 cx: &mut std::task::Context<'_>,
348 ) -> std::task::Poll<Option<Self::Item>> {
349 let this = &mut *self;
350 if this.inner.check_shutdown(cx) {
351 this.is_terminated = true;
352 return std::task::Poll::Ready(None);
353 }
354 if this.is_terminated {
355 panic!("polled ControlRequestStream after completion");
356 }
357 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
358 |bytes, handles| {
359 match this.inner.channel().read_etc(cx, bytes, handles) {
360 std::task::Poll::Ready(Ok(())) => {}
361 std::task::Poll::Pending => return std::task::Poll::Pending,
362 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
363 this.is_terminated = true;
364 return std::task::Poll::Ready(None);
365 }
366 std::task::Poll::Ready(Err(e)) => {
367 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
368 e.into(),
369 ))));
370 }
371 }
372
373 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
375
376 std::task::Poll::Ready(Some(match header.ordinal {
377 0x4c2c27ba4c60ea21 => {
378 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
379 let mut req = fidl::new_empty!(
380 ControlSetBatteryStatusRequest,
381 fidl::encoding::DefaultFuchsiaResourceDialect
382 );
383 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControlSetBatteryStatusRequest>(&header, _body_bytes, handles, &mut req)?;
384 let control_handle = ControlControlHandle { inner: this.inner.clone() };
385 Ok(ControlRequest::SetBatteryStatus {
386 status: req.status,
387
388 responder: ControlSetBatteryStatusResponder {
389 control_handle: std::mem::ManuallyDrop::new(control_handle),
390 tx_id: header.tx_id,
391 },
392 })
393 }
394 0x3d3137802b73710f => {
395 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
396 let mut req = fidl::new_empty!(
397 ControlSetSourceStatusRequest,
398 fidl::encoding::DefaultFuchsiaResourceDialect
399 );
400 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControlSetSourceStatusRequest>(&header, _body_bytes, handles, &mut req)?;
401 let control_handle = ControlControlHandle { inner: this.inner.clone() };
402 Ok(ControlRequest::SetSourceStatus {
403 status: req.status,
404
405 responder: ControlSetSourceStatusResponder {
406 control_handle: std::mem::ManuallyDrop::new(control_handle),
407 tx_id: header.tx_id,
408 },
409 })
410 }
411 _ => Err(fidl::Error::UnknownOrdinal {
412 ordinal: header.ordinal,
413 protocol_name:
414 <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
415 }),
416 }))
417 },
418 )
419 }
420}
421
422#[derive(Debug)]
423pub enum ControlRequest {
424 SetBatteryStatus {
428 status: fidl_fuchsia_hardware_power_battery::Status,
429 responder: ControlSetBatteryStatusResponder,
430 },
431 SetSourceStatus {
433 status: fidl_fuchsia_hardware_power_source::Status,
434 responder: ControlSetSourceStatusResponder,
435 },
436}
437
438impl ControlRequest {
439 #[allow(irrefutable_let_patterns)]
440 pub fn into_set_battery_status(
441 self,
442 ) -> Option<(fidl_fuchsia_hardware_power_battery::Status, ControlSetBatteryStatusResponder)>
443 {
444 if let ControlRequest::SetBatteryStatus { status, responder } = self {
445 Some((status, responder))
446 } else {
447 None
448 }
449 }
450
451 #[allow(irrefutable_let_patterns)]
452 pub fn into_set_source_status(
453 self,
454 ) -> Option<(fidl_fuchsia_hardware_power_source::Status, ControlSetSourceStatusResponder)> {
455 if let ControlRequest::SetSourceStatus { status, responder } = self {
456 Some((status, responder))
457 } else {
458 None
459 }
460 }
461
462 pub fn method_name(&self) -> &'static str {
464 match *self {
465 ControlRequest::SetBatteryStatus { .. } => "set_battery_status",
466 ControlRequest::SetSourceStatus { .. } => "set_source_status",
467 }
468 }
469}
470
471#[derive(Debug, Clone)]
472pub struct ControlControlHandle {
473 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
474}
475
476impl fidl::endpoints::ControlHandle for ControlControlHandle {
477 fn shutdown(&self) {
478 self.inner.shutdown()
479 }
480
481 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
482 self.inner.shutdown_with_epitaph(status)
483 }
484
485 fn is_closed(&self) -> bool {
486 self.inner.channel().is_closed()
487 }
488 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
489 self.inner.channel().on_closed()
490 }
491
492 #[cfg(target_os = "fuchsia")]
493 fn signal_peer(
494 &self,
495 clear_mask: zx::Signals,
496 set_mask: zx::Signals,
497 ) -> Result<(), zx_status::Status> {
498 use fidl::Peered;
499 self.inner.channel().signal_peer(clear_mask, set_mask)
500 }
501}
502
503impl ControlControlHandle {}
504
505#[must_use = "FIDL methods require a response to be sent"]
506#[derive(Debug)]
507pub struct ControlSetBatteryStatusResponder {
508 control_handle: std::mem::ManuallyDrop<ControlControlHandle>,
509 tx_id: u32,
510}
511
512impl std::ops::Drop for ControlSetBatteryStatusResponder {
516 fn drop(&mut self) {
517 self.control_handle.shutdown();
518 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
520 }
521}
522
523impl fidl::endpoints::Responder for ControlSetBatteryStatusResponder {
524 type ControlHandle = ControlControlHandle;
525
526 fn control_handle(&self) -> &ControlControlHandle {
527 &self.control_handle
528 }
529
530 fn drop_without_shutdown(mut self) {
531 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
533 std::mem::forget(self);
535 }
536}
537
538impl ControlSetBatteryStatusResponder {
539 pub fn send(self) -> Result<(), fidl::Error> {
543 let _result = self.send_raw();
544 if _result.is_err() {
545 self.control_handle.shutdown();
546 }
547 self.drop_without_shutdown();
548 _result
549 }
550
551 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
553 let _result = self.send_raw();
554 self.drop_without_shutdown();
555 _result
556 }
557
558 fn send_raw(&self) -> Result<(), fidl::Error> {
559 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
560 (),
561 self.tx_id,
562 0x4c2c27ba4c60ea21,
563 fidl::encoding::DynamicFlags::empty(),
564 )
565 }
566}
567
568#[must_use = "FIDL methods require a response to be sent"]
569#[derive(Debug)]
570pub struct ControlSetSourceStatusResponder {
571 control_handle: std::mem::ManuallyDrop<ControlControlHandle>,
572 tx_id: u32,
573}
574
575impl std::ops::Drop for ControlSetSourceStatusResponder {
579 fn drop(&mut self) {
580 self.control_handle.shutdown();
581 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
583 }
584}
585
586impl fidl::endpoints::Responder for ControlSetSourceStatusResponder {
587 type ControlHandle = ControlControlHandle;
588
589 fn control_handle(&self) -> &ControlControlHandle {
590 &self.control_handle
591 }
592
593 fn drop_without_shutdown(mut self) {
594 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
596 std::mem::forget(self);
598 }
599}
600
601impl ControlSetSourceStatusResponder {
602 pub fn send(self) -> Result<(), fidl::Error> {
606 let _result = self.send_raw();
607 if _result.is_err() {
608 self.control_handle.shutdown();
609 }
610 self.drop_without_shutdown();
611 _result
612 }
613
614 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
616 let _result = self.send_raw();
617 self.drop_without_shutdown();
618 _result
619 }
620
621 fn send_raw(&self) -> Result<(), fidl::Error> {
622 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
623 (),
624 self.tx_id,
625 0x3d3137802b73710f,
626 fidl::encoding::DynamicFlags::empty(),
627 )
628 }
629}
630
631#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
632pub struct ServiceMarker;
633
634#[cfg(target_os = "fuchsia")]
635impl fidl::endpoints::ServiceMarker for ServiceMarker {
636 type Proxy = ServiceProxy;
637 type Request = ServiceRequest;
638 const SERVICE_NAME: &'static str = "test.hardwarepowercontrol.Service";
639}
640
641#[cfg(target_os = "fuchsia")]
644pub enum ServiceRequest {
645 Control(ControlRequestStream),
646}
647
648#[cfg(target_os = "fuchsia")]
649impl fidl::endpoints::ServiceRequest for ServiceRequest {
650 type Service = ServiceMarker;
651
652 fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
653 match name {
654 "control" => Self::Control(
655 <ControlRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
656 ),
657 _ => panic!("no such member protocol name for service Service"),
658 }
659 }
660
661 fn member_names() -> &'static [&'static str] {
662 &["control"]
663 }
664}
665#[cfg(target_os = "fuchsia")]
666pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
667
668#[cfg(target_os = "fuchsia")]
669impl fidl::endpoints::ServiceProxy for ServiceProxy {
670 type Service = ServiceMarker;
671
672 fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
673 Self(opener)
674 }
675}
676
677#[cfg(target_os = "fuchsia")]
678impl ServiceProxy {
679 pub fn connect_to_control(&self) -> Result<ControlProxy, fidl::Error> {
680 let (proxy, server_end) = fidl::endpoints::create_proxy::<ControlMarker>();
681 self.connect_channel_to_control(server_end)?;
682 Ok(proxy)
683 }
684
685 pub fn connect_to_control_sync(&self) -> Result<ControlSynchronousProxy, fidl::Error> {
688 let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<ControlMarker>();
689 self.connect_channel_to_control(server_end)?;
690 Ok(proxy)
691 }
692
693 pub fn connect_channel_to_control(
696 &self,
697 server_end: fidl::endpoints::ServerEnd<ControlMarker>,
698 ) -> Result<(), fidl::Error> {
699 self.0.open_member("control", server_end.into_channel())
700 }
701
702 pub fn instance_name(&self) -> &str {
703 self.0.instance_name()
704 }
705}
706
707mod internal {
708 use super::*;
709}