fidl_fuchsia_bluetooth_pandora/
fidl_fuchsia_bluetooth_pandora.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![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_bluetooth_pandora__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct GrpcServerControllerMarker;
16
17impl fidl::endpoints::ProtocolMarker for GrpcServerControllerMarker {
18    type Proxy = GrpcServerControllerProxy;
19    type RequestStream = GrpcServerControllerRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = GrpcServerControllerSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.pandora.GrpcServerController";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for GrpcServerControllerMarker {}
26pub type GrpcServerControllerStartResult = Result<(), ServiceError>;
27
28pub trait GrpcServerControllerProxyInterface: Send + Sync {
29    type StartResponseFut: std::future::Future<Output = Result<GrpcServerControllerStartResult, fidl::Error>>
30        + Send;
31    fn r#start(&self, payload: &GrpcServerControllerStartRequest) -> Self::StartResponseFut;
32    type StopResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
33    fn r#stop(&self) -> Self::StopResponseFut;
34}
35#[derive(Debug)]
36#[cfg(target_os = "fuchsia")]
37pub struct GrpcServerControllerSynchronousProxy {
38    client: fidl::client::sync::Client,
39}
40
41#[cfg(target_os = "fuchsia")]
42impl fidl::endpoints::SynchronousProxy for GrpcServerControllerSynchronousProxy {
43    type Proxy = GrpcServerControllerProxy;
44    type Protocol = GrpcServerControllerMarker;
45
46    fn from_channel(inner: fidl::Channel) -> Self {
47        Self::new(inner)
48    }
49
50    fn into_channel(self) -> fidl::Channel {
51        self.client.into_channel()
52    }
53
54    fn as_channel(&self) -> &fidl::Channel {
55        self.client.as_channel()
56    }
57}
58
59#[cfg(target_os = "fuchsia")]
60impl GrpcServerControllerSynchronousProxy {
61    pub fn new(channel: fidl::Channel) -> Self {
62        let protocol_name =
63            <GrpcServerControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
64        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
65    }
66
67    pub fn into_channel(self) -> fidl::Channel {
68        self.client.into_channel()
69    }
70
71    /// Waits until an event arrives and returns it. It is safe for other
72    /// threads to make concurrent requests while waiting for an event.
73    pub fn wait_for_event(
74        &self,
75        deadline: zx::MonotonicInstant,
76    ) -> Result<GrpcServerControllerEvent, fidl::Error> {
77        GrpcServerControllerEvent::decode(self.client.wait_for_event(deadline)?)
78    }
79
80    /// Start Pandora interface gRPC server.
81    ///
82    /// + request `port` is the Fuchsia port on which the gRPC server will listen.
83    ///
84    /// * error Returns `ALREADY_RUNNING` if a gRPC server is already running.
85    /// * error Returns `FAILED` if there was an internal error starting the server.
86    pub fn r#start(
87        &self,
88        mut payload: &GrpcServerControllerStartRequest,
89        ___deadline: zx::MonotonicInstant,
90    ) -> Result<GrpcServerControllerStartResult, fidl::Error> {
91        let _response = self.client.send_query::<
92            GrpcServerControllerStartRequest,
93            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, ServiceError>,
94        >(
95            payload,
96            0x39b64f9031375c29,
97            fidl::encoding::DynamicFlags::FLEXIBLE,
98            ___deadline,
99        )?
100        .into_result::<GrpcServerControllerMarker>("start")?;
101        Ok(_response.map(|x| x))
102    }
103
104    /// Stop gRPC server if running.
105    pub fn r#stop(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
106        let _response = self.client.send_query::<
107            fidl::encoding::EmptyPayload,
108            fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
109        >(
110            (),
111            0x4e8601feb5d930b9,
112            fidl::encoding::DynamicFlags::FLEXIBLE,
113            ___deadline,
114        )?
115        .into_result::<GrpcServerControllerMarker>("stop")?;
116        Ok(_response)
117    }
118}
119
120#[cfg(target_os = "fuchsia")]
121impl From<GrpcServerControllerSynchronousProxy> for zx::NullableHandle {
122    fn from(value: GrpcServerControllerSynchronousProxy) -> Self {
123        value.into_channel().into()
124    }
125}
126
127#[cfg(target_os = "fuchsia")]
128impl From<fidl::Channel> for GrpcServerControllerSynchronousProxy {
129    fn from(value: fidl::Channel) -> Self {
130        Self::new(value)
131    }
132}
133
134#[cfg(target_os = "fuchsia")]
135impl fidl::endpoints::FromClient for GrpcServerControllerSynchronousProxy {
136    type Protocol = GrpcServerControllerMarker;
137
138    fn from_client(value: fidl::endpoints::ClientEnd<GrpcServerControllerMarker>) -> Self {
139        Self::new(value.into_channel())
140    }
141}
142
143#[derive(Debug, Clone)]
144pub struct GrpcServerControllerProxy {
145    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
146}
147
148impl fidl::endpoints::Proxy for GrpcServerControllerProxy {
149    type Protocol = GrpcServerControllerMarker;
150
151    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
152        Self::new(inner)
153    }
154
155    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
156        self.client.into_channel().map_err(|client| Self { client })
157    }
158
159    fn as_channel(&self) -> &::fidl::AsyncChannel {
160        self.client.as_channel()
161    }
162}
163
164impl GrpcServerControllerProxy {
165    /// Create a new Proxy for fuchsia.bluetooth.pandora/GrpcServerController.
166    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
167        let protocol_name =
168            <GrpcServerControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
169        Self { client: fidl::client::Client::new(channel, protocol_name) }
170    }
171
172    /// Get a Stream of events from the remote end of the protocol.
173    ///
174    /// # Panics
175    ///
176    /// Panics if the event stream was already taken.
177    pub fn take_event_stream(&self) -> GrpcServerControllerEventStream {
178        GrpcServerControllerEventStream { event_receiver: self.client.take_event_receiver() }
179    }
180
181    /// Start Pandora interface gRPC server.
182    ///
183    /// + request `port` is the Fuchsia port on which the gRPC server will listen.
184    ///
185    /// * error Returns `ALREADY_RUNNING` if a gRPC server is already running.
186    /// * error Returns `FAILED` if there was an internal error starting the server.
187    pub fn r#start(
188        &self,
189        mut payload: &GrpcServerControllerStartRequest,
190    ) -> fidl::client::QueryResponseFut<
191        GrpcServerControllerStartResult,
192        fidl::encoding::DefaultFuchsiaResourceDialect,
193    > {
194        GrpcServerControllerProxyInterface::r#start(self, payload)
195    }
196
197    /// Stop gRPC server if running.
198    pub fn r#stop(
199        &self,
200    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
201        GrpcServerControllerProxyInterface::r#stop(self)
202    }
203}
204
205impl GrpcServerControllerProxyInterface for GrpcServerControllerProxy {
206    type StartResponseFut = fidl::client::QueryResponseFut<
207        GrpcServerControllerStartResult,
208        fidl::encoding::DefaultFuchsiaResourceDialect,
209    >;
210    fn r#start(&self, mut payload: &GrpcServerControllerStartRequest) -> Self::StartResponseFut {
211        fn _decode(
212            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
213        ) -> Result<GrpcServerControllerStartResult, fidl::Error> {
214            let _response = fidl::client::decode_transaction_body::<
215                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, ServiceError>,
216                fidl::encoding::DefaultFuchsiaResourceDialect,
217                0x39b64f9031375c29,
218            >(_buf?)?
219            .into_result::<GrpcServerControllerMarker>("start")?;
220            Ok(_response.map(|x| x))
221        }
222        self.client.send_query_and_decode::<
223            GrpcServerControllerStartRequest,
224            GrpcServerControllerStartResult,
225        >(
226            payload,
227            0x39b64f9031375c29,
228            fidl::encoding::DynamicFlags::FLEXIBLE,
229            _decode,
230        )
231    }
232
233    type StopResponseFut =
234        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
235    fn r#stop(&self) -> Self::StopResponseFut {
236        fn _decode(
237            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
238        ) -> Result<(), fidl::Error> {
239            let _response = fidl::client::decode_transaction_body::<
240                fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
241                fidl::encoding::DefaultFuchsiaResourceDialect,
242                0x4e8601feb5d930b9,
243            >(_buf?)?
244            .into_result::<GrpcServerControllerMarker>("stop")?;
245            Ok(_response)
246        }
247        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
248            (),
249            0x4e8601feb5d930b9,
250            fidl::encoding::DynamicFlags::FLEXIBLE,
251            _decode,
252        )
253    }
254}
255
256pub struct GrpcServerControllerEventStream {
257    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
258}
259
260impl std::marker::Unpin for GrpcServerControllerEventStream {}
261
262impl futures::stream::FusedStream for GrpcServerControllerEventStream {
263    fn is_terminated(&self) -> bool {
264        self.event_receiver.is_terminated()
265    }
266}
267
268impl futures::Stream for GrpcServerControllerEventStream {
269    type Item = Result<GrpcServerControllerEvent, fidl::Error>;
270
271    fn poll_next(
272        mut self: std::pin::Pin<&mut Self>,
273        cx: &mut std::task::Context<'_>,
274    ) -> std::task::Poll<Option<Self::Item>> {
275        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
276            &mut self.event_receiver,
277            cx
278        )?) {
279            Some(buf) => std::task::Poll::Ready(Some(GrpcServerControllerEvent::decode(buf))),
280            None => std::task::Poll::Ready(None),
281        }
282    }
283}
284
285#[derive(Debug)]
286pub enum GrpcServerControllerEvent {
287    #[non_exhaustive]
288    _UnknownEvent {
289        /// Ordinal of the event that was sent.
290        ordinal: u64,
291    },
292}
293
294impl GrpcServerControllerEvent {
295    /// Decodes a message buffer as a [`GrpcServerControllerEvent`].
296    fn decode(
297        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
298    ) -> Result<GrpcServerControllerEvent, fidl::Error> {
299        let (bytes, _handles) = buf.split_mut();
300        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
301        debug_assert_eq!(tx_header.tx_id, 0);
302        match tx_header.ordinal {
303            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
304                Ok(GrpcServerControllerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
305            }
306            _ => Err(fidl::Error::UnknownOrdinal {
307                ordinal: tx_header.ordinal,
308                protocol_name:
309                    <GrpcServerControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
310            }),
311        }
312    }
313}
314
315/// A Stream of incoming requests for fuchsia.bluetooth.pandora/GrpcServerController.
316pub struct GrpcServerControllerRequestStream {
317    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
318    is_terminated: bool,
319}
320
321impl std::marker::Unpin for GrpcServerControllerRequestStream {}
322
323impl futures::stream::FusedStream for GrpcServerControllerRequestStream {
324    fn is_terminated(&self) -> bool {
325        self.is_terminated
326    }
327}
328
329impl fidl::endpoints::RequestStream for GrpcServerControllerRequestStream {
330    type Protocol = GrpcServerControllerMarker;
331    type ControlHandle = GrpcServerControllerControlHandle;
332
333    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
334        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
335    }
336
337    fn control_handle(&self) -> Self::ControlHandle {
338        GrpcServerControllerControlHandle { inner: self.inner.clone() }
339    }
340
341    fn into_inner(
342        self,
343    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
344    {
345        (self.inner, self.is_terminated)
346    }
347
348    fn from_inner(
349        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
350        is_terminated: bool,
351    ) -> Self {
352        Self { inner, is_terminated }
353    }
354}
355
356impl futures::Stream for GrpcServerControllerRequestStream {
357    type Item = Result<GrpcServerControllerRequest, fidl::Error>;
358
359    fn poll_next(
360        mut self: std::pin::Pin<&mut Self>,
361        cx: &mut std::task::Context<'_>,
362    ) -> std::task::Poll<Option<Self::Item>> {
363        let this = &mut *self;
364        if this.inner.check_shutdown(cx) {
365            this.is_terminated = true;
366            return std::task::Poll::Ready(None);
367        }
368        if this.is_terminated {
369            panic!("polled GrpcServerControllerRequestStream after completion");
370        }
371        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
372            |bytes, handles| {
373                match this.inner.channel().read_etc(cx, bytes, handles) {
374                    std::task::Poll::Ready(Ok(())) => {}
375                    std::task::Poll::Pending => return std::task::Poll::Pending,
376                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
377                        this.is_terminated = true;
378                        return std::task::Poll::Ready(None);
379                    }
380                    std::task::Poll::Ready(Err(e)) => {
381                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
382                            e.into(),
383                        ))));
384                    }
385                }
386
387                // A message has been received from the channel
388                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
389
390                std::task::Poll::Ready(Some(match header.ordinal {
391                0x39b64f9031375c29 => {
392                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
393                    let mut req = fidl::new_empty!(GrpcServerControllerStartRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
394                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GrpcServerControllerStartRequest>(&header, _body_bytes, handles, &mut req)?;
395                    let control_handle = GrpcServerControllerControlHandle {
396                        inner: this.inner.clone(),
397                    };
398                    Ok(GrpcServerControllerRequest::Start {payload: req,
399                        responder: GrpcServerControllerStartResponder {
400                            control_handle: std::mem::ManuallyDrop::new(control_handle),
401                            tx_id: header.tx_id,
402                        },
403                    })
404                }
405                0x4e8601feb5d930b9 => {
406                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
407                    let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload, fidl::encoding::DefaultFuchsiaResourceDialect);
408                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
409                    let control_handle = GrpcServerControllerControlHandle {
410                        inner: this.inner.clone(),
411                    };
412                    Ok(GrpcServerControllerRequest::Stop {
413                        responder: GrpcServerControllerStopResponder {
414                            control_handle: std::mem::ManuallyDrop::new(control_handle),
415                            tx_id: header.tx_id,
416                        },
417                    })
418                }
419                _ if header.tx_id == 0 && header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
420                    Ok(GrpcServerControllerRequest::_UnknownMethod {
421                        ordinal: header.ordinal,
422                        control_handle: GrpcServerControllerControlHandle { inner: this.inner.clone() },
423                        method_type: fidl::MethodType::OneWay,
424                    })
425                }
426                _ if header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
427                    this.inner.send_framework_err(
428                        fidl::encoding::FrameworkErr::UnknownMethod,
429                        header.tx_id,
430                        header.ordinal,
431                        header.dynamic_flags(),
432                        (bytes, handles),
433                    )?;
434                    Ok(GrpcServerControllerRequest::_UnknownMethod {
435                        ordinal: header.ordinal,
436                        control_handle: GrpcServerControllerControlHandle { inner: this.inner.clone() },
437                        method_type: fidl::MethodType::TwoWay,
438                    })
439                }
440                _ => Err(fidl::Error::UnknownOrdinal {
441                    ordinal: header.ordinal,
442                    protocol_name: <GrpcServerControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
443                }),
444            }))
445            },
446        )
447    }
448}
449
450/// Controls the lifecycle of a gRPC server that implements the [Pandora Bluetooth testing
451/// interfaces](https://github.com/google/bt-test-interfaces).
452#[derive(Debug)]
453pub enum GrpcServerControllerRequest {
454    /// Start Pandora interface gRPC server.
455    ///
456    /// + request `port` is the Fuchsia port on which the gRPC server will listen.
457    ///
458    /// * error Returns `ALREADY_RUNNING` if a gRPC server is already running.
459    /// * error Returns `FAILED` if there was an internal error starting the server.
460    Start {
461        payload: GrpcServerControllerStartRequest,
462        responder: GrpcServerControllerStartResponder,
463    },
464    /// Stop gRPC server if running.
465    Stop { responder: GrpcServerControllerStopResponder },
466    /// An interaction was received which does not match any known method.
467    #[non_exhaustive]
468    _UnknownMethod {
469        /// Ordinal of the method that was called.
470        ordinal: u64,
471        control_handle: GrpcServerControllerControlHandle,
472        method_type: fidl::MethodType,
473    },
474}
475
476impl GrpcServerControllerRequest {
477    #[allow(irrefutable_let_patterns)]
478    pub fn into_start(
479        self,
480    ) -> Option<(GrpcServerControllerStartRequest, GrpcServerControllerStartResponder)> {
481        if let GrpcServerControllerRequest::Start { payload, responder } = self {
482            Some((payload, responder))
483        } else {
484            None
485        }
486    }
487
488    #[allow(irrefutable_let_patterns)]
489    pub fn into_stop(self) -> Option<(GrpcServerControllerStopResponder)> {
490        if let GrpcServerControllerRequest::Stop { responder } = self {
491            Some((responder))
492        } else {
493            None
494        }
495    }
496
497    /// Name of the method defined in FIDL
498    pub fn method_name(&self) -> &'static str {
499        match *self {
500            GrpcServerControllerRequest::Start { .. } => "start",
501            GrpcServerControllerRequest::Stop { .. } => "stop",
502            GrpcServerControllerRequest::_UnknownMethod {
503                method_type: fidl::MethodType::OneWay,
504                ..
505            } => "unknown one-way method",
506            GrpcServerControllerRequest::_UnknownMethod {
507                method_type: fidl::MethodType::TwoWay,
508                ..
509            } => "unknown two-way method",
510        }
511    }
512}
513
514#[derive(Debug, Clone)]
515pub struct GrpcServerControllerControlHandle {
516    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
517}
518
519impl fidl::endpoints::ControlHandle for GrpcServerControllerControlHandle {
520    fn shutdown(&self) {
521        self.inner.shutdown()
522    }
523
524    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
525        self.inner.shutdown_with_epitaph(status)
526    }
527
528    fn is_closed(&self) -> bool {
529        self.inner.channel().is_closed()
530    }
531    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
532        self.inner.channel().on_closed()
533    }
534
535    #[cfg(target_os = "fuchsia")]
536    fn signal_peer(
537        &self,
538        clear_mask: zx::Signals,
539        set_mask: zx::Signals,
540    ) -> Result<(), zx_status::Status> {
541        use fidl::Peered;
542        self.inner.channel().signal_peer(clear_mask, set_mask)
543    }
544}
545
546impl GrpcServerControllerControlHandle {}
547
548#[must_use = "FIDL methods require a response to be sent"]
549#[derive(Debug)]
550pub struct GrpcServerControllerStartResponder {
551    control_handle: std::mem::ManuallyDrop<GrpcServerControllerControlHandle>,
552    tx_id: u32,
553}
554
555/// Set the the channel to be shutdown (see [`GrpcServerControllerControlHandle::shutdown`])
556/// if the responder is dropped without sending a response, so that the client
557/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
558impl std::ops::Drop for GrpcServerControllerStartResponder {
559    fn drop(&mut self) {
560        self.control_handle.shutdown();
561        // Safety: drops once, never accessed again
562        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
563    }
564}
565
566impl fidl::endpoints::Responder for GrpcServerControllerStartResponder {
567    type ControlHandle = GrpcServerControllerControlHandle;
568
569    fn control_handle(&self) -> &GrpcServerControllerControlHandle {
570        &self.control_handle
571    }
572
573    fn drop_without_shutdown(mut self) {
574        // Safety: drops once, never accessed again due to mem::forget
575        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
576        // Prevent Drop from running (which would shut down the channel)
577        std::mem::forget(self);
578    }
579}
580
581impl GrpcServerControllerStartResponder {
582    /// Sends a response to the FIDL transaction.
583    ///
584    /// Sets the channel to shutdown if an error occurs.
585    pub fn send(self, mut result: Result<(), ServiceError>) -> Result<(), fidl::Error> {
586        let _result = self.send_raw(result);
587        if _result.is_err() {
588            self.control_handle.shutdown();
589        }
590        self.drop_without_shutdown();
591        _result
592    }
593
594    /// Similar to "send" but does not shutdown the channel if an error occurs.
595    pub fn send_no_shutdown_on_err(
596        self,
597        mut result: Result<(), ServiceError>,
598    ) -> Result<(), fidl::Error> {
599        let _result = self.send_raw(result);
600        self.drop_without_shutdown();
601        _result
602    }
603
604    fn send_raw(&self, mut result: Result<(), ServiceError>) -> Result<(), fidl::Error> {
605        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
606            fidl::encoding::EmptyStruct,
607            ServiceError,
608        >>(
609            fidl::encoding::FlexibleResult::new(result),
610            self.tx_id,
611            0x39b64f9031375c29,
612            fidl::encoding::DynamicFlags::FLEXIBLE,
613        )
614    }
615}
616
617#[must_use = "FIDL methods require a response to be sent"]
618#[derive(Debug)]
619pub struct GrpcServerControllerStopResponder {
620    control_handle: std::mem::ManuallyDrop<GrpcServerControllerControlHandle>,
621    tx_id: u32,
622}
623
624/// Set the the channel to be shutdown (see [`GrpcServerControllerControlHandle::shutdown`])
625/// if the responder is dropped without sending a response, so that the client
626/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
627impl std::ops::Drop for GrpcServerControllerStopResponder {
628    fn drop(&mut self) {
629        self.control_handle.shutdown();
630        // Safety: drops once, never accessed again
631        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
632    }
633}
634
635impl fidl::endpoints::Responder for GrpcServerControllerStopResponder {
636    type ControlHandle = GrpcServerControllerControlHandle;
637
638    fn control_handle(&self) -> &GrpcServerControllerControlHandle {
639        &self.control_handle
640    }
641
642    fn drop_without_shutdown(mut self) {
643        // Safety: drops once, never accessed again due to mem::forget
644        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
645        // Prevent Drop from running (which would shut down the channel)
646        std::mem::forget(self);
647    }
648}
649
650impl GrpcServerControllerStopResponder {
651    /// Sends a response to the FIDL transaction.
652    ///
653    /// Sets the channel to shutdown if an error occurs.
654    pub fn send(self) -> Result<(), fidl::Error> {
655        let _result = self.send_raw();
656        if _result.is_err() {
657            self.control_handle.shutdown();
658        }
659        self.drop_without_shutdown();
660        _result
661    }
662
663    /// Similar to "send" but does not shutdown the channel if an error occurs.
664    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
665        let _result = self.send_raw();
666        self.drop_without_shutdown();
667        _result
668    }
669
670    fn send_raw(&self) -> Result<(), fidl::Error> {
671        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
672            fidl::encoding::Flexible::new(()),
673            self.tx_id,
674            0x4e8601feb5d930b9,
675            fidl::encoding::DynamicFlags::FLEXIBLE,
676        )
677    }
678}
679
680#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
681pub struct RootcanalClientControllerMarker;
682
683impl fidl::endpoints::ProtocolMarker for RootcanalClientControllerMarker {
684    type Proxy = RootcanalClientControllerProxy;
685    type RequestStream = RootcanalClientControllerRequestStream;
686    #[cfg(target_os = "fuchsia")]
687    type SynchronousProxy = RootcanalClientControllerSynchronousProxy;
688
689    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.pandora.RootcanalClientController";
690}
691impl fidl::endpoints::DiscoverableProtocolMarker for RootcanalClientControllerMarker {}
692pub type RootcanalClientControllerStartResult = Result<(), ServiceError>;
693
694pub trait RootcanalClientControllerProxyInterface: Send + Sync {
695    type StartResponseFut: std::future::Future<Output = Result<RootcanalClientControllerStartResult, fidl::Error>>
696        + Send;
697    fn r#start(&self, payload: &RootcanalClientControllerStartRequest) -> Self::StartResponseFut;
698    type StopResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
699    fn r#stop(&self) -> Self::StopResponseFut;
700}
701#[derive(Debug)]
702#[cfg(target_os = "fuchsia")]
703pub struct RootcanalClientControllerSynchronousProxy {
704    client: fidl::client::sync::Client,
705}
706
707#[cfg(target_os = "fuchsia")]
708impl fidl::endpoints::SynchronousProxy for RootcanalClientControllerSynchronousProxy {
709    type Proxy = RootcanalClientControllerProxy;
710    type Protocol = RootcanalClientControllerMarker;
711
712    fn from_channel(inner: fidl::Channel) -> Self {
713        Self::new(inner)
714    }
715
716    fn into_channel(self) -> fidl::Channel {
717        self.client.into_channel()
718    }
719
720    fn as_channel(&self) -> &fidl::Channel {
721        self.client.as_channel()
722    }
723}
724
725#[cfg(target_os = "fuchsia")]
726impl RootcanalClientControllerSynchronousProxy {
727    pub fn new(channel: fidl::Channel) -> Self {
728        let protocol_name =
729            <RootcanalClientControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
730        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
731    }
732
733    pub fn into_channel(self) -> fidl::Channel {
734        self.client.into_channel()
735    }
736
737    /// Waits until an event arrives and returns it. It is safe for other
738    /// threads to make concurrent requests while waiting for an event.
739    pub fn wait_for_event(
740        &self,
741        deadline: zx::MonotonicInstant,
742    ) -> Result<RootcanalClientControllerEvent, fidl::Error> {
743        RootcanalClientControllerEvent::decode(self.client.wait_for_event(deadline)?)
744    }
745
746    /// Start bt-rootcanal if it is not already running.
747    ///
748    /// + request `ip` is the IP address of the host running the Rootcanal server.
749    /// + request `port` is the port on the host on which the Rootcanal server is listening.
750    ///
751    /// * error Returns `ALREADY_RUNNING` if bt-rootcanal is already running.
752    /// * error Returns `INVALID_IP` if the IP address could not be parsed.
753    /// * error Returns `CONNECTION_FAILED` if a connection to the Rootcanal server could not be
754    ///         established.
755    /// * error Returns `FAILED` if there was an internal error starting bt-rootcanal.
756    pub fn r#start(
757        &self,
758        mut payload: &RootcanalClientControllerStartRequest,
759        ___deadline: zx::MonotonicInstant,
760    ) -> Result<RootcanalClientControllerStartResult, fidl::Error> {
761        let _response = self.client.send_query::<
762            RootcanalClientControllerStartRequest,
763            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, ServiceError>,
764        >(
765            payload,
766            0xde429b8e402832c,
767            fidl::encoding::DynamicFlags::FLEXIBLE,
768            ___deadline,
769        )?
770        .into_result::<RootcanalClientControllerMarker>("start")?;
771        Ok(_response.map(|x| x))
772    }
773
774    /// Stop bt-rootcanal if running.
775    pub fn r#stop(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
776        let _response = self.client.send_query::<
777            fidl::encoding::EmptyPayload,
778            fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
779        >(
780            (),
781            0x30419bba3f039d1d,
782            fidl::encoding::DynamicFlags::FLEXIBLE,
783            ___deadline,
784        )?
785        .into_result::<RootcanalClientControllerMarker>("stop")?;
786        Ok(_response)
787    }
788}
789
790#[cfg(target_os = "fuchsia")]
791impl From<RootcanalClientControllerSynchronousProxy> for zx::NullableHandle {
792    fn from(value: RootcanalClientControllerSynchronousProxy) -> Self {
793        value.into_channel().into()
794    }
795}
796
797#[cfg(target_os = "fuchsia")]
798impl From<fidl::Channel> for RootcanalClientControllerSynchronousProxy {
799    fn from(value: fidl::Channel) -> Self {
800        Self::new(value)
801    }
802}
803
804#[cfg(target_os = "fuchsia")]
805impl fidl::endpoints::FromClient for RootcanalClientControllerSynchronousProxy {
806    type Protocol = RootcanalClientControllerMarker;
807
808    fn from_client(value: fidl::endpoints::ClientEnd<RootcanalClientControllerMarker>) -> Self {
809        Self::new(value.into_channel())
810    }
811}
812
813#[derive(Debug, Clone)]
814pub struct RootcanalClientControllerProxy {
815    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
816}
817
818impl fidl::endpoints::Proxy for RootcanalClientControllerProxy {
819    type Protocol = RootcanalClientControllerMarker;
820
821    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
822        Self::new(inner)
823    }
824
825    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
826        self.client.into_channel().map_err(|client| Self { client })
827    }
828
829    fn as_channel(&self) -> &::fidl::AsyncChannel {
830        self.client.as_channel()
831    }
832}
833
834impl RootcanalClientControllerProxy {
835    /// Create a new Proxy for fuchsia.bluetooth.pandora/RootcanalClientController.
836    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
837        let protocol_name =
838            <RootcanalClientControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
839        Self { client: fidl::client::Client::new(channel, protocol_name) }
840    }
841
842    /// Get a Stream of events from the remote end of the protocol.
843    ///
844    /// # Panics
845    ///
846    /// Panics if the event stream was already taken.
847    pub fn take_event_stream(&self) -> RootcanalClientControllerEventStream {
848        RootcanalClientControllerEventStream { event_receiver: self.client.take_event_receiver() }
849    }
850
851    /// Start bt-rootcanal if it is not already running.
852    ///
853    /// + request `ip` is the IP address of the host running the Rootcanal server.
854    /// + request `port` is the port on the host on which the Rootcanal server is listening.
855    ///
856    /// * error Returns `ALREADY_RUNNING` if bt-rootcanal is already running.
857    /// * error Returns `INVALID_IP` if the IP address could not be parsed.
858    /// * error Returns `CONNECTION_FAILED` if a connection to the Rootcanal server could not be
859    ///         established.
860    /// * error Returns `FAILED` if there was an internal error starting bt-rootcanal.
861    pub fn r#start(
862        &self,
863        mut payload: &RootcanalClientControllerStartRequest,
864    ) -> fidl::client::QueryResponseFut<
865        RootcanalClientControllerStartResult,
866        fidl::encoding::DefaultFuchsiaResourceDialect,
867    > {
868        RootcanalClientControllerProxyInterface::r#start(self, payload)
869    }
870
871    /// Stop bt-rootcanal if running.
872    pub fn r#stop(
873        &self,
874    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
875        RootcanalClientControllerProxyInterface::r#stop(self)
876    }
877}
878
879impl RootcanalClientControllerProxyInterface for RootcanalClientControllerProxy {
880    type StartResponseFut = fidl::client::QueryResponseFut<
881        RootcanalClientControllerStartResult,
882        fidl::encoding::DefaultFuchsiaResourceDialect,
883    >;
884    fn r#start(
885        &self,
886        mut payload: &RootcanalClientControllerStartRequest,
887    ) -> Self::StartResponseFut {
888        fn _decode(
889            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
890        ) -> Result<RootcanalClientControllerStartResult, fidl::Error> {
891            let _response = fidl::client::decode_transaction_body::<
892                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, ServiceError>,
893                fidl::encoding::DefaultFuchsiaResourceDialect,
894                0xde429b8e402832c,
895            >(_buf?)?
896            .into_result::<RootcanalClientControllerMarker>("start")?;
897            Ok(_response.map(|x| x))
898        }
899        self.client.send_query_and_decode::<
900            RootcanalClientControllerStartRequest,
901            RootcanalClientControllerStartResult,
902        >(
903            payload,
904            0xde429b8e402832c,
905            fidl::encoding::DynamicFlags::FLEXIBLE,
906            _decode,
907        )
908    }
909
910    type StopResponseFut =
911        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
912    fn r#stop(&self) -> Self::StopResponseFut {
913        fn _decode(
914            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
915        ) -> Result<(), fidl::Error> {
916            let _response = fidl::client::decode_transaction_body::<
917                fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
918                fidl::encoding::DefaultFuchsiaResourceDialect,
919                0x30419bba3f039d1d,
920            >(_buf?)?
921            .into_result::<RootcanalClientControllerMarker>("stop")?;
922            Ok(_response)
923        }
924        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
925            (),
926            0x30419bba3f039d1d,
927            fidl::encoding::DynamicFlags::FLEXIBLE,
928            _decode,
929        )
930    }
931}
932
933pub struct RootcanalClientControllerEventStream {
934    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
935}
936
937impl std::marker::Unpin for RootcanalClientControllerEventStream {}
938
939impl futures::stream::FusedStream for RootcanalClientControllerEventStream {
940    fn is_terminated(&self) -> bool {
941        self.event_receiver.is_terminated()
942    }
943}
944
945impl futures::Stream for RootcanalClientControllerEventStream {
946    type Item = Result<RootcanalClientControllerEvent, fidl::Error>;
947
948    fn poll_next(
949        mut self: std::pin::Pin<&mut Self>,
950        cx: &mut std::task::Context<'_>,
951    ) -> std::task::Poll<Option<Self::Item>> {
952        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
953            &mut self.event_receiver,
954            cx
955        )?) {
956            Some(buf) => std::task::Poll::Ready(Some(RootcanalClientControllerEvent::decode(buf))),
957            None => std::task::Poll::Ready(None),
958        }
959    }
960}
961
962#[derive(Debug)]
963pub enum RootcanalClientControllerEvent {
964    #[non_exhaustive]
965    _UnknownEvent {
966        /// Ordinal of the event that was sent.
967        ordinal: u64,
968    },
969}
970
971impl RootcanalClientControllerEvent {
972    /// Decodes a message buffer as a [`RootcanalClientControllerEvent`].
973    fn decode(
974        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
975    ) -> Result<RootcanalClientControllerEvent, fidl::Error> {
976        let (bytes, _handles) = buf.split_mut();
977        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
978        debug_assert_eq!(tx_header.tx_id, 0);
979        match tx_header.ordinal {
980            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
981                Ok(RootcanalClientControllerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
982            }
983            _ => Err(fidl::Error::UnknownOrdinal {
984                ordinal: tx_header.ordinal,
985                protocol_name:
986                    <RootcanalClientControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
987            }),
988        }
989    }
990}
991
992/// A Stream of incoming requests for fuchsia.bluetooth.pandora/RootcanalClientController.
993pub struct RootcanalClientControllerRequestStream {
994    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
995    is_terminated: bool,
996}
997
998impl std::marker::Unpin for RootcanalClientControllerRequestStream {}
999
1000impl futures::stream::FusedStream for RootcanalClientControllerRequestStream {
1001    fn is_terminated(&self) -> bool {
1002        self.is_terminated
1003    }
1004}
1005
1006impl fidl::endpoints::RequestStream for RootcanalClientControllerRequestStream {
1007    type Protocol = RootcanalClientControllerMarker;
1008    type ControlHandle = RootcanalClientControllerControlHandle;
1009
1010    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1011        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1012    }
1013
1014    fn control_handle(&self) -> Self::ControlHandle {
1015        RootcanalClientControllerControlHandle { inner: self.inner.clone() }
1016    }
1017
1018    fn into_inner(
1019        self,
1020    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1021    {
1022        (self.inner, self.is_terminated)
1023    }
1024
1025    fn from_inner(
1026        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1027        is_terminated: bool,
1028    ) -> Self {
1029        Self { inner, is_terminated }
1030    }
1031}
1032
1033impl futures::Stream for RootcanalClientControllerRequestStream {
1034    type Item = Result<RootcanalClientControllerRequest, fidl::Error>;
1035
1036    fn poll_next(
1037        mut self: std::pin::Pin<&mut Self>,
1038        cx: &mut std::task::Context<'_>,
1039    ) -> std::task::Poll<Option<Self::Item>> {
1040        let this = &mut *self;
1041        if this.inner.check_shutdown(cx) {
1042            this.is_terminated = true;
1043            return std::task::Poll::Ready(None);
1044        }
1045        if this.is_terminated {
1046            panic!("polled RootcanalClientControllerRequestStream after completion");
1047        }
1048        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1049            |bytes, handles| {
1050                match this.inner.channel().read_etc(cx, bytes, handles) {
1051                    std::task::Poll::Ready(Ok(())) => {}
1052                    std::task::Poll::Pending => return std::task::Poll::Pending,
1053                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1054                        this.is_terminated = true;
1055                        return std::task::Poll::Ready(None);
1056                    }
1057                    std::task::Poll::Ready(Err(e)) => {
1058                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1059                            e.into(),
1060                        ))));
1061                    }
1062                }
1063
1064                // A message has been received from the channel
1065                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1066
1067                std::task::Poll::Ready(Some(match header.ordinal {
1068                0xde429b8e402832c => {
1069                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1070                    let mut req = fidl::new_empty!(RootcanalClientControllerStartRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
1071                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RootcanalClientControllerStartRequest>(&header, _body_bytes, handles, &mut req)?;
1072                    let control_handle = RootcanalClientControllerControlHandle {
1073                        inner: this.inner.clone(),
1074                    };
1075                    Ok(RootcanalClientControllerRequest::Start {payload: req,
1076                        responder: RootcanalClientControllerStartResponder {
1077                            control_handle: std::mem::ManuallyDrop::new(control_handle),
1078                            tx_id: header.tx_id,
1079                        },
1080                    })
1081                }
1082                0x30419bba3f039d1d => {
1083                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1084                    let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload, fidl::encoding::DefaultFuchsiaResourceDialect);
1085                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1086                    let control_handle = RootcanalClientControllerControlHandle {
1087                        inner: this.inner.clone(),
1088                    };
1089                    Ok(RootcanalClientControllerRequest::Stop {
1090                        responder: RootcanalClientControllerStopResponder {
1091                            control_handle: std::mem::ManuallyDrop::new(control_handle),
1092                            tx_id: header.tx_id,
1093                        },
1094                    })
1095                }
1096                _ if header.tx_id == 0 && header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
1097                    Ok(RootcanalClientControllerRequest::_UnknownMethod {
1098                        ordinal: header.ordinal,
1099                        control_handle: RootcanalClientControllerControlHandle { inner: this.inner.clone() },
1100                        method_type: fidl::MethodType::OneWay,
1101                    })
1102                }
1103                _ if header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
1104                    this.inner.send_framework_err(
1105                        fidl::encoding::FrameworkErr::UnknownMethod,
1106                        header.tx_id,
1107                        header.ordinal,
1108                        header.dynamic_flags(),
1109                        (bytes, handles),
1110                    )?;
1111                    Ok(RootcanalClientControllerRequest::_UnknownMethod {
1112                        ordinal: header.ordinal,
1113                        control_handle: RootcanalClientControllerControlHandle { inner: this.inner.clone() },
1114                        method_type: fidl::MethodType::TwoWay,
1115                    })
1116                }
1117                _ => Err(fidl::Error::UnknownOrdinal {
1118                    ordinal: header.ordinal,
1119                    protocol_name: <RootcanalClientControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1120                }),
1121            }))
1122            },
1123        )
1124    }
1125}
1126
1127/// Controls instances of bt-rootcanal, a tool that proxies HCI traffic between Fuchsia Bluetooth
1128/// and a [Rootcanal](https://github.com/google/rootcanal) server.
1129#[derive(Debug)]
1130pub enum RootcanalClientControllerRequest {
1131    /// Start bt-rootcanal if it is not already running.
1132    ///
1133    /// + request `ip` is the IP address of the host running the Rootcanal server.
1134    /// + request `port` is the port on the host on which the Rootcanal server is listening.
1135    ///
1136    /// * error Returns `ALREADY_RUNNING` if bt-rootcanal is already running.
1137    /// * error Returns `INVALID_IP` if the IP address could not be parsed.
1138    /// * error Returns `CONNECTION_FAILED` if a connection to the Rootcanal server could not be
1139    ///         established.
1140    /// * error Returns `FAILED` if there was an internal error starting bt-rootcanal.
1141    Start {
1142        payload: RootcanalClientControllerStartRequest,
1143        responder: RootcanalClientControllerStartResponder,
1144    },
1145    /// Stop bt-rootcanal if running.
1146    Stop { responder: RootcanalClientControllerStopResponder },
1147    /// An interaction was received which does not match any known method.
1148    #[non_exhaustive]
1149    _UnknownMethod {
1150        /// Ordinal of the method that was called.
1151        ordinal: u64,
1152        control_handle: RootcanalClientControllerControlHandle,
1153        method_type: fidl::MethodType,
1154    },
1155}
1156
1157impl RootcanalClientControllerRequest {
1158    #[allow(irrefutable_let_patterns)]
1159    pub fn into_start(
1160        self,
1161    ) -> Option<(RootcanalClientControllerStartRequest, RootcanalClientControllerStartResponder)>
1162    {
1163        if let RootcanalClientControllerRequest::Start { payload, responder } = self {
1164            Some((payload, responder))
1165        } else {
1166            None
1167        }
1168    }
1169
1170    #[allow(irrefutable_let_patterns)]
1171    pub fn into_stop(self) -> Option<(RootcanalClientControllerStopResponder)> {
1172        if let RootcanalClientControllerRequest::Stop { responder } = self {
1173            Some((responder))
1174        } else {
1175            None
1176        }
1177    }
1178
1179    /// Name of the method defined in FIDL
1180    pub fn method_name(&self) -> &'static str {
1181        match *self {
1182            RootcanalClientControllerRequest::Start { .. } => "start",
1183            RootcanalClientControllerRequest::Stop { .. } => "stop",
1184            RootcanalClientControllerRequest::_UnknownMethod {
1185                method_type: fidl::MethodType::OneWay,
1186                ..
1187            } => "unknown one-way method",
1188            RootcanalClientControllerRequest::_UnknownMethod {
1189                method_type: fidl::MethodType::TwoWay,
1190                ..
1191            } => "unknown two-way method",
1192        }
1193    }
1194}
1195
1196#[derive(Debug, Clone)]
1197pub struct RootcanalClientControllerControlHandle {
1198    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1199}
1200
1201impl fidl::endpoints::ControlHandle for RootcanalClientControllerControlHandle {
1202    fn shutdown(&self) {
1203        self.inner.shutdown()
1204    }
1205
1206    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1207        self.inner.shutdown_with_epitaph(status)
1208    }
1209
1210    fn is_closed(&self) -> bool {
1211        self.inner.channel().is_closed()
1212    }
1213    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1214        self.inner.channel().on_closed()
1215    }
1216
1217    #[cfg(target_os = "fuchsia")]
1218    fn signal_peer(
1219        &self,
1220        clear_mask: zx::Signals,
1221        set_mask: zx::Signals,
1222    ) -> Result<(), zx_status::Status> {
1223        use fidl::Peered;
1224        self.inner.channel().signal_peer(clear_mask, set_mask)
1225    }
1226}
1227
1228impl RootcanalClientControllerControlHandle {}
1229
1230#[must_use = "FIDL methods require a response to be sent"]
1231#[derive(Debug)]
1232pub struct RootcanalClientControllerStartResponder {
1233    control_handle: std::mem::ManuallyDrop<RootcanalClientControllerControlHandle>,
1234    tx_id: u32,
1235}
1236
1237/// Set the the channel to be shutdown (see [`RootcanalClientControllerControlHandle::shutdown`])
1238/// if the responder is dropped without sending a response, so that the client
1239/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1240impl std::ops::Drop for RootcanalClientControllerStartResponder {
1241    fn drop(&mut self) {
1242        self.control_handle.shutdown();
1243        // Safety: drops once, never accessed again
1244        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1245    }
1246}
1247
1248impl fidl::endpoints::Responder for RootcanalClientControllerStartResponder {
1249    type ControlHandle = RootcanalClientControllerControlHandle;
1250
1251    fn control_handle(&self) -> &RootcanalClientControllerControlHandle {
1252        &self.control_handle
1253    }
1254
1255    fn drop_without_shutdown(mut self) {
1256        // Safety: drops once, never accessed again due to mem::forget
1257        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1258        // Prevent Drop from running (which would shut down the channel)
1259        std::mem::forget(self);
1260    }
1261}
1262
1263impl RootcanalClientControllerStartResponder {
1264    /// Sends a response to the FIDL transaction.
1265    ///
1266    /// Sets the channel to shutdown if an error occurs.
1267    pub fn send(self, mut result: Result<(), ServiceError>) -> Result<(), fidl::Error> {
1268        let _result = self.send_raw(result);
1269        if _result.is_err() {
1270            self.control_handle.shutdown();
1271        }
1272        self.drop_without_shutdown();
1273        _result
1274    }
1275
1276    /// Similar to "send" but does not shutdown the channel if an error occurs.
1277    pub fn send_no_shutdown_on_err(
1278        self,
1279        mut result: Result<(), ServiceError>,
1280    ) -> Result<(), fidl::Error> {
1281        let _result = self.send_raw(result);
1282        self.drop_without_shutdown();
1283        _result
1284    }
1285
1286    fn send_raw(&self, mut result: Result<(), ServiceError>) -> Result<(), fidl::Error> {
1287        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1288            fidl::encoding::EmptyStruct,
1289            ServiceError,
1290        >>(
1291            fidl::encoding::FlexibleResult::new(result),
1292            self.tx_id,
1293            0xde429b8e402832c,
1294            fidl::encoding::DynamicFlags::FLEXIBLE,
1295        )
1296    }
1297}
1298
1299#[must_use = "FIDL methods require a response to be sent"]
1300#[derive(Debug)]
1301pub struct RootcanalClientControllerStopResponder {
1302    control_handle: std::mem::ManuallyDrop<RootcanalClientControllerControlHandle>,
1303    tx_id: u32,
1304}
1305
1306/// Set the the channel to be shutdown (see [`RootcanalClientControllerControlHandle::shutdown`])
1307/// if the responder is dropped without sending a response, so that the client
1308/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1309impl std::ops::Drop for RootcanalClientControllerStopResponder {
1310    fn drop(&mut self) {
1311        self.control_handle.shutdown();
1312        // Safety: drops once, never accessed again
1313        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1314    }
1315}
1316
1317impl fidl::endpoints::Responder for RootcanalClientControllerStopResponder {
1318    type ControlHandle = RootcanalClientControllerControlHandle;
1319
1320    fn control_handle(&self) -> &RootcanalClientControllerControlHandle {
1321        &self.control_handle
1322    }
1323
1324    fn drop_without_shutdown(mut self) {
1325        // Safety: drops once, never accessed again due to mem::forget
1326        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1327        // Prevent Drop from running (which would shut down the channel)
1328        std::mem::forget(self);
1329    }
1330}
1331
1332impl RootcanalClientControllerStopResponder {
1333    /// Sends a response to the FIDL transaction.
1334    ///
1335    /// Sets the channel to shutdown if an error occurs.
1336    pub fn send(self) -> Result<(), fidl::Error> {
1337        let _result = self.send_raw();
1338        if _result.is_err() {
1339            self.control_handle.shutdown();
1340        }
1341        self.drop_without_shutdown();
1342        _result
1343    }
1344
1345    /// Similar to "send" but does not shutdown the channel if an error occurs.
1346    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1347        let _result = self.send_raw();
1348        self.drop_without_shutdown();
1349        _result
1350    }
1351
1352    fn send_raw(&self) -> Result<(), fidl::Error> {
1353        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
1354            fidl::encoding::Flexible::new(()),
1355            self.tx_id,
1356            0x30419bba3f039d1d,
1357            fidl::encoding::DynamicFlags::FLEXIBLE,
1358        )
1359    }
1360}
1361
1362mod internal {
1363    use super::*;
1364}