Skip to main content

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