fidl_fuchsia_media_audio/
fidl_fuchsia_media_audio.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_media_audio__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct EffectsControllerMarker;
16
17impl fidl::endpoints::ProtocolMarker for EffectsControllerMarker {
18    type Proxy = EffectsControllerProxy;
19    type RequestStream = EffectsControllerRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = EffectsControllerSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.media.audio.EffectsController";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for EffectsControllerMarker {}
26pub type EffectsControllerUpdateEffectResult = Result<(), UpdateEffectError>;
27
28pub trait EffectsControllerProxyInterface: Send + Sync {
29    type UpdateEffectResponseFut: std::future::Future<Output = Result<EffectsControllerUpdateEffectResult, fidl::Error>>
30        + Send;
31    fn r#update_effect(&self, effect_name: &str, config: &str) -> Self::UpdateEffectResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct EffectsControllerSynchronousProxy {
36    client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for EffectsControllerSynchronousProxy {
41    type Proxy = EffectsControllerProxy;
42    type Protocol = EffectsControllerMarker;
43
44    fn from_channel(inner: fidl::Channel) -> Self {
45        Self::new(inner)
46    }
47
48    fn into_channel(self) -> fidl::Channel {
49        self.client.into_channel()
50    }
51
52    fn as_channel(&self) -> &fidl::Channel {
53        self.client.as_channel()
54    }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl EffectsControllerSynchronousProxy {
59    pub fn new(channel: fidl::Channel) -> Self {
60        let protocol_name =
61            <EffectsControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
62        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
63    }
64
65    pub fn into_channel(self) -> fidl::Channel {
66        self.client.into_channel()
67    }
68
69    /// Waits until an event arrives and returns it. It is safe for other
70    /// threads to make concurrent requests while waiting for an event.
71    pub fn wait_for_event(
72        &self,
73        deadline: zx::MonotonicInstant,
74    ) -> Result<EffectsControllerEvent, fidl::Error> {
75        EffectsControllerEvent::decode(self.client.wait_for_event(deadline)?)
76    }
77
78    /// Sends the `config` message to an audio effect named `effect_name`. If the
79    /// server closes the `EffectsController` connection for any reason, that
80    /// indicates that the effects have been reset and any state associated with
81    /// previous `UpdateEffect` messages have been lost. Clients who wish to re-apply
82    /// state should respond by reconnecting and resending any needed `UpdateEffect`
83    /// messages. If a client closes the connection, no state will be lost but the
84    /// client will also be unable to determine if and when any state associated with
85    /// previous messages have been lost.
86    ///
87    /// Returns success (empty response) if the message was accepted by an
88    /// effect named `effect_name`.
89    ///
90    /// Returns `UpdateEffectError.INVALID_CONFIG` if an effect with the name
91    /// `effect_name` was found, but the `config` message was rejected.
92    ///
93    /// Returns `UpdateEffectError.NOT_FOUND` if no effect with name `effect_name`
94    /// could be located.
95    pub fn r#update_effect(
96        &self,
97        mut effect_name: &str,
98        mut config: &str,
99        ___deadline: zx::MonotonicInstant,
100    ) -> Result<EffectsControllerUpdateEffectResult, fidl::Error> {
101        let _response = self.client.send_query::<
102            EffectsControllerUpdateEffectRequest,
103            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, UpdateEffectError>,
104        >(
105            (effect_name, config,),
106            0x4e39e4b5e6279125,
107            fidl::encoding::DynamicFlags::empty(),
108            ___deadline,
109        )?;
110        Ok(_response.map(|x| x))
111    }
112}
113
114#[cfg(target_os = "fuchsia")]
115impl From<EffectsControllerSynchronousProxy> for zx::NullableHandle {
116    fn from(value: EffectsControllerSynchronousProxy) -> Self {
117        value.into_channel().into()
118    }
119}
120
121#[cfg(target_os = "fuchsia")]
122impl From<fidl::Channel> for EffectsControllerSynchronousProxy {
123    fn from(value: fidl::Channel) -> Self {
124        Self::new(value)
125    }
126}
127
128#[cfg(target_os = "fuchsia")]
129impl fidl::endpoints::FromClient for EffectsControllerSynchronousProxy {
130    type Protocol = EffectsControllerMarker;
131
132    fn from_client(value: fidl::endpoints::ClientEnd<EffectsControllerMarker>) -> Self {
133        Self::new(value.into_channel())
134    }
135}
136
137#[derive(Debug, Clone)]
138pub struct EffectsControllerProxy {
139    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
140}
141
142impl fidl::endpoints::Proxy for EffectsControllerProxy {
143    type Protocol = EffectsControllerMarker;
144
145    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
146        Self::new(inner)
147    }
148
149    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
150        self.client.into_channel().map_err(|client| Self { client })
151    }
152
153    fn as_channel(&self) -> &::fidl::AsyncChannel {
154        self.client.as_channel()
155    }
156}
157
158impl EffectsControllerProxy {
159    /// Create a new Proxy for fuchsia.media.audio/EffectsController.
160    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
161        let protocol_name =
162            <EffectsControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
163        Self { client: fidl::client::Client::new(channel, protocol_name) }
164    }
165
166    /// Get a Stream of events from the remote end of the protocol.
167    ///
168    /// # Panics
169    ///
170    /// Panics if the event stream was already taken.
171    pub fn take_event_stream(&self) -> EffectsControllerEventStream {
172        EffectsControllerEventStream { event_receiver: self.client.take_event_receiver() }
173    }
174
175    /// Sends the `config` message to an audio effect named `effect_name`. If the
176    /// server closes the `EffectsController` connection for any reason, that
177    /// indicates that the effects have been reset and any state associated with
178    /// previous `UpdateEffect` messages have been lost. Clients who wish to re-apply
179    /// state should respond by reconnecting and resending any needed `UpdateEffect`
180    /// messages. If a client closes the connection, no state will be lost but the
181    /// client will also be unable to determine if and when any state associated with
182    /// previous messages have been lost.
183    ///
184    /// Returns success (empty response) if the message was accepted by an
185    /// effect named `effect_name`.
186    ///
187    /// Returns `UpdateEffectError.INVALID_CONFIG` if an effect with the name
188    /// `effect_name` was found, but the `config` message was rejected.
189    ///
190    /// Returns `UpdateEffectError.NOT_FOUND` if no effect with name `effect_name`
191    /// could be located.
192    pub fn r#update_effect(
193        &self,
194        mut effect_name: &str,
195        mut config: &str,
196    ) -> fidl::client::QueryResponseFut<
197        EffectsControllerUpdateEffectResult,
198        fidl::encoding::DefaultFuchsiaResourceDialect,
199    > {
200        EffectsControllerProxyInterface::r#update_effect(self, effect_name, config)
201    }
202}
203
204impl EffectsControllerProxyInterface for EffectsControllerProxy {
205    type UpdateEffectResponseFut = fidl::client::QueryResponseFut<
206        EffectsControllerUpdateEffectResult,
207        fidl::encoding::DefaultFuchsiaResourceDialect,
208    >;
209    fn r#update_effect(
210        &self,
211        mut effect_name: &str,
212        mut config: &str,
213    ) -> Self::UpdateEffectResponseFut {
214        fn _decode(
215            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
216        ) -> Result<EffectsControllerUpdateEffectResult, fidl::Error> {
217            let _response = fidl::client::decode_transaction_body::<
218                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, UpdateEffectError>,
219                fidl::encoding::DefaultFuchsiaResourceDialect,
220                0x4e39e4b5e6279125,
221            >(_buf?)?;
222            Ok(_response.map(|x| x))
223        }
224        self.client.send_query_and_decode::<
225            EffectsControllerUpdateEffectRequest,
226            EffectsControllerUpdateEffectResult,
227        >(
228            (effect_name, config,),
229            0x4e39e4b5e6279125,
230            fidl::encoding::DynamicFlags::empty(),
231            _decode,
232        )
233    }
234}
235
236pub struct EffectsControllerEventStream {
237    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
238}
239
240impl std::marker::Unpin for EffectsControllerEventStream {}
241
242impl futures::stream::FusedStream for EffectsControllerEventStream {
243    fn is_terminated(&self) -> bool {
244        self.event_receiver.is_terminated()
245    }
246}
247
248impl futures::Stream for EffectsControllerEventStream {
249    type Item = Result<EffectsControllerEvent, fidl::Error>;
250
251    fn poll_next(
252        mut self: std::pin::Pin<&mut Self>,
253        cx: &mut std::task::Context<'_>,
254    ) -> std::task::Poll<Option<Self::Item>> {
255        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
256            &mut self.event_receiver,
257            cx
258        )?) {
259            Some(buf) => std::task::Poll::Ready(Some(EffectsControllerEvent::decode(buf))),
260            None => std::task::Poll::Ready(None),
261        }
262    }
263}
264
265#[derive(Debug)]
266pub enum EffectsControllerEvent {}
267
268impl EffectsControllerEvent {
269    /// Decodes a message buffer as a [`EffectsControllerEvent`].
270    fn decode(
271        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
272    ) -> Result<EffectsControllerEvent, fidl::Error> {
273        let (bytes, _handles) = buf.split_mut();
274        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
275        debug_assert_eq!(tx_header.tx_id, 0);
276        match tx_header.ordinal {
277            _ => Err(fidl::Error::UnknownOrdinal {
278                ordinal: tx_header.ordinal,
279                protocol_name:
280                    <EffectsControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
281            }),
282        }
283    }
284}
285
286/// A Stream of incoming requests for fuchsia.media.audio/EffectsController.
287pub struct EffectsControllerRequestStream {
288    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
289    is_terminated: bool,
290}
291
292impl std::marker::Unpin for EffectsControllerRequestStream {}
293
294impl futures::stream::FusedStream for EffectsControllerRequestStream {
295    fn is_terminated(&self) -> bool {
296        self.is_terminated
297    }
298}
299
300impl fidl::endpoints::RequestStream for EffectsControllerRequestStream {
301    type Protocol = EffectsControllerMarker;
302    type ControlHandle = EffectsControllerControlHandle;
303
304    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
305        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
306    }
307
308    fn control_handle(&self) -> Self::ControlHandle {
309        EffectsControllerControlHandle { inner: self.inner.clone() }
310    }
311
312    fn into_inner(
313        self,
314    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
315    {
316        (self.inner, self.is_terminated)
317    }
318
319    fn from_inner(
320        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
321        is_terminated: bool,
322    ) -> Self {
323        Self { inner, is_terminated }
324    }
325}
326
327impl futures::Stream for EffectsControllerRequestStream {
328    type Item = Result<EffectsControllerRequest, fidl::Error>;
329
330    fn poll_next(
331        mut self: std::pin::Pin<&mut Self>,
332        cx: &mut std::task::Context<'_>,
333    ) -> std::task::Poll<Option<Self::Item>> {
334        let this = &mut *self;
335        if this.inner.check_shutdown(cx) {
336            this.is_terminated = true;
337            return std::task::Poll::Ready(None);
338        }
339        if this.is_terminated {
340            panic!("polled EffectsControllerRequestStream after completion");
341        }
342        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
343            |bytes, handles| {
344                match this.inner.channel().read_etc(cx, bytes, handles) {
345                    std::task::Poll::Ready(Ok(())) => {}
346                    std::task::Poll::Pending => return std::task::Poll::Pending,
347                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
348                        this.is_terminated = true;
349                        return std::task::Poll::Ready(None);
350                    }
351                    std::task::Poll::Ready(Err(e)) => {
352                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
353                            e.into(),
354                        ))));
355                    }
356                }
357
358                // A message has been received from the channel
359                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
360
361                std::task::Poll::Ready(Some(match header.ordinal {
362                    0x4e39e4b5e6279125 => {
363                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
364                        let mut req = fidl::new_empty!(
365                            EffectsControllerUpdateEffectRequest,
366                            fidl::encoding::DefaultFuchsiaResourceDialect
367                        );
368                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<EffectsControllerUpdateEffectRequest>(&header, _body_bytes, handles, &mut req)?;
369                        let control_handle =
370                            EffectsControllerControlHandle { inner: this.inner.clone() };
371                        Ok(EffectsControllerRequest::UpdateEffect {
372                            effect_name: req.effect_name,
373                            config: req.config,
374
375                            responder: EffectsControllerUpdateEffectResponder {
376                                control_handle: std::mem::ManuallyDrop::new(control_handle),
377                                tx_id: header.tx_id,
378                            },
379                        })
380                    }
381                    _ => Err(fidl::Error::UnknownOrdinal {
382                        ordinal: header.ordinal,
383                        protocol_name:
384                            <EffectsControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
385                    }),
386                }))
387            },
388        )
389    }
390}
391
392#[derive(Debug)]
393pub enum EffectsControllerRequest {
394    /// Sends the `config` message to an audio effect named `effect_name`. If the
395    /// server closes the `EffectsController` connection for any reason, that
396    /// indicates that the effects have been reset and any state associated with
397    /// previous `UpdateEffect` messages have been lost. Clients who wish to re-apply
398    /// state should respond by reconnecting and resending any needed `UpdateEffect`
399    /// messages. If a client closes the connection, no state will be lost but the
400    /// client will also be unable to determine if and when any state associated with
401    /// previous messages have been lost.
402    ///
403    /// Returns success (empty response) if the message was accepted by an
404    /// effect named `effect_name`.
405    ///
406    /// Returns `UpdateEffectError.INVALID_CONFIG` if an effect with the name
407    /// `effect_name` was found, but the `config` message was rejected.
408    ///
409    /// Returns `UpdateEffectError.NOT_FOUND` if no effect with name `effect_name`
410    /// could be located.
411    UpdateEffect {
412        effect_name: String,
413        config: String,
414        responder: EffectsControllerUpdateEffectResponder,
415    },
416}
417
418impl EffectsControllerRequest {
419    #[allow(irrefutable_let_patterns)]
420    pub fn into_update_effect(
421        self,
422    ) -> Option<(String, String, EffectsControllerUpdateEffectResponder)> {
423        if let EffectsControllerRequest::UpdateEffect { effect_name, config, responder } = self {
424            Some((effect_name, config, responder))
425        } else {
426            None
427        }
428    }
429
430    /// Name of the method defined in FIDL
431    pub fn method_name(&self) -> &'static str {
432        match *self {
433            EffectsControllerRequest::UpdateEffect { .. } => "update_effect",
434        }
435    }
436}
437
438#[derive(Debug, Clone)]
439pub struct EffectsControllerControlHandle {
440    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
441}
442
443impl fidl::endpoints::ControlHandle for EffectsControllerControlHandle {
444    fn shutdown(&self) {
445        self.inner.shutdown()
446    }
447
448    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
449        self.inner.shutdown_with_epitaph(status)
450    }
451
452    fn is_closed(&self) -> bool {
453        self.inner.channel().is_closed()
454    }
455    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
456        self.inner.channel().on_closed()
457    }
458
459    #[cfg(target_os = "fuchsia")]
460    fn signal_peer(
461        &self,
462        clear_mask: zx::Signals,
463        set_mask: zx::Signals,
464    ) -> Result<(), zx_status::Status> {
465        use fidl::Peered;
466        self.inner.channel().signal_peer(clear_mask, set_mask)
467    }
468}
469
470impl EffectsControllerControlHandle {}
471
472#[must_use = "FIDL methods require a response to be sent"]
473#[derive(Debug)]
474pub struct EffectsControllerUpdateEffectResponder {
475    control_handle: std::mem::ManuallyDrop<EffectsControllerControlHandle>,
476    tx_id: u32,
477}
478
479/// Set the the channel to be shutdown (see [`EffectsControllerControlHandle::shutdown`])
480/// if the responder is dropped without sending a response, so that the client
481/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
482impl std::ops::Drop for EffectsControllerUpdateEffectResponder {
483    fn drop(&mut self) {
484        self.control_handle.shutdown();
485        // Safety: drops once, never accessed again
486        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
487    }
488}
489
490impl fidl::endpoints::Responder for EffectsControllerUpdateEffectResponder {
491    type ControlHandle = EffectsControllerControlHandle;
492
493    fn control_handle(&self) -> &EffectsControllerControlHandle {
494        &self.control_handle
495    }
496
497    fn drop_without_shutdown(mut self) {
498        // Safety: drops once, never accessed again due to mem::forget
499        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
500        // Prevent Drop from running (which would shut down the channel)
501        std::mem::forget(self);
502    }
503}
504
505impl EffectsControllerUpdateEffectResponder {
506    /// Sends a response to the FIDL transaction.
507    ///
508    /// Sets the channel to shutdown if an error occurs.
509    pub fn send(self, mut result: Result<(), UpdateEffectError>) -> Result<(), fidl::Error> {
510        let _result = self.send_raw(result);
511        if _result.is_err() {
512            self.control_handle.shutdown();
513        }
514        self.drop_without_shutdown();
515        _result
516    }
517
518    /// Similar to "send" but does not shutdown the channel if an error occurs.
519    pub fn send_no_shutdown_on_err(
520        self,
521        mut result: Result<(), UpdateEffectError>,
522    ) -> Result<(), fidl::Error> {
523        let _result = self.send_raw(result);
524        self.drop_without_shutdown();
525        _result
526    }
527
528    fn send_raw(&self, mut result: Result<(), UpdateEffectError>) -> Result<(), fidl::Error> {
529        self.control_handle.inner.send::<fidl::encoding::ResultType<
530            fidl::encoding::EmptyStruct,
531            UpdateEffectError,
532        >>(
533            result,
534            self.tx_id,
535            0x4e39e4b5e6279125,
536            fidl::encoding::DynamicFlags::empty(),
537        )
538    }
539}
540
541#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
542pub struct GainControlMarker;
543
544impl fidl::endpoints::ProtocolMarker for GainControlMarker {
545    type Proxy = GainControlProxy;
546    type RequestStream = GainControlRequestStream;
547    #[cfg(target_os = "fuchsia")]
548    type SynchronousProxy = GainControlSynchronousProxy;
549
550    const DEBUG_NAME: &'static str = "(anonymous) GainControl";
551}
552
553pub trait GainControlProxyInterface: Send + Sync {
554    fn r#set_gain(&self, gain_db: f32) -> Result<(), fidl::Error>;
555    fn r#set_gain_with_ramp(
556        &self,
557        gain_db: f32,
558        duration: i64,
559        ramp_type: RampType,
560    ) -> Result<(), fidl::Error>;
561    fn r#set_mute(&self, muted: bool) -> Result<(), fidl::Error>;
562}
563#[derive(Debug)]
564#[cfg(target_os = "fuchsia")]
565pub struct GainControlSynchronousProxy {
566    client: fidl::client::sync::Client,
567}
568
569#[cfg(target_os = "fuchsia")]
570impl fidl::endpoints::SynchronousProxy for GainControlSynchronousProxy {
571    type Proxy = GainControlProxy;
572    type Protocol = GainControlMarker;
573
574    fn from_channel(inner: fidl::Channel) -> Self {
575        Self::new(inner)
576    }
577
578    fn into_channel(self) -> fidl::Channel {
579        self.client.into_channel()
580    }
581
582    fn as_channel(&self) -> &fidl::Channel {
583        self.client.as_channel()
584    }
585}
586
587#[cfg(target_os = "fuchsia")]
588impl GainControlSynchronousProxy {
589    pub fn new(channel: fidl::Channel) -> Self {
590        let protocol_name = <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
591        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
592    }
593
594    pub fn into_channel(self) -> fidl::Channel {
595        self.client.into_channel()
596    }
597
598    /// Waits until an event arrives and returns it. It is safe for other
599    /// threads to make concurrent requests while waiting for an event.
600    pub fn wait_for_event(
601        &self,
602        deadline: zx::MonotonicInstant,
603    ) -> Result<GainControlEvent, fidl::Error> {
604        GainControlEvent::decode(self.client.wait_for_event(deadline)?)
605    }
606
607    /// Sets the gain in decibels.
608    pub fn r#set_gain(&self, mut gain_db: f32) -> Result<(), fidl::Error> {
609        self.client.send::<GainControlSetGainRequest>(
610            (gain_db,),
611            0x2fc070871d033f64,
612            fidl::encoding::DynamicFlags::empty(),
613        )
614    }
615
616    /// Smoothly changes gain from its current value to specified value, over the
617    /// specified duration (in milliseconds). If 'duration_ns' is 0, gain changes
618    /// immediately. Otherwise, gain changes only while the stream is running.
619    ///
620    /// Any active or pending ramp is cancelled by subsequent call to SetGain.
621    ///
622    /// There can be at most 1 active ramp at any time. Any active or pending
623    /// ramp is replaced by a later call to SetGainWithRamp (even if duration is
624    /// 0). In this case gain would ramps directly from its most recent
625    /// (mid-ramp) value to the newly-specified one, over the new duration,
626    /// using the new easing.
627    ///
628    /// Usage example (using time in seconds):
629    ///  Time 0
630    ///      SetGainWithRamp(`MUTED_GAIN_DB`, 0, SCALE_LINEAR)         // Ramp 1
631    ///      SetGainWithRamp(0.0f, `ZX_SEC`(4), SCALE_LINEAR)          // Ramp 2
632    ///  Time 3
633    ///      PlayNoReply(kNoTimestamp, any_media_time)
634    ///  Time 4
635    ///      PauseNoReply()
636    ///  Time 7
637    ///      PlayNoReply(kNoTimestamp, any_media_time)
638    ///  Time 8
639    ///      SetGainWithRamp(`MUTED_GAIN_DB`, ZX_SEC(1), SCALE_LINEAR) // Ramp 3
640    ///
641    ///
642    /// Time 0: Ramp 1 completes immediately, changing the gain to `MUTED_GAIN_DB`.
643    ///         Ramp 2 is pending, since we are not in playback.
644    /// Time 3, Ramp 2 begins ramping from `MUTED_GAIN_DB` to 0 dB
645    ///         (scale 0.0=>1.0).
646    /// Time 4: Ramp 2 pauses (3s remain). Per `SCALE_LINEAR`, scale is approx.
647    ///         0.25.
648    /// Time 7: Ramp 2 resumes from most recent value toward the target.
649    /// Time 8: Ramp 3 replaces Ramp 2 and starts from current scale
650    ///         (approx 0.5).
651    /// Time 9: Ramp 3 completes; current scale value is now 0.0 (`MUTED_GAIN_DB`).
652    pub fn r#set_gain_with_ramp(
653        &self,
654        mut gain_db: f32,
655        mut duration: i64,
656        mut ramp_type: RampType,
657    ) -> Result<(), fidl::Error> {
658        self.client.send::<GainControlSetGainWithRampRequest>(
659            (gain_db, duration, ramp_type),
660            0x3a175b2d6979e8ea,
661            fidl::encoding::DynamicFlags::empty(),
662        )
663    }
664
665    /// Sets the mute value. Ramping and mute are fully independent, although
666    /// they both affect the scaling that is applied.
667    pub fn r#set_mute(&self, mut muted: bool) -> Result<(), fidl::Error> {
668        self.client.send::<GainControlSetMuteRequest>(
669            (muted,),
670            0x5415723c1e31448,
671            fidl::encoding::DynamicFlags::empty(),
672        )
673    }
674}
675
676#[cfg(target_os = "fuchsia")]
677impl From<GainControlSynchronousProxy> for zx::NullableHandle {
678    fn from(value: GainControlSynchronousProxy) -> Self {
679        value.into_channel().into()
680    }
681}
682
683#[cfg(target_os = "fuchsia")]
684impl From<fidl::Channel> for GainControlSynchronousProxy {
685    fn from(value: fidl::Channel) -> Self {
686        Self::new(value)
687    }
688}
689
690#[cfg(target_os = "fuchsia")]
691impl fidl::endpoints::FromClient for GainControlSynchronousProxy {
692    type Protocol = GainControlMarker;
693
694    fn from_client(value: fidl::endpoints::ClientEnd<GainControlMarker>) -> Self {
695        Self::new(value.into_channel())
696    }
697}
698
699#[derive(Debug, Clone)]
700pub struct GainControlProxy {
701    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
702}
703
704impl fidl::endpoints::Proxy for GainControlProxy {
705    type Protocol = GainControlMarker;
706
707    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
708        Self::new(inner)
709    }
710
711    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
712        self.client.into_channel().map_err(|client| Self { client })
713    }
714
715    fn as_channel(&self) -> &::fidl::AsyncChannel {
716        self.client.as_channel()
717    }
718}
719
720impl GainControlProxy {
721    /// Create a new Proxy for fuchsia.media.audio/GainControl.
722    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
723        let protocol_name = <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
724        Self { client: fidl::client::Client::new(channel, protocol_name) }
725    }
726
727    /// Get a Stream of events from the remote end of the protocol.
728    ///
729    /// # Panics
730    ///
731    /// Panics if the event stream was already taken.
732    pub fn take_event_stream(&self) -> GainControlEventStream {
733        GainControlEventStream { event_receiver: self.client.take_event_receiver() }
734    }
735
736    /// Sets the gain in decibels.
737    pub fn r#set_gain(&self, mut gain_db: f32) -> Result<(), fidl::Error> {
738        GainControlProxyInterface::r#set_gain(self, gain_db)
739    }
740
741    /// Smoothly changes gain from its current value to specified value, over the
742    /// specified duration (in milliseconds). If 'duration_ns' is 0, gain changes
743    /// immediately. Otherwise, gain changes only while the stream is running.
744    ///
745    /// Any active or pending ramp is cancelled by subsequent call to SetGain.
746    ///
747    /// There can be at most 1 active ramp at any time. Any active or pending
748    /// ramp is replaced by a later call to SetGainWithRamp (even if duration is
749    /// 0). In this case gain would ramps directly from its most recent
750    /// (mid-ramp) value to the newly-specified one, over the new duration,
751    /// using the new easing.
752    ///
753    /// Usage example (using time in seconds):
754    ///  Time 0
755    ///      SetGainWithRamp(`MUTED_GAIN_DB`, 0, SCALE_LINEAR)         // Ramp 1
756    ///      SetGainWithRamp(0.0f, `ZX_SEC`(4), SCALE_LINEAR)          // Ramp 2
757    ///  Time 3
758    ///      PlayNoReply(kNoTimestamp, any_media_time)
759    ///  Time 4
760    ///      PauseNoReply()
761    ///  Time 7
762    ///      PlayNoReply(kNoTimestamp, any_media_time)
763    ///  Time 8
764    ///      SetGainWithRamp(`MUTED_GAIN_DB`, ZX_SEC(1), SCALE_LINEAR) // Ramp 3
765    ///
766    ///
767    /// Time 0: Ramp 1 completes immediately, changing the gain to `MUTED_GAIN_DB`.
768    ///         Ramp 2 is pending, since we are not in playback.
769    /// Time 3, Ramp 2 begins ramping from `MUTED_GAIN_DB` to 0 dB
770    ///         (scale 0.0=>1.0).
771    /// Time 4: Ramp 2 pauses (3s remain). Per `SCALE_LINEAR`, scale is approx.
772    ///         0.25.
773    /// Time 7: Ramp 2 resumes from most recent value toward the target.
774    /// Time 8: Ramp 3 replaces Ramp 2 and starts from current scale
775    ///         (approx 0.5).
776    /// Time 9: Ramp 3 completes; current scale value is now 0.0 (`MUTED_GAIN_DB`).
777    pub fn r#set_gain_with_ramp(
778        &self,
779        mut gain_db: f32,
780        mut duration: i64,
781        mut ramp_type: RampType,
782    ) -> Result<(), fidl::Error> {
783        GainControlProxyInterface::r#set_gain_with_ramp(self, gain_db, duration, ramp_type)
784    }
785
786    /// Sets the mute value. Ramping and mute are fully independent, although
787    /// they both affect the scaling that is applied.
788    pub fn r#set_mute(&self, mut muted: bool) -> Result<(), fidl::Error> {
789        GainControlProxyInterface::r#set_mute(self, muted)
790    }
791}
792
793impl GainControlProxyInterface for GainControlProxy {
794    fn r#set_gain(&self, mut gain_db: f32) -> Result<(), fidl::Error> {
795        self.client.send::<GainControlSetGainRequest>(
796            (gain_db,),
797            0x2fc070871d033f64,
798            fidl::encoding::DynamicFlags::empty(),
799        )
800    }
801
802    fn r#set_gain_with_ramp(
803        &self,
804        mut gain_db: f32,
805        mut duration: i64,
806        mut ramp_type: RampType,
807    ) -> Result<(), fidl::Error> {
808        self.client.send::<GainControlSetGainWithRampRequest>(
809            (gain_db, duration, ramp_type),
810            0x3a175b2d6979e8ea,
811            fidl::encoding::DynamicFlags::empty(),
812        )
813    }
814
815    fn r#set_mute(&self, mut muted: bool) -> Result<(), fidl::Error> {
816        self.client.send::<GainControlSetMuteRequest>(
817            (muted,),
818            0x5415723c1e31448,
819            fidl::encoding::DynamicFlags::empty(),
820        )
821    }
822}
823
824pub struct GainControlEventStream {
825    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
826}
827
828impl std::marker::Unpin for GainControlEventStream {}
829
830impl futures::stream::FusedStream for GainControlEventStream {
831    fn is_terminated(&self) -> bool {
832        self.event_receiver.is_terminated()
833    }
834}
835
836impl futures::Stream for GainControlEventStream {
837    type Item = Result<GainControlEvent, fidl::Error>;
838
839    fn poll_next(
840        mut self: std::pin::Pin<&mut Self>,
841        cx: &mut std::task::Context<'_>,
842    ) -> std::task::Poll<Option<Self::Item>> {
843        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
844            &mut self.event_receiver,
845            cx
846        )?) {
847            Some(buf) => std::task::Poll::Ready(Some(GainControlEvent::decode(buf))),
848            None => std::task::Poll::Ready(None),
849        }
850    }
851}
852
853#[derive(Debug)]
854pub enum GainControlEvent {
855    OnGainMuteChanged { gain_db: f32, muted: bool },
856}
857
858impl GainControlEvent {
859    #[allow(irrefutable_let_patterns)]
860    pub fn into_on_gain_mute_changed(self) -> Option<(f32, bool)> {
861        if let GainControlEvent::OnGainMuteChanged { gain_db, muted } = self {
862            Some((gain_db, muted))
863        } else {
864            None
865        }
866    }
867
868    /// Decodes a message buffer as a [`GainControlEvent`].
869    fn decode(
870        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
871    ) -> Result<GainControlEvent, fidl::Error> {
872        let (bytes, _handles) = buf.split_mut();
873        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
874        debug_assert_eq!(tx_header.tx_id, 0);
875        match tx_header.ordinal {
876            0x66d528cad4e0d753 => {
877                let mut out = fidl::new_empty!(
878                    GainControlOnGainMuteChangedRequest,
879                    fidl::encoding::DefaultFuchsiaResourceDialect
880                );
881                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlOnGainMuteChangedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
882                Ok((GainControlEvent::OnGainMuteChanged { gain_db: out.gain_db, muted: out.muted }))
883            }
884            _ => Err(fidl::Error::UnknownOrdinal {
885                ordinal: tx_header.ordinal,
886                protocol_name: <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
887            }),
888        }
889    }
890}
891
892/// A Stream of incoming requests for fuchsia.media.audio/GainControl.
893pub struct GainControlRequestStream {
894    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
895    is_terminated: bool,
896}
897
898impl std::marker::Unpin for GainControlRequestStream {}
899
900impl futures::stream::FusedStream for GainControlRequestStream {
901    fn is_terminated(&self) -> bool {
902        self.is_terminated
903    }
904}
905
906impl fidl::endpoints::RequestStream for GainControlRequestStream {
907    type Protocol = GainControlMarker;
908    type ControlHandle = GainControlControlHandle;
909
910    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
911        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
912    }
913
914    fn control_handle(&self) -> Self::ControlHandle {
915        GainControlControlHandle { inner: self.inner.clone() }
916    }
917
918    fn into_inner(
919        self,
920    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
921    {
922        (self.inner, self.is_terminated)
923    }
924
925    fn from_inner(
926        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
927        is_terminated: bool,
928    ) -> Self {
929        Self { inner, is_terminated }
930    }
931}
932
933impl futures::Stream for GainControlRequestStream {
934    type Item = Result<GainControlRequest, fidl::Error>;
935
936    fn poll_next(
937        mut self: std::pin::Pin<&mut Self>,
938        cx: &mut std::task::Context<'_>,
939    ) -> std::task::Poll<Option<Self::Item>> {
940        let this = &mut *self;
941        if this.inner.check_shutdown(cx) {
942            this.is_terminated = true;
943            return std::task::Poll::Ready(None);
944        }
945        if this.is_terminated {
946            panic!("polled GainControlRequestStream after completion");
947        }
948        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
949            |bytes, handles| {
950                match this.inner.channel().read_etc(cx, bytes, handles) {
951                    std::task::Poll::Ready(Ok(())) => {}
952                    std::task::Poll::Pending => return std::task::Poll::Pending,
953                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
954                        this.is_terminated = true;
955                        return std::task::Poll::Ready(None);
956                    }
957                    std::task::Poll::Ready(Err(e)) => {
958                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
959                            e.into(),
960                        ))));
961                    }
962                }
963
964                // A message has been received from the channel
965                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
966
967                std::task::Poll::Ready(Some(match header.ordinal {
968                    0x2fc070871d033f64 => {
969                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
970                        let mut req = fidl::new_empty!(
971                            GainControlSetGainRequest,
972                            fidl::encoding::DefaultFuchsiaResourceDialect
973                        );
974                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlSetGainRequest>(&header, _body_bytes, handles, &mut req)?;
975                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
976                        Ok(GainControlRequest::SetGain { gain_db: req.gain_db, control_handle })
977                    }
978                    0x3a175b2d6979e8ea => {
979                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
980                        let mut req = fidl::new_empty!(
981                            GainControlSetGainWithRampRequest,
982                            fidl::encoding::DefaultFuchsiaResourceDialect
983                        );
984                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlSetGainWithRampRequest>(&header, _body_bytes, handles, &mut req)?;
985                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
986                        Ok(GainControlRequest::SetGainWithRamp {
987                            gain_db: req.gain_db,
988                            duration: req.duration,
989                            ramp_type: req.ramp_type,
990
991                            control_handle,
992                        })
993                    }
994                    0x5415723c1e31448 => {
995                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
996                        let mut req = fidl::new_empty!(
997                            GainControlSetMuteRequest,
998                            fidl::encoding::DefaultFuchsiaResourceDialect
999                        );
1000                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlSetMuteRequest>(&header, _body_bytes, handles, &mut req)?;
1001                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
1002                        Ok(GainControlRequest::SetMute { muted: req.muted, control_handle })
1003                    }
1004                    _ => Err(fidl::Error::UnknownOrdinal {
1005                        ordinal: header.ordinal,
1006                        protocol_name:
1007                            <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1008                    }),
1009                }))
1010            },
1011        )
1012    }
1013}
1014
1015/// Enables control and monitoring of audio gain. This interface is typically
1016/// a tear-off of other interfaces. For example, `fuchsia.media.audio.Renderer`
1017/// has a `BindGainControl` method that binds to a gain control that controls
1018/// gain for the renderer.
1019#[derive(Debug)]
1020pub enum GainControlRequest {
1021    /// Sets the gain in decibels.
1022    SetGain { gain_db: f32, control_handle: GainControlControlHandle },
1023    /// Smoothly changes gain from its current value to specified value, over the
1024    /// specified duration (in milliseconds). If 'duration_ns' is 0, gain changes
1025    /// immediately. Otherwise, gain changes only while the stream is running.
1026    ///
1027    /// Any active or pending ramp is cancelled by subsequent call to SetGain.
1028    ///
1029    /// There can be at most 1 active ramp at any time. Any active or pending
1030    /// ramp is replaced by a later call to SetGainWithRamp (even if duration is
1031    /// 0). In this case gain would ramps directly from its most recent
1032    /// (mid-ramp) value to the newly-specified one, over the new duration,
1033    /// using the new easing.
1034    ///
1035    /// Usage example (using time in seconds):
1036    ///  Time 0
1037    ///      SetGainWithRamp(`MUTED_GAIN_DB`, 0, SCALE_LINEAR)         // Ramp 1
1038    ///      SetGainWithRamp(0.0f, `ZX_SEC`(4), SCALE_LINEAR)          // Ramp 2
1039    ///  Time 3
1040    ///      PlayNoReply(kNoTimestamp, any_media_time)
1041    ///  Time 4
1042    ///      PauseNoReply()
1043    ///  Time 7
1044    ///      PlayNoReply(kNoTimestamp, any_media_time)
1045    ///  Time 8
1046    ///      SetGainWithRamp(`MUTED_GAIN_DB`, ZX_SEC(1), SCALE_LINEAR) // Ramp 3
1047    ///
1048    ///
1049    /// Time 0: Ramp 1 completes immediately, changing the gain to `MUTED_GAIN_DB`.
1050    ///         Ramp 2 is pending, since we are not in playback.
1051    /// Time 3, Ramp 2 begins ramping from `MUTED_GAIN_DB` to 0 dB
1052    ///         (scale 0.0=>1.0).
1053    /// Time 4: Ramp 2 pauses (3s remain). Per `SCALE_LINEAR`, scale is approx.
1054    ///         0.25.
1055    /// Time 7: Ramp 2 resumes from most recent value toward the target.
1056    /// Time 8: Ramp 3 replaces Ramp 2 and starts from current scale
1057    ///         (approx 0.5).
1058    /// Time 9: Ramp 3 completes; current scale value is now 0.0 (`MUTED_GAIN_DB`).
1059    SetGainWithRamp {
1060        gain_db: f32,
1061        duration: i64,
1062        ramp_type: RampType,
1063        control_handle: GainControlControlHandle,
1064    },
1065    /// Sets the mute value. Ramping and mute are fully independent, although
1066    /// they both affect the scaling that is applied.
1067    SetMute { muted: bool, control_handle: GainControlControlHandle },
1068}
1069
1070impl GainControlRequest {
1071    #[allow(irrefutable_let_patterns)]
1072    pub fn into_set_gain(self) -> Option<(f32, GainControlControlHandle)> {
1073        if let GainControlRequest::SetGain { gain_db, control_handle } = self {
1074            Some((gain_db, control_handle))
1075        } else {
1076            None
1077        }
1078    }
1079
1080    #[allow(irrefutable_let_patterns)]
1081    pub fn into_set_gain_with_ramp(self) -> Option<(f32, i64, RampType, GainControlControlHandle)> {
1082        if let GainControlRequest::SetGainWithRamp {
1083            gain_db,
1084            duration,
1085            ramp_type,
1086            control_handle,
1087        } = self
1088        {
1089            Some((gain_db, duration, ramp_type, control_handle))
1090        } else {
1091            None
1092        }
1093    }
1094
1095    #[allow(irrefutable_let_patterns)]
1096    pub fn into_set_mute(self) -> Option<(bool, GainControlControlHandle)> {
1097        if let GainControlRequest::SetMute { muted, control_handle } = self {
1098            Some((muted, control_handle))
1099        } else {
1100            None
1101        }
1102    }
1103
1104    /// Name of the method defined in FIDL
1105    pub fn method_name(&self) -> &'static str {
1106        match *self {
1107            GainControlRequest::SetGain { .. } => "set_gain",
1108            GainControlRequest::SetGainWithRamp { .. } => "set_gain_with_ramp",
1109            GainControlRequest::SetMute { .. } => "set_mute",
1110        }
1111    }
1112}
1113
1114#[derive(Debug, Clone)]
1115pub struct GainControlControlHandle {
1116    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1117}
1118
1119impl fidl::endpoints::ControlHandle for GainControlControlHandle {
1120    fn shutdown(&self) {
1121        self.inner.shutdown()
1122    }
1123
1124    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1125        self.inner.shutdown_with_epitaph(status)
1126    }
1127
1128    fn is_closed(&self) -> bool {
1129        self.inner.channel().is_closed()
1130    }
1131    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1132        self.inner.channel().on_closed()
1133    }
1134
1135    #[cfg(target_os = "fuchsia")]
1136    fn signal_peer(
1137        &self,
1138        clear_mask: zx::Signals,
1139        set_mask: zx::Signals,
1140    ) -> Result<(), zx_status::Status> {
1141        use fidl::Peered;
1142        self.inner.channel().signal_peer(clear_mask, set_mask)
1143    }
1144}
1145
1146impl GainControlControlHandle {
1147    pub fn send_on_gain_mute_changed(
1148        &self,
1149        mut gain_db: f32,
1150        mut muted: bool,
1151    ) -> Result<(), fidl::Error> {
1152        self.inner.send::<GainControlOnGainMuteChangedRequest>(
1153            (gain_db, muted),
1154            0,
1155            0x66d528cad4e0d753,
1156            fidl::encoding::DynamicFlags::empty(),
1157        )
1158    }
1159}
1160
1161#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1162pub struct VolumeControlMarker;
1163
1164impl fidl::endpoints::ProtocolMarker for VolumeControlMarker {
1165    type Proxy = VolumeControlProxy;
1166    type RequestStream = VolumeControlRequestStream;
1167    #[cfg(target_os = "fuchsia")]
1168    type SynchronousProxy = VolumeControlSynchronousProxy;
1169
1170    const DEBUG_NAME: &'static str = "(anonymous) VolumeControl";
1171}
1172
1173pub trait VolumeControlProxyInterface: Send + Sync {
1174    fn r#set_volume(&self, volume: f32) -> Result<(), fidl::Error>;
1175    fn r#set_mute(&self, mute: bool) -> Result<(), fidl::Error>;
1176}
1177#[derive(Debug)]
1178#[cfg(target_os = "fuchsia")]
1179pub struct VolumeControlSynchronousProxy {
1180    client: fidl::client::sync::Client,
1181}
1182
1183#[cfg(target_os = "fuchsia")]
1184impl fidl::endpoints::SynchronousProxy for VolumeControlSynchronousProxy {
1185    type Proxy = VolumeControlProxy;
1186    type Protocol = VolumeControlMarker;
1187
1188    fn from_channel(inner: fidl::Channel) -> Self {
1189        Self::new(inner)
1190    }
1191
1192    fn into_channel(self) -> fidl::Channel {
1193        self.client.into_channel()
1194    }
1195
1196    fn as_channel(&self) -> &fidl::Channel {
1197        self.client.as_channel()
1198    }
1199}
1200
1201#[cfg(target_os = "fuchsia")]
1202impl VolumeControlSynchronousProxy {
1203    pub fn new(channel: fidl::Channel) -> Self {
1204        let protocol_name = <VolumeControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1205        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1206    }
1207
1208    pub fn into_channel(self) -> fidl::Channel {
1209        self.client.into_channel()
1210    }
1211
1212    /// Waits until an event arrives and returns it. It is safe for other
1213    /// threads to make concurrent requests while waiting for an event.
1214    pub fn wait_for_event(
1215        &self,
1216        deadline: zx::MonotonicInstant,
1217    ) -> Result<VolumeControlEvent, fidl::Error> {
1218        VolumeControlEvent::decode(self.client.wait_for_event(deadline)?)
1219    }
1220
1221    /// Sets the volume of the audio element to the given value in
1222    /// [0.0, 1.0]. If the value is provided is outside of [0.0, 1.0],
1223    /// the value is clamped before application.
1224    pub fn r#set_volume(&self, mut volume: f32) -> Result<(), fidl::Error> {
1225        self.client.send::<VolumeControlSetVolumeRequest>(
1226            (volume,),
1227            0x6ff4231809a697da,
1228            fidl::encoding::DynamicFlags::empty(),
1229        )
1230    }
1231
1232    /// Sets whether the controlled element is muted. Mute is not the same
1233    /// as setting volume to 0.0; volume will persist for the duration of
1234    /// a mute. If volume was 0.5 before mute, volume will resume at 0.5
1235    /// following unmute.
1236    pub fn r#set_mute(&self, mut mute: bool) -> Result<(), fidl::Error> {
1237        self.client.send::<VolumeControlSetMuteRequest>(
1238            (mute,),
1239            0x50c10c28bba46425,
1240            fidl::encoding::DynamicFlags::empty(),
1241        )
1242    }
1243}
1244
1245#[cfg(target_os = "fuchsia")]
1246impl From<VolumeControlSynchronousProxy> for zx::NullableHandle {
1247    fn from(value: VolumeControlSynchronousProxy) -> Self {
1248        value.into_channel().into()
1249    }
1250}
1251
1252#[cfg(target_os = "fuchsia")]
1253impl From<fidl::Channel> for VolumeControlSynchronousProxy {
1254    fn from(value: fidl::Channel) -> Self {
1255        Self::new(value)
1256    }
1257}
1258
1259#[cfg(target_os = "fuchsia")]
1260impl fidl::endpoints::FromClient for VolumeControlSynchronousProxy {
1261    type Protocol = VolumeControlMarker;
1262
1263    fn from_client(value: fidl::endpoints::ClientEnd<VolumeControlMarker>) -> Self {
1264        Self::new(value.into_channel())
1265    }
1266}
1267
1268#[derive(Debug, Clone)]
1269pub struct VolumeControlProxy {
1270    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1271}
1272
1273impl fidl::endpoints::Proxy for VolumeControlProxy {
1274    type Protocol = VolumeControlMarker;
1275
1276    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1277        Self::new(inner)
1278    }
1279
1280    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1281        self.client.into_channel().map_err(|client| Self { client })
1282    }
1283
1284    fn as_channel(&self) -> &::fidl::AsyncChannel {
1285        self.client.as_channel()
1286    }
1287}
1288
1289impl VolumeControlProxy {
1290    /// Create a new Proxy for fuchsia.media.audio/VolumeControl.
1291    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1292        let protocol_name = <VolumeControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1293        Self { client: fidl::client::Client::new(channel, protocol_name) }
1294    }
1295
1296    /// Get a Stream of events from the remote end of the protocol.
1297    ///
1298    /// # Panics
1299    ///
1300    /// Panics if the event stream was already taken.
1301    pub fn take_event_stream(&self) -> VolumeControlEventStream {
1302        VolumeControlEventStream { event_receiver: self.client.take_event_receiver() }
1303    }
1304
1305    /// Sets the volume of the audio element to the given value in
1306    /// [0.0, 1.0]. If the value is provided is outside of [0.0, 1.0],
1307    /// the value is clamped before application.
1308    pub fn r#set_volume(&self, mut volume: f32) -> Result<(), fidl::Error> {
1309        VolumeControlProxyInterface::r#set_volume(self, volume)
1310    }
1311
1312    /// Sets whether the controlled element is muted. Mute is not the same
1313    /// as setting volume to 0.0; volume will persist for the duration of
1314    /// a mute. If volume was 0.5 before mute, volume will resume at 0.5
1315    /// following unmute.
1316    pub fn r#set_mute(&self, mut mute: bool) -> Result<(), fidl::Error> {
1317        VolumeControlProxyInterface::r#set_mute(self, mute)
1318    }
1319}
1320
1321impl VolumeControlProxyInterface for VolumeControlProxy {
1322    fn r#set_volume(&self, mut volume: f32) -> Result<(), fidl::Error> {
1323        self.client.send::<VolumeControlSetVolumeRequest>(
1324            (volume,),
1325            0x6ff4231809a697da,
1326            fidl::encoding::DynamicFlags::empty(),
1327        )
1328    }
1329
1330    fn r#set_mute(&self, mut mute: bool) -> Result<(), fidl::Error> {
1331        self.client.send::<VolumeControlSetMuteRequest>(
1332            (mute,),
1333            0x50c10c28bba46425,
1334            fidl::encoding::DynamicFlags::empty(),
1335        )
1336    }
1337}
1338
1339pub struct VolumeControlEventStream {
1340    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1341}
1342
1343impl std::marker::Unpin for VolumeControlEventStream {}
1344
1345impl futures::stream::FusedStream for VolumeControlEventStream {
1346    fn is_terminated(&self) -> bool {
1347        self.event_receiver.is_terminated()
1348    }
1349}
1350
1351impl futures::Stream for VolumeControlEventStream {
1352    type Item = Result<VolumeControlEvent, fidl::Error>;
1353
1354    fn poll_next(
1355        mut self: std::pin::Pin<&mut Self>,
1356        cx: &mut std::task::Context<'_>,
1357    ) -> std::task::Poll<Option<Self::Item>> {
1358        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1359            &mut self.event_receiver,
1360            cx
1361        )?) {
1362            Some(buf) => std::task::Poll::Ready(Some(VolumeControlEvent::decode(buf))),
1363            None => std::task::Poll::Ready(None),
1364        }
1365    }
1366}
1367
1368#[derive(Debug)]
1369pub enum VolumeControlEvent {
1370    OnVolumeMuteChanged { new_volume: f32, new_muted: bool },
1371}
1372
1373impl VolumeControlEvent {
1374    #[allow(irrefutable_let_patterns)]
1375    pub fn into_on_volume_mute_changed(self) -> Option<(f32, bool)> {
1376        if let VolumeControlEvent::OnVolumeMuteChanged { new_volume, new_muted } = self {
1377            Some((new_volume, new_muted))
1378        } else {
1379            None
1380        }
1381    }
1382
1383    /// Decodes a message buffer as a [`VolumeControlEvent`].
1384    fn decode(
1385        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1386    ) -> Result<VolumeControlEvent, fidl::Error> {
1387        let (bytes, _handles) = buf.split_mut();
1388        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1389        debug_assert_eq!(tx_header.tx_id, 0);
1390        match tx_header.ordinal {
1391            0x9cea352bd86c171 => {
1392                let mut out = fidl::new_empty!(
1393                    VolumeControlOnVolumeMuteChangedRequest,
1394                    fidl::encoding::DefaultFuchsiaResourceDialect
1395                );
1396                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VolumeControlOnVolumeMuteChangedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
1397                Ok((VolumeControlEvent::OnVolumeMuteChanged {
1398                    new_volume: out.new_volume,
1399                    new_muted: out.new_muted,
1400                }))
1401            }
1402            _ => Err(fidl::Error::UnknownOrdinal {
1403                ordinal: tx_header.ordinal,
1404                protocol_name: <VolumeControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1405            }),
1406        }
1407    }
1408}
1409
1410/// A Stream of incoming requests for fuchsia.media.audio/VolumeControl.
1411pub struct VolumeControlRequestStream {
1412    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1413    is_terminated: bool,
1414}
1415
1416impl std::marker::Unpin for VolumeControlRequestStream {}
1417
1418impl futures::stream::FusedStream for VolumeControlRequestStream {
1419    fn is_terminated(&self) -> bool {
1420        self.is_terminated
1421    }
1422}
1423
1424impl fidl::endpoints::RequestStream for VolumeControlRequestStream {
1425    type Protocol = VolumeControlMarker;
1426    type ControlHandle = VolumeControlControlHandle;
1427
1428    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1429        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1430    }
1431
1432    fn control_handle(&self) -> Self::ControlHandle {
1433        VolumeControlControlHandle { inner: self.inner.clone() }
1434    }
1435
1436    fn into_inner(
1437        self,
1438    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1439    {
1440        (self.inner, self.is_terminated)
1441    }
1442
1443    fn from_inner(
1444        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1445        is_terminated: bool,
1446    ) -> Self {
1447        Self { inner, is_terminated }
1448    }
1449}
1450
1451impl futures::Stream for VolumeControlRequestStream {
1452    type Item = Result<VolumeControlRequest, fidl::Error>;
1453
1454    fn poll_next(
1455        mut self: std::pin::Pin<&mut Self>,
1456        cx: &mut std::task::Context<'_>,
1457    ) -> std::task::Poll<Option<Self::Item>> {
1458        let this = &mut *self;
1459        if this.inner.check_shutdown(cx) {
1460            this.is_terminated = true;
1461            return std::task::Poll::Ready(None);
1462        }
1463        if this.is_terminated {
1464            panic!("polled VolumeControlRequestStream after completion");
1465        }
1466        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1467            |bytes, handles| {
1468                match this.inner.channel().read_etc(cx, bytes, handles) {
1469                    std::task::Poll::Ready(Ok(())) => {}
1470                    std::task::Poll::Pending => return std::task::Poll::Pending,
1471                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1472                        this.is_terminated = true;
1473                        return std::task::Poll::Ready(None);
1474                    }
1475                    std::task::Poll::Ready(Err(e)) => {
1476                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1477                            e.into(),
1478                        ))));
1479                    }
1480                }
1481
1482                // A message has been received from the channel
1483                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1484
1485                std::task::Poll::Ready(Some(match header.ordinal {
1486                    0x6ff4231809a697da => {
1487                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1488                        let mut req = fidl::new_empty!(
1489                            VolumeControlSetVolumeRequest,
1490                            fidl::encoding::DefaultFuchsiaResourceDialect
1491                        );
1492                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VolumeControlSetVolumeRequest>(&header, _body_bytes, handles, &mut req)?;
1493                        let control_handle =
1494                            VolumeControlControlHandle { inner: this.inner.clone() };
1495                        Ok(VolumeControlRequest::SetVolume { volume: req.volume, control_handle })
1496                    }
1497                    0x50c10c28bba46425 => {
1498                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1499                        let mut req = fidl::new_empty!(
1500                            VolumeControlSetMuteRequest,
1501                            fidl::encoding::DefaultFuchsiaResourceDialect
1502                        );
1503                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VolumeControlSetMuteRequest>(&header, _body_bytes, handles, &mut req)?;
1504                        let control_handle =
1505                            VolumeControlControlHandle { inner: this.inner.clone() };
1506                        Ok(VolumeControlRequest::SetMute { mute: req.mute, control_handle })
1507                    }
1508                    _ => Err(fidl::Error::UnknownOrdinal {
1509                        ordinal: header.ordinal,
1510                        protocol_name:
1511                            <VolumeControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1512                    }),
1513                }))
1514            },
1515        )
1516    }
1517}
1518
1519/// A protocol for controlling volume.
1520#[derive(Debug)]
1521pub enum VolumeControlRequest {
1522    /// Sets the volume of the audio element to the given value in
1523    /// [0.0, 1.0]. If the value is provided is outside of [0.0, 1.0],
1524    /// the value is clamped before application.
1525    SetVolume { volume: f32, control_handle: VolumeControlControlHandle },
1526    /// Sets whether the controlled element is muted. Mute is not the same
1527    /// as setting volume to 0.0; volume will persist for the duration of
1528    /// a mute. If volume was 0.5 before mute, volume will resume at 0.5
1529    /// following unmute.
1530    SetMute { mute: bool, control_handle: VolumeControlControlHandle },
1531}
1532
1533impl VolumeControlRequest {
1534    #[allow(irrefutable_let_patterns)]
1535    pub fn into_set_volume(self) -> Option<(f32, VolumeControlControlHandle)> {
1536        if let VolumeControlRequest::SetVolume { volume, control_handle } = self {
1537            Some((volume, control_handle))
1538        } else {
1539            None
1540        }
1541    }
1542
1543    #[allow(irrefutable_let_patterns)]
1544    pub fn into_set_mute(self) -> Option<(bool, VolumeControlControlHandle)> {
1545        if let VolumeControlRequest::SetMute { mute, control_handle } = self {
1546            Some((mute, control_handle))
1547        } else {
1548            None
1549        }
1550    }
1551
1552    /// Name of the method defined in FIDL
1553    pub fn method_name(&self) -> &'static str {
1554        match *self {
1555            VolumeControlRequest::SetVolume { .. } => "set_volume",
1556            VolumeControlRequest::SetMute { .. } => "set_mute",
1557        }
1558    }
1559}
1560
1561#[derive(Debug, Clone)]
1562pub struct VolumeControlControlHandle {
1563    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1564}
1565
1566impl fidl::endpoints::ControlHandle for VolumeControlControlHandle {
1567    fn shutdown(&self) {
1568        self.inner.shutdown()
1569    }
1570
1571    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1572        self.inner.shutdown_with_epitaph(status)
1573    }
1574
1575    fn is_closed(&self) -> bool {
1576        self.inner.channel().is_closed()
1577    }
1578    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1579        self.inner.channel().on_closed()
1580    }
1581
1582    #[cfg(target_os = "fuchsia")]
1583    fn signal_peer(
1584        &self,
1585        clear_mask: zx::Signals,
1586        set_mask: zx::Signals,
1587    ) -> Result<(), zx_status::Status> {
1588        use fidl::Peered;
1589        self.inner.channel().signal_peer(clear_mask, set_mask)
1590    }
1591}
1592
1593impl VolumeControlControlHandle {
1594    pub fn send_on_volume_mute_changed(
1595        &self,
1596        mut new_volume: f32,
1597        mut new_muted: bool,
1598    ) -> Result<(), fidl::Error> {
1599        self.inner.send::<VolumeControlOnVolumeMuteChangedRequest>(
1600            (new_volume, new_muted),
1601            0,
1602            0x9cea352bd86c171,
1603            fidl::encoding::DynamicFlags::empty(),
1604        )
1605    }
1606}
1607
1608mod internal {
1609    use super::*;
1610}