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