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