fidl_fuchsia_diagnostics_persist/
fidl_fuchsia_diagnostics_persist.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_diagnostics_persist_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DataPersistenceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DataPersistenceMarker {
18    type Proxy = DataPersistenceProxy;
19    type RequestStream = DataPersistenceRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DataPersistenceSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.diagnostics.persist.DataPersistence";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DataPersistenceMarker {}
26
27pub trait DataPersistenceProxyInterface: Send + Sync {
28    type PersistResponseFut: std::future::Future<Output = Result<PersistResult, fidl::Error>> + Send;
29    fn r#persist(&self, tag: &str) -> Self::PersistResponseFut;
30    type PersistTagsResponseFut: std::future::Future<Output = Result<Vec<PersistResult>, fidl::Error>>
31        + Send;
32    fn r#persist_tags(&self, tags: &[String]) -> Self::PersistTagsResponseFut;
33}
34#[derive(Debug)]
35#[cfg(target_os = "fuchsia")]
36pub struct DataPersistenceSynchronousProxy {
37    client: fidl::client::sync::Client,
38}
39
40#[cfg(target_os = "fuchsia")]
41impl fidl::endpoints::SynchronousProxy for DataPersistenceSynchronousProxy {
42    type Proxy = DataPersistenceProxy;
43    type Protocol = DataPersistenceMarker;
44
45    fn from_channel(inner: fidl::Channel) -> Self {
46        Self::new(inner)
47    }
48
49    fn into_channel(self) -> fidl::Channel {
50        self.client.into_channel()
51    }
52
53    fn as_channel(&self) -> &fidl::Channel {
54        self.client.as_channel()
55    }
56}
57
58#[cfg(target_os = "fuchsia")]
59impl DataPersistenceSynchronousProxy {
60    pub fn new(channel: fidl::Channel) -> Self {
61        let protocol_name = <DataPersistenceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
62        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
63    }
64
65    pub fn into_channel(self) -> fidl::Channel {
66        self.client.into_channel()
67    }
68
69    /// Waits until an event arrives and returns it. It is safe for other
70    /// threads to make concurrent requests while waiting for an event.
71    pub fn wait_for_event(
72        &self,
73        deadline: zx::MonotonicInstant,
74    ) -> Result<DataPersistenceEvent, fidl::Error> {
75        DataPersistenceEvent::decode(self.client.wait_for_event(deadline)?)
76    }
77
78    /// Schedule the persistence of the selected data associated with this
79    /// tag in diagnostics-persistence config files.  Fetching the selected
80    /// data may be delayed if there is other work in a given service's queue.
81    pub fn r#persist(
82        &self,
83        mut tag: &str,
84        ___deadline: zx::MonotonicInstant,
85    ) -> Result<PersistResult, fidl::Error> {
86        let _response = self
87            .client
88            .send_query::<DataPersistencePersistRequest, DataPersistencePersistResponse>(
89                (tag,),
90                0x6193adf95c67926e,
91                fidl::encoding::DynamicFlags::empty(),
92                ___deadline,
93            )?;
94        Ok(_response.result)
95    }
96
97    /// Schedule the persistence of the selected data associated with these
98    /// tags in diagnostics-persistence config files.  Fetching the selected
99    /// data may be delayed if there is other work in a given service's queue.
100    pub fn r#persist_tags(
101        &self,
102        mut tags: &[String],
103        ___deadline: zx::MonotonicInstant,
104    ) -> Result<Vec<PersistResult>, fidl::Error> {
105        let _response = self
106            .client
107            .send_query::<DataPersistencePersistTagsRequest, DataPersistencePersistTagsResponse>(
108                (tags,),
109                0x4a5f2795aceb0ae4,
110                fidl::encoding::DynamicFlags::empty(),
111                ___deadline,
112            )?;
113        Ok(_response.results)
114    }
115}
116
117#[derive(Debug, Clone)]
118pub struct DataPersistenceProxy {
119    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
120}
121
122impl fidl::endpoints::Proxy for DataPersistenceProxy {
123    type Protocol = DataPersistenceMarker;
124
125    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
126        Self::new(inner)
127    }
128
129    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
130        self.client.into_channel().map_err(|client| Self { client })
131    }
132
133    fn as_channel(&self) -> &::fidl::AsyncChannel {
134        self.client.as_channel()
135    }
136}
137
138impl DataPersistenceProxy {
139    /// Create a new Proxy for fuchsia.diagnostics.persist/DataPersistence.
140    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
141        let protocol_name = <DataPersistenceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
142        Self { client: fidl::client::Client::new(channel, protocol_name) }
143    }
144
145    /// Get a Stream of events from the remote end of the protocol.
146    ///
147    /// # Panics
148    ///
149    /// Panics if the event stream was already taken.
150    pub fn take_event_stream(&self) -> DataPersistenceEventStream {
151        DataPersistenceEventStream { event_receiver: self.client.take_event_receiver() }
152    }
153
154    /// Schedule the persistence of the selected data associated with this
155    /// tag in diagnostics-persistence config files.  Fetching the selected
156    /// data may be delayed if there is other work in a given service's queue.
157    pub fn r#persist(
158        &self,
159        mut tag: &str,
160    ) -> fidl::client::QueryResponseFut<PersistResult, fidl::encoding::DefaultFuchsiaResourceDialect>
161    {
162        DataPersistenceProxyInterface::r#persist(self, tag)
163    }
164
165    /// Schedule the persistence of the selected data associated with these
166    /// tags in diagnostics-persistence config files.  Fetching the selected
167    /// data may be delayed if there is other work in a given service's queue.
168    pub fn r#persist_tags(
169        &self,
170        mut tags: &[String],
171    ) -> fidl::client::QueryResponseFut<
172        Vec<PersistResult>,
173        fidl::encoding::DefaultFuchsiaResourceDialect,
174    > {
175        DataPersistenceProxyInterface::r#persist_tags(self, tags)
176    }
177}
178
179impl DataPersistenceProxyInterface for DataPersistenceProxy {
180    type PersistResponseFut = fidl::client::QueryResponseFut<
181        PersistResult,
182        fidl::encoding::DefaultFuchsiaResourceDialect,
183    >;
184    fn r#persist(&self, mut tag: &str) -> Self::PersistResponseFut {
185        fn _decode(
186            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
187        ) -> Result<PersistResult, fidl::Error> {
188            let _response = fidl::client::decode_transaction_body::<
189                DataPersistencePersistResponse,
190                fidl::encoding::DefaultFuchsiaResourceDialect,
191                0x6193adf95c67926e,
192            >(_buf?)?;
193            Ok(_response.result)
194        }
195        self.client.send_query_and_decode::<DataPersistencePersistRequest, PersistResult>(
196            (tag,),
197            0x6193adf95c67926e,
198            fidl::encoding::DynamicFlags::empty(),
199            _decode,
200        )
201    }
202
203    type PersistTagsResponseFut = fidl::client::QueryResponseFut<
204        Vec<PersistResult>,
205        fidl::encoding::DefaultFuchsiaResourceDialect,
206    >;
207    fn r#persist_tags(&self, mut tags: &[String]) -> Self::PersistTagsResponseFut {
208        fn _decode(
209            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
210        ) -> Result<Vec<PersistResult>, fidl::Error> {
211            let _response = fidl::client::decode_transaction_body::<
212                DataPersistencePersistTagsResponse,
213                fidl::encoding::DefaultFuchsiaResourceDialect,
214                0x4a5f2795aceb0ae4,
215            >(_buf?)?;
216            Ok(_response.results)
217        }
218        self.client.send_query_and_decode::<DataPersistencePersistTagsRequest, Vec<PersistResult>>(
219            (tags,),
220            0x4a5f2795aceb0ae4,
221            fidl::encoding::DynamicFlags::empty(),
222            _decode,
223        )
224    }
225}
226
227pub struct DataPersistenceEventStream {
228    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
229}
230
231impl std::marker::Unpin for DataPersistenceEventStream {}
232
233impl futures::stream::FusedStream for DataPersistenceEventStream {
234    fn is_terminated(&self) -> bool {
235        self.event_receiver.is_terminated()
236    }
237}
238
239impl futures::Stream for DataPersistenceEventStream {
240    type Item = Result<DataPersistenceEvent, fidl::Error>;
241
242    fn poll_next(
243        mut self: std::pin::Pin<&mut Self>,
244        cx: &mut std::task::Context<'_>,
245    ) -> std::task::Poll<Option<Self::Item>> {
246        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
247            &mut self.event_receiver,
248            cx
249        )?) {
250            Some(buf) => std::task::Poll::Ready(Some(DataPersistenceEvent::decode(buf))),
251            None => std::task::Poll::Ready(None),
252        }
253    }
254}
255
256#[derive(Debug)]
257pub enum DataPersistenceEvent {}
258
259impl DataPersistenceEvent {
260    /// Decodes a message buffer as a [`DataPersistenceEvent`].
261    fn decode(
262        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
263    ) -> Result<DataPersistenceEvent, fidl::Error> {
264        let (bytes, _handles) = buf.split_mut();
265        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
266        debug_assert_eq!(tx_header.tx_id, 0);
267        match tx_header.ordinal {
268            _ => Err(fidl::Error::UnknownOrdinal {
269                ordinal: tx_header.ordinal,
270                protocol_name:
271                    <DataPersistenceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
272            }),
273        }
274    }
275}
276
277/// A Stream of incoming requests for fuchsia.diagnostics.persist/DataPersistence.
278pub struct DataPersistenceRequestStream {
279    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
280    is_terminated: bool,
281}
282
283impl std::marker::Unpin for DataPersistenceRequestStream {}
284
285impl futures::stream::FusedStream for DataPersistenceRequestStream {
286    fn is_terminated(&self) -> bool {
287        self.is_terminated
288    }
289}
290
291impl fidl::endpoints::RequestStream for DataPersistenceRequestStream {
292    type Protocol = DataPersistenceMarker;
293    type ControlHandle = DataPersistenceControlHandle;
294
295    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
296        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
297    }
298
299    fn control_handle(&self) -> Self::ControlHandle {
300        DataPersistenceControlHandle { inner: self.inner.clone() }
301    }
302
303    fn into_inner(
304        self,
305    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
306    {
307        (self.inner, self.is_terminated)
308    }
309
310    fn from_inner(
311        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
312        is_terminated: bool,
313    ) -> Self {
314        Self { inner, is_terminated }
315    }
316}
317
318impl futures::Stream for DataPersistenceRequestStream {
319    type Item = Result<DataPersistenceRequest, fidl::Error>;
320
321    fn poll_next(
322        mut self: std::pin::Pin<&mut Self>,
323        cx: &mut std::task::Context<'_>,
324    ) -> std::task::Poll<Option<Self::Item>> {
325        let this = &mut *self;
326        if this.inner.check_shutdown(cx) {
327            this.is_terminated = true;
328            return std::task::Poll::Ready(None);
329        }
330        if this.is_terminated {
331            panic!("polled DataPersistenceRequestStream after completion");
332        }
333        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
334            |bytes, handles| {
335                match this.inner.channel().read_etc(cx, bytes, handles) {
336                    std::task::Poll::Ready(Ok(())) => {}
337                    std::task::Poll::Pending => return std::task::Poll::Pending,
338                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
339                        this.is_terminated = true;
340                        return std::task::Poll::Ready(None);
341                    }
342                    std::task::Poll::Ready(Err(e)) => {
343                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
344                            e.into(),
345                        ))))
346                    }
347                }
348
349                // A message has been received from the channel
350                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
351
352                std::task::Poll::Ready(Some(match header.ordinal {
353                    0x6193adf95c67926e => {
354                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
355                        let mut req = fidl::new_empty!(
356                            DataPersistencePersistRequest,
357                            fidl::encoding::DefaultFuchsiaResourceDialect
358                        );
359                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DataPersistencePersistRequest>(&header, _body_bytes, handles, &mut req)?;
360                        let control_handle =
361                            DataPersistenceControlHandle { inner: this.inner.clone() };
362                        Ok(DataPersistenceRequest::Persist {
363                            tag: req.tag,
364
365                            responder: DataPersistencePersistResponder {
366                                control_handle: std::mem::ManuallyDrop::new(control_handle),
367                                tx_id: header.tx_id,
368                            },
369                        })
370                    }
371                    0x4a5f2795aceb0ae4 => {
372                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
373                        let mut req = fidl::new_empty!(
374                            DataPersistencePersistTagsRequest,
375                            fidl::encoding::DefaultFuchsiaResourceDialect
376                        );
377                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DataPersistencePersistTagsRequest>(&header, _body_bytes, handles, &mut req)?;
378                        let control_handle =
379                            DataPersistenceControlHandle { inner: this.inner.clone() };
380                        Ok(DataPersistenceRequest::PersistTags {
381                            tags: req.tags,
382
383                            responder: DataPersistencePersistTagsResponder {
384                                control_handle: std::mem::ManuallyDrop::new(control_handle),
385                                tx_id: header.tx_id,
386                            },
387                        })
388                    }
389                    _ => Err(fidl::Error::UnknownOrdinal {
390                        ordinal: header.ordinal,
391                        protocol_name:
392                            <DataPersistenceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
393                    }),
394                }))
395            },
396        )
397    }
398}
399
400/// Stores limited amounts of Inspect-formatted data till the next boot and publishes it in
401/// the "diagnostics-persistence" component's inspect tree.
402#[derive(Debug)]
403pub enum DataPersistenceRequest {
404    /// Schedule the persistence of the selected data associated with this
405    /// tag in diagnostics-persistence config files.  Fetching the selected
406    /// data may be delayed if there is other work in a given service's queue.
407    Persist { tag: String, responder: DataPersistencePersistResponder },
408    /// Schedule the persistence of the selected data associated with these
409    /// tags in diagnostics-persistence config files.  Fetching the selected
410    /// data may be delayed if there is other work in a given service's queue.
411    PersistTags { tags: Vec<String>, responder: DataPersistencePersistTagsResponder },
412}
413
414impl DataPersistenceRequest {
415    #[allow(irrefutable_let_patterns)]
416    pub fn into_persist(self) -> Option<(String, DataPersistencePersistResponder)> {
417        if let DataPersistenceRequest::Persist { tag, responder } = self {
418            Some((tag, responder))
419        } else {
420            None
421        }
422    }
423
424    #[allow(irrefutable_let_patterns)]
425    pub fn into_persist_tags(self) -> Option<(Vec<String>, DataPersistencePersistTagsResponder)> {
426        if let DataPersistenceRequest::PersistTags { tags, responder } = self {
427            Some((tags, responder))
428        } else {
429            None
430        }
431    }
432
433    /// Name of the method defined in FIDL
434    pub fn method_name(&self) -> &'static str {
435        match *self {
436            DataPersistenceRequest::Persist { .. } => "persist",
437            DataPersistenceRequest::PersistTags { .. } => "persist_tags",
438        }
439    }
440}
441
442#[derive(Debug, Clone)]
443pub struct DataPersistenceControlHandle {
444    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
445}
446
447impl fidl::endpoints::ControlHandle for DataPersistenceControlHandle {
448    fn shutdown(&self) {
449        self.inner.shutdown()
450    }
451    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
452        self.inner.shutdown_with_epitaph(status)
453    }
454
455    fn is_closed(&self) -> bool {
456        self.inner.channel().is_closed()
457    }
458    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
459        self.inner.channel().on_closed()
460    }
461
462    #[cfg(target_os = "fuchsia")]
463    fn signal_peer(
464        &self,
465        clear_mask: zx::Signals,
466        set_mask: zx::Signals,
467    ) -> Result<(), zx_status::Status> {
468        use fidl::Peered;
469        self.inner.channel().signal_peer(clear_mask, set_mask)
470    }
471}
472
473impl DataPersistenceControlHandle {}
474
475#[must_use = "FIDL methods require a response to be sent"]
476#[derive(Debug)]
477pub struct DataPersistencePersistResponder {
478    control_handle: std::mem::ManuallyDrop<DataPersistenceControlHandle>,
479    tx_id: u32,
480}
481
482/// Set the the channel to be shutdown (see [`DataPersistenceControlHandle::shutdown`])
483/// if the responder is dropped without sending a response, so that the client
484/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
485impl std::ops::Drop for DataPersistencePersistResponder {
486    fn drop(&mut self) {
487        self.control_handle.shutdown();
488        // Safety: drops once, never accessed again
489        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
490    }
491}
492
493impl fidl::endpoints::Responder for DataPersistencePersistResponder {
494    type ControlHandle = DataPersistenceControlHandle;
495
496    fn control_handle(&self) -> &DataPersistenceControlHandle {
497        &self.control_handle
498    }
499
500    fn drop_without_shutdown(mut self) {
501        // Safety: drops once, never accessed again due to mem::forget
502        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
503        // Prevent Drop from running (which would shut down the channel)
504        std::mem::forget(self);
505    }
506}
507
508impl DataPersistencePersistResponder {
509    /// Sends a response to the FIDL transaction.
510    ///
511    /// Sets the channel to shutdown if an error occurs.
512    pub fn send(self, mut result: PersistResult) -> Result<(), fidl::Error> {
513        let _result = self.send_raw(result);
514        if _result.is_err() {
515            self.control_handle.shutdown();
516        }
517        self.drop_without_shutdown();
518        _result
519    }
520
521    /// Similar to "send" but does not shutdown the channel if an error occurs.
522    pub fn send_no_shutdown_on_err(self, mut result: PersistResult) -> Result<(), fidl::Error> {
523        let _result = self.send_raw(result);
524        self.drop_without_shutdown();
525        _result
526    }
527
528    fn send_raw(&self, mut result: PersistResult) -> Result<(), fidl::Error> {
529        self.control_handle.inner.send::<DataPersistencePersistResponse>(
530            (result,),
531            self.tx_id,
532            0x6193adf95c67926e,
533            fidl::encoding::DynamicFlags::empty(),
534        )
535    }
536}
537
538#[must_use = "FIDL methods require a response to be sent"]
539#[derive(Debug)]
540pub struct DataPersistencePersistTagsResponder {
541    control_handle: std::mem::ManuallyDrop<DataPersistenceControlHandle>,
542    tx_id: u32,
543}
544
545/// Set the the channel to be shutdown (see [`DataPersistenceControlHandle::shutdown`])
546/// if the responder is dropped without sending a response, so that the client
547/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
548impl std::ops::Drop for DataPersistencePersistTagsResponder {
549    fn drop(&mut self) {
550        self.control_handle.shutdown();
551        // Safety: drops once, never accessed again
552        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
553    }
554}
555
556impl fidl::endpoints::Responder for DataPersistencePersistTagsResponder {
557    type ControlHandle = DataPersistenceControlHandle;
558
559    fn control_handle(&self) -> &DataPersistenceControlHandle {
560        &self.control_handle
561    }
562
563    fn drop_without_shutdown(mut self) {
564        // Safety: drops once, never accessed again due to mem::forget
565        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
566        // Prevent Drop from running (which would shut down the channel)
567        std::mem::forget(self);
568    }
569}
570
571impl DataPersistencePersistTagsResponder {
572    /// Sends a response to the FIDL transaction.
573    ///
574    /// Sets the channel to shutdown if an error occurs.
575    pub fn send(self, mut results: &[PersistResult]) -> Result<(), fidl::Error> {
576        let _result = self.send_raw(results);
577        if _result.is_err() {
578            self.control_handle.shutdown();
579        }
580        self.drop_without_shutdown();
581        _result
582    }
583
584    /// Similar to "send" but does not shutdown the channel if an error occurs.
585    pub fn send_no_shutdown_on_err(self, mut results: &[PersistResult]) -> Result<(), fidl::Error> {
586        let _result = self.send_raw(results);
587        self.drop_without_shutdown();
588        _result
589    }
590
591    fn send_raw(&self, mut results: &[PersistResult]) -> Result<(), fidl::Error> {
592        self.control_handle.inner.send::<DataPersistencePersistTagsResponse>(
593            (results,),
594            self.tx_id,
595            0x4a5f2795aceb0ae4,
596            fidl::encoding::DynamicFlags::empty(),
597        )
598    }
599}
600
601mod internal {
602    use super::*;
603}