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