fidl_test_configexample/
fidl_test_configexample.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_test_configexample_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ConfigUserMarker;
16
17impl fidl::endpoints::ProtocolMarker for ConfigUserMarker {
18    type Proxy = ConfigUserProxy;
19    type RequestStream = ConfigUserRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = ConfigUserSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "test.configexample.ConfigUser";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for ConfigUserMarker {}
26
27pub trait ConfigUserProxyInterface: Send + Sync {
28    type IsManagingPowerResponseFut: std::future::Future<Output = Result<bool, fidl::Error>> + Send;
29    fn r#is_managing_power(&self) -> Self::IsManagingPowerResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct ConfigUserSynchronousProxy {
34    client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for ConfigUserSynchronousProxy {
39    type Proxy = ConfigUserProxy;
40    type Protocol = ConfigUserMarker;
41
42    fn from_channel(inner: fidl::Channel) -> Self {
43        Self::new(inner)
44    }
45
46    fn into_channel(self) -> fidl::Channel {
47        self.client.into_channel()
48    }
49
50    fn as_channel(&self) -> &fidl::Channel {
51        self.client.as_channel()
52    }
53}
54
55#[cfg(target_os = "fuchsia")]
56impl ConfigUserSynchronousProxy {
57    pub fn new(channel: fidl::Channel) -> Self {
58        let protocol_name = <ConfigUserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
60    }
61
62    pub fn into_channel(self) -> fidl::Channel {
63        self.client.into_channel()
64    }
65
66    /// Waits until an event arrives and returns it. It is safe for other
67    /// threads to make concurrent requests while waiting for an event.
68    pub fn wait_for_event(
69        &self,
70        deadline: zx::MonotonicInstant,
71    ) -> Result<ConfigUserEvent, fidl::Error> {
72        ConfigUserEvent::decode(self.client.wait_for_event(deadline)?)
73    }
74
75    pub fn r#is_managing_power(
76        &self,
77        ___deadline: zx::MonotonicInstant,
78    ) -> Result<bool, fidl::Error> {
79        let _response = self.client.send_query::<
80            fidl::encoding::EmptyPayload,
81            fidl::encoding::FlexibleType<ConfigUserIsManagingPowerResponse>,
82        >(
83            (),
84            0x3ed8a6f9f9f9fae7,
85            fidl::encoding::DynamicFlags::FLEXIBLE,
86            ___deadline,
87        )?
88        .into_result::<ConfigUserMarker>("is_managing_power")?;
89        Ok(_response.is_managing_power)
90    }
91}
92
93#[derive(Debug, Clone)]
94pub struct ConfigUserProxy {
95    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
96}
97
98impl fidl::endpoints::Proxy for ConfigUserProxy {
99    type Protocol = ConfigUserMarker;
100
101    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
102        Self::new(inner)
103    }
104
105    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
106        self.client.into_channel().map_err(|client| Self { client })
107    }
108
109    fn as_channel(&self) -> &::fidl::AsyncChannel {
110        self.client.as_channel()
111    }
112}
113
114impl ConfigUserProxy {
115    /// Create a new Proxy for test.configexample/ConfigUser.
116    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
117        let protocol_name = <ConfigUserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
118        Self { client: fidl::client::Client::new(channel, protocol_name) }
119    }
120
121    /// Get a Stream of events from the remote end of the protocol.
122    ///
123    /// # Panics
124    ///
125    /// Panics if the event stream was already taken.
126    pub fn take_event_stream(&self) -> ConfigUserEventStream {
127        ConfigUserEventStream { event_receiver: self.client.take_event_receiver() }
128    }
129
130    pub fn r#is_managing_power(
131        &self,
132    ) -> fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect> {
133        ConfigUserProxyInterface::r#is_managing_power(self)
134    }
135}
136
137impl ConfigUserProxyInterface for ConfigUserProxy {
138    type IsManagingPowerResponseFut =
139        fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect>;
140    fn r#is_managing_power(&self) -> Self::IsManagingPowerResponseFut {
141        fn _decode(
142            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
143        ) -> Result<bool, fidl::Error> {
144            let _response = fidl::client::decode_transaction_body::<
145                fidl::encoding::FlexibleType<ConfigUserIsManagingPowerResponse>,
146                fidl::encoding::DefaultFuchsiaResourceDialect,
147                0x3ed8a6f9f9f9fae7,
148            >(_buf?)?
149            .into_result::<ConfigUserMarker>("is_managing_power")?;
150            Ok(_response.is_managing_power)
151        }
152        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, bool>(
153            (),
154            0x3ed8a6f9f9f9fae7,
155            fidl::encoding::DynamicFlags::FLEXIBLE,
156            _decode,
157        )
158    }
159}
160
161pub struct ConfigUserEventStream {
162    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
163}
164
165impl std::marker::Unpin for ConfigUserEventStream {}
166
167impl futures::stream::FusedStream for ConfigUserEventStream {
168    fn is_terminated(&self) -> bool {
169        self.event_receiver.is_terminated()
170    }
171}
172
173impl futures::Stream for ConfigUserEventStream {
174    type Item = Result<ConfigUserEvent, fidl::Error>;
175
176    fn poll_next(
177        mut self: std::pin::Pin<&mut Self>,
178        cx: &mut std::task::Context<'_>,
179    ) -> std::task::Poll<Option<Self::Item>> {
180        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
181            &mut self.event_receiver,
182            cx
183        )?) {
184            Some(buf) => std::task::Poll::Ready(Some(ConfigUserEvent::decode(buf))),
185            None => std::task::Poll::Ready(None),
186        }
187    }
188}
189
190#[derive(Debug)]
191pub enum ConfigUserEvent {
192    #[non_exhaustive]
193    _UnknownEvent {
194        /// Ordinal of the event that was sent.
195        ordinal: u64,
196    },
197}
198
199impl ConfigUserEvent {
200    /// Decodes a message buffer as a [`ConfigUserEvent`].
201    fn decode(
202        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
203    ) -> Result<ConfigUserEvent, fidl::Error> {
204        let (bytes, _handles) = buf.split_mut();
205        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
206        debug_assert_eq!(tx_header.tx_id, 0);
207        match tx_header.ordinal {
208            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
209                Ok(ConfigUserEvent::_UnknownEvent { ordinal: tx_header.ordinal })
210            }
211            _ => Err(fidl::Error::UnknownOrdinal {
212                ordinal: tx_header.ordinal,
213                protocol_name: <ConfigUserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
214            }),
215        }
216    }
217}
218
219/// A Stream of incoming requests for test.configexample/ConfigUser.
220pub struct ConfigUserRequestStream {
221    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
222    is_terminated: bool,
223}
224
225impl std::marker::Unpin for ConfigUserRequestStream {}
226
227impl futures::stream::FusedStream for ConfigUserRequestStream {
228    fn is_terminated(&self) -> bool {
229        self.is_terminated
230    }
231}
232
233impl fidl::endpoints::RequestStream for ConfigUserRequestStream {
234    type Protocol = ConfigUserMarker;
235    type ControlHandle = ConfigUserControlHandle;
236
237    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
238        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
239    }
240
241    fn control_handle(&self) -> Self::ControlHandle {
242        ConfigUserControlHandle { inner: self.inner.clone() }
243    }
244
245    fn into_inner(
246        self,
247    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
248    {
249        (self.inner, self.is_terminated)
250    }
251
252    fn from_inner(
253        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
254        is_terminated: bool,
255    ) -> Self {
256        Self { inner, is_terminated }
257    }
258}
259
260impl futures::Stream for ConfigUserRequestStream {
261    type Item = Result<ConfigUserRequest, fidl::Error>;
262
263    fn poll_next(
264        mut self: std::pin::Pin<&mut Self>,
265        cx: &mut std::task::Context<'_>,
266    ) -> std::task::Poll<Option<Self::Item>> {
267        let this = &mut *self;
268        if this.inner.check_shutdown(cx) {
269            this.is_terminated = true;
270            return std::task::Poll::Ready(None);
271        }
272        if this.is_terminated {
273            panic!("polled ConfigUserRequestStream after completion");
274        }
275        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
276            |bytes, handles| {
277                match this.inner.channel().read_etc(cx, bytes, handles) {
278                    std::task::Poll::Ready(Ok(())) => {}
279                    std::task::Poll::Pending => return std::task::Poll::Pending,
280                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
281                        this.is_terminated = true;
282                        return std::task::Poll::Ready(None);
283                    }
284                    std::task::Poll::Ready(Err(e)) => {
285                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
286                            e.into(),
287                        ))))
288                    }
289                }
290
291                // A message has been received from the channel
292                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
293
294                std::task::Poll::Ready(Some(match header.ordinal {
295                    0x3ed8a6f9f9f9fae7 => {
296                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
297                        let mut req = fidl::new_empty!(
298                            fidl::encoding::EmptyPayload,
299                            fidl::encoding::DefaultFuchsiaResourceDialect
300                        );
301                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
302                        let control_handle = ConfigUserControlHandle { inner: this.inner.clone() };
303                        Ok(ConfigUserRequest::IsManagingPower {
304                            responder: ConfigUserIsManagingPowerResponder {
305                                control_handle: std::mem::ManuallyDrop::new(control_handle),
306                                tx_id: header.tx_id,
307                            },
308                        })
309                    }
310                    _ if header.tx_id == 0
311                        && header
312                            .dynamic_flags()
313                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
314                    {
315                        Ok(ConfigUserRequest::_UnknownMethod {
316                            ordinal: header.ordinal,
317                            control_handle: ConfigUserControlHandle { inner: this.inner.clone() },
318                            method_type: fidl::MethodType::OneWay,
319                        })
320                    }
321                    _ if header
322                        .dynamic_flags()
323                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
324                    {
325                        this.inner.send_framework_err(
326                            fidl::encoding::FrameworkErr::UnknownMethod,
327                            header.tx_id,
328                            header.ordinal,
329                            header.dynamic_flags(),
330                            (bytes, handles),
331                        )?;
332                        Ok(ConfigUserRequest::_UnknownMethod {
333                            ordinal: header.ordinal,
334                            control_handle: ConfigUserControlHandle { inner: this.inner.clone() },
335                            method_type: fidl::MethodType::TwoWay,
336                        })
337                    }
338                    _ => Err(fidl::Error::UnknownOrdinal {
339                        ordinal: header.ordinal,
340                        protocol_name:
341                            <ConfigUserMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
342                    }),
343                }))
344            },
345        )
346    }
347}
348
349/// This protocol allows the config client to report whether it is managing power. This provides a
350/// minimal way for the client to demonstrate a behavior change that is observable to the test
351/// component. A real client's interactions with the external system will likely change in ways that
352/// are considerably more complex.
353#[derive(Debug)]
354pub enum ConfigUserRequest {
355    IsManagingPower {
356        responder: ConfigUserIsManagingPowerResponder,
357    },
358    /// An interaction was received which does not match any known method.
359    #[non_exhaustive]
360    _UnknownMethod {
361        /// Ordinal of the method that was called.
362        ordinal: u64,
363        control_handle: ConfigUserControlHandle,
364        method_type: fidl::MethodType,
365    },
366}
367
368impl ConfigUserRequest {
369    #[allow(irrefutable_let_patterns)]
370    pub fn into_is_managing_power(self) -> Option<(ConfigUserIsManagingPowerResponder)> {
371        if let ConfigUserRequest::IsManagingPower { responder } = self {
372            Some((responder))
373        } else {
374            None
375        }
376    }
377
378    /// Name of the method defined in FIDL
379    pub fn method_name(&self) -> &'static str {
380        match *self {
381            ConfigUserRequest::IsManagingPower { .. } => "is_managing_power",
382            ConfigUserRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
383                "unknown one-way method"
384            }
385            ConfigUserRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
386                "unknown two-way method"
387            }
388        }
389    }
390}
391
392#[derive(Debug, Clone)]
393pub struct ConfigUserControlHandle {
394    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
395}
396
397impl fidl::endpoints::ControlHandle for ConfigUserControlHandle {
398    fn shutdown(&self) {
399        self.inner.shutdown()
400    }
401    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
402        self.inner.shutdown_with_epitaph(status)
403    }
404
405    fn is_closed(&self) -> bool {
406        self.inner.channel().is_closed()
407    }
408    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
409        self.inner.channel().on_closed()
410    }
411
412    #[cfg(target_os = "fuchsia")]
413    fn signal_peer(
414        &self,
415        clear_mask: zx::Signals,
416        set_mask: zx::Signals,
417    ) -> Result<(), zx_status::Status> {
418        use fidl::Peered;
419        self.inner.channel().signal_peer(clear_mask, set_mask)
420    }
421}
422
423impl ConfigUserControlHandle {}
424
425#[must_use = "FIDL methods require a response to be sent"]
426#[derive(Debug)]
427pub struct ConfigUserIsManagingPowerResponder {
428    control_handle: std::mem::ManuallyDrop<ConfigUserControlHandle>,
429    tx_id: u32,
430}
431
432/// Set the the channel to be shutdown (see [`ConfigUserControlHandle::shutdown`])
433/// if the responder is dropped without sending a response, so that the client
434/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
435impl std::ops::Drop for ConfigUserIsManagingPowerResponder {
436    fn drop(&mut self) {
437        self.control_handle.shutdown();
438        // Safety: drops once, never accessed again
439        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
440    }
441}
442
443impl fidl::endpoints::Responder for ConfigUserIsManagingPowerResponder {
444    type ControlHandle = ConfigUserControlHandle;
445
446    fn control_handle(&self) -> &ConfigUserControlHandle {
447        &self.control_handle
448    }
449
450    fn drop_without_shutdown(mut self) {
451        // Safety: drops once, never accessed again due to mem::forget
452        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
453        // Prevent Drop from running (which would shut down the channel)
454        std::mem::forget(self);
455    }
456}
457
458impl ConfigUserIsManagingPowerResponder {
459    /// Sends a response to the FIDL transaction.
460    ///
461    /// Sets the channel to shutdown if an error occurs.
462    pub fn send(self, mut is_managing_power: bool) -> Result<(), fidl::Error> {
463        let _result = self.send_raw(is_managing_power);
464        if _result.is_err() {
465            self.control_handle.shutdown();
466        }
467        self.drop_without_shutdown();
468        _result
469    }
470
471    /// Similar to "send" but does not shutdown the channel if an error occurs.
472    pub fn send_no_shutdown_on_err(self, mut is_managing_power: bool) -> Result<(), fidl::Error> {
473        let _result = self.send_raw(is_managing_power);
474        self.drop_without_shutdown();
475        _result
476    }
477
478    fn send_raw(&self, mut is_managing_power: bool) -> Result<(), fidl::Error> {
479        self.control_handle
480            .inner
481            .send::<fidl::encoding::FlexibleType<ConfigUserIsManagingPowerResponse>>(
482                fidl::encoding::Flexible::new((is_managing_power,)),
483                self.tx_id,
484                0x3ed8a6f9f9f9fae7,
485                fidl::encoding::DynamicFlags::FLEXIBLE,
486            )
487    }
488}
489
490mod internal {
491    use super::*;
492}