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 ControlControlHandle {
477 pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
478 self.inner.shutdown_with_epitaph(status.into())
479 }
480}
481
482impl fidl::endpoints::ControlHandle for ControlControlHandle {
483 fn shutdown(&self) {
484 self.inner.shutdown()
485 }
486
487 fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
488 self.inner.shutdown_with_epitaph(status)
489 }
490
491 fn is_closed(&self) -> bool {
492 self.inner.channel().is_closed()
493 }
494 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
495 self.inner.channel().on_closed()
496 }
497
498 #[cfg(target_os = "fuchsia")]
499 fn signal_peer(
500 &self,
501 clear_mask: zx::Signals,
502 set_mask: zx::Signals,
503 ) -> Result<(), zx_status::Status> {
504 use fidl::Peered;
505 self.inner.channel().signal_peer(clear_mask, set_mask)
506 }
507}
508
509impl ControlControlHandle {}
510
511#[must_use = "FIDL methods require a response to be sent"]
512#[derive(Debug)]
513pub struct ControlSetBatteryStatusResponder {
514 control_handle: std::mem::ManuallyDrop<ControlControlHandle>,
515 tx_id: u32,
516}
517
518impl std::ops::Drop for ControlSetBatteryStatusResponder {
522 fn drop(&mut self) {
523 self.control_handle.shutdown();
524 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
526 }
527}
528
529impl fidl::endpoints::Responder for ControlSetBatteryStatusResponder {
530 type ControlHandle = ControlControlHandle;
531
532 fn control_handle(&self) -> &ControlControlHandle {
533 &self.control_handle
534 }
535
536 fn drop_without_shutdown(mut self) {
537 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
539 std::mem::forget(self);
541 }
542}
543
544impl ControlSetBatteryStatusResponder {
545 pub fn send(self) -> Result<(), fidl::Error> {
549 let _result = self.send_raw();
550 if _result.is_err() {
551 self.control_handle.shutdown();
552 }
553 self.drop_without_shutdown();
554 _result
555 }
556
557 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
559 let _result = self.send_raw();
560 self.drop_without_shutdown();
561 _result
562 }
563
564 fn send_raw(&self) -> Result<(), fidl::Error> {
565 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
566 (),
567 self.tx_id,
568 0x4c2c27ba4c60ea21,
569 fidl::encoding::DynamicFlags::empty(),
570 )
571 }
572}
573
574#[must_use = "FIDL methods require a response to be sent"]
575#[derive(Debug)]
576pub struct ControlSetSourceStatusResponder {
577 control_handle: std::mem::ManuallyDrop<ControlControlHandle>,
578 tx_id: u32,
579}
580
581impl std::ops::Drop for ControlSetSourceStatusResponder {
585 fn drop(&mut self) {
586 self.control_handle.shutdown();
587 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
589 }
590}
591
592impl fidl::endpoints::Responder for ControlSetSourceStatusResponder {
593 type ControlHandle = ControlControlHandle;
594
595 fn control_handle(&self) -> &ControlControlHandle {
596 &self.control_handle
597 }
598
599 fn drop_without_shutdown(mut self) {
600 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
602 std::mem::forget(self);
604 }
605}
606
607impl ControlSetSourceStatusResponder {
608 pub fn send(self) -> Result<(), fidl::Error> {
612 let _result = self.send_raw();
613 if _result.is_err() {
614 self.control_handle.shutdown();
615 }
616 self.drop_without_shutdown();
617 _result
618 }
619
620 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
622 let _result = self.send_raw();
623 self.drop_without_shutdown();
624 _result
625 }
626
627 fn send_raw(&self) -> Result<(), fidl::Error> {
628 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
629 (),
630 self.tx_id,
631 0x3d3137802b73710f,
632 fidl::encoding::DynamicFlags::empty(),
633 )
634 }
635}
636
637#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
638pub struct ServiceMarker;
639
640#[cfg(target_os = "fuchsia")]
641impl fidl::endpoints::ServiceMarker for ServiceMarker {
642 type Proxy = ServiceProxy;
643 type Request = ServiceRequest;
644 const SERVICE_NAME: &'static str = "test.hardwarepowercontrol.Service";
645}
646
647#[cfg(target_os = "fuchsia")]
650pub enum ServiceRequest {
651 Control(ControlRequestStream),
652}
653
654#[cfg(target_os = "fuchsia")]
655impl fidl::endpoints::ServiceRequest for ServiceRequest {
656 type Service = ServiceMarker;
657
658 fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
659 match name {
660 "control" => Self::Control(
661 <ControlRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
662 ),
663 _ => panic!("no such member protocol name for service Service"),
664 }
665 }
666
667 fn member_names() -> &'static [&'static str] {
668 &["control"]
669 }
670}
671#[cfg(target_os = "fuchsia")]
672pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
673
674#[cfg(target_os = "fuchsia")]
675impl fidl::endpoints::ServiceProxy for ServiceProxy {
676 type Service = ServiceMarker;
677
678 fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
679 Self(opener)
680 }
681}
682
683#[cfg(target_os = "fuchsia")]
684impl ServiceProxy {
685 pub fn connect_to_control(&self) -> Result<ControlProxy, fidl::Error> {
686 let (proxy, server_end) = fidl::endpoints::create_proxy::<ControlMarker>();
687 self.connect_channel_to_control(server_end)?;
688 Ok(proxy)
689 }
690
691 pub fn connect_to_control_sync(&self) -> Result<ControlSynchronousProxy, fidl::Error> {
694 let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<ControlMarker>();
695 self.connect_channel_to_control(server_end)?;
696 Ok(proxy)
697 }
698
699 pub fn connect_channel_to_control(
702 &self,
703 server_end: fidl::endpoints::ServerEnd<ControlMarker>,
704 ) -> Result<(), fidl::Error> {
705 self.0.open_member("control", server_end.into_channel())
706 }
707
708 pub fn instance_name(&self) -> &str {
709 self.0.instance_name()
710 }
711}
712
713mod internal {
714 use super::*;
715}