Skip to main content

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