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