Skip to main content

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