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