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