fidl_fuchsia_netemul_sync/
fidl_fuchsia_netemul_sync.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_netemul_sync__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct SyncManagerBusSubscribeRequest {
16    pub bus_name: String,
17    pub client_name: String,
18    pub bus: fidl::endpoints::ServerEnd<BusMarker>,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
22    for SyncManagerBusSubscribeRequest
23{
24}
25
26#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
27pub struct BusMarker;
28
29impl fidl::endpoints::ProtocolMarker for BusMarker {
30    type Proxy = BusProxy;
31    type RequestStream = BusRequestStream;
32    #[cfg(target_os = "fuchsia")]
33    type SynchronousProxy = BusSynchronousProxy;
34
35    const DEBUG_NAME: &'static str = "(anonymous) Bus";
36}
37
38pub trait BusProxyInterface: Send + Sync {
39    fn r#publish(&self, data: &Event) -> Result<(), fidl::Error>;
40    type EnsurePublishResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
41    fn r#ensure_publish(&self, data: &Event) -> Self::EnsurePublishResponseFut;
42    type GetClientsResponseFut: std::future::Future<Output = Result<Vec<String>, fidl::Error>>
43        + Send;
44    fn r#get_clients(&self) -> Self::GetClientsResponseFut;
45    type WaitForClientsResponseFut: std::future::Future<Output = Result<(bool, Option<Vec<String>>), fidl::Error>>
46        + Send;
47    fn r#wait_for_clients(
48        &self,
49        clients: &[String],
50        timeout: i64,
51    ) -> Self::WaitForClientsResponseFut;
52    type WaitForEvent_ResponseFut: std::future::Future<Output = Result<bool, fidl::Error>> + Send;
53    fn r#wait_for_event_(&self, data: &Event, timeout: i64) -> Self::WaitForEvent_ResponseFut;
54}
55#[derive(Debug)]
56#[cfg(target_os = "fuchsia")]
57pub struct BusSynchronousProxy {
58    client: fidl::client::sync::Client,
59}
60
61#[cfg(target_os = "fuchsia")]
62impl fidl::endpoints::SynchronousProxy for BusSynchronousProxy {
63    type Proxy = BusProxy;
64    type Protocol = BusMarker;
65
66    fn from_channel(inner: fidl::Channel) -> Self {
67        Self::new(inner)
68    }
69
70    fn into_channel(self) -> fidl::Channel {
71        self.client.into_channel()
72    }
73
74    fn as_channel(&self) -> &fidl::Channel {
75        self.client.as_channel()
76    }
77}
78
79#[cfg(target_os = "fuchsia")]
80impl BusSynchronousProxy {
81    pub fn new(channel: fidl::Channel) -> Self {
82        let protocol_name = <BusMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
83        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
84    }
85
86    pub fn into_channel(self) -> fidl::Channel {
87        self.client.into_channel()
88    }
89
90    /// Waits until an event arrives and returns it. It is safe for other
91    /// threads to make concurrent requests while waiting for an event.
92    pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<BusEvent, fidl::Error> {
93        BusEvent::decode(self.client.wait_for_event(deadline)?)
94    }
95
96    /// Publishes event on the bus.
97    pub fn r#publish(&self, mut data: &Event) -> Result<(), fidl::Error> {
98        self.client.send::<BusPublishRequest>(
99            (data,),
100            0x331ceb644024c14b,
101            fidl::encoding::DynamicFlags::empty(),
102        )
103    }
104
105    /// Publishes data on bus and only returns when data has been dispatched.
106    /// Use this if you need guarantees that the data was broadcast before continuing.
107    /// Note that this ensures that the data will be *published* to all listening clients,
108    /// but it cannot guarantee that all clients will have observed the event before it returns.
109    pub fn r#ensure_publish(
110        &self,
111        mut data: &Event,
112        ___deadline: zx::MonotonicInstant,
113    ) -> Result<(), fidl::Error> {
114        let _response =
115            self.client.send_query::<BusEnsurePublishRequest, fidl::encoding::EmptyPayload>(
116                (data,),
117                0x2969c5f5de5bb64,
118                fidl::encoding::DynamicFlags::empty(),
119                ___deadline,
120            )?;
121        Ok(_response)
122    }
123
124    /// Get list of named clients.
125    pub fn r#get_clients(
126        &self,
127        ___deadline: zx::MonotonicInstant,
128    ) -> Result<Vec<String>, fidl::Error> {
129        let _response =
130            self.client.send_query::<fidl::encoding::EmptyPayload, BusGetClientsResponse>(
131                (),
132                0x733c5e2d525a006b,
133                fidl::encoding::DynamicFlags::empty(),
134                ___deadline,
135            )?;
136        Ok(_response.clients)
137    }
138
139    /// Waits for up to `timeout` (nsec) for all the clients in `clients`.
140    /// Returns true if all clients are present on the bus before timeout expired.
141    /// If `result` is false, `absent` will contain the entries in `clients` that still weren't
142    /// present on the bus when the timout expired.
143    /// Use `timeout` <= 0 for indefinite wait.
144    pub fn r#wait_for_clients(
145        &self,
146        mut clients: &[String],
147        mut timeout: i64,
148        ___deadline: zx::MonotonicInstant,
149    ) -> Result<(bool, Option<Vec<String>>), fidl::Error> {
150        let _response =
151            self.client.send_query::<BusWaitForClientsRequest, BusWaitForClientsResponse>(
152                (clients, timeout),
153                0x21c89fc6be990b23,
154                fidl::encoding::DynamicFlags::empty(),
155                ___deadline,
156            )?;
157        Ok((_response.result, _response.absent))
158    }
159
160    /// Waits for up to `timeout` (nsec) for an event that matches `data`.
161    /// Event equality is performed by comparing *all* set fields in `data`.
162    /// Returns true if event was received before timeout expired.
163    /// Use `timeout` <= 0 for indefinite wait.
164    pub fn r#wait_for_event_(
165        &self,
166        mut data: &Event,
167        mut timeout: i64,
168        ___deadline: zx::MonotonicInstant,
169    ) -> Result<bool, fidl::Error> {
170        let _response = self.client.send_query::<BusWaitForEventRequest, BusWaitForEventResponse>(
171            (data, timeout),
172            0x600ca084a42ee5bf,
173            fidl::encoding::DynamicFlags::empty(),
174            ___deadline,
175        )?;
176        Ok(_response.result)
177    }
178}
179
180#[cfg(target_os = "fuchsia")]
181impl From<BusSynchronousProxy> for zx::Handle {
182    fn from(value: BusSynchronousProxy) -> Self {
183        value.into_channel().into()
184    }
185}
186
187#[cfg(target_os = "fuchsia")]
188impl From<fidl::Channel> for BusSynchronousProxy {
189    fn from(value: fidl::Channel) -> Self {
190        Self::new(value)
191    }
192}
193
194#[cfg(target_os = "fuchsia")]
195impl fidl::endpoints::FromClient for BusSynchronousProxy {
196    type Protocol = BusMarker;
197
198    fn from_client(value: fidl::endpoints::ClientEnd<BusMarker>) -> Self {
199        Self::new(value.into_channel())
200    }
201}
202
203#[derive(Debug, Clone)]
204pub struct BusProxy {
205    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
206}
207
208impl fidl::endpoints::Proxy for BusProxy {
209    type Protocol = BusMarker;
210
211    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
212        Self::new(inner)
213    }
214
215    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
216        self.client.into_channel().map_err(|client| Self { client })
217    }
218
219    fn as_channel(&self) -> &::fidl::AsyncChannel {
220        self.client.as_channel()
221    }
222}
223
224impl BusProxy {
225    /// Create a new Proxy for fuchsia.netemul.sync/Bus.
226    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
227        let protocol_name = <BusMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
228        Self { client: fidl::client::Client::new(channel, protocol_name) }
229    }
230
231    /// Get a Stream of events from the remote end of the protocol.
232    ///
233    /// # Panics
234    ///
235    /// Panics if the event stream was already taken.
236    pub fn take_event_stream(&self) -> BusEventStream {
237        BusEventStream { event_receiver: self.client.take_event_receiver() }
238    }
239
240    /// Publishes event on the bus.
241    pub fn r#publish(&self, mut data: &Event) -> Result<(), fidl::Error> {
242        BusProxyInterface::r#publish(self, data)
243    }
244
245    /// Publishes data on bus and only returns when data has been dispatched.
246    /// Use this if you need guarantees that the data was broadcast before continuing.
247    /// Note that this ensures that the data will be *published* to all listening clients,
248    /// but it cannot guarantee that all clients will have observed the event before it returns.
249    pub fn r#ensure_publish(
250        &self,
251        mut data: &Event,
252    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
253        BusProxyInterface::r#ensure_publish(self, data)
254    }
255
256    /// Get list of named clients.
257    pub fn r#get_clients(
258        &self,
259    ) -> fidl::client::QueryResponseFut<Vec<String>, fidl::encoding::DefaultFuchsiaResourceDialect>
260    {
261        BusProxyInterface::r#get_clients(self)
262    }
263
264    /// Waits for up to `timeout` (nsec) for all the clients in `clients`.
265    /// Returns true if all clients are present on the bus before timeout expired.
266    /// If `result` is false, `absent` will contain the entries in `clients` that still weren't
267    /// present on the bus when the timout expired.
268    /// Use `timeout` <= 0 for indefinite wait.
269    pub fn r#wait_for_clients(
270        &self,
271        mut clients: &[String],
272        mut timeout: i64,
273    ) -> fidl::client::QueryResponseFut<
274        (bool, Option<Vec<String>>),
275        fidl::encoding::DefaultFuchsiaResourceDialect,
276    > {
277        BusProxyInterface::r#wait_for_clients(self, clients, timeout)
278    }
279
280    /// Waits for up to `timeout` (nsec) for an event that matches `data`.
281    /// Event equality is performed by comparing *all* set fields in `data`.
282    /// Returns true if event was received before timeout expired.
283    /// Use `timeout` <= 0 for indefinite wait.
284    pub fn r#wait_for_event_(
285        &self,
286        mut data: &Event,
287        mut timeout: i64,
288    ) -> fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect> {
289        BusProxyInterface::r#wait_for_event_(self, data, timeout)
290    }
291}
292
293impl BusProxyInterface for BusProxy {
294    fn r#publish(&self, mut data: &Event) -> Result<(), fidl::Error> {
295        self.client.send::<BusPublishRequest>(
296            (data,),
297            0x331ceb644024c14b,
298            fidl::encoding::DynamicFlags::empty(),
299        )
300    }
301
302    type EnsurePublishResponseFut =
303        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
304    fn r#ensure_publish(&self, mut data: &Event) -> Self::EnsurePublishResponseFut {
305        fn _decode(
306            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
307        ) -> Result<(), fidl::Error> {
308            let _response = fidl::client::decode_transaction_body::<
309                fidl::encoding::EmptyPayload,
310                fidl::encoding::DefaultFuchsiaResourceDialect,
311                0x2969c5f5de5bb64,
312            >(_buf?)?;
313            Ok(_response)
314        }
315        self.client.send_query_and_decode::<BusEnsurePublishRequest, ()>(
316            (data,),
317            0x2969c5f5de5bb64,
318            fidl::encoding::DynamicFlags::empty(),
319            _decode,
320        )
321    }
322
323    type GetClientsResponseFut =
324        fidl::client::QueryResponseFut<Vec<String>, fidl::encoding::DefaultFuchsiaResourceDialect>;
325    fn r#get_clients(&self) -> Self::GetClientsResponseFut {
326        fn _decode(
327            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
328        ) -> Result<Vec<String>, fidl::Error> {
329            let _response = fidl::client::decode_transaction_body::<
330                BusGetClientsResponse,
331                fidl::encoding::DefaultFuchsiaResourceDialect,
332                0x733c5e2d525a006b,
333            >(_buf?)?;
334            Ok(_response.clients)
335        }
336        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Vec<String>>(
337            (),
338            0x733c5e2d525a006b,
339            fidl::encoding::DynamicFlags::empty(),
340            _decode,
341        )
342    }
343
344    type WaitForClientsResponseFut = fidl::client::QueryResponseFut<
345        (bool, Option<Vec<String>>),
346        fidl::encoding::DefaultFuchsiaResourceDialect,
347    >;
348    fn r#wait_for_clients(
349        &self,
350        mut clients: &[String],
351        mut timeout: i64,
352    ) -> Self::WaitForClientsResponseFut {
353        fn _decode(
354            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
355        ) -> Result<(bool, Option<Vec<String>>), fidl::Error> {
356            let _response = fidl::client::decode_transaction_body::<
357                BusWaitForClientsResponse,
358                fidl::encoding::DefaultFuchsiaResourceDialect,
359                0x21c89fc6be990b23,
360            >(_buf?)?;
361            Ok((_response.result, _response.absent))
362        }
363        self.client.send_query_and_decode::<BusWaitForClientsRequest, (bool, Option<Vec<String>>)>(
364            (clients, timeout),
365            0x21c89fc6be990b23,
366            fidl::encoding::DynamicFlags::empty(),
367            _decode,
368        )
369    }
370
371    type WaitForEvent_ResponseFut =
372        fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect>;
373    fn r#wait_for_event_(
374        &self,
375        mut data: &Event,
376        mut timeout: i64,
377    ) -> Self::WaitForEvent_ResponseFut {
378        fn _decode(
379            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
380        ) -> Result<bool, fidl::Error> {
381            let _response = fidl::client::decode_transaction_body::<
382                BusWaitForEventResponse,
383                fidl::encoding::DefaultFuchsiaResourceDialect,
384                0x600ca084a42ee5bf,
385            >(_buf?)?;
386            Ok(_response.result)
387        }
388        self.client.send_query_and_decode::<BusWaitForEventRequest, bool>(
389            (data, timeout),
390            0x600ca084a42ee5bf,
391            fidl::encoding::DynamicFlags::empty(),
392            _decode,
393        )
394    }
395}
396
397pub struct BusEventStream {
398    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
399}
400
401impl std::marker::Unpin for BusEventStream {}
402
403impl futures::stream::FusedStream for BusEventStream {
404    fn is_terminated(&self) -> bool {
405        self.event_receiver.is_terminated()
406    }
407}
408
409impl futures::Stream for BusEventStream {
410    type Item = Result<BusEvent, fidl::Error>;
411
412    fn poll_next(
413        mut self: std::pin::Pin<&mut Self>,
414        cx: &mut std::task::Context<'_>,
415    ) -> std::task::Poll<Option<Self::Item>> {
416        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
417            &mut self.event_receiver,
418            cx
419        )?) {
420            Some(buf) => std::task::Poll::Ready(Some(BusEvent::decode(buf))),
421            None => std::task::Poll::Ready(None),
422        }
423    }
424}
425
426#[derive(Debug)]
427pub enum BusEvent {
428    OnBusData { data: Event },
429    OnClientAttached { client: String },
430    OnClientDetached { client: String },
431}
432
433impl BusEvent {
434    #[allow(irrefutable_let_patterns)]
435    pub fn into_on_bus_data(self) -> Option<Event> {
436        if let BusEvent::OnBusData { data } = self {
437            Some((data))
438        } else {
439            None
440        }
441    }
442    #[allow(irrefutable_let_patterns)]
443    pub fn into_on_client_attached(self) -> Option<String> {
444        if let BusEvent::OnClientAttached { client } = self {
445            Some((client))
446        } else {
447            None
448        }
449    }
450    #[allow(irrefutable_let_patterns)]
451    pub fn into_on_client_detached(self) -> Option<String> {
452        if let BusEvent::OnClientDetached { client } = self {
453            Some((client))
454        } else {
455            None
456        }
457    }
458
459    /// Decodes a message buffer as a [`BusEvent`].
460    fn decode(
461        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
462    ) -> Result<BusEvent, fidl::Error> {
463        let (bytes, _handles) = buf.split_mut();
464        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
465        debug_assert_eq!(tx_header.tx_id, 0);
466        match tx_header.ordinal {
467            0x26e9b9ffb43f638f => {
468                let mut out = fidl::new_empty!(
469                    BusOnBusDataRequest,
470                    fidl::encoding::DefaultFuchsiaResourceDialect
471                );
472                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BusOnBusDataRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
473                Ok((BusEvent::OnBusData { data: out.data }))
474            }
475            0x41af94df60bf8ba7 => {
476                let mut out = fidl::new_empty!(
477                    BusOnClientAttachedRequest,
478                    fidl::encoding::DefaultFuchsiaResourceDialect
479                );
480                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BusOnClientAttachedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
481                Ok((BusEvent::OnClientAttached { client: out.client }))
482            }
483            0x31a36387f8ab00d8 => {
484                let mut out = fidl::new_empty!(
485                    BusOnClientDetachedRequest,
486                    fidl::encoding::DefaultFuchsiaResourceDialect
487                );
488                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BusOnClientDetachedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
489                Ok((BusEvent::OnClientDetached { client: out.client }))
490            }
491            _ => Err(fidl::Error::UnknownOrdinal {
492                ordinal: tx_header.ordinal,
493                protocol_name: <BusMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
494            }),
495        }
496    }
497}
498
499/// A Stream of incoming requests for fuchsia.netemul.sync/Bus.
500pub struct BusRequestStream {
501    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
502    is_terminated: bool,
503}
504
505impl std::marker::Unpin for BusRequestStream {}
506
507impl futures::stream::FusedStream for BusRequestStream {
508    fn is_terminated(&self) -> bool {
509        self.is_terminated
510    }
511}
512
513impl fidl::endpoints::RequestStream for BusRequestStream {
514    type Protocol = BusMarker;
515    type ControlHandle = BusControlHandle;
516
517    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
518        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
519    }
520
521    fn control_handle(&self) -> Self::ControlHandle {
522        BusControlHandle { inner: self.inner.clone() }
523    }
524
525    fn into_inner(
526        self,
527    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
528    {
529        (self.inner, self.is_terminated)
530    }
531
532    fn from_inner(
533        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
534        is_terminated: bool,
535    ) -> Self {
536        Self { inner, is_terminated }
537    }
538}
539
540impl futures::Stream for BusRequestStream {
541    type Item = Result<BusRequest, fidl::Error>;
542
543    fn poll_next(
544        mut self: std::pin::Pin<&mut Self>,
545        cx: &mut std::task::Context<'_>,
546    ) -> std::task::Poll<Option<Self::Item>> {
547        let this = &mut *self;
548        if this.inner.check_shutdown(cx) {
549            this.is_terminated = true;
550            return std::task::Poll::Ready(None);
551        }
552        if this.is_terminated {
553            panic!("polled BusRequestStream after completion");
554        }
555        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
556            |bytes, handles| {
557                match this.inner.channel().read_etc(cx, bytes, handles) {
558                    std::task::Poll::Ready(Ok(())) => {}
559                    std::task::Poll::Pending => return std::task::Poll::Pending,
560                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
561                        this.is_terminated = true;
562                        return std::task::Poll::Ready(None);
563                    }
564                    std::task::Poll::Ready(Err(e)) => {
565                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
566                            e.into(),
567                        ))))
568                    }
569                }
570
571                // A message has been received from the channel
572                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
573
574                std::task::Poll::Ready(Some(match header.ordinal {
575                    0x331ceb644024c14b => {
576                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
577                        let mut req = fidl::new_empty!(
578                            BusPublishRequest,
579                            fidl::encoding::DefaultFuchsiaResourceDialect
580                        );
581                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BusPublishRequest>(&header, _body_bytes, handles, &mut req)?;
582                        let control_handle = BusControlHandle { inner: this.inner.clone() };
583                        Ok(BusRequest::Publish { data: req.data, control_handle })
584                    }
585                    0x2969c5f5de5bb64 => {
586                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
587                        let mut req = fidl::new_empty!(
588                            BusEnsurePublishRequest,
589                            fidl::encoding::DefaultFuchsiaResourceDialect
590                        );
591                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BusEnsurePublishRequest>(&header, _body_bytes, handles, &mut req)?;
592                        let control_handle = BusControlHandle { inner: this.inner.clone() };
593                        Ok(BusRequest::EnsurePublish {
594                            data: req.data,
595
596                            responder: BusEnsurePublishResponder {
597                                control_handle: std::mem::ManuallyDrop::new(control_handle),
598                                tx_id: header.tx_id,
599                            },
600                        })
601                    }
602                    0x733c5e2d525a006b => {
603                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
604                        let mut req = fidl::new_empty!(
605                            fidl::encoding::EmptyPayload,
606                            fidl::encoding::DefaultFuchsiaResourceDialect
607                        );
608                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
609                        let control_handle = BusControlHandle { inner: this.inner.clone() };
610                        Ok(BusRequest::GetClients {
611                            responder: BusGetClientsResponder {
612                                control_handle: std::mem::ManuallyDrop::new(control_handle),
613                                tx_id: header.tx_id,
614                            },
615                        })
616                    }
617                    0x21c89fc6be990b23 => {
618                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
619                        let mut req = fidl::new_empty!(
620                            BusWaitForClientsRequest,
621                            fidl::encoding::DefaultFuchsiaResourceDialect
622                        );
623                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BusWaitForClientsRequest>(&header, _body_bytes, handles, &mut req)?;
624                        let control_handle = BusControlHandle { inner: this.inner.clone() };
625                        Ok(BusRequest::WaitForClients {
626                            clients: req.clients,
627                            timeout: req.timeout,
628
629                            responder: BusWaitForClientsResponder {
630                                control_handle: std::mem::ManuallyDrop::new(control_handle),
631                                tx_id: header.tx_id,
632                            },
633                        })
634                    }
635                    0x600ca084a42ee5bf => {
636                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
637                        let mut req = fidl::new_empty!(
638                            BusWaitForEventRequest,
639                            fidl::encoding::DefaultFuchsiaResourceDialect
640                        );
641                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BusWaitForEventRequest>(&header, _body_bytes, handles, &mut req)?;
642                        let control_handle = BusControlHandle { inner: this.inner.clone() };
643                        Ok(BusRequest::WaitForEvent_ {
644                            data: req.data,
645                            timeout: req.timeout,
646
647                            responder: BusWaitForEvent_Responder {
648                                control_handle: std::mem::ManuallyDrop::new(control_handle),
649                                tx_id: header.tx_id,
650                            },
651                        })
652                    }
653                    _ => Err(fidl::Error::UnknownOrdinal {
654                        ordinal: header.ordinal,
655                        protocol_name: <BusMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
656                    }),
657                }))
658            },
659        )
660    }
661}
662
663/// Represents a named bus:
664///    a bus is a broadcast pub/sub network that distributes Events.
665///    Events are not stored, only forwarded to attached clients.
666#[derive(Debug)]
667pub enum BusRequest {
668    /// Publishes event on the bus.
669    Publish { data: Event, control_handle: BusControlHandle },
670    /// Publishes data on bus and only returns when data has been dispatched.
671    /// Use this if you need guarantees that the data was broadcast before continuing.
672    /// Note that this ensures that the data will be *published* to all listening clients,
673    /// but it cannot guarantee that all clients will have observed the event before it returns.
674    EnsurePublish { data: Event, responder: BusEnsurePublishResponder },
675    /// Get list of named clients.
676    GetClients { responder: BusGetClientsResponder },
677    /// Waits for up to `timeout` (nsec) for all the clients in `clients`.
678    /// Returns true if all clients are present on the bus before timeout expired.
679    /// If `result` is false, `absent` will contain the entries in `clients` that still weren't
680    /// present on the bus when the timout expired.
681    /// Use `timeout` <= 0 for indefinite wait.
682    WaitForClients { clients: Vec<String>, timeout: i64, responder: BusWaitForClientsResponder },
683    /// Waits for up to `timeout` (nsec) for an event that matches `data`.
684    /// Event equality is performed by comparing *all* set fields in `data`.
685    /// Returns true if event was received before timeout expired.
686    /// Use `timeout` <= 0 for indefinite wait.
687    WaitForEvent_ { data: Event, timeout: i64, responder: BusWaitForEvent_Responder },
688}
689
690impl BusRequest {
691    #[allow(irrefutable_let_patterns)]
692    pub fn into_publish(self) -> Option<(Event, BusControlHandle)> {
693        if let BusRequest::Publish { data, control_handle } = self {
694            Some((data, control_handle))
695        } else {
696            None
697        }
698    }
699
700    #[allow(irrefutable_let_patterns)]
701    pub fn into_ensure_publish(self) -> Option<(Event, BusEnsurePublishResponder)> {
702        if let BusRequest::EnsurePublish { data, responder } = self {
703            Some((data, responder))
704        } else {
705            None
706        }
707    }
708
709    #[allow(irrefutable_let_patterns)]
710    pub fn into_get_clients(self) -> Option<(BusGetClientsResponder)> {
711        if let BusRequest::GetClients { responder } = self {
712            Some((responder))
713        } else {
714            None
715        }
716    }
717
718    #[allow(irrefutable_let_patterns)]
719    pub fn into_wait_for_clients(self) -> Option<(Vec<String>, i64, BusWaitForClientsResponder)> {
720        if let BusRequest::WaitForClients { clients, timeout, responder } = self {
721            Some((clients, timeout, responder))
722        } else {
723            None
724        }
725    }
726
727    #[allow(irrefutable_let_patterns)]
728    pub fn into_wait_for_event_(self) -> Option<(Event, i64, BusWaitForEvent_Responder)> {
729        if let BusRequest::WaitForEvent_ { data, timeout, responder } = self {
730            Some((data, timeout, responder))
731        } else {
732            None
733        }
734    }
735
736    /// Name of the method defined in FIDL
737    pub fn method_name(&self) -> &'static str {
738        match *self {
739            BusRequest::Publish { .. } => "publish",
740            BusRequest::EnsurePublish { .. } => "ensure_publish",
741            BusRequest::GetClients { .. } => "get_clients",
742            BusRequest::WaitForClients { .. } => "wait_for_clients",
743            BusRequest::WaitForEvent_ { .. } => "wait_for_event_",
744        }
745    }
746}
747
748#[derive(Debug, Clone)]
749pub struct BusControlHandle {
750    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
751}
752
753impl fidl::endpoints::ControlHandle for BusControlHandle {
754    fn shutdown(&self) {
755        self.inner.shutdown()
756    }
757    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
758        self.inner.shutdown_with_epitaph(status)
759    }
760
761    fn is_closed(&self) -> bool {
762        self.inner.channel().is_closed()
763    }
764    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
765        self.inner.channel().on_closed()
766    }
767
768    #[cfg(target_os = "fuchsia")]
769    fn signal_peer(
770        &self,
771        clear_mask: zx::Signals,
772        set_mask: zx::Signals,
773    ) -> Result<(), zx_status::Status> {
774        use fidl::Peered;
775        self.inner.channel().signal_peer(clear_mask, set_mask)
776    }
777}
778
779impl BusControlHandle {
780    pub fn send_on_bus_data(&self, mut data: &Event) -> Result<(), fidl::Error> {
781        self.inner.send::<BusOnBusDataRequest>(
782            (data,),
783            0,
784            0x26e9b9ffb43f638f,
785            fidl::encoding::DynamicFlags::empty(),
786        )
787    }
788
789    pub fn send_on_client_attached(&self, mut client: &str) -> Result<(), fidl::Error> {
790        self.inner.send::<BusOnClientAttachedRequest>(
791            (client,),
792            0,
793            0x41af94df60bf8ba7,
794            fidl::encoding::DynamicFlags::empty(),
795        )
796    }
797
798    pub fn send_on_client_detached(&self, mut client: &str) -> Result<(), fidl::Error> {
799        self.inner.send::<BusOnClientDetachedRequest>(
800            (client,),
801            0,
802            0x31a36387f8ab00d8,
803            fidl::encoding::DynamicFlags::empty(),
804        )
805    }
806}
807
808#[must_use = "FIDL methods require a response to be sent"]
809#[derive(Debug)]
810pub struct BusEnsurePublishResponder {
811    control_handle: std::mem::ManuallyDrop<BusControlHandle>,
812    tx_id: u32,
813}
814
815/// Set the the channel to be shutdown (see [`BusControlHandle::shutdown`])
816/// if the responder is dropped without sending a response, so that the client
817/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
818impl std::ops::Drop for BusEnsurePublishResponder {
819    fn drop(&mut self) {
820        self.control_handle.shutdown();
821        // Safety: drops once, never accessed again
822        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
823    }
824}
825
826impl fidl::endpoints::Responder for BusEnsurePublishResponder {
827    type ControlHandle = BusControlHandle;
828
829    fn control_handle(&self) -> &BusControlHandle {
830        &self.control_handle
831    }
832
833    fn drop_without_shutdown(mut self) {
834        // Safety: drops once, never accessed again due to mem::forget
835        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
836        // Prevent Drop from running (which would shut down the channel)
837        std::mem::forget(self);
838    }
839}
840
841impl BusEnsurePublishResponder {
842    /// Sends a response to the FIDL transaction.
843    ///
844    /// Sets the channel to shutdown if an error occurs.
845    pub fn send(self) -> Result<(), fidl::Error> {
846        let _result = self.send_raw();
847        if _result.is_err() {
848            self.control_handle.shutdown();
849        }
850        self.drop_without_shutdown();
851        _result
852    }
853
854    /// Similar to "send" but does not shutdown the channel if an error occurs.
855    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
856        let _result = self.send_raw();
857        self.drop_without_shutdown();
858        _result
859    }
860
861    fn send_raw(&self) -> Result<(), fidl::Error> {
862        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
863            (),
864            self.tx_id,
865            0x2969c5f5de5bb64,
866            fidl::encoding::DynamicFlags::empty(),
867        )
868    }
869}
870
871#[must_use = "FIDL methods require a response to be sent"]
872#[derive(Debug)]
873pub struct BusGetClientsResponder {
874    control_handle: std::mem::ManuallyDrop<BusControlHandle>,
875    tx_id: u32,
876}
877
878/// Set the the channel to be shutdown (see [`BusControlHandle::shutdown`])
879/// if the responder is dropped without sending a response, so that the client
880/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
881impl std::ops::Drop for BusGetClientsResponder {
882    fn drop(&mut self) {
883        self.control_handle.shutdown();
884        // Safety: drops once, never accessed again
885        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
886    }
887}
888
889impl fidl::endpoints::Responder for BusGetClientsResponder {
890    type ControlHandle = BusControlHandle;
891
892    fn control_handle(&self) -> &BusControlHandle {
893        &self.control_handle
894    }
895
896    fn drop_without_shutdown(mut self) {
897        // Safety: drops once, never accessed again due to mem::forget
898        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
899        // Prevent Drop from running (which would shut down the channel)
900        std::mem::forget(self);
901    }
902}
903
904impl BusGetClientsResponder {
905    /// Sends a response to the FIDL transaction.
906    ///
907    /// Sets the channel to shutdown if an error occurs.
908    pub fn send(self, mut clients: &[String]) -> Result<(), fidl::Error> {
909        let _result = self.send_raw(clients);
910        if _result.is_err() {
911            self.control_handle.shutdown();
912        }
913        self.drop_without_shutdown();
914        _result
915    }
916
917    /// Similar to "send" but does not shutdown the channel if an error occurs.
918    pub fn send_no_shutdown_on_err(self, mut clients: &[String]) -> Result<(), fidl::Error> {
919        let _result = self.send_raw(clients);
920        self.drop_without_shutdown();
921        _result
922    }
923
924    fn send_raw(&self, mut clients: &[String]) -> Result<(), fidl::Error> {
925        self.control_handle.inner.send::<BusGetClientsResponse>(
926            (clients,),
927            self.tx_id,
928            0x733c5e2d525a006b,
929            fidl::encoding::DynamicFlags::empty(),
930        )
931    }
932}
933
934#[must_use = "FIDL methods require a response to be sent"]
935#[derive(Debug)]
936pub struct BusWaitForClientsResponder {
937    control_handle: std::mem::ManuallyDrop<BusControlHandle>,
938    tx_id: u32,
939}
940
941/// Set the the channel to be shutdown (see [`BusControlHandle::shutdown`])
942/// if the responder is dropped without sending a response, so that the client
943/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
944impl std::ops::Drop for BusWaitForClientsResponder {
945    fn drop(&mut self) {
946        self.control_handle.shutdown();
947        // Safety: drops once, never accessed again
948        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
949    }
950}
951
952impl fidl::endpoints::Responder for BusWaitForClientsResponder {
953    type ControlHandle = BusControlHandle;
954
955    fn control_handle(&self) -> &BusControlHandle {
956        &self.control_handle
957    }
958
959    fn drop_without_shutdown(mut self) {
960        // Safety: drops once, never accessed again due to mem::forget
961        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
962        // Prevent Drop from running (which would shut down the channel)
963        std::mem::forget(self);
964    }
965}
966
967impl BusWaitForClientsResponder {
968    /// Sends a response to the FIDL transaction.
969    ///
970    /// Sets the channel to shutdown if an error occurs.
971    pub fn send(self, mut result: bool, mut absent: Option<&[String]>) -> Result<(), fidl::Error> {
972        let _result = self.send_raw(result, absent);
973        if _result.is_err() {
974            self.control_handle.shutdown();
975        }
976        self.drop_without_shutdown();
977        _result
978    }
979
980    /// Similar to "send" but does not shutdown the channel if an error occurs.
981    pub fn send_no_shutdown_on_err(
982        self,
983        mut result: bool,
984        mut absent: Option<&[String]>,
985    ) -> Result<(), fidl::Error> {
986        let _result = self.send_raw(result, absent);
987        self.drop_without_shutdown();
988        _result
989    }
990
991    fn send_raw(&self, mut result: bool, mut absent: Option<&[String]>) -> Result<(), fidl::Error> {
992        self.control_handle.inner.send::<BusWaitForClientsResponse>(
993            (result, absent),
994            self.tx_id,
995            0x21c89fc6be990b23,
996            fidl::encoding::DynamicFlags::empty(),
997        )
998    }
999}
1000
1001#[must_use = "FIDL methods require a response to be sent"]
1002#[derive(Debug)]
1003pub struct BusWaitForEvent_Responder {
1004    control_handle: std::mem::ManuallyDrop<BusControlHandle>,
1005    tx_id: u32,
1006}
1007
1008/// Set the the channel to be shutdown (see [`BusControlHandle::shutdown`])
1009/// if the responder is dropped without sending a response, so that the client
1010/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1011impl std::ops::Drop for BusWaitForEvent_Responder {
1012    fn drop(&mut self) {
1013        self.control_handle.shutdown();
1014        // Safety: drops once, never accessed again
1015        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1016    }
1017}
1018
1019impl fidl::endpoints::Responder for BusWaitForEvent_Responder {
1020    type ControlHandle = BusControlHandle;
1021
1022    fn control_handle(&self) -> &BusControlHandle {
1023        &self.control_handle
1024    }
1025
1026    fn drop_without_shutdown(mut self) {
1027        // Safety: drops once, never accessed again due to mem::forget
1028        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1029        // Prevent Drop from running (which would shut down the channel)
1030        std::mem::forget(self);
1031    }
1032}
1033
1034impl BusWaitForEvent_Responder {
1035    /// Sends a response to the FIDL transaction.
1036    ///
1037    /// Sets the channel to shutdown if an error occurs.
1038    pub fn send(self, mut result: bool) -> Result<(), fidl::Error> {
1039        let _result = self.send_raw(result);
1040        if _result.is_err() {
1041            self.control_handle.shutdown();
1042        }
1043        self.drop_without_shutdown();
1044        _result
1045    }
1046
1047    /// Similar to "send" but does not shutdown the channel if an error occurs.
1048    pub fn send_no_shutdown_on_err(self, mut result: bool) -> Result<(), fidl::Error> {
1049        let _result = self.send_raw(result);
1050        self.drop_without_shutdown();
1051        _result
1052    }
1053
1054    fn send_raw(&self, mut result: bool) -> Result<(), fidl::Error> {
1055        self.control_handle.inner.send::<BusWaitForEventResponse>(
1056            (result,),
1057            self.tx_id,
1058            0x600ca084a42ee5bf,
1059            fidl::encoding::DynamicFlags::empty(),
1060        )
1061    }
1062}
1063
1064#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1065pub struct SyncManagerMarker;
1066
1067impl fidl::endpoints::ProtocolMarker for SyncManagerMarker {
1068    type Proxy = SyncManagerProxy;
1069    type RequestStream = SyncManagerRequestStream;
1070    #[cfg(target_os = "fuchsia")]
1071    type SynchronousProxy = SyncManagerSynchronousProxy;
1072
1073    const DEBUG_NAME: &'static str = "fuchsia.netemul.sync.SyncManager";
1074}
1075impl fidl::endpoints::DiscoverableProtocolMarker for SyncManagerMarker {}
1076
1077pub trait SyncManagerProxyInterface: Send + Sync {
1078    fn r#bus_subscribe(
1079        &self,
1080        bus_name: &str,
1081        client_name: &str,
1082        bus: fidl::endpoints::ServerEnd<BusMarker>,
1083    ) -> Result<(), fidl::Error>;
1084    type WaitForBarrierThresholdResponseFut: std::future::Future<Output = Result<bool, fidl::Error>>
1085        + Send;
1086    fn r#wait_for_barrier_threshold(
1087        &self,
1088        barrier_name: &str,
1089        threshold: u32,
1090        timeout: i64,
1091    ) -> Self::WaitForBarrierThresholdResponseFut;
1092}
1093#[derive(Debug)]
1094#[cfg(target_os = "fuchsia")]
1095pub struct SyncManagerSynchronousProxy {
1096    client: fidl::client::sync::Client,
1097}
1098
1099#[cfg(target_os = "fuchsia")]
1100impl fidl::endpoints::SynchronousProxy for SyncManagerSynchronousProxy {
1101    type Proxy = SyncManagerProxy;
1102    type Protocol = SyncManagerMarker;
1103
1104    fn from_channel(inner: fidl::Channel) -> Self {
1105        Self::new(inner)
1106    }
1107
1108    fn into_channel(self) -> fidl::Channel {
1109        self.client.into_channel()
1110    }
1111
1112    fn as_channel(&self) -> &fidl::Channel {
1113        self.client.as_channel()
1114    }
1115}
1116
1117#[cfg(target_os = "fuchsia")]
1118impl SyncManagerSynchronousProxy {
1119    pub fn new(channel: fidl::Channel) -> Self {
1120        let protocol_name = <SyncManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1121        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1122    }
1123
1124    pub fn into_channel(self) -> fidl::Channel {
1125        self.client.into_channel()
1126    }
1127
1128    /// Waits until an event arrives and returns it. It is safe for other
1129    /// threads to make concurrent requests while waiting for an event.
1130    pub fn wait_for_event(
1131        &self,
1132        deadline: zx::MonotonicInstant,
1133    ) -> Result<SyncManagerEvent, fidl::Error> {
1134        SyncManagerEvent::decode(self.client.wait_for_event(deadline)?)
1135    }
1136
1137    /// Subscribes to bus 'busName' with a given client name.
1138    /// Duplicate client names are disallowed and will cause the request to return unfulfilled.
1139    pub fn r#bus_subscribe(
1140        &self,
1141        mut bus_name: &str,
1142        mut client_name: &str,
1143        mut bus: fidl::endpoints::ServerEnd<BusMarker>,
1144    ) -> Result<(), fidl::Error> {
1145        self.client.send::<SyncManagerBusSubscribeRequest>(
1146            (bus_name, client_name, bus),
1147            0x39c25d810b5e7407,
1148            fidl::encoding::DynamicFlags::empty(),
1149        )
1150    }
1151
1152    /// Waits on a named counter barrier with name `barrierName`.
1153    /// Functon will return true if the number of waits pending on the barrier matches or exceeds
1154    /// `threshold` before  `timeout` (nsec) expires.
1155    /// Use `timeout` <= 0 for indefinite wait.
1156    pub fn r#wait_for_barrier_threshold(
1157        &self,
1158        mut barrier_name: &str,
1159        mut threshold: u32,
1160        mut timeout: i64,
1161        ___deadline: zx::MonotonicInstant,
1162    ) -> Result<bool, fidl::Error> {
1163        let _response = self.client.send_query::<
1164            SyncManagerWaitForBarrierThresholdRequest,
1165            SyncManagerWaitForBarrierThresholdResponse,
1166        >(
1167            (barrier_name, threshold, timeout,),
1168            0x592056b5825f4292,
1169            fidl::encoding::DynamicFlags::empty(),
1170            ___deadline,
1171        )?;
1172        Ok(_response.result)
1173    }
1174}
1175
1176#[cfg(target_os = "fuchsia")]
1177impl From<SyncManagerSynchronousProxy> for zx::Handle {
1178    fn from(value: SyncManagerSynchronousProxy) -> Self {
1179        value.into_channel().into()
1180    }
1181}
1182
1183#[cfg(target_os = "fuchsia")]
1184impl From<fidl::Channel> for SyncManagerSynchronousProxy {
1185    fn from(value: fidl::Channel) -> Self {
1186        Self::new(value)
1187    }
1188}
1189
1190#[cfg(target_os = "fuchsia")]
1191impl fidl::endpoints::FromClient for SyncManagerSynchronousProxy {
1192    type Protocol = SyncManagerMarker;
1193
1194    fn from_client(value: fidl::endpoints::ClientEnd<SyncManagerMarker>) -> Self {
1195        Self::new(value.into_channel())
1196    }
1197}
1198
1199#[derive(Debug, Clone)]
1200pub struct SyncManagerProxy {
1201    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1202}
1203
1204impl fidl::endpoints::Proxy for SyncManagerProxy {
1205    type Protocol = SyncManagerMarker;
1206
1207    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1208        Self::new(inner)
1209    }
1210
1211    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1212        self.client.into_channel().map_err(|client| Self { client })
1213    }
1214
1215    fn as_channel(&self) -> &::fidl::AsyncChannel {
1216        self.client.as_channel()
1217    }
1218}
1219
1220impl SyncManagerProxy {
1221    /// Create a new Proxy for fuchsia.netemul.sync/SyncManager.
1222    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1223        let protocol_name = <SyncManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1224        Self { client: fidl::client::Client::new(channel, protocol_name) }
1225    }
1226
1227    /// Get a Stream of events from the remote end of the protocol.
1228    ///
1229    /// # Panics
1230    ///
1231    /// Panics if the event stream was already taken.
1232    pub fn take_event_stream(&self) -> SyncManagerEventStream {
1233        SyncManagerEventStream { event_receiver: self.client.take_event_receiver() }
1234    }
1235
1236    /// Subscribes to bus 'busName' with a given client name.
1237    /// Duplicate client names are disallowed and will cause the request to return unfulfilled.
1238    pub fn r#bus_subscribe(
1239        &self,
1240        mut bus_name: &str,
1241        mut client_name: &str,
1242        mut bus: fidl::endpoints::ServerEnd<BusMarker>,
1243    ) -> Result<(), fidl::Error> {
1244        SyncManagerProxyInterface::r#bus_subscribe(self, bus_name, client_name, bus)
1245    }
1246
1247    /// Waits on a named counter barrier with name `barrierName`.
1248    /// Functon will return true if the number of waits pending on the barrier matches or exceeds
1249    /// `threshold` before  `timeout` (nsec) expires.
1250    /// Use `timeout` <= 0 for indefinite wait.
1251    pub fn r#wait_for_barrier_threshold(
1252        &self,
1253        mut barrier_name: &str,
1254        mut threshold: u32,
1255        mut timeout: i64,
1256    ) -> fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect> {
1257        SyncManagerProxyInterface::r#wait_for_barrier_threshold(
1258            self,
1259            barrier_name,
1260            threshold,
1261            timeout,
1262        )
1263    }
1264}
1265
1266impl SyncManagerProxyInterface for SyncManagerProxy {
1267    fn r#bus_subscribe(
1268        &self,
1269        mut bus_name: &str,
1270        mut client_name: &str,
1271        mut bus: fidl::endpoints::ServerEnd<BusMarker>,
1272    ) -> Result<(), fidl::Error> {
1273        self.client.send::<SyncManagerBusSubscribeRequest>(
1274            (bus_name, client_name, bus),
1275            0x39c25d810b5e7407,
1276            fidl::encoding::DynamicFlags::empty(),
1277        )
1278    }
1279
1280    type WaitForBarrierThresholdResponseFut =
1281        fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect>;
1282    fn r#wait_for_barrier_threshold(
1283        &self,
1284        mut barrier_name: &str,
1285        mut threshold: u32,
1286        mut timeout: i64,
1287    ) -> Self::WaitForBarrierThresholdResponseFut {
1288        fn _decode(
1289            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1290        ) -> Result<bool, fidl::Error> {
1291            let _response = fidl::client::decode_transaction_body::<
1292                SyncManagerWaitForBarrierThresholdResponse,
1293                fidl::encoding::DefaultFuchsiaResourceDialect,
1294                0x592056b5825f4292,
1295            >(_buf?)?;
1296            Ok(_response.result)
1297        }
1298        self.client.send_query_and_decode::<SyncManagerWaitForBarrierThresholdRequest, bool>(
1299            (barrier_name, threshold, timeout),
1300            0x592056b5825f4292,
1301            fidl::encoding::DynamicFlags::empty(),
1302            _decode,
1303        )
1304    }
1305}
1306
1307pub struct SyncManagerEventStream {
1308    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1309}
1310
1311impl std::marker::Unpin for SyncManagerEventStream {}
1312
1313impl futures::stream::FusedStream for SyncManagerEventStream {
1314    fn is_terminated(&self) -> bool {
1315        self.event_receiver.is_terminated()
1316    }
1317}
1318
1319impl futures::Stream for SyncManagerEventStream {
1320    type Item = Result<SyncManagerEvent, fidl::Error>;
1321
1322    fn poll_next(
1323        mut self: std::pin::Pin<&mut Self>,
1324        cx: &mut std::task::Context<'_>,
1325    ) -> std::task::Poll<Option<Self::Item>> {
1326        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1327            &mut self.event_receiver,
1328            cx
1329        )?) {
1330            Some(buf) => std::task::Poll::Ready(Some(SyncManagerEvent::decode(buf))),
1331            None => std::task::Poll::Ready(None),
1332        }
1333    }
1334}
1335
1336#[derive(Debug)]
1337pub enum SyncManagerEvent {}
1338
1339impl SyncManagerEvent {
1340    /// Decodes a message buffer as a [`SyncManagerEvent`].
1341    fn decode(
1342        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1343    ) -> Result<SyncManagerEvent, fidl::Error> {
1344        let (bytes, _handles) = buf.split_mut();
1345        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1346        debug_assert_eq!(tx_header.tx_id, 0);
1347        match tx_header.ordinal {
1348            _ => Err(fidl::Error::UnknownOrdinal {
1349                ordinal: tx_header.ordinal,
1350                protocol_name: <SyncManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1351            }),
1352        }
1353    }
1354}
1355
1356/// A Stream of incoming requests for fuchsia.netemul.sync/SyncManager.
1357pub struct SyncManagerRequestStream {
1358    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1359    is_terminated: bool,
1360}
1361
1362impl std::marker::Unpin for SyncManagerRequestStream {}
1363
1364impl futures::stream::FusedStream for SyncManagerRequestStream {
1365    fn is_terminated(&self) -> bool {
1366        self.is_terminated
1367    }
1368}
1369
1370impl fidl::endpoints::RequestStream for SyncManagerRequestStream {
1371    type Protocol = SyncManagerMarker;
1372    type ControlHandle = SyncManagerControlHandle;
1373
1374    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1375        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1376    }
1377
1378    fn control_handle(&self) -> Self::ControlHandle {
1379        SyncManagerControlHandle { inner: self.inner.clone() }
1380    }
1381
1382    fn into_inner(
1383        self,
1384    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1385    {
1386        (self.inner, self.is_terminated)
1387    }
1388
1389    fn from_inner(
1390        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1391        is_terminated: bool,
1392    ) -> Self {
1393        Self { inner, is_terminated }
1394    }
1395}
1396
1397impl futures::Stream for SyncManagerRequestStream {
1398    type Item = Result<SyncManagerRequest, fidl::Error>;
1399
1400    fn poll_next(
1401        mut self: std::pin::Pin<&mut Self>,
1402        cx: &mut std::task::Context<'_>,
1403    ) -> std::task::Poll<Option<Self::Item>> {
1404        let this = &mut *self;
1405        if this.inner.check_shutdown(cx) {
1406            this.is_terminated = true;
1407            return std::task::Poll::Ready(None);
1408        }
1409        if this.is_terminated {
1410            panic!("polled SyncManagerRequestStream after completion");
1411        }
1412        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1413            |bytes, handles| {
1414                match this.inner.channel().read_etc(cx, bytes, handles) {
1415                    std::task::Poll::Ready(Ok(())) => {}
1416                    std::task::Poll::Pending => return std::task::Poll::Pending,
1417                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1418                        this.is_terminated = true;
1419                        return std::task::Poll::Ready(None);
1420                    }
1421                    std::task::Poll::Ready(Err(e)) => {
1422                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1423                            e.into(),
1424                        ))))
1425                    }
1426                }
1427
1428                // A message has been received from the channel
1429                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1430
1431                std::task::Poll::Ready(Some(match header.ordinal {
1432                    0x39c25d810b5e7407 => {
1433                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1434                        let mut req = fidl::new_empty!(
1435                            SyncManagerBusSubscribeRequest,
1436                            fidl::encoding::DefaultFuchsiaResourceDialect
1437                        );
1438                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SyncManagerBusSubscribeRequest>(&header, _body_bytes, handles, &mut req)?;
1439                        let control_handle = SyncManagerControlHandle { inner: this.inner.clone() };
1440                        Ok(SyncManagerRequest::BusSubscribe {
1441                            bus_name: req.bus_name,
1442                            client_name: req.client_name,
1443                            bus: req.bus,
1444
1445                            control_handle,
1446                        })
1447                    }
1448                    0x592056b5825f4292 => {
1449                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1450                        let mut req = fidl::new_empty!(
1451                            SyncManagerWaitForBarrierThresholdRequest,
1452                            fidl::encoding::DefaultFuchsiaResourceDialect
1453                        );
1454                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SyncManagerWaitForBarrierThresholdRequest>(&header, _body_bytes, handles, &mut req)?;
1455                        let control_handle = SyncManagerControlHandle { inner: this.inner.clone() };
1456                        Ok(SyncManagerRequest::WaitForBarrierThreshold {
1457                            barrier_name: req.barrier_name,
1458                            threshold: req.threshold,
1459                            timeout: req.timeout,
1460
1461                            responder: SyncManagerWaitForBarrierThresholdResponder {
1462                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1463                                tx_id: header.tx_id,
1464                            },
1465                        })
1466                    }
1467                    _ => Err(fidl::Error::UnknownOrdinal {
1468                        ordinal: header.ordinal,
1469                        protocol_name:
1470                            <SyncManagerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1471                    }),
1472                }))
1473            },
1474        )
1475    }
1476}
1477
1478/// The SyncManager is the entry point to attach a client to a bus or use other synchronization
1479/// primitives.
1480/// The client's 'ticket' to remain on the bus is the channel obtained through the 'BusSubscribe' call.
1481#[derive(Debug)]
1482pub enum SyncManagerRequest {
1483    /// Subscribes to bus 'busName' with a given client name.
1484    /// Duplicate client names are disallowed and will cause the request to return unfulfilled.
1485    BusSubscribe {
1486        bus_name: String,
1487        client_name: String,
1488        bus: fidl::endpoints::ServerEnd<BusMarker>,
1489        control_handle: SyncManagerControlHandle,
1490    },
1491    /// Waits on a named counter barrier with name `barrierName`.
1492    /// Functon will return true if the number of waits pending on the barrier matches or exceeds
1493    /// `threshold` before  `timeout` (nsec) expires.
1494    /// Use `timeout` <= 0 for indefinite wait.
1495    WaitForBarrierThreshold {
1496        barrier_name: String,
1497        threshold: u32,
1498        timeout: i64,
1499        responder: SyncManagerWaitForBarrierThresholdResponder,
1500    },
1501}
1502
1503impl SyncManagerRequest {
1504    #[allow(irrefutable_let_patterns)]
1505    pub fn into_bus_subscribe(
1506        self,
1507    ) -> Option<(String, String, fidl::endpoints::ServerEnd<BusMarker>, SyncManagerControlHandle)>
1508    {
1509        if let SyncManagerRequest::BusSubscribe { bus_name, client_name, bus, control_handle } =
1510            self
1511        {
1512            Some((bus_name, client_name, bus, control_handle))
1513        } else {
1514            None
1515        }
1516    }
1517
1518    #[allow(irrefutable_let_patterns)]
1519    pub fn into_wait_for_barrier_threshold(
1520        self,
1521    ) -> Option<(String, u32, i64, SyncManagerWaitForBarrierThresholdResponder)> {
1522        if let SyncManagerRequest::WaitForBarrierThreshold {
1523            barrier_name,
1524            threshold,
1525            timeout,
1526            responder,
1527        } = self
1528        {
1529            Some((barrier_name, threshold, timeout, responder))
1530        } else {
1531            None
1532        }
1533    }
1534
1535    /// Name of the method defined in FIDL
1536    pub fn method_name(&self) -> &'static str {
1537        match *self {
1538            SyncManagerRequest::BusSubscribe { .. } => "bus_subscribe",
1539            SyncManagerRequest::WaitForBarrierThreshold { .. } => "wait_for_barrier_threshold",
1540        }
1541    }
1542}
1543
1544#[derive(Debug, Clone)]
1545pub struct SyncManagerControlHandle {
1546    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1547}
1548
1549impl fidl::endpoints::ControlHandle for SyncManagerControlHandle {
1550    fn shutdown(&self) {
1551        self.inner.shutdown()
1552    }
1553    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1554        self.inner.shutdown_with_epitaph(status)
1555    }
1556
1557    fn is_closed(&self) -> bool {
1558        self.inner.channel().is_closed()
1559    }
1560    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1561        self.inner.channel().on_closed()
1562    }
1563
1564    #[cfg(target_os = "fuchsia")]
1565    fn signal_peer(
1566        &self,
1567        clear_mask: zx::Signals,
1568        set_mask: zx::Signals,
1569    ) -> Result<(), zx_status::Status> {
1570        use fidl::Peered;
1571        self.inner.channel().signal_peer(clear_mask, set_mask)
1572    }
1573}
1574
1575impl SyncManagerControlHandle {}
1576
1577#[must_use = "FIDL methods require a response to be sent"]
1578#[derive(Debug)]
1579pub struct SyncManagerWaitForBarrierThresholdResponder {
1580    control_handle: std::mem::ManuallyDrop<SyncManagerControlHandle>,
1581    tx_id: u32,
1582}
1583
1584/// Set the the channel to be shutdown (see [`SyncManagerControlHandle::shutdown`])
1585/// if the responder is dropped without sending a response, so that the client
1586/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1587impl std::ops::Drop for SyncManagerWaitForBarrierThresholdResponder {
1588    fn drop(&mut self) {
1589        self.control_handle.shutdown();
1590        // Safety: drops once, never accessed again
1591        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1592    }
1593}
1594
1595impl fidl::endpoints::Responder for SyncManagerWaitForBarrierThresholdResponder {
1596    type ControlHandle = SyncManagerControlHandle;
1597
1598    fn control_handle(&self) -> &SyncManagerControlHandle {
1599        &self.control_handle
1600    }
1601
1602    fn drop_without_shutdown(mut self) {
1603        // Safety: drops once, never accessed again due to mem::forget
1604        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1605        // Prevent Drop from running (which would shut down the channel)
1606        std::mem::forget(self);
1607    }
1608}
1609
1610impl SyncManagerWaitForBarrierThresholdResponder {
1611    /// Sends a response to the FIDL transaction.
1612    ///
1613    /// Sets the channel to shutdown if an error occurs.
1614    pub fn send(self, mut result: bool) -> Result<(), fidl::Error> {
1615        let _result = self.send_raw(result);
1616        if _result.is_err() {
1617            self.control_handle.shutdown();
1618        }
1619        self.drop_without_shutdown();
1620        _result
1621    }
1622
1623    /// Similar to "send" but does not shutdown the channel if an error occurs.
1624    pub fn send_no_shutdown_on_err(self, mut result: bool) -> Result<(), fidl::Error> {
1625        let _result = self.send_raw(result);
1626        self.drop_without_shutdown();
1627        _result
1628    }
1629
1630    fn send_raw(&self, mut result: bool) -> Result<(), fidl::Error> {
1631        self.control_handle.inner.send::<SyncManagerWaitForBarrierThresholdResponse>(
1632            (result,),
1633            self.tx_id,
1634            0x592056b5825f4292,
1635            fidl::encoding::DynamicFlags::empty(),
1636        )
1637    }
1638}
1639
1640mod internal {
1641    use super::*;
1642
1643    impl fidl::encoding::ResourceTypeMarker for SyncManagerBusSubscribeRequest {
1644        type Borrowed<'a> = &'a mut Self;
1645        fn take_or_borrow<'a>(
1646            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1647        ) -> Self::Borrowed<'a> {
1648            value
1649        }
1650    }
1651
1652    unsafe impl fidl::encoding::TypeMarker for SyncManagerBusSubscribeRequest {
1653        type Owned = Self;
1654
1655        #[inline(always)]
1656        fn inline_align(_context: fidl::encoding::Context) -> usize {
1657            8
1658        }
1659
1660        #[inline(always)]
1661        fn inline_size(_context: fidl::encoding::Context) -> usize {
1662            40
1663        }
1664    }
1665
1666    unsafe impl
1667        fidl::encoding::Encode<
1668            SyncManagerBusSubscribeRequest,
1669            fidl::encoding::DefaultFuchsiaResourceDialect,
1670        > for &mut SyncManagerBusSubscribeRequest
1671    {
1672        #[inline]
1673        unsafe fn encode(
1674            self,
1675            encoder: &mut fidl::encoding::Encoder<
1676                '_,
1677                fidl::encoding::DefaultFuchsiaResourceDialect,
1678            >,
1679            offset: usize,
1680            _depth: fidl::encoding::Depth,
1681        ) -> fidl::Result<()> {
1682            encoder.debug_check_bounds::<SyncManagerBusSubscribeRequest>(offset);
1683            // Delegate to tuple encoding.
1684            fidl::encoding::Encode::<SyncManagerBusSubscribeRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1685                (
1686                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow(&self.bus_name),
1687                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow(&self.client_name),
1688                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<BusMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.bus),
1689                ),
1690                encoder, offset, _depth
1691            )
1692        }
1693    }
1694    unsafe impl<
1695            T0: fidl::encoding::Encode<
1696                fidl::encoding::UnboundedString,
1697                fidl::encoding::DefaultFuchsiaResourceDialect,
1698            >,
1699            T1: fidl::encoding::Encode<
1700                fidl::encoding::UnboundedString,
1701                fidl::encoding::DefaultFuchsiaResourceDialect,
1702            >,
1703            T2: fidl::encoding::Encode<
1704                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<BusMarker>>,
1705                fidl::encoding::DefaultFuchsiaResourceDialect,
1706            >,
1707        >
1708        fidl::encoding::Encode<
1709            SyncManagerBusSubscribeRequest,
1710            fidl::encoding::DefaultFuchsiaResourceDialect,
1711        > for (T0, T1, T2)
1712    {
1713        #[inline]
1714        unsafe fn encode(
1715            self,
1716            encoder: &mut fidl::encoding::Encoder<
1717                '_,
1718                fidl::encoding::DefaultFuchsiaResourceDialect,
1719            >,
1720            offset: usize,
1721            depth: fidl::encoding::Depth,
1722        ) -> fidl::Result<()> {
1723            encoder.debug_check_bounds::<SyncManagerBusSubscribeRequest>(offset);
1724            // Zero out padding regions. There's no need to apply masks
1725            // because the unmasked parts will be overwritten by fields.
1726            unsafe {
1727                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
1728                (ptr as *mut u64).write_unaligned(0);
1729            }
1730            // Write the fields.
1731            self.0.encode(encoder, offset + 0, depth)?;
1732            self.1.encode(encoder, offset + 16, depth)?;
1733            self.2.encode(encoder, offset + 32, depth)?;
1734            Ok(())
1735        }
1736    }
1737
1738    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1739        for SyncManagerBusSubscribeRequest
1740    {
1741        #[inline(always)]
1742        fn new_empty() -> Self {
1743            Self {
1744                bus_name: fidl::new_empty!(
1745                    fidl::encoding::UnboundedString,
1746                    fidl::encoding::DefaultFuchsiaResourceDialect
1747                ),
1748                client_name: fidl::new_empty!(
1749                    fidl::encoding::UnboundedString,
1750                    fidl::encoding::DefaultFuchsiaResourceDialect
1751                ),
1752                bus: fidl::new_empty!(
1753                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<BusMarker>>,
1754                    fidl::encoding::DefaultFuchsiaResourceDialect
1755                ),
1756            }
1757        }
1758
1759        #[inline]
1760        unsafe fn decode(
1761            &mut self,
1762            decoder: &mut fidl::encoding::Decoder<
1763                '_,
1764                fidl::encoding::DefaultFuchsiaResourceDialect,
1765            >,
1766            offset: usize,
1767            _depth: fidl::encoding::Depth,
1768        ) -> fidl::Result<()> {
1769            decoder.debug_check_bounds::<Self>(offset);
1770            // Verify that padding bytes are zero.
1771            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
1772            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1773            let mask = 0xffffffff00000000u64;
1774            let maskedval = padval & mask;
1775            if maskedval != 0 {
1776                return Err(fidl::Error::NonZeroPadding {
1777                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
1778                });
1779            }
1780            fidl::decode!(
1781                fidl::encoding::UnboundedString,
1782                fidl::encoding::DefaultFuchsiaResourceDialect,
1783                &mut self.bus_name,
1784                decoder,
1785                offset + 0,
1786                _depth
1787            )?;
1788            fidl::decode!(
1789                fidl::encoding::UnboundedString,
1790                fidl::encoding::DefaultFuchsiaResourceDialect,
1791                &mut self.client_name,
1792                decoder,
1793                offset + 16,
1794                _depth
1795            )?;
1796            fidl::decode!(
1797                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<BusMarker>>,
1798                fidl::encoding::DefaultFuchsiaResourceDialect,
1799                &mut self.bus,
1800                decoder,
1801                offset + 32,
1802                _depth
1803            )?;
1804            Ok(())
1805        }
1806    }
1807}