Skip to main content

fidl_fuchsia_driver_metadata/
fidl_fuchsia_driver_metadata.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_driver_metadata__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct MetadataMarker;
16
17impl fidl::endpoints::ProtocolMarker for MetadataMarker {
18    type Proxy = MetadataProxy;
19    type RequestStream = MetadataRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = MetadataSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "(anonymous) Metadata";
24}
25pub type MetadataGetPersistedMetadataResult = Result<Vec<u8>, i32>;
26
27pub trait MetadataProxyInterface: Send + Sync {
28    type GetPersistedMetadataResponseFut: std::future::Future<Output = Result<MetadataGetPersistedMetadataResult, fidl::Error>>
29        + Send;
30    fn r#get_persisted_metadata(&self) -> Self::GetPersistedMetadataResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct MetadataSynchronousProxy {
35    client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for MetadataSynchronousProxy {
40    type Proxy = MetadataProxy;
41    type Protocol = MetadataMarker;
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 MetadataSynchronousProxy {
58    pub fn new(channel: fidl::Channel) -> Self {
59        Self { client: fidl::client::sync::Client::new(channel) }
60    }
61
62    pub fn into_channel(self) -> fidl::Channel {
63        self.client.into_channel()
64    }
65
66    /// Waits until an event arrives and returns it. It is safe for other
67    /// threads to make concurrent requests while waiting for an event.
68    pub fn wait_for_event(
69        &self,
70        deadline: zx::MonotonicInstant,
71    ) -> Result<MetadataEvent, fidl::Error> {
72        MetadataEvent::decode(self.client.wait_for_event::<MetadataMarker>(deadline)?)
73    }
74
75    /// Retrieve the persisted metadata provided by the server. Returns ZX_ERR_NOT_FOUND if the
76    /// server does not have metadata to provide.
77    pub fn r#get_persisted_metadata(
78        &self,
79        ___deadline: zx::MonotonicInstant,
80    ) -> Result<MetadataGetPersistedMetadataResult, fidl::Error> {
81        let _response = self.client.send_query::<
82            fidl::encoding::EmptyPayload,
83            fidl::encoding::ResultType<MetadataGetPersistedMetadataResponse, i32>,
84            MetadataMarker,
85        >(
86            (),
87            0x431a76979a5b3277,
88            fidl::encoding::DynamicFlags::empty(),
89            ___deadline,
90        )?;
91        Ok(_response.map(|x| x.persisted_metadata))
92    }
93}
94
95#[cfg(target_os = "fuchsia")]
96impl From<MetadataSynchronousProxy> for zx::NullableHandle {
97    fn from(value: MetadataSynchronousProxy) -> Self {
98        value.into_channel().into()
99    }
100}
101
102#[cfg(target_os = "fuchsia")]
103impl From<fidl::Channel> for MetadataSynchronousProxy {
104    fn from(value: fidl::Channel) -> Self {
105        Self::new(value)
106    }
107}
108
109#[cfg(target_os = "fuchsia")]
110impl fidl::endpoints::FromClient for MetadataSynchronousProxy {
111    type Protocol = MetadataMarker;
112
113    fn from_client(value: fidl::endpoints::ClientEnd<MetadataMarker>) -> Self {
114        Self::new(value.into_channel())
115    }
116}
117
118#[derive(Debug, Clone)]
119pub struct MetadataProxy {
120    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
121}
122
123impl fidl::endpoints::Proxy for MetadataProxy {
124    type Protocol = MetadataMarker;
125
126    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
127        Self::new(inner)
128    }
129
130    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
131        self.client.into_channel().map_err(|client| Self { client })
132    }
133
134    fn as_channel(&self) -> &::fidl::AsyncChannel {
135        self.client.as_channel()
136    }
137}
138
139impl MetadataProxy {
140    /// Create a new Proxy for fuchsia.driver.metadata/Metadata.
141    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
142        let protocol_name = <MetadataMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
143        Self { client: fidl::client::Client::new(channel, protocol_name) }
144    }
145
146    /// Get a Stream of events from the remote end of the protocol.
147    ///
148    /// # Panics
149    ///
150    /// Panics if the event stream was already taken.
151    pub fn take_event_stream(&self) -> MetadataEventStream {
152        MetadataEventStream { event_receiver: self.client.take_event_receiver() }
153    }
154
155    /// Retrieve the persisted metadata provided by the server. Returns ZX_ERR_NOT_FOUND if the
156    /// server does not have metadata to provide.
157    pub fn r#get_persisted_metadata(
158        &self,
159    ) -> fidl::client::QueryResponseFut<
160        MetadataGetPersistedMetadataResult,
161        fidl::encoding::DefaultFuchsiaResourceDialect,
162    > {
163        MetadataProxyInterface::r#get_persisted_metadata(self)
164    }
165}
166
167impl MetadataProxyInterface for MetadataProxy {
168    type GetPersistedMetadataResponseFut = fidl::client::QueryResponseFut<
169        MetadataGetPersistedMetadataResult,
170        fidl::encoding::DefaultFuchsiaResourceDialect,
171    >;
172    fn r#get_persisted_metadata(&self) -> Self::GetPersistedMetadataResponseFut {
173        fn _decode(
174            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
175        ) -> Result<MetadataGetPersistedMetadataResult, fidl::Error> {
176            let _response = fidl::client::decode_transaction_body::<
177                fidl::encoding::ResultType<MetadataGetPersistedMetadataResponse, i32>,
178                fidl::encoding::DefaultFuchsiaResourceDialect,
179                0x431a76979a5b3277,
180            >(_buf?)?;
181            Ok(_response.map(|x| x.persisted_metadata))
182        }
183        self.client.send_query_and_decode::<
184            fidl::encoding::EmptyPayload,
185            MetadataGetPersistedMetadataResult,
186        >(
187            (),
188            0x431a76979a5b3277,
189            fidl::encoding::DynamicFlags::empty(),
190            _decode,
191        )
192    }
193}
194
195pub struct MetadataEventStream {
196    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
197}
198
199impl std::marker::Unpin for MetadataEventStream {}
200
201impl futures::stream::FusedStream for MetadataEventStream {
202    fn is_terminated(&self) -> bool {
203        self.event_receiver.is_terminated()
204    }
205}
206
207impl futures::Stream for MetadataEventStream {
208    type Item = Result<MetadataEvent, fidl::Error>;
209
210    fn poll_next(
211        mut self: std::pin::Pin<&mut Self>,
212        cx: &mut std::task::Context<'_>,
213    ) -> std::task::Poll<Option<Self::Item>> {
214        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
215            &mut self.event_receiver,
216            cx
217        )?) {
218            Some(buf) => std::task::Poll::Ready(Some(MetadataEvent::decode(buf))),
219            None => std::task::Poll::Ready(None),
220        }
221    }
222}
223
224#[derive(Debug)]
225pub enum MetadataEvent {}
226
227impl MetadataEvent {
228    /// Decodes a message buffer as a [`MetadataEvent`].
229    fn decode(
230        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
231    ) -> Result<MetadataEvent, fidl::Error> {
232        let (bytes, _handles) = buf.split_mut();
233        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
234        debug_assert_eq!(tx_header.tx_id, 0);
235        match tx_header.ordinal {
236            _ => Err(fidl::Error::UnknownOrdinal {
237                ordinal: tx_header.ordinal,
238                protocol_name: <MetadataMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
239            }),
240        }
241    }
242}
243
244/// A Stream of incoming requests for fuchsia.driver.metadata/Metadata.
245pub struct MetadataRequestStream {
246    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
247    is_terminated: bool,
248}
249
250impl std::marker::Unpin for MetadataRequestStream {}
251
252impl futures::stream::FusedStream for MetadataRequestStream {
253    fn is_terminated(&self) -> bool {
254        self.is_terminated
255    }
256}
257
258impl fidl::endpoints::RequestStream for MetadataRequestStream {
259    type Protocol = MetadataMarker;
260    type ControlHandle = MetadataControlHandle;
261
262    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
263        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
264    }
265
266    fn control_handle(&self) -> Self::ControlHandle {
267        MetadataControlHandle { inner: self.inner.clone() }
268    }
269
270    fn into_inner(
271        self,
272    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
273    {
274        (self.inner, self.is_terminated)
275    }
276
277    fn from_inner(
278        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
279        is_terminated: bool,
280    ) -> Self {
281        Self { inner, is_terminated }
282    }
283}
284
285impl futures::Stream for MetadataRequestStream {
286    type Item = Result<MetadataRequest, fidl::Error>;
287
288    fn poll_next(
289        mut self: std::pin::Pin<&mut Self>,
290        cx: &mut std::task::Context<'_>,
291    ) -> std::task::Poll<Option<Self::Item>> {
292        let this = &mut *self;
293        if this.inner.check_shutdown(cx) {
294            this.is_terminated = true;
295            return std::task::Poll::Ready(None);
296        }
297        if this.is_terminated {
298            panic!("polled MetadataRequestStream after completion");
299        }
300        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
301            |bytes, handles| {
302                match this.inner.channel().read_etc(cx, bytes, handles) {
303                    std::task::Poll::Ready(Ok(())) => {}
304                    std::task::Poll::Pending => return std::task::Poll::Pending,
305                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
306                        this.is_terminated = true;
307                        return std::task::Poll::Ready(None);
308                    }
309                    std::task::Poll::Ready(Err(e)) => {
310                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
311                            e.into(),
312                        ))));
313                    }
314                }
315
316                // A message has been received from the channel
317                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
318
319                std::task::Poll::Ready(Some(match header.ordinal {
320                    0x431a76979a5b3277 => {
321                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
322                        let mut req = fidl::new_empty!(
323                            fidl::encoding::EmptyPayload,
324                            fidl::encoding::DefaultFuchsiaResourceDialect
325                        );
326                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
327                        let control_handle = MetadataControlHandle { inner: this.inner.clone() };
328                        Ok(MetadataRequest::GetPersistedMetadata {
329                            responder: MetadataGetPersistedMetadataResponder {
330                                control_handle: std::mem::ManuallyDrop::new(control_handle),
331                                tx_id: header.tx_id,
332                            },
333                        })
334                    }
335                    _ => Err(fidl::Error::UnknownOrdinal {
336                        ordinal: header.ordinal,
337                        protocol_name:
338                            <MetadataMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
339                    }),
340                }))
341            },
342        )
343    }
344}
345
346#[derive(Debug)]
347pub enum MetadataRequest {
348    /// Retrieve the persisted metadata provided by the server. Returns ZX_ERR_NOT_FOUND if the
349    /// server does not have metadata to provide.
350    GetPersistedMetadata { responder: MetadataGetPersistedMetadataResponder },
351}
352
353impl MetadataRequest {
354    #[allow(irrefutable_let_patterns)]
355    pub fn into_get_persisted_metadata(self) -> Option<(MetadataGetPersistedMetadataResponder)> {
356        if let MetadataRequest::GetPersistedMetadata { responder } = self {
357            Some((responder))
358        } else {
359            None
360        }
361    }
362
363    /// Name of the method defined in FIDL
364    pub fn method_name(&self) -> &'static str {
365        match *self {
366            MetadataRequest::GetPersistedMetadata { .. } => "get_persisted_metadata",
367        }
368    }
369}
370
371#[derive(Debug, Clone)]
372pub struct MetadataControlHandle {
373    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
374}
375
376impl fidl::endpoints::ControlHandle for MetadataControlHandle {
377    fn shutdown(&self) {
378        self.inner.shutdown()
379    }
380
381    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
382        self.inner.shutdown_with_epitaph(status)
383    }
384
385    fn is_closed(&self) -> bool {
386        self.inner.channel().is_closed()
387    }
388    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
389        self.inner.channel().on_closed()
390    }
391
392    #[cfg(target_os = "fuchsia")]
393    fn signal_peer(
394        &self,
395        clear_mask: zx::Signals,
396        set_mask: zx::Signals,
397    ) -> Result<(), zx_status::Status> {
398        use fidl::Peered;
399        self.inner.channel().signal_peer(clear_mask, set_mask)
400    }
401}
402
403impl MetadataControlHandle {}
404
405#[must_use = "FIDL methods require a response to be sent"]
406#[derive(Debug)]
407pub struct MetadataGetPersistedMetadataResponder {
408    control_handle: std::mem::ManuallyDrop<MetadataControlHandle>,
409    tx_id: u32,
410}
411
412/// Set the the channel to be shutdown (see [`MetadataControlHandle::shutdown`])
413/// if the responder is dropped without sending a response, so that the client
414/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
415impl std::ops::Drop for MetadataGetPersistedMetadataResponder {
416    fn drop(&mut self) {
417        self.control_handle.shutdown();
418        // Safety: drops once, never accessed again
419        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
420    }
421}
422
423impl fidl::endpoints::Responder for MetadataGetPersistedMetadataResponder {
424    type ControlHandle = MetadataControlHandle;
425
426    fn control_handle(&self) -> &MetadataControlHandle {
427        &self.control_handle
428    }
429
430    fn drop_without_shutdown(mut self) {
431        // Safety: drops once, never accessed again due to mem::forget
432        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
433        // Prevent Drop from running (which would shut down the channel)
434        std::mem::forget(self);
435    }
436}
437
438impl MetadataGetPersistedMetadataResponder {
439    /// Sends a response to the FIDL transaction.
440    ///
441    /// Sets the channel to shutdown if an error occurs.
442    pub fn send(self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
443        let _result = self.send_raw(result);
444        if _result.is_err() {
445            self.control_handle.shutdown();
446        }
447        self.drop_without_shutdown();
448        _result
449    }
450
451    /// Similar to "send" but does not shutdown the channel if an error occurs.
452    pub fn send_no_shutdown_on_err(
453        self,
454        mut result: Result<&[u8], i32>,
455    ) -> Result<(), fidl::Error> {
456        let _result = self.send_raw(result);
457        self.drop_without_shutdown();
458        _result
459    }
460
461    fn send_raw(&self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
462        self.control_handle.inner.send::<fidl::encoding::ResultType<
463            MetadataGetPersistedMetadataResponse,
464            i32,
465        >>(
466            result.map(|persisted_metadata| (persisted_metadata,)),
467            self.tx_id,
468            0x431a76979a5b3277,
469            fidl::encoding::DynamicFlags::empty(),
470        )
471    }
472}
473
474#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
475pub struct ServiceMarker;
476
477#[cfg(target_os = "fuchsia")]
478impl fidl::endpoints::ServiceMarker for ServiceMarker {
479    type Proxy = ServiceProxy;
480    type Request = ServiceRequest;
481    const SERVICE_NAME: &'static str = "fuchsia.driver.metadata.Service";
482}
483
484/// A request for one of the member protocols of Service.
485///
486#[cfg(target_os = "fuchsia")]
487pub enum ServiceRequest {
488    Metadata(MetadataRequestStream),
489}
490
491#[cfg(target_os = "fuchsia")]
492impl fidl::endpoints::ServiceRequest for ServiceRequest {
493    type Service = ServiceMarker;
494
495    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
496        match name {
497            "metadata" => Self::Metadata(
498                <MetadataRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
499            ),
500            _ => panic!("no such member protocol name for service Service"),
501        }
502    }
503
504    fn member_names() -> &'static [&'static str] {
505        &["metadata"]
506    }
507}
508#[cfg(target_os = "fuchsia")]
509pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
510
511#[cfg(target_os = "fuchsia")]
512impl fidl::endpoints::ServiceProxy for ServiceProxy {
513    type Service = ServiceMarker;
514
515    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
516        Self(opener)
517    }
518}
519
520#[cfg(target_os = "fuchsia")]
521impl ServiceProxy {
522    pub fn connect_to_metadata(&self) -> Result<MetadataProxy, fidl::Error> {
523        let (proxy, server_end) = fidl::endpoints::create_proxy::<MetadataMarker>();
524        self.connect_channel_to_metadata(server_end)?;
525        Ok(proxy)
526    }
527
528    /// Like `connect_to_metadata`, but returns a sync proxy.
529    /// See [`Self::connect_to_metadata`] for more details.
530    pub fn connect_to_metadata_sync(&self) -> Result<MetadataSynchronousProxy, fidl::Error> {
531        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<MetadataMarker>();
532        self.connect_channel_to_metadata(server_end)?;
533        Ok(proxy)
534    }
535
536    /// Like `connect_to_metadata`, but accepts a server end.
537    /// See [`Self::connect_to_metadata`] for more details.
538    pub fn connect_channel_to_metadata(
539        &self,
540        server_end: fidl::endpoints::ServerEnd<MetadataMarker>,
541    ) -> Result<(), fidl::Error> {
542        self.0.open_member("metadata", server_end.into_channel())
543    }
544
545    pub fn instance_name(&self) -> &str {
546        self.0.instance_name()
547    }
548}
549
550mod internal {
551    use super::*;
552}