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