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 Self { client: fidl::client::sync::Client::new(channel) }
61 }
62
63 pub fn into_channel(self) -> fidl::Channel {
64 self.client.into_channel()
65 }
66
67 pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<TestEvent, fidl::Error> {
70 TestEvent::decode(self.client.wait_for_event::<TestMarker>(deadline)?)
71 }
72
73 pub fn r#ping(&self, ___deadline: zx::MonotonicInstant) -> Result<u32, fidl::Error> {
74 let _response =
75 self.client.send_query::<fidl::encoding::EmptyPayload, TestPingResponse, TestMarker>(
76 (),
77 0x23aa1eb7d24346cf,
78 fidl::encoding::DynamicFlags::empty(),
79 ___deadline,
80 )?;
81 Ok(_response.generation)
82 }
83
84 pub fn r#disconnect(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
85 let _response = self
86 .client
87 .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload, TestMarker>(
88 (),
89 0x5a1b547382bf672e,
90 fidl::encoding::DynamicFlags::empty(),
91 ___deadline,
92 )?;
93 Ok(_response)
94 }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl From<TestSynchronousProxy> for zx::NullableHandle {
99 fn from(value: TestSynchronousProxy) -> Self {
100 value.into_channel().into()
101 }
102}
103
104#[cfg(target_os = "fuchsia")]
105impl From<fidl::Channel> for TestSynchronousProxy {
106 fn from(value: fidl::Channel) -> Self {
107 Self::new(value)
108 }
109}
110
111#[cfg(target_os = "fuchsia")]
112impl fidl::endpoints::FromClient for TestSynchronousProxy {
113 type Protocol = TestMarker;
114
115 fn from_client(value: fidl::endpoints::ClientEnd<TestMarker>) -> Self {
116 Self::new(value.into_channel())
117 }
118}
119
120#[derive(Debug, Clone)]
121pub struct TestProxy {
122 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
123}
124
125impl fidl::endpoints::Proxy for TestProxy {
126 type Protocol = TestMarker;
127
128 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
129 Self::new(inner)
130 }
131
132 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
133 self.client.into_channel().map_err(|client| Self { client })
134 }
135
136 fn as_channel(&self) -> &::fidl::AsyncChannel {
137 self.client.as_channel()
138 }
139}
140
141impl TestProxy {
142 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
144 let protocol_name = <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
145 Self { client: fidl::client::Client::new(channel, protocol_name) }
146 }
147
148 pub fn take_event_stream(&self) -> TestEventStream {
154 TestEventStream { event_receiver: self.client.take_event_receiver() }
155 }
156
157 pub fn r#ping(
158 &self,
159 ) -> fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect> {
160 TestProxyInterface::r#ping(self)
161 }
162
163 pub fn r#disconnect(
164 &self,
165 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
166 TestProxyInterface::r#disconnect(self)
167 }
168}
169
170impl TestProxyInterface for TestProxy {
171 type PingResponseFut =
172 fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect>;
173 fn r#ping(&self) -> Self::PingResponseFut {
174 fn _decode(
175 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
176 ) -> Result<u32, fidl::Error> {
177 let _response = fidl::client::decode_transaction_body::<
178 TestPingResponse,
179 fidl::encoding::DefaultFuchsiaResourceDialect,
180 0x23aa1eb7d24346cf,
181 >(_buf?)?;
182 Ok(_response.generation)
183 }
184 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, u32>(
185 (),
186 0x23aa1eb7d24346cf,
187 fidl::encoding::DynamicFlags::empty(),
188 _decode,
189 )
190 }
191
192 type DisconnectResponseFut =
193 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
194 fn r#disconnect(&self) -> Self::DisconnectResponseFut {
195 fn _decode(
196 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
197 ) -> Result<(), fidl::Error> {
198 let _response = fidl::client::decode_transaction_body::<
199 fidl::encoding::EmptyPayload,
200 fidl::encoding::DefaultFuchsiaResourceDialect,
201 0x5a1b547382bf672e,
202 >(_buf?)?;
203 Ok(_response)
204 }
205 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
206 (),
207 0x5a1b547382bf672e,
208 fidl::encoding::DynamicFlags::empty(),
209 _decode,
210 )
211 }
212}
213
214pub struct TestEventStream {
215 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
216}
217
218impl std::marker::Unpin for TestEventStream {}
219
220impl futures::stream::FusedStream for TestEventStream {
221 fn is_terminated(&self) -> bool {
222 self.event_receiver.is_terminated()
223 }
224}
225
226impl futures::Stream for TestEventStream {
227 type Item = Result<TestEvent, fidl::Error>;
228
229 fn poll_next(
230 mut self: std::pin::Pin<&mut Self>,
231 cx: &mut std::task::Context<'_>,
232 ) -> std::task::Poll<Option<Self::Item>> {
233 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
234 &mut self.event_receiver,
235 cx
236 )?) {
237 Some(buf) => std::task::Poll::Ready(Some(TestEvent::decode(buf))),
238 None => std::task::Poll::Ready(None),
239 }
240 }
241}
242
243#[derive(Debug)]
244pub enum TestEvent {}
245
246impl TestEvent {
247 fn decode(
249 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
250 ) -> Result<TestEvent, fidl::Error> {
251 let (bytes, _handles) = buf.split_mut();
252 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
253 debug_assert_eq!(tx_header.tx_id, 0);
254 match tx_header.ordinal {
255 _ => Err(fidl::Error::UnknownOrdinal {
256 ordinal: tx_header.ordinal,
257 protocol_name: <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
258 }),
259 }
260 }
261}
262
263pub struct TestRequestStream {
265 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
266 is_terminated: bool,
267}
268
269impl std::marker::Unpin for TestRequestStream {}
270
271impl futures::stream::FusedStream for TestRequestStream {
272 fn is_terminated(&self) -> bool {
273 self.is_terminated
274 }
275}
276
277impl fidl::endpoints::RequestStream for TestRequestStream {
278 type Protocol = TestMarker;
279 type ControlHandle = TestControlHandle;
280
281 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
282 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
283 }
284
285 fn control_handle(&self) -> Self::ControlHandle {
286 TestControlHandle { inner: self.inner.clone() }
287 }
288
289 fn into_inner(
290 self,
291 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
292 {
293 (self.inner, self.is_terminated)
294 }
295
296 fn from_inner(
297 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
298 is_terminated: bool,
299 ) -> Self {
300 Self { inner, is_terminated }
301 }
302}
303
304impl futures::Stream for TestRequestStream {
305 type Item = Result<TestRequest, fidl::Error>;
306
307 fn poll_next(
308 mut self: std::pin::Pin<&mut Self>,
309 cx: &mut std::task::Context<'_>,
310 ) -> std::task::Poll<Option<Self::Item>> {
311 let this = &mut *self;
312 if this.inner.check_shutdown(cx) {
313 this.is_terminated = true;
314 return std::task::Poll::Ready(None);
315 }
316 if this.is_terminated {
317 panic!("polled TestRequestStream after completion");
318 }
319 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
320 |bytes, handles| {
321 match this.inner.channel().read_etc(cx, bytes, handles) {
322 std::task::Poll::Ready(Ok(())) => {}
323 std::task::Poll::Pending => return std::task::Poll::Pending,
324 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
325 this.is_terminated = true;
326 return std::task::Poll::Ready(None);
327 }
328 std::task::Poll::Ready(Err(e)) => {
329 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
330 e.into(),
331 ))));
332 }
333 }
334
335 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
337
338 std::task::Poll::Ready(Some(match header.ordinal {
339 0x23aa1eb7d24346cf => {
340 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
341 let mut req = fidl::new_empty!(
342 fidl::encoding::EmptyPayload,
343 fidl::encoding::DefaultFuchsiaResourceDialect
344 );
345 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
346 let control_handle = TestControlHandle { inner: this.inner.clone() };
347 Ok(TestRequest::Ping {
348 responder: TestPingResponder {
349 control_handle: std::mem::ManuallyDrop::new(control_handle),
350 tx_id: header.tx_id,
351 },
352 })
353 }
354 0x5a1b547382bf672e => {
355 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
356 let mut req = fidl::new_empty!(
357 fidl::encoding::EmptyPayload,
358 fidl::encoding::DefaultFuchsiaResourceDialect
359 );
360 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
361 let control_handle = TestControlHandle { inner: this.inner.clone() };
362 Ok(TestRequest::Disconnect {
363 responder: TestDisconnectResponder {
364 control_handle: std::mem::ManuallyDrop::new(control_handle),
365 tx_id: header.tx_id,
366 },
367 })
368 }
369 _ => Err(fidl::Error::UnknownOrdinal {
370 ordinal: header.ordinal,
371 protocol_name: <TestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
372 }),
373 }))
374 },
375 )
376 }
377}
378
379#[derive(Debug)]
380pub enum TestRequest {
381 Ping { responder: TestPingResponder },
382 Disconnect { responder: TestDisconnectResponder },
383}
384
385impl TestRequest {
386 #[allow(irrefutable_let_patterns)]
387 pub fn into_ping(self) -> Option<(TestPingResponder)> {
388 if let TestRequest::Ping { responder } = self { Some((responder)) } else { None }
389 }
390
391 #[allow(irrefutable_let_patterns)]
392 pub fn into_disconnect(self) -> Option<(TestDisconnectResponder)> {
393 if let TestRequest::Disconnect { responder } = self { Some((responder)) } else { None }
394 }
395
396 pub fn method_name(&self) -> &'static str {
398 match *self {
399 TestRequest::Ping { .. } => "ping",
400 TestRequest::Disconnect { .. } => "disconnect",
401 }
402 }
403}
404
405#[derive(Debug, Clone)]
406pub struct TestControlHandle {
407 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
408}
409
410impl TestControlHandle {
411 pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
412 self.inner.shutdown_with_epitaph(status.into())
413 }
414}
415
416impl fidl::endpoints::ControlHandle for TestControlHandle {
417 fn shutdown(&self) {
418 self.inner.shutdown()
419 }
420
421 fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
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 generation: u32) -> Result<(), fidl::Error> {
483 let _result = self.send_raw(generation);
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 generation: u32) -> Result<(), fidl::Error> {
493 let _result = self.send_raw(generation);
494 self.drop_without_shutdown();
495 _result
496 }
497
498 fn send_raw(&self, mut generation: u32) -> Result<(), fidl::Error> {
499 self.control_handle.inner.send::<TestPingResponse>(
500 (generation,),
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}