fidl_fuchsia_net_reachability/
fidl_fuchsia_net_reachability.rs1#![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_reachability__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct MonitorMarker;
16
17impl fidl::endpoints::ProtocolMarker for MonitorMarker {
18 type Proxy = MonitorProxy;
19 type RequestStream = MonitorRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = MonitorSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.net.reachability.Monitor";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for MonitorMarker {}
26
27pub trait MonitorProxyInterface: Send + Sync {
28 fn r#set_options(&self, payload: &MonitorOptions) -> Result<(), fidl::Error>;
29 type WatchResponseFut: std::future::Future<Output = Result<Snapshot, fidl::Error>> + Send;
30 fn r#watch(&self) -> Self::WatchResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct MonitorSynchronousProxy {
35 client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for MonitorSynchronousProxy {
40 type Proxy = MonitorProxy;
41 type Protocol = MonitorMarker;
42
43 fn from_channel(inner: fidl::Channel) -> Self {
44 Self::new(inner)
45 }
46
47 fn into_channel(self) -> fidl::Channel {
48 self.client.into_channel()
49 }
50
51 fn as_channel(&self) -> &fidl::Channel {
52 self.client.as_channel()
53 }
54}
55
56#[cfg(target_os = "fuchsia")]
57impl MonitorSynchronousProxy {
58 pub fn new(channel: fidl::Channel) -> Self {
59 let protocol_name = <MonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
60 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
61 }
62
63 pub fn into_channel(self) -> fidl::Channel {
64 self.client.into_channel()
65 }
66
67 pub fn wait_for_event(
70 &self,
71 deadline: zx::MonotonicInstant,
72 ) -> Result<MonitorEvent, fidl::Error> {
73 MonitorEvent::decode(self.client.wait_for_event(deadline)?)
74 }
75
76 pub fn r#set_options(&self, mut payload: &MonitorOptions) -> Result<(), fidl::Error> {
85 self.client.send::<MonitorOptions>(
86 payload,
87 0x2e4e66abc4374253,
88 fidl::encoding::DynamicFlags::empty(),
89 )
90 }
91
92 pub fn r#watch(&self, ___deadline: zx::MonotonicInstant) -> Result<Snapshot, fidl::Error> {
109 let _response = self.client.send_query::<fidl::encoding::EmptyPayload, Snapshot>(
110 (),
111 0x381ea392fef3667f,
112 fidl::encoding::DynamicFlags::empty(),
113 ___deadline,
114 )?;
115 Ok(_response)
116 }
117}
118
119#[cfg(target_os = "fuchsia")]
120impl From<MonitorSynchronousProxy> for zx::Handle {
121 fn from(value: MonitorSynchronousProxy) -> Self {
122 value.into_channel().into()
123 }
124}
125
126#[cfg(target_os = "fuchsia")]
127impl From<fidl::Channel> for MonitorSynchronousProxy {
128 fn from(value: fidl::Channel) -> Self {
129 Self::new(value)
130 }
131}
132
133#[cfg(target_os = "fuchsia")]
134impl fidl::endpoints::FromClient for MonitorSynchronousProxy {
135 type Protocol = MonitorMarker;
136
137 fn from_client(value: fidl::endpoints::ClientEnd<MonitorMarker>) -> Self {
138 Self::new(value.into_channel())
139 }
140}
141
142#[derive(Debug, Clone)]
143pub struct MonitorProxy {
144 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
145}
146
147impl fidl::endpoints::Proxy for MonitorProxy {
148 type Protocol = MonitorMarker;
149
150 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
151 Self::new(inner)
152 }
153
154 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
155 self.client.into_channel().map_err(|client| Self { client })
156 }
157
158 fn as_channel(&self) -> &::fidl::AsyncChannel {
159 self.client.as_channel()
160 }
161}
162
163impl MonitorProxy {
164 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
166 let protocol_name = <MonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
167 Self { client: fidl::client::Client::new(channel, protocol_name) }
168 }
169
170 pub fn take_event_stream(&self) -> MonitorEventStream {
176 MonitorEventStream { event_receiver: self.client.take_event_receiver() }
177 }
178
179 pub fn r#set_options(&self, mut payload: &MonitorOptions) -> Result<(), fidl::Error> {
188 MonitorProxyInterface::r#set_options(self, payload)
189 }
190
191 pub fn r#watch(
208 &self,
209 ) -> fidl::client::QueryResponseFut<Snapshot, fidl::encoding::DefaultFuchsiaResourceDialect>
210 {
211 MonitorProxyInterface::r#watch(self)
212 }
213}
214
215impl MonitorProxyInterface for MonitorProxy {
216 fn r#set_options(&self, mut payload: &MonitorOptions) -> Result<(), fidl::Error> {
217 self.client.send::<MonitorOptions>(
218 payload,
219 0x2e4e66abc4374253,
220 fidl::encoding::DynamicFlags::empty(),
221 )
222 }
223
224 type WatchResponseFut =
225 fidl::client::QueryResponseFut<Snapshot, fidl::encoding::DefaultFuchsiaResourceDialect>;
226 fn r#watch(&self) -> Self::WatchResponseFut {
227 fn _decode(
228 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
229 ) -> Result<Snapshot, fidl::Error> {
230 let _response = fidl::client::decode_transaction_body::<
231 Snapshot,
232 fidl::encoding::DefaultFuchsiaResourceDialect,
233 0x381ea392fef3667f,
234 >(_buf?)?;
235 Ok(_response)
236 }
237 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Snapshot>(
238 (),
239 0x381ea392fef3667f,
240 fidl::encoding::DynamicFlags::empty(),
241 _decode,
242 )
243 }
244}
245
246pub struct MonitorEventStream {
247 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
248}
249
250impl std::marker::Unpin for MonitorEventStream {}
251
252impl futures::stream::FusedStream for MonitorEventStream {
253 fn is_terminated(&self) -> bool {
254 self.event_receiver.is_terminated()
255 }
256}
257
258impl futures::Stream for MonitorEventStream {
259 type Item = Result<MonitorEvent, fidl::Error>;
260
261 fn poll_next(
262 mut self: std::pin::Pin<&mut Self>,
263 cx: &mut std::task::Context<'_>,
264 ) -> std::task::Poll<Option<Self::Item>> {
265 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
266 &mut self.event_receiver,
267 cx
268 )?) {
269 Some(buf) => std::task::Poll::Ready(Some(MonitorEvent::decode(buf))),
270 None => std::task::Poll::Ready(None),
271 }
272 }
273}
274
275#[derive(Debug)]
276pub enum MonitorEvent {}
277
278impl MonitorEvent {
279 fn decode(
281 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
282 ) -> Result<MonitorEvent, fidl::Error> {
283 let (bytes, _handles) = buf.split_mut();
284 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
285 debug_assert_eq!(tx_header.tx_id, 0);
286 match tx_header.ordinal {
287 _ => Err(fidl::Error::UnknownOrdinal {
288 ordinal: tx_header.ordinal,
289 protocol_name: <MonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
290 }),
291 }
292 }
293}
294
295pub struct MonitorRequestStream {
297 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
298 is_terminated: bool,
299}
300
301impl std::marker::Unpin for MonitorRequestStream {}
302
303impl futures::stream::FusedStream for MonitorRequestStream {
304 fn is_terminated(&self) -> bool {
305 self.is_terminated
306 }
307}
308
309impl fidl::endpoints::RequestStream for MonitorRequestStream {
310 type Protocol = MonitorMarker;
311 type ControlHandle = MonitorControlHandle;
312
313 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
314 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
315 }
316
317 fn control_handle(&self) -> Self::ControlHandle {
318 MonitorControlHandle { inner: self.inner.clone() }
319 }
320
321 fn into_inner(
322 self,
323 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
324 {
325 (self.inner, self.is_terminated)
326 }
327
328 fn from_inner(
329 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
330 is_terminated: bool,
331 ) -> Self {
332 Self { inner, is_terminated }
333 }
334}
335
336impl futures::Stream for MonitorRequestStream {
337 type Item = Result<MonitorRequest, fidl::Error>;
338
339 fn poll_next(
340 mut self: std::pin::Pin<&mut Self>,
341 cx: &mut std::task::Context<'_>,
342 ) -> std::task::Poll<Option<Self::Item>> {
343 let this = &mut *self;
344 if this.inner.check_shutdown(cx) {
345 this.is_terminated = true;
346 return std::task::Poll::Ready(None);
347 }
348 if this.is_terminated {
349 panic!("polled MonitorRequestStream after completion");
350 }
351 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
352 |bytes, handles| {
353 match this.inner.channel().read_etc(cx, bytes, handles) {
354 std::task::Poll::Ready(Ok(())) => {}
355 std::task::Poll::Pending => return std::task::Poll::Pending,
356 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
357 this.is_terminated = true;
358 return std::task::Poll::Ready(None);
359 }
360 std::task::Poll::Ready(Err(e)) => {
361 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
362 e.into(),
363 ))))
364 }
365 }
366
367 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
369
370 std::task::Poll::Ready(Some(match header.ordinal {
371 0x2e4e66abc4374253 => {
372 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
373 let mut req = fidl::new_empty!(
374 MonitorOptions,
375 fidl::encoding::DefaultFuchsiaResourceDialect
376 );
377 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<MonitorOptions>(&header, _body_bytes, handles, &mut req)?;
378 let control_handle = MonitorControlHandle { inner: this.inner.clone() };
379 Ok(MonitorRequest::SetOptions { payload: req, control_handle })
380 }
381 0x381ea392fef3667f => {
382 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
383 let mut req = fidl::new_empty!(
384 fidl::encoding::EmptyPayload,
385 fidl::encoding::DefaultFuchsiaResourceDialect
386 );
387 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
388 let control_handle = MonitorControlHandle { inner: this.inner.clone() };
389 Ok(MonitorRequest::Watch {
390 responder: MonitorWatchResponder {
391 control_handle: std::mem::ManuallyDrop::new(control_handle),
392 tx_id: header.tx_id,
393 },
394 })
395 }
396 _ => Err(fidl::Error::UnknownOrdinal {
397 ordinal: header.ordinal,
398 protocol_name:
399 <MonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
400 }),
401 }))
402 },
403 )
404 }
405}
406
407#[derive(Debug)]
409pub enum MonitorRequest {
410 SetOptions { payload: MonitorOptions, control_handle: MonitorControlHandle },
419 Watch { responder: MonitorWatchResponder },
436}
437
438impl MonitorRequest {
439 #[allow(irrefutable_let_patterns)]
440 pub fn into_set_options(self) -> Option<(MonitorOptions, MonitorControlHandle)> {
441 if let MonitorRequest::SetOptions { payload, control_handle } = self {
442 Some((payload, control_handle))
443 } else {
444 None
445 }
446 }
447
448 #[allow(irrefutable_let_patterns)]
449 pub fn into_watch(self) -> Option<(MonitorWatchResponder)> {
450 if let MonitorRequest::Watch { responder } = self {
451 Some((responder))
452 } else {
453 None
454 }
455 }
456
457 pub fn method_name(&self) -> &'static str {
459 match *self {
460 MonitorRequest::SetOptions { .. } => "set_options",
461 MonitorRequest::Watch { .. } => "watch",
462 }
463 }
464}
465
466#[derive(Debug, Clone)]
467pub struct MonitorControlHandle {
468 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
469}
470
471impl fidl::endpoints::ControlHandle for MonitorControlHandle {
472 fn shutdown(&self) {
473 self.inner.shutdown()
474 }
475 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
476 self.inner.shutdown_with_epitaph(status)
477 }
478
479 fn is_closed(&self) -> bool {
480 self.inner.channel().is_closed()
481 }
482 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
483 self.inner.channel().on_closed()
484 }
485
486 #[cfg(target_os = "fuchsia")]
487 fn signal_peer(
488 &self,
489 clear_mask: zx::Signals,
490 set_mask: zx::Signals,
491 ) -> Result<(), zx_status::Status> {
492 use fidl::Peered;
493 self.inner.channel().signal_peer(clear_mask, set_mask)
494 }
495}
496
497impl MonitorControlHandle {}
498
499#[must_use = "FIDL methods require a response to be sent"]
500#[derive(Debug)]
501pub struct MonitorWatchResponder {
502 control_handle: std::mem::ManuallyDrop<MonitorControlHandle>,
503 tx_id: u32,
504}
505
506impl std::ops::Drop for MonitorWatchResponder {
510 fn drop(&mut self) {
511 self.control_handle.shutdown();
512 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
514 }
515}
516
517impl fidl::endpoints::Responder for MonitorWatchResponder {
518 type ControlHandle = MonitorControlHandle;
519
520 fn control_handle(&self) -> &MonitorControlHandle {
521 &self.control_handle
522 }
523
524 fn drop_without_shutdown(mut self) {
525 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
527 std::mem::forget(self);
529 }
530}
531
532impl MonitorWatchResponder {
533 pub fn send(self, mut payload: &Snapshot) -> Result<(), fidl::Error> {
537 let _result = self.send_raw(payload);
538 if _result.is_err() {
539 self.control_handle.shutdown();
540 }
541 self.drop_without_shutdown();
542 _result
543 }
544
545 pub fn send_no_shutdown_on_err(self, mut payload: &Snapshot) -> Result<(), fidl::Error> {
547 let _result = self.send_raw(payload);
548 self.drop_without_shutdown();
549 _result
550 }
551
552 fn send_raw(&self, mut payload: &Snapshot) -> Result<(), fidl::Error> {
553 self.control_handle.inner.send::<Snapshot>(
554 payload,
555 self.tx_id,
556 0x381ea392fef3667f,
557 fidl::encoding::DynamicFlags::empty(),
558 )
559 }
560}
561
562mod internal {
563 use super::*;
564}