Skip to main content

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