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