fidl_test_fidl_connector/
fidl_test_fidl_connector.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_test_fidl_connector_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct TestMarker;
16
17impl fidl::endpoints::ProtocolMarker for TestMarker {
18    type Proxy = TestProxy;
19    type RequestStream = TestRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = TestSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "test.fidl.connector.Test";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for TestMarker {}
26
27pub trait TestProxyInterface: Send + Sync {
28    type PingResponseFut: std::future::Future<Output = Result<u32, fidl::Error>> + Send;
29    fn r#ping(&self) -> Self::PingResponseFut;
30    type DisconnectResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
31    fn r#disconnect(&self) -> Self::DisconnectResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct TestSynchronousProxy {
36    client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for TestSynchronousProxy {
41    type Proxy = TestProxy;
42    type Protocol = TestMarker;
43
44    fn from_channel(inner: fidl::Channel) -> Self {
45        Self::new(inner)
46    }
47
48    fn into_channel(self) -> fidl::Channel {
49        self.client.into_channel()
50    }
51
52    fn as_channel(&self) -> &fidl::Channel {
53        self.client.as_channel()
54    }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl TestSynchronousProxy {
59    pub fn new(channel: fidl::Channel) -> Self {
60        let protocol_name = <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62    }
63
64    pub fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    /// Waits until an event arrives and returns it. It is safe for other
69    /// threads to make concurrent requests while waiting for an event.
70    pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<TestEvent, fidl::Error> {
71        TestEvent::decode(self.client.wait_for_event(deadline)?)
72    }
73
74    pub fn r#ping(&self, ___deadline: zx::MonotonicInstant) -> Result<u32, fidl::Error> {
75        let _response = self.client.send_query::<fidl::encoding::EmptyPayload, TestPingResponse>(
76            (),
77            0x23aa1eb7d24346cf,
78            fidl::encoding::DynamicFlags::empty(),
79            ___deadline,
80        )?;
81        Ok(_response.gen)
82    }
83
84    pub fn r#disconnect(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
85        let _response =
86            self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
87                (),
88                0x5a1b547382bf672e,
89                fidl::encoding::DynamicFlags::empty(),
90                ___deadline,
91            )?;
92        Ok(_response)
93    }
94}
95
96#[derive(Debug, Clone)]
97pub struct TestProxy {
98    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
99}
100
101impl fidl::endpoints::Proxy for TestProxy {
102    type Protocol = TestMarker;
103
104    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
105        Self::new(inner)
106    }
107
108    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
109        self.client.into_channel().map_err(|client| Self { client })
110    }
111
112    fn as_channel(&self) -> &::fidl::AsyncChannel {
113        self.client.as_channel()
114    }
115}
116
117impl TestProxy {
118    /// Create a new Proxy for test.fidl.connector/Test.
119    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
120        let protocol_name = <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
121        Self { client: fidl::client::Client::new(channel, protocol_name) }
122    }
123
124    /// Get a Stream of events from the remote end of the protocol.
125    ///
126    /// # Panics
127    ///
128    /// Panics if the event stream was already taken.
129    pub fn take_event_stream(&self) -> TestEventStream {
130        TestEventStream { event_receiver: self.client.take_event_receiver() }
131    }
132
133    pub fn r#ping(
134        &self,
135    ) -> fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect> {
136        TestProxyInterface::r#ping(self)
137    }
138
139    pub fn r#disconnect(
140        &self,
141    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
142        TestProxyInterface::r#disconnect(self)
143    }
144}
145
146impl TestProxyInterface for TestProxy {
147    type PingResponseFut =
148        fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect>;
149    fn r#ping(&self) -> Self::PingResponseFut {
150        fn _decode(
151            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
152        ) -> Result<u32, fidl::Error> {
153            let _response = fidl::client::decode_transaction_body::<
154                TestPingResponse,
155                fidl::encoding::DefaultFuchsiaResourceDialect,
156                0x23aa1eb7d24346cf,
157            >(_buf?)?;
158            Ok(_response.gen)
159        }
160        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, u32>(
161            (),
162            0x23aa1eb7d24346cf,
163            fidl::encoding::DynamicFlags::empty(),
164            _decode,
165        )
166    }
167
168    type DisconnectResponseFut =
169        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
170    fn r#disconnect(&self) -> Self::DisconnectResponseFut {
171        fn _decode(
172            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
173        ) -> Result<(), fidl::Error> {
174            let _response = fidl::client::decode_transaction_body::<
175                fidl::encoding::EmptyPayload,
176                fidl::encoding::DefaultFuchsiaResourceDialect,
177                0x5a1b547382bf672e,
178            >(_buf?)?;
179            Ok(_response)
180        }
181        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
182            (),
183            0x5a1b547382bf672e,
184            fidl::encoding::DynamicFlags::empty(),
185            _decode,
186        )
187    }
188}
189
190pub struct TestEventStream {
191    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
192}
193
194impl std::marker::Unpin for TestEventStream {}
195
196impl futures::stream::FusedStream for TestEventStream {
197    fn is_terminated(&self) -> bool {
198        self.event_receiver.is_terminated()
199    }
200}
201
202impl futures::Stream for TestEventStream {
203    type Item = Result<TestEvent, fidl::Error>;
204
205    fn poll_next(
206        mut self: std::pin::Pin<&mut Self>,
207        cx: &mut std::task::Context<'_>,
208    ) -> std::task::Poll<Option<Self::Item>> {
209        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
210            &mut self.event_receiver,
211            cx
212        )?) {
213            Some(buf) => std::task::Poll::Ready(Some(TestEvent::decode(buf))),
214            None => std::task::Poll::Ready(None),
215        }
216    }
217}
218
219#[derive(Debug)]
220pub enum TestEvent {}
221
222impl TestEvent {
223    /// Decodes a message buffer as a [`TestEvent`].
224    fn decode(
225        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
226    ) -> Result<TestEvent, fidl::Error> {
227        let (bytes, _handles) = buf.split_mut();
228        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
229        debug_assert_eq!(tx_header.tx_id, 0);
230        match tx_header.ordinal {
231            _ => Err(fidl::Error::UnknownOrdinal {
232                ordinal: tx_header.ordinal,
233                protocol_name: <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
234            }),
235        }
236    }
237}
238
239/// A Stream of incoming requests for test.fidl.connector/Test.
240pub struct TestRequestStream {
241    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
242    is_terminated: bool,
243}
244
245impl std::marker::Unpin for TestRequestStream {}
246
247impl futures::stream::FusedStream for TestRequestStream {
248    fn is_terminated(&self) -> bool {
249        self.is_terminated
250    }
251}
252
253impl fidl::endpoints::RequestStream for TestRequestStream {
254    type Protocol = TestMarker;
255    type ControlHandle = TestControlHandle;
256
257    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
258        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
259    }
260
261    fn control_handle(&self) -> Self::ControlHandle {
262        TestControlHandle { inner: self.inner.clone() }
263    }
264
265    fn into_inner(
266        self,
267    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
268    {
269        (self.inner, self.is_terminated)
270    }
271
272    fn from_inner(
273        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
274        is_terminated: bool,
275    ) -> Self {
276        Self { inner, is_terminated }
277    }
278}
279
280impl futures::Stream for TestRequestStream {
281    type Item = Result<TestRequest, fidl::Error>;
282
283    fn poll_next(
284        mut self: std::pin::Pin<&mut Self>,
285        cx: &mut std::task::Context<'_>,
286    ) -> std::task::Poll<Option<Self::Item>> {
287        let this = &mut *self;
288        if this.inner.check_shutdown(cx) {
289            this.is_terminated = true;
290            return std::task::Poll::Ready(None);
291        }
292        if this.is_terminated {
293            panic!("polled TestRequestStream after completion");
294        }
295        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
296            |bytes, handles| {
297                match this.inner.channel().read_etc(cx, bytes, handles) {
298                    std::task::Poll::Ready(Ok(())) => {}
299                    std::task::Poll::Pending => return std::task::Poll::Pending,
300                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
301                        this.is_terminated = true;
302                        return std::task::Poll::Ready(None);
303                    }
304                    std::task::Poll::Ready(Err(e)) => {
305                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
306                            e.into(),
307                        ))))
308                    }
309                }
310
311                // A message has been received from the channel
312                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
313
314                std::task::Poll::Ready(Some(match header.ordinal {
315                    0x23aa1eb7d24346cf => {
316                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
317                        let mut req = fidl::new_empty!(
318                            fidl::encoding::EmptyPayload,
319                            fidl::encoding::DefaultFuchsiaResourceDialect
320                        );
321                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
322                        let control_handle = TestControlHandle { inner: this.inner.clone() };
323                        Ok(TestRequest::Ping {
324                            responder: TestPingResponder {
325                                control_handle: std::mem::ManuallyDrop::new(control_handle),
326                                tx_id: header.tx_id,
327                            },
328                        })
329                    }
330                    0x5a1b547382bf672e => {
331                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
332                        let mut req = fidl::new_empty!(
333                            fidl::encoding::EmptyPayload,
334                            fidl::encoding::DefaultFuchsiaResourceDialect
335                        );
336                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
337                        let control_handle = TestControlHandle { inner: this.inner.clone() };
338                        Ok(TestRequest::Disconnect {
339                            responder: TestDisconnectResponder {
340                                control_handle: std::mem::ManuallyDrop::new(control_handle),
341                                tx_id: header.tx_id,
342                            },
343                        })
344                    }
345                    _ => Err(fidl::Error::UnknownOrdinal {
346                        ordinal: header.ordinal,
347                        protocol_name: <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
348                    }),
349                }))
350            },
351        )
352    }
353}
354
355#[derive(Debug)]
356pub enum TestRequest {
357    Ping { responder: TestPingResponder },
358    Disconnect { responder: TestDisconnectResponder },
359}
360
361impl TestRequest {
362    #[allow(irrefutable_let_patterns)]
363    pub fn into_ping(self) -> Option<(TestPingResponder)> {
364        if let TestRequest::Ping { responder } = self {
365            Some((responder))
366        } else {
367            None
368        }
369    }
370
371    #[allow(irrefutable_let_patterns)]
372    pub fn into_disconnect(self) -> Option<(TestDisconnectResponder)> {
373        if let TestRequest::Disconnect { responder } = self {
374            Some((responder))
375        } else {
376            None
377        }
378    }
379
380    /// Name of the method defined in FIDL
381    pub fn method_name(&self) -> &'static str {
382        match *self {
383            TestRequest::Ping { .. } => "ping",
384            TestRequest::Disconnect { .. } => "disconnect",
385        }
386    }
387}
388
389#[derive(Debug, Clone)]
390pub struct TestControlHandle {
391    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
392}
393
394impl fidl::endpoints::ControlHandle for TestControlHandle {
395    fn shutdown(&self) {
396        self.inner.shutdown()
397    }
398    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
399        self.inner.shutdown_with_epitaph(status)
400    }
401
402    fn is_closed(&self) -> bool {
403        self.inner.channel().is_closed()
404    }
405    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
406        self.inner.channel().on_closed()
407    }
408
409    #[cfg(target_os = "fuchsia")]
410    fn signal_peer(
411        &self,
412        clear_mask: zx::Signals,
413        set_mask: zx::Signals,
414    ) -> Result<(), zx_status::Status> {
415        use fidl::Peered;
416        self.inner.channel().signal_peer(clear_mask, set_mask)
417    }
418}
419
420impl TestControlHandle {}
421
422#[must_use = "FIDL methods require a response to be sent"]
423#[derive(Debug)]
424pub struct TestPingResponder {
425    control_handle: std::mem::ManuallyDrop<TestControlHandle>,
426    tx_id: u32,
427}
428
429/// Set the the channel to be shutdown (see [`TestControlHandle::shutdown`])
430/// if the responder is dropped without sending a response, so that the client
431/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
432impl std::ops::Drop for TestPingResponder {
433    fn drop(&mut self) {
434        self.control_handle.shutdown();
435        // Safety: drops once, never accessed again
436        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
437    }
438}
439
440impl fidl::endpoints::Responder for TestPingResponder {
441    type ControlHandle = TestControlHandle;
442
443    fn control_handle(&self) -> &TestControlHandle {
444        &self.control_handle
445    }
446
447    fn drop_without_shutdown(mut self) {
448        // Safety: drops once, never accessed again due to mem::forget
449        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
450        // Prevent Drop from running (which would shut down the channel)
451        std::mem::forget(self);
452    }
453}
454
455impl TestPingResponder {
456    /// Sends a response to the FIDL transaction.
457    ///
458    /// Sets the channel to shutdown if an error occurs.
459    pub fn send(self, mut gen: u32) -> Result<(), fidl::Error> {
460        let _result = self.send_raw(gen);
461        if _result.is_err() {
462            self.control_handle.shutdown();
463        }
464        self.drop_without_shutdown();
465        _result
466    }
467
468    /// Similar to "send" but does not shutdown the channel if an error occurs.
469    pub fn send_no_shutdown_on_err(self, mut gen: u32) -> Result<(), fidl::Error> {
470        let _result = self.send_raw(gen);
471        self.drop_without_shutdown();
472        _result
473    }
474
475    fn send_raw(&self, mut gen: u32) -> Result<(), fidl::Error> {
476        self.control_handle.inner.send::<TestPingResponse>(
477            (gen,),
478            self.tx_id,
479            0x23aa1eb7d24346cf,
480            fidl::encoding::DynamicFlags::empty(),
481        )
482    }
483}
484
485#[must_use = "FIDL methods require a response to be sent"]
486#[derive(Debug)]
487pub struct TestDisconnectResponder {
488    control_handle: std::mem::ManuallyDrop<TestControlHandle>,
489    tx_id: u32,
490}
491
492/// Set the the channel to be shutdown (see [`TestControlHandle::shutdown`])
493/// if the responder is dropped without sending a response, so that the client
494/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
495impl std::ops::Drop for TestDisconnectResponder {
496    fn drop(&mut self) {
497        self.control_handle.shutdown();
498        // Safety: drops once, never accessed again
499        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
500    }
501}
502
503impl fidl::endpoints::Responder for TestDisconnectResponder {
504    type ControlHandle = TestControlHandle;
505
506    fn control_handle(&self) -> &TestControlHandle {
507        &self.control_handle
508    }
509
510    fn drop_without_shutdown(mut self) {
511        // Safety: drops once, never accessed again due to mem::forget
512        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
513        // Prevent Drop from running (which would shut down the channel)
514        std::mem::forget(self);
515    }
516}
517
518impl TestDisconnectResponder {
519    /// Sends a response to the FIDL transaction.
520    ///
521    /// Sets the channel to shutdown if an error occurs.
522    pub fn send(self) -> Result<(), fidl::Error> {
523        let _result = self.send_raw();
524        if _result.is_err() {
525            self.control_handle.shutdown();
526        }
527        self.drop_without_shutdown();
528        _result
529    }
530
531    /// Similar to "send" but does not shutdown the channel if an error occurs.
532    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
533        let _result = self.send_raw();
534        self.drop_without_shutdown();
535        _result
536    }
537
538    fn send_raw(&self) -> Result<(), fidl::Error> {
539        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
540            (),
541            self.tx_id,
542            0x5a1b547382bf672e,
543            fidl::encoding::DynamicFlags::empty(),
544        )
545    }
546}
547
548mod internal {
549    use super::*;
550}