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