fidl_fuchsia_power_metrics/
fidl_fuchsia_power_metrics.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_power_metrics_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct RecorderMarker;
16
17impl fidl::endpoints::ProtocolMarker for RecorderMarker {
18    type Proxy = RecorderProxy;
19    type RequestStream = RecorderRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = RecorderSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.power.metrics.Recorder";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for RecorderMarker {}
26pub type RecorderStartLoggingResult = Result<(), RecorderError>;
27pub type RecorderStartLoggingForeverResult = Result<(), RecorderError>;
28
29pub trait RecorderProxyInterface: Send + Sync {
30    type StartLoggingResponseFut: std::future::Future<Output = Result<RecorderStartLoggingResult, fidl::Error>>
31        + Send;
32    fn r#start_logging(
33        &self,
34        client_id: &str,
35        metrics: &[Metric],
36        duration_ms: u32,
37        output_samples_to_syslog: bool,
38        output_stats_to_syslog: bool,
39    ) -> Self::StartLoggingResponseFut;
40    type StartLoggingForeverResponseFut: std::future::Future<Output = Result<RecorderStartLoggingForeverResult, fidl::Error>>
41        + Send;
42    fn r#start_logging_forever(
43        &self,
44        client_id: &str,
45        metrics: &[Metric],
46        output_samples_to_syslog: bool,
47        output_stats_to_syslog: bool,
48    ) -> Self::StartLoggingForeverResponseFut;
49    type StopLoggingResponseFut: std::future::Future<Output = Result<bool, fidl::Error>> + Send;
50    fn r#stop_logging(&self, client_id: &str) -> Self::StopLoggingResponseFut;
51}
52#[derive(Debug)]
53#[cfg(target_os = "fuchsia")]
54pub struct RecorderSynchronousProxy {
55    client: fidl::client::sync::Client,
56}
57
58#[cfg(target_os = "fuchsia")]
59impl fidl::endpoints::SynchronousProxy for RecorderSynchronousProxy {
60    type Proxy = RecorderProxy;
61    type Protocol = RecorderMarker;
62
63    fn from_channel(inner: fidl::Channel) -> Self {
64        Self::new(inner)
65    }
66
67    fn into_channel(self) -> fidl::Channel {
68        self.client.into_channel()
69    }
70
71    fn as_channel(&self) -> &fidl::Channel {
72        self.client.as_channel()
73    }
74}
75
76#[cfg(target_os = "fuchsia")]
77impl RecorderSynchronousProxy {
78    pub fn new(channel: fidl::Channel) -> Self {
79        let protocol_name = <RecorderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
80        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
81    }
82
83    pub fn into_channel(self) -> fidl::Channel {
84        self.client.into_channel()
85    }
86
87    /// Waits until an event arrives and returns it. It is safe for other
88    /// threads to make concurrent requests while waiting for an event.
89    pub fn wait_for_event(
90        &self,
91        deadline: zx::MonotonicInstant,
92    ) -> Result<RecorderEvent, fidl::Error> {
93        RecorderEvent::decode(self.client.wait_for_event(deadline)?)
94    }
95
96    /// Initiates logging of specified metrics for the provided duration.
97    /// Supports concurrent logging of different metrics. Logging may be
98    /// terminated early with a call to `StopLogging`.
99    ///
100    /// This call will fail if logging of the specified metric is already
101    /// active. For this reason, a client may wish to precede a `StartLogging`
102    /// call with a `StopLogging` call, after which the only reason for The
103    /// logger to be active would be a conflict with another client.
104    ///
105    /// + request `client_id` String format Id of the client. Client may choose
106    ///     any Id with a maximum byte size of 8 (e.g., "ffxTest").
107    /// + request `metrics` Type of the metrics to be polled and logged.
108    /// + request `duration_ms` Duration of logging in milliseconds. After this
109    ///     duration, polling and logging will cease.
110    /// + request `output_samples_to_syslog` Toggle for outputting raw data to
111    ///     syslog.
112    /// + request `output_stats_to_syslog` Toggle for outputting any available
113    ///     statistics to syslog.
114    /// + error a [fuchsia.metrics.test/MeticsLoggerError] value indicating why
115    ///     the request failed.
116    pub fn r#start_logging(
117        &self,
118        mut client_id: &str,
119        mut metrics: &[Metric],
120        mut duration_ms: u32,
121        mut output_samples_to_syslog: bool,
122        mut output_stats_to_syslog: bool,
123        ___deadline: zx::MonotonicInstant,
124    ) -> Result<RecorderStartLoggingResult, fidl::Error> {
125        let _response = self.client.send_query::<
126            RecorderStartLoggingRequest,
127            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, RecorderError>,
128        >(
129            (client_id, metrics, duration_ms, output_samples_to_syslog, output_stats_to_syslog,),
130            0x40e4e1a9c6c42bd2,
131            fidl::encoding::DynamicFlags::empty(),
132            ___deadline,
133        )?;
134        Ok(_response.map(|x| x))
135    }
136
137    /// Initiates logging of specified metrics. Supports concurrent logging of
138    /// different metrics. Logging will only end upon a `StopLogging` call.
139    ///
140    /// `StartLogging` should be preferred for usage in automated tests to
141    /// ensure that logging terminates even if the test crashes.
142    ///
143    /// + request `client_id` String format Id of the client. Client may choose
144    ///     any Id with a maximum byte size of 8 (e.g., "ffxTest").
145    /// + request `metrics` Type of the metrics to be polled and logged.
146    /// + request `output_samples_to_syslog` Toggle for outputting raw data to
147    ///     syslog.
148    /// + request `output_stats_to_syslog` Toggle for outputting any available
149    ///     statistics to syslog.
150    /// + error a [fuchsia.metrics.test/RecorderError] value indicating why
151    ///     the request failed.
152    pub fn r#start_logging_forever(
153        &self,
154        mut client_id: &str,
155        mut metrics: &[Metric],
156        mut output_samples_to_syslog: bool,
157        mut output_stats_to_syslog: bool,
158        ___deadline: zx::MonotonicInstant,
159    ) -> Result<RecorderStartLoggingForeverResult, fidl::Error> {
160        let _response = self.client.send_query::<
161            RecorderStartLoggingForeverRequest,
162            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, RecorderError>,
163        >(
164            (client_id, metrics, output_samples_to_syslog, output_stats_to_syslog,),
165            0x37b2675fdc61ff94,
166            fidl::encoding::DynamicFlags::empty(),
167            ___deadline,
168        )?;
169        Ok(_response.map(|x| x))
170    }
171
172    /// Terminates all active logging tasks with the given client_id. It is
173    /// valid to call this method when logging is inactive.
174    ///
175    /// + request `client_id` String format Id of the client.
176    /// - response `status` A bool value indicating if existing logging was
177    ///     stopped (true) or there'sno existing logging for the client.
178    pub fn r#stop_logging(
179        &self,
180        mut client_id: &str,
181        ___deadline: zx::MonotonicInstant,
182    ) -> Result<bool, fidl::Error> {
183        let _response =
184            self.client.send_query::<RecorderStopLoggingRequest, RecorderStopLoggingResponse>(
185                (client_id,),
186                0x615d67a4d94d4732,
187                fidl::encoding::DynamicFlags::empty(),
188                ___deadline,
189            )?;
190        Ok(_response.stopped)
191    }
192}
193
194#[derive(Debug, Clone)]
195pub struct RecorderProxy {
196    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
197}
198
199impl fidl::endpoints::Proxy for RecorderProxy {
200    type Protocol = RecorderMarker;
201
202    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
203        Self::new(inner)
204    }
205
206    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
207        self.client.into_channel().map_err(|client| Self { client })
208    }
209
210    fn as_channel(&self) -> &::fidl::AsyncChannel {
211        self.client.as_channel()
212    }
213}
214
215impl RecorderProxy {
216    /// Create a new Proxy for fuchsia.power.metrics/Recorder.
217    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
218        let protocol_name = <RecorderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
219        Self { client: fidl::client::Client::new(channel, protocol_name) }
220    }
221
222    /// Get a Stream of events from the remote end of the protocol.
223    ///
224    /// # Panics
225    ///
226    /// Panics if the event stream was already taken.
227    pub fn take_event_stream(&self) -> RecorderEventStream {
228        RecorderEventStream { event_receiver: self.client.take_event_receiver() }
229    }
230
231    /// Initiates logging of specified metrics for the provided duration.
232    /// Supports concurrent logging of different metrics. Logging may be
233    /// terminated early with a call to `StopLogging`.
234    ///
235    /// This call will fail if logging of the specified metric is already
236    /// active. For this reason, a client may wish to precede a `StartLogging`
237    /// call with a `StopLogging` call, after which the only reason for The
238    /// logger to be active would be a conflict with another client.
239    ///
240    /// + request `client_id` String format Id of the client. Client may choose
241    ///     any Id with a maximum byte size of 8 (e.g., "ffxTest").
242    /// + request `metrics` Type of the metrics to be polled and logged.
243    /// + request `duration_ms` Duration of logging in milliseconds. After this
244    ///     duration, polling and logging will cease.
245    /// + request `output_samples_to_syslog` Toggle for outputting raw data to
246    ///     syslog.
247    /// + request `output_stats_to_syslog` Toggle for outputting any available
248    ///     statistics to syslog.
249    /// + error a [fuchsia.metrics.test/MeticsLoggerError] value indicating why
250    ///     the request failed.
251    pub fn r#start_logging(
252        &self,
253        mut client_id: &str,
254        mut metrics: &[Metric],
255        mut duration_ms: u32,
256        mut output_samples_to_syslog: bool,
257        mut output_stats_to_syslog: bool,
258    ) -> fidl::client::QueryResponseFut<
259        RecorderStartLoggingResult,
260        fidl::encoding::DefaultFuchsiaResourceDialect,
261    > {
262        RecorderProxyInterface::r#start_logging(
263            self,
264            client_id,
265            metrics,
266            duration_ms,
267            output_samples_to_syslog,
268            output_stats_to_syslog,
269        )
270    }
271
272    /// Initiates logging of specified metrics. Supports concurrent logging of
273    /// different metrics. Logging will only end upon a `StopLogging` call.
274    ///
275    /// `StartLogging` should be preferred for usage in automated tests to
276    /// ensure that logging terminates even if the test crashes.
277    ///
278    /// + request `client_id` String format Id of the client. Client may choose
279    ///     any Id with a maximum byte size of 8 (e.g., "ffxTest").
280    /// + request `metrics` Type of the metrics to be polled and logged.
281    /// + request `output_samples_to_syslog` Toggle for outputting raw data to
282    ///     syslog.
283    /// + request `output_stats_to_syslog` Toggle for outputting any available
284    ///     statistics to syslog.
285    /// + error a [fuchsia.metrics.test/RecorderError] value indicating why
286    ///     the request failed.
287    pub fn r#start_logging_forever(
288        &self,
289        mut client_id: &str,
290        mut metrics: &[Metric],
291        mut output_samples_to_syslog: bool,
292        mut output_stats_to_syslog: bool,
293    ) -> fidl::client::QueryResponseFut<
294        RecorderStartLoggingForeverResult,
295        fidl::encoding::DefaultFuchsiaResourceDialect,
296    > {
297        RecorderProxyInterface::r#start_logging_forever(
298            self,
299            client_id,
300            metrics,
301            output_samples_to_syslog,
302            output_stats_to_syslog,
303        )
304    }
305
306    /// Terminates all active logging tasks with the given client_id. It is
307    /// valid to call this method when logging is inactive.
308    ///
309    /// + request `client_id` String format Id of the client.
310    /// - response `status` A bool value indicating if existing logging was
311    ///     stopped (true) or there'sno existing logging for the client.
312    pub fn r#stop_logging(
313        &self,
314        mut client_id: &str,
315    ) -> fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect> {
316        RecorderProxyInterface::r#stop_logging(self, client_id)
317    }
318}
319
320impl RecorderProxyInterface for RecorderProxy {
321    type StartLoggingResponseFut = fidl::client::QueryResponseFut<
322        RecorderStartLoggingResult,
323        fidl::encoding::DefaultFuchsiaResourceDialect,
324    >;
325    fn r#start_logging(
326        &self,
327        mut client_id: &str,
328        mut metrics: &[Metric],
329        mut duration_ms: u32,
330        mut output_samples_to_syslog: bool,
331        mut output_stats_to_syslog: bool,
332    ) -> Self::StartLoggingResponseFut {
333        fn _decode(
334            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
335        ) -> Result<RecorderStartLoggingResult, fidl::Error> {
336            let _response = fidl::client::decode_transaction_body::<
337                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, RecorderError>,
338                fidl::encoding::DefaultFuchsiaResourceDialect,
339                0x40e4e1a9c6c42bd2,
340            >(_buf?)?;
341            Ok(_response.map(|x| x))
342        }
343        self.client
344            .send_query_and_decode::<RecorderStartLoggingRequest, RecorderStartLoggingResult>(
345                (client_id, metrics, duration_ms, output_samples_to_syslog, output_stats_to_syslog),
346                0x40e4e1a9c6c42bd2,
347                fidl::encoding::DynamicFlags::empty(),
348                _decode,
349            )
350    }
351
352    type StartLoggingForeverResponseFut = fidl::client::QueryResponseFut<
353        RecorderStartLoggingForeverResult,
354        fidl::encoding::DefaultFuchsiaResourceDialect,
355    >;
356    fn r#start_logging_forever(
357        &self,
358        mut client_id: &str,
359        mut metrics: &[Metric],
360        mut output_samples_to_syslog: bool,
361        mut output_stats_to_syslog: bool,
362    ) -> Self::StartLoggingForeverResponseFut {
363        fn _decode(
364            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
365        ) -> Result<RecorderStartLoggingForeverResult, fidl::Error> {
366            let _response = fidl::client::decode_transaction_body::<
367                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, RecorderError>,
368                fidl::encoding::DefaultFuchsiaResourceDialect,
369                0x37b2675fdc61ff94,
370            >(_buf?)?;
371            Ok(_response.map(|x| x))
372        }
373        self.client.send_query_and_decode::<
374            RecorderStartLoggingForeverRequest,
375            RecorderStartLoggingForeverResult,
376        >(
377            (client_id, metrics, output_samples_to_syslog, output_stats_to_syslog,),
378            0x37b2675fdc61ff94,
379            fidl::encoding::DynamicFlags::empty(),
380            _decode,
381        )
382    }
383
384    type StopLoggingResponseFut =
385        fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect>;
386    fn r#stop_logging(&self, mut client_id: &str) -> Self::StopLoggingResponseFut {
387        fn _decode(
388            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
389        ) -> Result<bool, fidl::Error> {
390            let _response = fidl::client::decode_transaction_body::<
391                RecorderStopLoggingResponse,
392                fidl::encoding::DefaultFuchsiaResourceDialect,
393                0x615d67a4d94d4732,
394            >(_buf?)?;
395            Ok(_response.stopped)
396        }
397        self.client.send_query_and_decode::<RecorderStopLoggingRequest, bool>(
398            (client_id,),
399            0x615d67a4d94d4732,
400            fidl::encoding::DynamicFlags::empty(),
401            _decode,
402        )
403    }
404}
405
406pub struct RecorderEventStream {
407    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
408}
409
410impl std::marker::Unpin for RecorderEventStream {}
411
412impl futures::stream::FusedStream for RecorderEventStream {
413    fn is_terminated(&self) -> bool {
414        self.event_receiver.is_terminated()
415    }
416}
417
418impl futures::Stream for RecorderEventStream {
419    type Item = Result<RecorderEvent, fidl::Error>;
420
421    fn poll_next(
422        mut self: std::pin::Pin<&mut Self>,
423        cx: &mut std::task::Context<'_>,
424    ) -> std::task::Poll<Option<Self::Item>> {
425        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
426            &mut self.event_receiver,
427            cx
428        )?) {
429            Some(buf) => std::task::Poll::Ready(Some(RecorderEvent::decode(buf))),
430            None => std::task::Poll::Ready(None),
431        }
432    }
433}
434
435#[derive(Debug)]
436pub enum RecorderEvent {}
437
438impl RecorderEvent {
439    /// Decodes a message buffer as a [`RecorderEvent`].
440    fn decode(
441        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
442    ) -> Result<RecorderEvent, fidl::Error> {
443        let (bytes, _handles) = buf.split_mut();
444        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
445        debug_assert_eq!(tx_header.tx_id, 0);
446        match tx_header.ordinal {
447            _ => Err(fidl::Error::UnknownOrdinal {
448                ordinal: tx_header.ordinal,
449                protocol_name: <RecorderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
450            }),
451        }
452    }
453}
454
455/// A Stream of incoming requests for fuchsia.power.metrics/Recorder.
456pub struct RecorderRequestStream {
457    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
458    is_terminated: bool,
459}
460
461impl std::marker::Unpin for RecorderRequestStream {}
462
463impl futures::stream::FusedStream for RecorderRequestStream {
464    fn is_terminated(&self) -> bool {
465        self.is_terminated
466    }
467}
468
469impl fidl::endpoints::RequestStream for RecorderRequestStream {
470    type Protocol = RecorderMarker;
471    type ControlHandle = RecorderControlHandle;
472
473    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
474        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
475    }
476
477    fn control_handle(&self) -> Self::ControlHandle {
478        RecorderControlHandle { inner: self.inner.clone() }
479    }
480
481    fn into_inner(
482        self,
483    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
484    {
485        (self.inner, self.is_terminated)
486    }
487
488    fn from_inner(
489        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
490        is_terminated: bool,
491    ) -> Self {
492        Self { inner, is_terminated }
493    }
494}
495
496impl futures::Stream for RecorderRequestStream {
497    type Item = Result<RecorderRequest, fidl::Error>;
498
499    fn poll_next(
500        mut self: std::pin::Pin<&mut Self>,
501        cx: &mut std::task::Context<'_>,
502    ) -> std::task::Poll<Option<Self::Item>> {
503        let this = &mut *self;
504        if this.inner.check_shutdown(cx) {
505            this.is_terminated = true;
506            return std::task::Poll::Ready(None);
507        }
508        if this.is_terminated {
509            panic!("polled RecorderRequestStream after completion");
510        }
511        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
512            |bytes, handles| {
513                match this.inner.channel().read_etc(cx, bytes, handles) {
514                    std::task::Poll::Ready(Ok(())) => {}
515                    std::task::Poll::Pending => return std::task::Poll::Pending,
516                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
517                        this.is_terminated = true;
518                        return std::task::Poll::Ready(None);
519                    }
520                    std::task::Poll::Ready(Err(e)) => {
521                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
522                            e.into(),
523                        ))))
524                    }
525                }
526
527                // A message has been received from the channel
528                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
529
530                std::task::Poll::Ready(Some(match header.ordinal {
531                    0x40e4e1a9c6c42bd2 => {
532                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
533                        let mut req = fidl::new_empty!(
534                            RecorderStartLoggingRequest,
535                            fidl::encoding::DefaultFuchsiaResourceDialect
536                        );
537                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RecorderStartLoggingRequest>(&header, _body_bytes, handles, &mut req)?;
538                        let control_handle = RecorderControlHandle { inner: this.inner.clone() };
539                        Ok(RecorderRequest::StartLogging {
540                            client_id: req.client_id,
541                            metrics: req.metrics,
542                            duration_ms: req.duration_ms,
543                            output_samples_to_syslog: req.output_samples_to_syslog,
544                            output_stats_to_syslog: req.output_stats_to_syslog,
545
546                            responder: RecorderStartLoggingResponder {
547                                control_handle: std::mem::ManuallyDrop::new(control_handle),
548                                tx_id: header.tx_id,
549                            },
550                        })
551                    }
552                    0x37b2675fdc61ff94 => {
553                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
554                        let mut req = fidl::new_empty!(
555                            RecorderStartLoggingForeverRequest,
556                            fidl::encoding::DefaultFuchsiaResourceDialect
557                        );
558                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RecorderStartLoggingForeverRequest>(&header, _body_bytes, handles, &mut req)?;
559                        let control_handle = RecorderControlHandle { inner: this.inner.clone() };
560                        Ok(RecorderRequest::StartLoggingForever {
561                            client_id: req.client_id,
562                            metrics: req.metrics,
563                            output_samples_to_syslog: req.output_samples_to_syslog,
564                            output_stats_to_syslog: req.output_stats_to_syslog,
565
566                            responder: RecorderStartLoggingForeverResponder {
567                                control_handle: std::mem::ManuallyDrop::new(control_handle),
568                                tx_id: header.tx_id,
569                            },
570                        })
571                    }
572                    0x615d67a4d94d4732 => {
573                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
574                        let mut req = fidl::new_empty!(
575                            RecorderStopLoggingRequest,
576                            fidl::encoding::DefaultFuchsiaResourceDialect
577                        );
578                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RecorderStopLoggingRequest>(&header, _body_bytes, handles, &mut req)?;
579                        let control_handle = RecorderControlHandle { inner: this.inner.clone() };
580                        Ok(RecorderRequest::StopLogging {
581                            client_id: req.client_id,
582
583                            responder: RecorderStopLoggingResponder {
584                                control_handle: std::mem::ManuallyDrop::new(control_handle),
585                                tx_id: header.tx_id,
586                            },
587                        })
588                    }
589                    _ => Err(fidl::Error::UnknownOrdinal {
590                        ordinal: header.ordinal,
591                        protocol_name:
592                            <RecorderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
593                    }),
594                }))
595            },
596        )
597    }
598}
599
600/// A protocol for managing on-demand metrics logging.
601#[derive(Debug)]
602pub enum RecorderRequest {
603    /// Initiates logging of specified metrics for the provided duration.
604    /// Supports concurrent logging of different metrics. Logging may be
605    /// terminated early with a call to `StopLogging`.
606    ///
607    /// This call will fail if logging of the specified metric is already
608    /// active. For this reason, a client may wish to precede a `StartLogging`
609    /// call with a `StopLogging` call, after which the only reason for The
610    /// logger to be active would be a conflict with another client.
611    ///
612    /// + request `client_id` String format Id of the client. Client may choose
613    ///     any Id with a maximum byte size of 8 (e.g., "ffxTest").
614    /// + request `metrics` Type of the metrics to be polled and logged.
615    /// + request `duration_ms` Duration of logging in milliseconds. After this
616    ///     duration, polling and logging will cease.
617    /// + request `output_samples_to_syslog` Toggle for outputting raw data to
618    ///     syslog.
619    /// + request `output_stats_to_syslog` Toggle for outputting any available
620    ///     statistics to syslog.
621    /// + error a [fuchsia.metrics.test/MeticsLoggerError] value indicating why
622    ///     the request failed.
623    StartLogging {
624        client_id: String,
625        metrics: Vec<Metric>,
626        duration_ms: u32,
627        output_samples_to_syslog: bool,
628        output_stats_to_syslog: bool,
629        responder: RecorderStartLoggingResponder,
630    },
631    /// Initiates logging of specified metrics. Supports concurrent logging of
632    /// different metrics. Logging will only end upon a `StopLogging` call.
633    ///
634    /// `StartLogging` should be preferred for usage in automated tests to
635    /// ensure that logging terminates even if the test crashes.
636    ///
637    /// + request `client_id` String format Id of the client. Client may choose
638    ///     any Id with a maximum byte size of 8 (e.g., "ffxTest").
639    /// + request `metrics` Type of the metrics to be polled and logged.
640    /// + request `output_samples_to_syslog` Toggle for outputting raw data to
641    ///     syslog.
642    /// + request `output_stats_to_syslog` Toggle for outputting any available
643    ///     statistics to syslog.
644    /// + error a [fuchsia.metrics.test/RecorderError] value indicating why
645    ///     the request failed.
646    StartLoggingForever {
647        client_id: String,
648        metrics: Vec<Metric>,
649        output_samples_to_syslog: bool,
650        output_stats_to_syslog: bool,
651        responder: RecorderStartLoggingForeverResponder,
652    },
653    /// Terminates all active logging tasks with the given client_id. It is
654    /// valid to call this method when logging is inactive.
655    ///
656    /// + request `client_id` String format Id of the client.
657    /// - response `status` A bool value indicating if existing logging was
658    ///     stopped (true) or there'sno existing logging for the client.
659    StopLogging { client_id: String, responder: RecorderStopLoggingResponder },
660}
661
662impl RecorderRequest {
663    #[allow(irrefutable_let_patterns)]
664    pub fn into_start_logging(
665        self,
666    ) -> Option<(String, Vec<Metric>, u32, bool, bool, RecorderStartLoggingResponder)> {
667        if let RecorderRequest::StartLogging {
668            client_id,
669            metrics,
670            duration_ms,
671            output_samples_to_syslog,
672            output_stats_to_syslog,
673            responder,
674        } = self
675        {
676            Some((
677                client_id,
678                metrics,
679                duration_ms,
680                output_samples_to_syslog,
681                output_stats_to_syslog,
682                responder,
683            ))
684        } else {
685            None
686        }
687    }
688
689    #[allow(irrefutable_let_patterns)]
690    pub fn into_start_logging_forever(
691        self,
692    ) -> Option<(String, Vec<Metric>, bool, bool, RecorderStartLoggingForeverResponder)> {
693        if let RecorderRequest::StartLoggingForever {
694            client_id,
695            metrics,
696            output_samples_to_syslog,
697            output_stats_to_syslog,
698            responder,
699        } = self
700        {
701            Some((client_id, metrics, output_samples_to_syslog, output_stats_to_syslog, responder))
702        } else {
703            None
704        }
705    }
706
707    #[allow(irrefutable_let_patterns)]
708    pub fn into_stop_logging(self) -> Option<(String, RecorderStopLoggingResponder)> {
709        if let RecorderRequest::StopLogging { client_id, responder } = self {
710            Some((client_id, responder))
711        } else {
712            None
713        }
714    }
715
716    /// Name of the method defined in FIDL
717    pub fn method_name(&self) -> &'static str {
718        match *self {
719            RecorderRequest::StartLogging { .. } => "start_logging",
720            RecorderRequest::StartLoggingForever { .. } => "start_logging_forever",
721            RecorderRequest::StopLogging { .. } => "stop_logging",
722        }
723    }
724}
725
726#[derive(Debug, Clone)]
727pub struct RecorderControlHandle {
728    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
729}
730
731impl fidl::endpoints::ControlHandle for RecorderControlHandle {
732    fn shutdown(&self) {
733        self.inner.shutdown()
734    }
735    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
736        self.inner.shutdown_with_epitaph(status)
737    }
738
739    fn is_closed(&self) -> bool {
740        self.inner.channel().is_closed()
741    }
742    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
743        self.inner.channel().on_closed()
744    }
745
746    #[cfg(target_os = "fuchsia")]
747    fn signal_peer(
748        &self,
749        clear_mask: zx::Signals,
750        set_mask: zx::Signals,
751    ) -> Result<(), zx_status::Status> {
752        use fidl::Peered;
753        self.inner.channel().signal_peer(clear_mask, set_mask)
754    }
755}
756
757impl RecorderControlHandle {}
758
759#[must_use = "FIDL methods require a response to be sent"]
760#[derive(Debug)]
761pub struct RecorderStartLoggingResponder {
762    control_handle: std::mem::ManuallyDrop<RecorderControlHandle>,
763    tx_id: u32,
764}
765
766/// Set the the channel to be shutdown (see [`RecorderControlHandle::shutdown`])
767/// if the responder is dropped without sending a response, so that the client
768/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
769impl std::ops::Drop for RecorderStartLoggingResponder {
770    fn drop(&mut self) {
771        self.control_handle.shutdown();
772        // Safety: drops once, never accessed again
773        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
774    }
775}
776
777impl fidl::endpoints::Responder for RecorderStartLoggingResponder {
778    type ControlHandle = RecorderControlHandle;
779
780    fn control_handle(&self) -> &RecorderControlHandle {
781        &self.control_handle
782    }
783
784    fn drop_without_shutdown(mut self) {
785        // Safety: drops once, never accessed again due to mem::forget
786        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
787        // Prevent Drop from running (which would shut down the channel)
788        std::mem::forget(self);
789    }
790}
791
792impl RecorderStartLoggingResponder {
793    /// Sends a response to the FIDL transaction.
794    ///
795    /// Sets the channel to shutdown if an error occurs.
796    pub fn send(self, mut result: Result<(), RecorderError>) -> Result<(), fidl::Error> {
797        let _result = self.send_raw(result);
798        if _result.is_err() {
799            self.control_handle.shutdown();
800        }
801        self.drop_without_shutdown();
802        _result
803    }
804
805    /// Similar to "send" but does not shutdown the channel if an error occurs.
806    pub fn send_no_shutdown_on_err(
807        self,
808        mut result: Result<(), RecorderError>,
809    ) -> Result<(), fidl::Error> {
810        let _result = self.send_raw(result);
811        self.drop_without_shutdown();
812        _result
813    }
814
815    fn send_raw(&self, mut result: Result<(), RecorderError>) -> Result<(), fidl::Error> {
816        self.control_handle.inner.send::<fidl::encoding::ResultType<
817            fidl::encoding::EmptyStruct,
818            RecorderError,
819        >>(
820            result,
821            self.tx_id,
822            0x40e4e1a9c6c42bd2,
823            fidl::encoding::DynamicFlags::empty(),
824        )
825    }
826}
827
828#[must_use = "FIDL methods require a response to be sent"]
829#[derive(Debug)]
830pub struct RecorderStartLoggingForeverResponder {
831    control_handle: std::mem::ManuallyDrop<RecorderControlHandle>,
832    tx_id: u32,
833}
834
835/// Set the the channel to be shutdown (see [`RecorderControlHandle::shutdown`])
836/// if the responder is dropped without sending a response, so that the client
837/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
838impl std::ops::Drop for RecorderStartLoggingForeverResponder {
839    fn drop(&mut self) {
840        self.control_handle.shutdown();
841        // Safety: drops once, never accessed again
842        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
843    }
844}
845
846impl fidl::endpoints::Responder for RecorderStartLoggingForeverResponder {
847    type ControlHandle = RecorderControlHandle;
848
849    fn control_handle(&self) -> &RecorderControlHandle {
850        &self.control_handle
851    }
852
853    fn drop_without_shutdown(mut self) {
854        // Safety: drops once, never accessed again due to mem::forget
855        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
856        // Prevent Drop from running (which would shut down the channel)
857        std::mem::forget(self);
858    }
859}
860
861impl RecorderStartLoggingForeverResponder {
862    /// Sends a response to the FIDL transaction.
863    ///
864    /// Sets the channel to shutdown if an error occurs.
865    pub fn send(self, mut result: Result<(), RecorderError>) -> Result<(), fidl::Error> {
866        let _result = self.send_raw(result);
867        if _result.is_err() {
868            self.control_handle.shutdown();
869        }
870        self.drop_without_shutdown();
871        _result
872    }
873
874    /// Similar to "send" but does not shutdown the channel if an error occurs.
875    pub fn send_no_shutdown_on_err(
876        self,
877        mut result: Result<(), RecorderError>,
878    ) -> Result<(), fidl::Error> {
879        let _result = self.send_raw(result);
880        self.drop_without_shutdown();
881        _result
882    }
883
884    fn send_raw(&self, mut result: Result<(), RecorderError>) -> Result<(), fidl::Error> {
885        self.control_handle.inner.send::<fidl::encoding::ResultType<
886            fidl::encoding::EmptyStruct,
887            RecorderError,
888        >>(
889            result,
890            self.tx_id,
891            0x37b2675fdc61ff94,
892            fidl::encoding::DynamicFlags::empty(),
893        )
894    }
895}
896
897#[must_use = "FIDL methods require a response to be sent"]
898#[derive(Debug)]
899pub struct RecorderStopLoggingResponder {
900    control_handle: std::mem::ManuallyDrop<RecorderControlHandle>,
901    tx_id: u32,
902}
903
904/// Set the the channel to be shutdown (see [`RecorderControlHandle::shutdown`])
905/// if the responder is dropped without sending a response, so that the client
906/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
907impl std::ops::Drop for RecorderStopLoggingResponder {
908    fn drop(&mut self) {
909        self.control_handle.shutdown();
910        // Safety: drops once, never accessed again
911        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
912    }
913}
914
915impl fidl::endpoints::Responder for RecorderStopLoggingResponder {
916    type ControlHandle = RecorderControlHandle;
917
918    fn control_handle(&self) -> &RecorderControlHandle {
919        &self.control_handle
920    }
921
922    fn drop_without_shutdown(mut self) {
923        // Safety: drops once, never accessed again due to mem::forget
924        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
925        // Prevent Drop from running (which would shut down the channel)
926        std::mem::forget(self);
927    }
928}
929
930impl RecorderStopLoggingResponder {
931    /// Sends a response to the FIDL transaction.
932    ///
933    /// Sets the channel to shutdown if an error occurs.
934    pub fn send(self, mut stopped: bool) -> Result<(), fidl::Error> {
935        let _result = self.send_raw(stopped);
936        if _result.is_err() {
937            self.control_handle.shutdown();
938        }
939        self.drop_without_shutdown();
940        _result
941    }
942
943    /// Similar to "send" but does not shutdown the channel if an error occurs.
944    pub fn send_no_shutdown_on_err(self, mut stopped: bool) -> Result<(), fidl::Error> {
945        let _result = self.send_raw(stopped);
946        self.drop_without_shutdown();
947        _result
948    }
949
950    fn send_raw(&self, mut stopped: bool) -> Result<(), fidl::Error> {
951        self.control_handle.inner.send::<RecorderStopLoggingResponse>(
952            (stopped,),
953            self.tx_id,
954            0x615d67a4d94d4732,
955            fidl::encoding::DynamicFlags::empty(),
956        )
957    }
958}
959
960mod internal {
961    use super::*;
962}