fidl_test_fidl_connector/
fidl_test_fidl_connector.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_fidl_connector__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct TestMarker;
16
17impl fidl::endpoints::ProtocolMarker for TestMarker {
18 type Proxy = TestProxy;
19 type RequestStream = TestRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = TestSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "test.fidl.connector.Test";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for TestMarker {}
26
27pub trait TestProxyInterface: Send + Sync {
28 type PingResponseFut: std::future::Future<Output = Result<u32, fidl::Error>> + Send;
29 fn r#ping(&self) -> Self::PingResponseFut;
30 type DisconnectResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
31 fn r#disconnect(&self) -> Self::DisconnectResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct TestSynchronousProxy {
36 client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for TestSynchronousProxy {
41 type Proxy = TestProxy;
42 type Protocol = TestMarker;
43
44 fn from_channel(inner: fidl::Channel) -> Self {
45 Self::new(inner)
46 }
47
48 fn into_channel(self) -> fidl::Channel {
49 self.client.into_channel()
50 }
51
52 fn as_channel(&self) -> &fidl::Channel {
53 self.client.as_channel()
54 }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl TestSynchronousProxy {
59 pub fn new(channel: fidl::Channel) -> Self {
60 let protocol_name = <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62 }
63
64 pub fn into_channel(self) -> fidl::Channel {
65 self.client.into_channel()
66 }
67
68 pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<TestEvent, fidl::Error> {
71 TestEvent::decode(self.client.wait_for_event(deadline)?)
72 }
73
74 pub fn r#ping(&self, ___deadline: zx::MonotonicInstant) -> Result<u32, fidl::Error> {
75 let _response = self.client.send_query::<fidl::encoding::EmptyPayload, TestPingResponse>(
76 (),
77 0x23aa1eb7d24346cf,
78 fidl::encoding::DynamicFlags::empty(),
79 ___deadline,
80 )?;
81 Ok(_response.gen)
82 }
83
84 pub fn r#disconnect(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
85 let _response =
86 self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
87 (),
88 0x5a1b547382bf672e,
89 fidl::encoding::DynamicFlags::empty(),
90 ___deadline,
91 )?;
92 Ok(_response)
93 }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl From<TestSynchronousProxy> for zx::Handle {
98 fn from(value: TestSynchronousProxy) -> Self {
99 value.into_channel().into()
100 }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<fidl::Channel> for TestSynchronousProxy {
105 fn from(value: fidl::Channel) -> Self {
106 Self::new(value)
107 }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl fidl::endpoints::FromClient for TestSynchronousProxy {
112 type Protocol = TestMarker;
113
114 fn from_client(value: fidl::endpoints::ClientEnd<TestMarker>) -> Self {
115 Self::new(value.into_channel())
116 }
117}
118
119#[derive(Debug, Clone)]
120pub struct TestProxy {
121 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
122}
123
124impl fidl::endpoints::Proxy for TestProxy {
125 type Protocol = TestMarker;
126
127 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
128 Self::new(inner)
129 }
130
131 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
132 self.client.into_channel().map_err(|client| Self { client })
133 }
134
135 fn as_channel(&self) -> &::fidl::AsyncChannel {
136 self.client.as_channel()
137 }
138}
139
140impl TestProxy {
141 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
143 let protocol_name = <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
144 Self { client: fidl::client::Client::new(channel, protocol_name) }
145 }
146
147 pub fn take_event_stream(&self) -> TestEventStream {
153 TestEventStream { event_receiver: self.client.take_event_receiver() }
154 }
155
156 pub fn r#ping(
157 &self,
158 ) -> fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect> {
159 TestProxyInterface::r#ping(self)
160 }
161
162 pub fn r#disconnect(
163 &self,
164 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
165 TestProxyInterface::r#disconnect(self)
166 }
167}
168
169impl TestProxyInterface for TestProxy {
170 type PingResponseFut =
171 fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect>;
172 fn r#ping(&self) -> Self::PingResponseFut {
173 fn _decode(
174 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
175 ) -> Result<u32, fidl::Error> {
176 let _response = fidl::client::decode_transaction_body::<
177 TestPingResponse,
178 fidl::encoding::DefaultFuchsiaResourceDialect,
179 0x23aa1eb7d24346cf,
180 >(_buf?)?;
181 Ok(_response.gen)
182 }
183 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, u32>(
184 (),
185 0x23aa1eb7d24346cf,
186 fidl::encoding::DynamicFlags::empty(),
187 _decode,
188 )
189 }
190
191 type DisconnectResponseFut =
192 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
193 fn r#disconnect(&self) -> Self::DisconnectResponseFut {
194 fn _decode(
195 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
196 ) -> Result<(), fidl::Error> {
197 let _response = fidl::client::decode_transaction_body::<
198 fidl::encoding::EmptyPayload,
199 fidl::encoding::DefaultFuchsiaResourceDialect,
200 0x5a1b547382bf672e,
201 >(_buf?)?;
202 Ok(_response)
203 }
204 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
205 (),
206 0x5a1b547382bf672e,
207 fidl::encoding::DynamicFlags::empty(),
208 _decode,
209 )
210 }
211}
212
213pub struct TestEventStream {
214 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
215}
216
217impl std::marker::Unpin for TestEventStream {}
218
219impl futures::stream::FusedStream for TestEventStream {
220 fn is_terminated(&self) -> bool {
221 self.event_receiver.is_terminated()
222 }
223}
224
225impl futures::Stream for TestEventStream {
226 type Item = Result<TestEvent, fidl::Error>;
227
228 fn poll_next(
229 mut self: std::pin::Pin<&mut Self>,
230 cx: &mut std::task::Context<'_>,
231 ) -> std::task::Poll<Option<Self::Item>> {
232 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
233 &mut self.event_receiver,
234 cx
235 )?) {
236 Some(buf) => std::task::Poll::Ready(Some(TestEvent::decode(buf))),
237 None => std::task::Poll::Ready(None),
238 }
239 }
240}
241
242#[derive(Debug)]
243pub enum TestEvent {}
244
245impl TestEvent {
246 fn decode(
248 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
249 ) -> Result<TestEvent, fidl::Error> {
250 let (bytes, _handles) = buf.split_mut();
251 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
252 debug_assert_eq!(tx_header.tx_id, 0);
253 match tx_header.ordinal {
254 _ => Err(fidl::Error::UnknownOrdinal {
255 ordinal: tx_header.ordinal,
256 protocol_name: <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
257 }),
258 }
259 }
260}
261
262pub struct TestRequestStream {
264 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
265 is_terminated: bool,
266}
267
268impl std::marker::Unpin for TestRequestStream {}
269
270impl futures::stream::FusedStream for TestRequestStream {
271 fn is_terminated(&self) -> bool {
272 self.is_terminated
273 }
274}
275
276impl fidl::endpoints::RequestStream for TestRequestStream {
277 type Protocol = TestMarker;
278 type ControlHandle = TestControlHandle;
279
280 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
281 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
282 }
283
284 fn control_handle(&self) -> Self::ControlHandle {
285 TestControlHandle { inner: self.inner.clone() }
286 }
287
288 fn into_inner(
289 self,
290 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
291 {
292 (self.inner, self.is_terminated)
293 }
294
295 fn from_inner(
296 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
297 is_terminated: bool,
298 ) -> Self {
299 Self { inner, is_terminated }
300 }
301}
302
303impl futures::Stream for TestRequestStream {
304 type Item = Result<TestRequest, fidl::Error>;
305
306 fn poll_next(
307 mut self: std::pin::Pin<&mut Self>,
308 cx: &mut std::task::Context<'_>,
309 ) -> std::task::Poll<Option<Self::Item>> {
310 let this = &mut *self;
311 if this.inner.check_shutdown(cx) {
312 this.is_terminated = true;
313 return std::task::Poll::Ready(None);
314 }
315 if this.is_terminated {
316 panic!("polled TestRequestStream after completion");
317 }
318 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
319 |bytes, handles| {
320 match this.inner.channel().read_etc(cx, bytes, handles) {
321 std::task::Poll::Ready(Ok(())) => {}
322 std::task::Poll::Pending => return std::task::Poll::Pending,
323 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
324 this.is_terminated = true;
325 return std::task::Poll::Ready(None);
326 }
327 std::task::Poll::Ready(Err(e)) => {
328 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
329 e.into(),
330 ))))
331 }
332 }
333
334 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
336
337 std::task::Poll::Ready(Some(match header.ordinal {
338 0x23aa1eb7d24346cf => {
339 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
340 let mut req = fidl::new_empty!(
341 fidl::encoding::EmptyPayload,
342 fidl::encoding::DefaultFuchsiaResourceDialect
343 );
344 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
345 let control_handle = TestControlHandle { inner: this.inner.clone() };
346 Ok(TestRequest::Ping {
347 responder: TestPingResponder {
348 control_handle: std::mem::ManuallyDrop::new(control_handle),
349 tx_id: header.tx_id,
350 },
351 })
352 }
353 0x5a1b547382bf672e => {
354 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
355 let mut req = fidl::new_empty!(
356 fidl::encoding::EmptyPayload,
357 fidl::encoding::DefaultFuchsiaResourceDialect
358 );
359 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
360 let control_handle = TestControlHandle { inner: this.inner.clone() };
361 Ok(TestRequest::Disconnect {
362 responder: TestDisconnectResponder {
363 control_handle: std::mem::ManuallyDrop::new(control_handle),
364 tx_id: header.tx_id,
365 },
366 })
367 }
368 _ => Err(fidl::Error::UnknownOrdinal {
369 ordinal: header.ordinal,
370 protocol_name: <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
371 }),
372 }))
373 },
374 )
375 }
376}
377
378#[derive(Debug)]
379pub enum TestRequest {
380 Ping { responder: TestPingResponder },
381 Disconnect { responder: TestDisconnectResponder },
382}
383
384impl TestRequest {
385 #[allow(irrefutable_let_patterns)]
386 pub fn into_ping(self) -> Option<(TestPingResponder)> {
387 if let TestRequest::Ping { responder } = self {
388 Some((responder))
389 } else {
390 None
391 }
392 }
393
394 #[allow(irrefutable_let_patterns)]
395 pub fn into_disconnect(self) -> Option<(TestDisconnectResponder)> {
396 if let TestRequest::Disconnect { responder } = self {
397 Some((responder))
398 } else {
399 None
400 }
401 }
402
403 pub fn method_name(&self) -> &'static str {
405 match *self {
406 TestRequest::Ping { .. } => "ping",
407 TestRequest::Disconnect { .. } => "disconnect",
408 }
409 }
410}
411
412#[derive(Debug, Clone)]
413pub struct TestControlHandle {
414 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
415}
416
417impl fidl::endpoints::ControlHandle for TestControlHandle {
418 fn shutdown(&self) {
419 self.inner.shutdown()
420 }
421 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
422 self.inner.shutdown_with_epitaph(status)
423 }
424
425 fn is_closed(&self) -> bool {
426 self.inner.channel().is_closed()
427 }
428 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
429 self.inner.channel().on_closed()
430 }
431
432 #[cfg(target_os = "fuchsia")]
433 fn signal_peer(
434 &self,
435 clear_mask: zx::Signals,
436 set_mask: zx::Signals,
437 ) -> Result<(), zx_status::Status> {
438 use fidl::Peered;
439 self.inner.channel().signal_peer(clear_mask, set_mask)
440 }
441}
442
443impl TestControlHandle {}
444
445#[must_use = "FIDL methods require a response to be sent"]
446#[derive(Debug)]
447pub struct TestPingResponder {
448 control_handle: std::mem::ManuallyDrop<TestControlHandle>,
449 tx_id: u32,
450}
451
452impl std::ops::Drop for TestPingResponder {
456 fn drop(&mut self) {
457 self.control_handle.shutdown();
458 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
460 }
461}
462
463impl fidl::endpoints::Responder for TestPingResponder {
464 type ControlHandle = TestControlHandle;
465
466 fn control_handle(&self) -> &TestControlHandle {
467 &self.control_handle
468 }
469
470 fn drop_without_shutdown(mut self) {
471 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
473 std::mem::forget(self);
475 }
476}
477
478impl TestPingResponder {
479 pub fn send(self, mut gen: u32) -> Result<(), fidl::Error> {
483 let _result = self.send_raw(gen);
484 if _result.is_err() {
485 self.control_handle.shutdown();
486 }
487 self.drop_without_shutdown();
488 _result
489 }
490
491 pub fn send_no_shutdown_on_err(self, mut gen: u32) -> Result<(), fidl::Error> {
493 let _result = self.send_raw(gen);
494 self.drop_without_shutdown();
495 _result
496 }
497
498 fn send_raw(&self, mut gen: u32) -> Result<(), fidl::Error> {
499 self.control_handle.inner.send::<TestPingResponse>(
500 (gen,),
501 self.tx_id,
502 0x23aa1eb7d24346cf,
503 fidl::encoding::DynamicFlags::empty(),
504 )
505 }
506}
507
508#[must_use = "FIDL methods require a response to be sent"]
509#[derive(Debug)]
510pub struct TestDisconnectResponder {
511 control_handle: std::mem::ManuallyDrop<TestControlHandle>,
512 tx_id: u32,
513}
514
515impl std::ops::Drop for TestDisconnectResponder {
519 fn drop(&mut self) {
520 self.control_handle.shutdown();
521 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
523 }
524}
525
526impl fidl::endpoints::Responder for TestDisconnectResponder {
527 type ControlHandle = TestControlHandle;
528
529 fn control_handle(&self) -> &TestControlHandle {
530 &self.control_handle
531 }
532
533 fn drop_without_shutdown(mut self) {
534 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
536 std::mem::forget(self);
538 }
539}
540
541impl TestDisconnectResponder {
542 pub fn send(self) -> Result<(), fidl::Error> {
546 let _result = self.send_raw();
547 if _result.is_err() {
548 self.control_handle.shutdown();
549 }
550 self.drop_without_shutdown();
551 _result
552 }
553
554 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
556 let _result = self.send_raw();
557 self.drop_without_shutdown();
558 _result
559 }
560
561 fn send_raw(&self) -> Result<(), fidl::Error> {
562 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
563 (),
564 self.tx_id,
565 0x5a1b547382bf672e,
566 fidl::encoding::DynamicFlags::empty(),
567 )
568 }
569}
570
571mod internal {
572 use super::*;
573}