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