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