fidl_fuchsia_test_intl_manager/
fidl_fuchsia_test_intl_manager.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_test_intl_manager_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct PropertyManagerMarker;
16
17impl fidl::endpoints::ProtocolMarker for PropertyManagerMarker {
18    type Proxy = PropertyManagerProxy;
19    type RequestStream = PropertyManagerRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = PropertyManagerSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.test.intl.manager.PropertyManager";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for PropertyManagerMarker {}
26
27pub trait PropertyManagerProxyInterface: Send + Sync {
28    type SetProfileResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29    fn r#set_profile(
30        &self,
31        intl_profile: &fidl_fuchsia_intl::Profile,
32    ) -> Self::SetProfileResponseFut;
33}
34#[derive(Debug)]
35#[cfg(target_os = "fuchsia")]
36pub struct PropertyManagerSynchronousProxy {
37    client: fidl::client::sync::Client,
38}
39
40#[cfg(target_os = "fuchsia")]
41impl fidl::endpoints::SynchronousProxy for PropertyManagerSynchronousProxy {
42    type Proxy = PropertyManagerProxy;
43    type Protocol = PropertyManagerMarker;
44
45    fn from_channel(inner: fidl::Channel) -> Self {
46        Self::new(inner)
47    }
48
49    fn into_channel(self) -> fidl::Channel {
50        self.client.into_channel()
51    }
52
53    fn as_channel(&self) -> &fidl::Channel {
54        self.client.as_channel()
55    }
56}
57
58#[cfg(target_os = "fuchsia")]
59impl PropertyManagerSynchronousProxy {
60    pub fn new(channel: fidl::Channel) -> Self {
61        let protocol_name = <PropertyManagerMarker 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<PropertyManagerEvent, fidl::Error> {
75        PropertyManagerEvent::decode(self.client.wait_for_event(deadline)?)
76    }
77
78    /// Set the internationalization profile that is served by this provider.
79    pub fn r#set_profile(
80        &self,
81        mut intl_profile: &fidl_fuchsia_intl::Profile,
82        ___deadline: zx::MonotonicInstant,
83    ) -> Result<(), fidl::Error> {
84        let _response = self
85            .client
86            .send_query::<PropertyManagerSetProfileRequest, fidl::encoding::EmptyPayload>(
87                (intl_profile,),
88                0x359d8cfc3cdd020d,
89                fidl::encoding::DynamicFlags::empty(),
90                ___deadline,
91            )?;
92        Ok(_response)
93    }
94}
95
96#[derive(Debug, Clone)]
97pub struct PropertyManagerProxy {
98    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
99}
100
101impl fidl::endpoints::Proxy for PropertyManagerProxy {
102    type Protocol = PropertyManagerMarker;
103
104    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
105        Self::new(inner)
106    }
107
108    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
109        self.client.into_channel().map_err(|client| Self { client })
110    }
111
112    fn as_channel(&self) -> &::fidl::AsyncChannel {
113        self.client.as_channel()
114    }
115}
116
117impl PropertyManagerProxy {
118    /// Create a new Proxy for fuchsia.test.intl.manager/PropertyManager.
119    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
120        let protocol_name = <PropertyManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
121        Self { client: fidl::client::Client::new(channel, protocol_name) }
122    }
123
124    /// Get a Stream of events from the remote end of the protocol.
125    ///
126    /// # Panics
127    ///
128    /// Panics if the event stream was already taken.
129    pub fn take_event_stream(&self) -> PropertyManagerEventStream {
130        PropertyManagerEventStream { event_receiver: self.client.take_event_receiver() }
131    }
132
133    /// Set the internationalization profile that is served by this provider.
134    pub fn r#set_profile(
135        &self,
136        mut intl_profile: &fidl_fuchsia_intl::Profile,
137    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
138        PropertyManagerProxyInterface::r#set_profile(self, intl_profile)
139    }
140}
141
142impl PropertyManagerProxyInterface for PropertyManagerProxy {
143    type SetProfileResponseFut =
144        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
145    fn r#set_profile(
146        &self,
147        mut intl_profile: &fidl_fuchsia_intl::Profile,
148    ) -> Self::SetProfileResponseFut {
149        fn _decode(
150            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
151        ) -> Result<(), fidl::Error> {
152            let _response = fidl::client::decode_transaction_body::<
153                fidl::encoding::EmptyPayload,
154                fidl::encoding::DefaultFuchsiaResourceDialect,
155                0x359d8cfc3cdd020d,
156            >(_buf?)?;
157            Ok(_response)
158        }
159        self.client.send_query_and_decode::<PropertyManagerSetProfileRequest, ()>(
160            (intl_profile,),
161            0x359d8cfc3cdd020d,
162            fidl::encoding::DynamicFlags::empty(),
163            _decode,
164        )
165    }
166}
167
168pub struct PropertyManagerEventStream {
169    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
170}
171
172impl std::marker::Unpin for PropertyManagerEventStream {}
173
174impl futures::stream::FusedStream for PropertyManagerEventStream {
175    fn is_terminated(&self) -> bool {
176        self.event_receiver.is_terminated()
177    }
178}
179
180impl futures::Stream for PropertyManagerEventStream {
181    type Item = Result<PropertyManagerEvent, fidl::Error>;
182
183    fn poll_next(
184        mut self: std::pin::Pin<&mut Self>,
185        cx: &mut std::task::Context<'_>,
186    ) -> std::task::Poll<Option<Self::Item>> {
187        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
188            &mut self.event_receiver,
189            cx
190        )?) {
191            Some(buf) => std::task::Poll::Ready(Some(PropertyManagerEvent::decode(buf))),
192            None => std::task::Poll::Ready(None),
193        }
194    }
195}
196
197#[derive(Debug)]
198pub enum PropertyManagerEvent {}
199
200impl PropertyManagerEvent {
201    /// Decodes a message buffer as a [`PropertyManagerEvent`].
202    fn decode(
203        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
204    ) -> Result<PropertyManagerEvent, fidl::Error> {
205        let (bytes, _handles) = buf.split_mut();
206        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
207        debug_assert_eq!(tx_header.tx_id, 0);
208        match tx_header.ordinal {
209            _ => Err(fidl::Error::UnknownOrdinal {
210                ordinal: tx_header.ordinal,
211                protocol_name:
212                    <PropertyManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
213            }),
214        }
215    }
216}
217
218/// A Stream of incoming requests for fuchsia.test.intl.manager/PropertyManager.
219pub struct PropertyManagerRequestStream {
220    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
221    is_terminated: bool,
222}
223
224impl std::marker::Unpin for PropertyManagerRequestStream {}
225
226impl futures::stream::FusedStream for PropertyManagerRequestStream {
227    fn is_terminated(&self) -> bool {
228        self.is_terminated
229    }
230}
231
232impl fidl::endpoints::RequestStream for PropertyManagerRequestStream {
233    type Protocol = PropertyManagerMarker;
234    type ControlHandle = PropertyManagerControlHandle;
235
236    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
237        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
238    }
239
240    fn control_handle(&self) -> Self::ControlHandle {
241        PropertyManagerControlHandle { inner: self.inner.clone() }
242    }
243
244    fn into_inner(
245        self,
246    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
247    {
248        (self.inner, self.is_terminated)
249    }
250
251    fn from_inner(
252        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
253        is_terminated: bool,
254    ) -> Self {
255        Self { inner, is_terminated }
256    }
257}
258
259impl futures::Stream for PropertyManagerRequestStream {
260    type Item = Result<PropertyManagerRequest, fidl::Error>;
261
262    fn poll_next(
263        mut self: std::pin::Pin<&mut Self>,
264        cx: &mut std::task::Context<'_>,
265    ) -> std::task::Poll<Option<Self::Item>> {
266        let this = &mut *self;
267        if this.inner.check_shutdown(cx) {
268            this.is_terminated = true;
269            return std::task::Poll::Ready(None);
270        }
271        if this.is_terminated {
272            panic!("polled PropertyManagerRequestStream after completion");
273        }
274        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
275            |bytes, handles| {
276                match this.inner.channel().read_etc(cx, bytes, handles) {
277                    std::task::Poll::Ready(Ok(())) => {}
278                    std::task::Poll::Pending => return std::task::Poll::Pending,
279                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
280                        this.is_terminated = true;
281                        return std::task::Poll::Ready(None);
282                    }
283                    std::task::Poll::Ready(Err(e)) => {
284                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
285                            e.into(),
286                        ))))
287                    }
288                }
289
290                // A message has been received from the channel
291                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
292
293                std::task::Poll::Ready(Some(match header.ordinal {
294                    0x359d8cfc3cdd020d => {
295                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
296                        let mut req = fidl::new_empty!(
297                            PropertyManagerSetProfileRequest,
298                            fidl::encoding::DefaultFuchsiaResourceDialect
299                        );
300                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PropertyManagerSetProfileRequest>(&header, _body_bytes, handles, &mut req)?;
301                        let control_handle =
302                            PropertyManagerControlHandle { inner: this.inner.clone() };
303                        Ok(PropertyManagerRequest::SetProfile {
304                            intl_profile: req.intl_profile,
305
306                            responder: PropertyManagerSetProfileResponder {
307                                control_handle: std::mem::ManuallyDrop::new(control_handle),
308                                tx_id: header.tx_id,
309                            },
310                        })
311                    }
312                    _ => Err(fidl::Error::UnknownOrdinal {
313                        ordinal: header.ordinal,
314                        protocol_name:
315                            <PropertyManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
316                    }),
317                }))
318            },
319        )
320    }
321}
322
323/// For toy examples, defines the setter counterpart to the getter in
324/// `fuchsia.intl.PropertyProvider`, allowing the internationalization `Profile` to be set via FIDL,
325/// and hence passed on to additional recipients.
326///
327/// Note that in production scenarios, a `fuchsia.intl.PropertyProvider` would like be reading the
328/// user's internationalization preferences from a preferences service and generating a `Profile`,
329/// rather than allowing a `Profile` to be set directly.
330#[derive(Debug)]
331pub enum PropertyManagerRequest {
332    /// Set the internationalization profile that is served by this provider.
333    SetProfile {
334        intl_profile: fidl_fuchsia_intl::Profile,
335        responder: PropertyManagerSetProfileResponder,
336    },
337}
338
339impl PropertyManagerRequest {
340    #[allow(irrefutable_let_patterns)]
341    pub fn into_set_profile(
342        self,
343    ) -> Option<(fidl_fuchsia_intl::Profile, PropertyManagerSetProfileResponder)> {
344        if let PropertyManagerRequest::SetProfile { intl_profile, responder } = self {
345            Some((intl_profile, responder))
346        } else {
347            None
348        }
349    }
350
351    /// Name of the method defined in FIDL
352    pub fn method_name(&self) -> &'static str {
353        match *self {
354            PropertyManagerRequest::SetProfile { .. } => "set_profile",
355        }
356    }
357}
358
359#[derive(Debug, Clone)]
360pub struct PropertyManagerControlHandle {
361    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
362}
363
364impl fidl::endpoints::ControlHandle for PropertyManagerControlHandle {
365    fn shutdown(&self) {
366        self.inner.shutdown()
367    }
368    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
369        self.inner.shutdown_with_epitaph(status)
370    }
371
372    fn is_closed(&self) -> bool {
373        self.inner.channel().is_closed()
374    }
375    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
376        self.inner.channel().on_closed()
377    }
378
379    #[cfg(target_os = "fuchsia")]
380    fn signal_peer(
381        &self,
382        clear_mask: zx::Signals,
383        set_mask: zx::Signals,
384    ) -> Result<(), zx_status::Status> {
385        use fidl::Peered;
386        self.inner.channel().signal_peer(clear_mask, set_mask)
387    }
388}
389
390impl PropertyManagerControlHandle {}
391
392#[must_use = "FIDL methods require a response to be sent"]
393#[derive(Debug)]
394pub struct PropertyManagerSetProfileResponder {
395    control_handle: std::mem::ManuallyDrop<PropertyManagerControlHandle>,
396    tx_id: u32,
397}
398
399/// Set the the channel to be shutdown (see [`PropertyManagerControlHandle::shutdown`])
400/// if the responder is dropped without sending a response, so that the client
401/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
402impl std::ops::Drop for PropertyManagerSetProfileResponder {
403    fn drop(&mut self) {
404        self.control_handle.shutdown();
405        // Safety: drops once, never accessed again
406        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
407    }
408}
409
410impl fidl::endpoints::Responder for PropertyManagerSetProfileResponder {
411    type ControlHandle = PropertyManagerControlHandle;
412
413    fn control_handle(&self) -> &PropertyManagerControlHandle {
414        &self.control_handle
415    }
416
417    fn drop_without_shutdown(mut self) {
418        // Safety: drops once, never accessed again due to mem::forget
419        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
420        // Prevent Drop from running (which would shut down the channel)
421        std::mem::forget(self);
422    }
423}
424
425impl PropertyManagerSetProfileResponder {
426    /// Sends a response to the FIDL transaction.
427    ///
428    /// Sets the channel to shutdown if an error occurs.
429    pub fn send(self) -> Result<(), fidl::Error> {
430        let _result = self.send_raw();
431        if _result.is_err() {
432            self.control_handle.shutdown();
433        }
434        self.drop_without_shutdown();
435        _result
436    }
437
438    /// Similar to "send" but does not shutdown the channel if an error occurs.
439    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
440        let _result = self.send_raw();
441        self.drop_without_shutdown();
442        _result
443    }
444
445    fn send_raw(&self) -> Result<(), fidl::Error> {
446        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
447            (),
448            self.tx_id,
449            0x359d8cfc3cdd020d,
450            fidl::encoding::DynamicFlags::empty(),
451        )
452    }
453}
454
455mod internal {
456    use super::*;
457}