fidl_test_pkg_eventqueue/
fidl_test_pkg_eventqueue.rs1#![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_test_pkg_eventqueue__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ExampleEventMonitorMarker;
16
17impl fidl::endpoints::ProtocolMarker for ExampleEventMonitorMarker {
18 type Proxy = ExampleEventMonitorProxy;
19 type RequestStream = ExampleEventMonitorRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = ExampleEventMonitorSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "(anonymous) ExampleEventMonitor";
24}
25
26pub trait ExampleEventMonitorProxyInterface: Send + Sync {
27 type OnEventResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
28 fn r#on_event(&self, event: &str) -> Self::OnEventResponseFut;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct ExampleEventMonitorSynchronousProxy {
33 client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for ExampleEventMonitorSynchronousProxy {
38 type Proxy = ExampleEventMonitorProxy;
39 type Protocol = ExampleEventMonitorMarker;
40
41 fn from_channel(inner: fidl::Channel) -> Self {
42 Self::new(inner)
43 }
44
45 fn into_channel(self) -> fidl::Channel {
46 self.client.into_channel()
47 }
48
49 fn as_channel(&self) -> &fidl::Channel {
50 self.client.as_channel()
51 }
52}
53
54#[cfg(target_os = "fuchsia")]
55impl ExampleEventMonitorSynchronousProxy {
56 pub fn new(channel: fidl::Channel) -> Self {
57 let protocol_name =
58 <ExampleEventMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
60 }
61
62 pub fn into_channel(self) -> fidl::Channel {
63 self.client.into_channel()
64 }
65
66 pub fn wait_for_event(
69 &self,
70 deadline: zx::MonotonicInstant,
71 ) -> Result<ExampleEventMonitorEvent, fidl::Error> {
72 ExampleEventMonitorEvent::decode(self.client.wait_for_event(deadline)?)
73 }
74
75 pub fn r#on_event(
76 &self,
77 mut event: &str,
78 ___deadline: zx::MonotonicInstant,
79 ) -> Result<(), fidl::Error> {
80 let _response = self
81 .client
82 .send_query::<ExampleEventMonitorOnEventRequest, fidl::encoding::EmptyPayload>(
83 (event,),
84 0x28e8b219d2d480c6,
85 fidl::encoding::DynamicFlags::empty(),
86 ___deadline,
87 )?;
88 Ok(_response)
89 }
90}
91
92#[cfg(target_os = "fuchsia")]
93impl From<ExampleEventMonitorSynchronousProxy> for zx::Handle {
94 fn from(value: ExampleEventMonitorSynchronousProxy) -> Self {
95 value.into_channel().into()
96 }
97}
98
99#[cfg(target_os = "fuchsia")]
100impl From<fidl::Channel> for ExampleEventMonitorSynchronousProxy {
101 fn from(value: fidl::Channel) -> Self {
102 Self::new(value)
103 }
104}
105
106#[cfg(target_os = "fuchsia")]
107impl fidl::endpoints::FromClient for ExampleEventMonitorSynchronousProxy {
108 type Protocol = ExampleEventMonitorMarker;
109
110 fn from_client(value: fidl::endpoints::ClientEnd<ExampleEventMonitorMarker>) -> Self {
111 Self::new(value.into_channel())
112 }
113}
114
115#[derive(Debug, Clone)]
116pub struct ExampleEventMonitorProxy {
117 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
118}
119
120impl fidl::endpoints::Proxy for ExampleEventMonitorProxy {
121 type Protocol = ExampleEventMonitorMarker;
122
123 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
124 Self::new(inner)
125 }
126
127 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
128 self.client.into_channel().map_err(|client| Self { client })
129 }
130
131 fn as_channel(&self) -> &::fidl::AsyncChannel {
132 self.client.as_channel()
133 }
134}
135
136impl ExampleEventMonitorProxy {
137 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
139 let protocol_name =
140 <ExampleEventMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
141 Self { client: fidl::client::Client::new(channel, protocol_name) }
142 }
143
144 pub fn take_event_stream(&self) -> ExampleEventMonitorEventStream {
150 ExampleEventMonitorEventStream { event_receiver: self.client.take_event_receiver() }
151 }
152
153 pub fn r#on_event(
154 &self,
155 mut event: &str,
156 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
157 ExampleEventMonitorProxyInterface::r#on_event(self, event)
158 }
159}
160
161impl ExampleEventMonitorProxyInterface for ExampleEventMonitorProxy {
162 type OnEventResponseFut =
163 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
164 fn r#on_event(&self, mut event: &str) -> Self::OnEventResponseFut {
165 fn _decode(
166 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
167 ) -> Result<(), fidl::Error> {
168 let _response = fidl::client::decode_transaction_body::<
169 fidl::encoding::EmptyPayload,
170 fidl::encoding::DefaultFuchsiaResourceDialect,
171 0x28e8b219d2d480c6,
172 >(_buf?)?;
173 Ok(_response)
174 }
175 self.client.send_query_and_decode::<ExampleEventMonitorOnEventRequest, ()>(
176 (event,),
177 0x28e8b219d2d480c6,
178 fidl::encoding::DynamicFlags::empty(),
179 _decode,
180 )
181 }
182}
183
184pub struct ExampleEventMonitorEventStream {
185 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
186}
187
188impl std::marker::Unpin for ExampleEventMonitorEventStream {}
189
190impl futures::stream::FusedStream for ExampleEventMonitorEventStream {
191 fn is_terminated(&self) -> bool {
192 self.event_receiver.is_terminated()
193 }
194}
195
196impl futures::Stream for ExampleEventMonitorEventStream {
197 type Item = Result<ExampleEventMonitorEvent, fidl::Error>;
198
199 fn poll_next(
200 mut self: std::pin::Pin<&mut Self>,
201 cx: &mut std::task::Context<'_>,
202 ) -> std::task::Poll<Option<Self::Item>> {
203 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
204 &mut self.event_receiver,
205 cx
206 )?) {
207 Some(buf) => std::task::Poll::Ready(Some(ExampleEventMonitorEvent::decode(buf))),
208 None => std::task::Poll::Ready(None),
209 }
210 }
211}
212
213#[derive(Debug)]
214pub enum ExampleEventMonitorEvent {}
215
216impl ExampleEventMonitorEvent {
217 fn decode(
219 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
220 ) -> Result<ExampleEventMonitorEvent, fidl::Error> {
221 let (bytes, _handles) = buf.split_mut();
222 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
223 debug_assert_eq!(tx_header.tx_id, 0);
224 match tx_header.ordinal {
225 _ => Err(fidl::Error::UnknownOrdinal {
226 ordinal: tx_header.ordinal,
227 protocol_name:
228 <ExampleEventMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
229 }),
230 }
231 }
232}
233
234pub struct ExampleEventMonitorRequestStream {
236 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
237 is_terminated: bool,
238}
239
240impl std::marker::Unpin for ExampleEventMonitorRequestStream {}
241
242impl futures::stream::FusedStream for ExampleEventMonitorRequestStream {
243 fn is_terminated(&self) -> bool {
244 self.is_terminated
245 }
246}
247
248impl fidl::endpoints::RequestStream for ExampleEventMonitorRequestStream {
249 type Protocol = ExampleEventMonitorMarker;
250 type ControlHandle = ExampleEventMonitorControlHandle;
251
252 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
253 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
254 }
255
256 fn control_handle(&self) -> Self::ControlHandle {
257 ExampleEventMonitorControlHandle { inner: self.inner.clone() }
258 }
259
260 fn into_inner(
261 self,
262 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
263 {
264 (self.inner, self.is_terminated)
265 }
266
267 fn from_inner(
268 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
269 is_terminated: bool,
270 ) -> Self {
271 Self { inner, is_terminated }
272 }
273}
274
275impl futures::Stream for ExampleEventMonitorRequestStream {
276 type Item = Result<ExampleEventMonitorRequest, fidl::Error>;
277
278 fn poll_next(
279 mut self: std::pin::Pin<&mut Self>,
280 cx: &mut std::task::Context<'_>,
281 ) -> std::task::Poll<Option<Self::Item>> {
282 let this = &mut *self;
283 if this.inner.check_shutdown(cx) {
284 this.is_terminated = true;
285 return std::task::Poll::Ready(None);
286 }
287 if this.is_terminated {
288 panic!("polled ExampleEventMonitorRequestStream after completion");
289 }
290 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
291 |bytes, handles| {
292 match this.inner.channel().read_etc(cx, bytes, handles) {
293 std::task::Poll::Ready(Ok(())) => {}
294 std::task::Poll::Pending => return std::task::Poll::Pending,
295 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
296 this.is_terminated = true;
297 return std::task::Poll::Ready(None);
298 }
299 std::task::Poll::Ready(Err(e)) => {
300 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
301 e.into(),
302 ))))
303 }
304 }
305
306 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
308
309 std::task::Poll::Ready(Some(match header.ordinal {
310 0x28e8b219d2d480c6 => {
311 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
312 let mut req = fidl::new_empty!(ExampleEventMonitorOnEventRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
313 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ExampleEventMonitorOnEventRequest>(&header, _body_bytes, handles, &mut req)?;
314 let control_handle = ExampleEventMonitorControlHandle {
315 inner: this.inner.clone(),
316 };
317 Ok(ExampleEventMonitorRequest::OnEvent {event: req.event,
318
319 responder: ExampleEventMonitorOnEventResponder {
320 control_handle: std::mem::ManuallyDrop::new(control_handle),
321 tx_id: header.tx_id,
322 },
323 })
324 }
325 _ => Err(fidl::Error::UnknownOrdinal {
326 ordinal: header.ordinal,
327 protocol_name: <ExampleEventMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
328 }),
329 }))
330 },
331 )
332 }
333}
334
335#[derive(Debug)]
336pub enum ExampleEventMonitorRequest {
337 OnEvent { event: String, responder: ExampleEventMonitorOnEventResponder },
338}
339
340impl ExampleEventMonitorRequest {
341 #[allow(irrefutable_let_patterns)]
342 pub fn into_on_event(self) -> Option<(String, ExampleEventMonitorOnEventResponder)> {
343 if let ExampleEventMonitorRequest::OnEvent { event, responder } = self {
344 Some((event, responder))
345 } else {
346 None
347 }
348 }
349
350 pub fn method_name(&self) -> &'static str {
352 match *self {
353 ExampleEventMonitorRequest::OnEvent { .. } => "on_event",
354 }
355 }
356}
357
358#[derive(Debug, Clone)]
359pub struct ExampleEventMonitorControlHandle {
360 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
361}
362
363impl fidl::endpoints::ControlHandle for ExampleEventMonitorControlHandle {
364 fn shutdown(&self) {
365 self.inner.shutdown()
366 }
367 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
368 self.inner.shutdown_with_epitaph(status)
369 }
370
371 fn is_closed(&self) -> bool {
372 self.inner.channel().is_closed()
373 }
374 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
375 self.inner.channel().on_closed()
376 }
377
378 #[cfg(target_os = "fuchsia")]
379 fn signal_peer(
380 &self,
381 clear_mask: zx::Signals,
382 set_mask: zx::Signals,
383 ) -> Result<(), zx_status::Status> {
384 use fidl::Peered;
385 self.inner.channel().signal_peer(clear_mask, set_mask)
386 }
387}
388
389impl ExampleEventMonitorControlHandle {}
390
391#[must_use = "FIDL methods require a response to be sent"]
392#[derive(Debug)]
393pub struct ExampleEventMonitorOnEventResponder {
394 control_handle: std::mem::ManuallyDrop<ExampleEventMonitorControlHandle>,
395 tx_id: u32,
396}
397
398impl std::ops::Drop for ExampleEventMonitorOnEventResponder {
402 fn drop(&mut self) {
403 self.control_handle.shutdown();
404 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
406 }
407}
408
409impl fidl::endpoints::Responder for ExampleEventMonitorOnEventResponder {
410 type ControlHandle = ExampleEventMonitorControlHandle;
411
412 fn control_handle(&self) -> &ExampleEventMonitorControlHandle {
413 &self.control_handle
414 }
415
416 fn drop_without_shutdown(mut self) {
417 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
419 std::mem::forget(self);
421 }
422}
423
424impl ExampleEventMonitorOnEventResponder {
425 pub fn send(self) -> Result<(), fidl::Error> {
429 let _result = self.send_raw();
430 if _result.is_err() {
431 self.control_handle.shutdown();
432 }
433 self.drop_without_shutdown();
434 _result
435 }
436
437 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
439 let _result = self.send_raw();
440 self.drop_without_shutdown();
441 _result
442 }
443
444 fn send_raw(&self) -> Result<(), fidl::Error> {
445 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
446 (),
447 self.tx_id,
448 0x28e8b219d2d480c6,
449 fidl::encoding::DynamicFlags::empty(),
450 )
451 }
452}
453
454mod internal {
455 use super::*;
456}