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