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