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 fidl::endpoints::ControlHandle for TestControlHandle {
411 fn shutdown(&self) {
412 self.inner.shutdown()
413 }
414
415 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
416 self.inner.shutdown_with_epitaph(status)
417 }
418
419 fn is_closed(&self) -> bool {
420 self.inner.channel().is_closed()
421 }
422 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
423 self.inner.channel().on_closed()
424 }
425
426 #[cfg(target_os = "fuchsia")]
427 fn signal_peer(
428 &self,
429 clear_mask: zx::Signals,
430 set_mask: zx::Signals,
431 ) -> Result<(), zx_status::Status> {
432 use fidl::Peered;
433 self.inner.channel().signal_peer(clear_mask, set_mask)
434 }
435}
436
437impl TestControlHandle {}
438
439#[must_use = "FIDL methods require a response to be sent"]
440#[derive(Debug)]
441pub struct TestPingResponder {
442 control_handle: std::mem::ManuallyDrop<TestControlHandle>,
443 tx_id: u32,
444}
445
446impl std::ops::Drop for TestPingResponder {
450 fn drop(&mut self) {
451 self.control_handle.shutdown();
452 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
454 }
455}
456
457impl fidl::endpoints::Responder for TestPingResponder {
458 type ControlHandle = TestControlHandle;
459
460 fn control_handle(&self) -> &TestControlHandle {
461 &self.control_handle
462 }
463
464 fn drop_without_shutdown(mut self) {
465 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
467 std::mem::forget(self);
469 }
470}
471
472impl TestPingResponder {
473 pub fn send(self, mut generation: u32) -> Result<(), fidl::Error> {
477 let _result = self.send_raw(generation);
478 if _result.is_err() {
479 self.control_handle.shutdown();
480 }
481 self.drop_without_shutdown();
482 _result
483 }
484
485 pub fn send_no_shutdown_on_err(self, mut generation: u32) -> Result<(), fidl::Error> {
487 let _result = self.send_raw(generation);
488 self.drop_without_shutdown();
489 _result
490 }
491
492 fn send_raw(&self, mut generation: u32) -> Result<(), fidl::Error> {
493 self.control_handle.inner.send::<TestPingResponse>(
494 (generation,),
495 self.tx_id,
496 0x23aa1eb7d24346cf,
497 fidl::encoding::DynamicFlags::empty(),
498 )
499 }
500}
501
502#[must_use = "FIDL methods require a response to be sent"]
503#[derive(Debug)]
504pub struct TestDisconnectResponder {
505 control_handle: std::mem::ManuallyDrop<TestControlHandle>,
506 tx_id: u32,
507}
508
509impl std::ops::Drop for TestDisconnectResponder {
513 fn drop(&mut self) {
514 self.control_handle.shutdown();
515 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
517 }
518}
519
520impl fidl::endpoints::Responder for TestDisconnectResponder {
521 type ControlHandle = TestControlHandle;
522
523 fn control_handle(&self) -> &TestControlHandle {
524 &self.control_handle
525 }
526
527 fn drop_without_shutdown(mut self) {
528 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
530 std::mem::forget(self);
532 }
533}
534
535impl TestDisconnectResponder {
536 pub fn send(self) -> Result<(), fidl::Error> {
540 let _result = self.send_raw();
541 if _result.is_err() {
542 self.control_handle.shutdown();
543 }
544 self.drop_without_shutdown();
545 _result
546 }
547
548 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
550 let _result = self.send_raw();
551 self.drop_without_shutdown();
552 _result
553 }
554
555 fn send_raw(&self) -> Result<(), fidl::Error> {
556 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
557 (),
558 self.tx_id,
559 0x5a1b547382bf672e,
560 fidl::encoding::DynamicFlags::empty(),
561 )
562 }
563}
564
565mod internal {
566 use super::*;
567}