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