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.generation)
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.generation)
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 { Some((responder)) } else { None }
388 }
389
390 #[allow(irrefutable_let_patterns)]
391 pub fn into_disconnect(self) -> Option<(TestDisconnectResponder)> {
392 if let TestRequest::Disconnect { responder } = self { Some((responder)) } else { None }
393 }
394
395 pub fn method_name(&self) -> &'static str {
397 match *self {
398 TestRequest::Ping { .. } => "ping",
399 TestRequest::Disconnect { .. } => "disconnect",
400 }
401 }
402}
403
404#[derive(Debug, Clone)]
405pub struct TestControlHandle {
406 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
407}
408
409impl fidl::endpoints::ControlHandle for TestControlHandle {
410 fn shutdown(&self) {
411 self.inner.shutdown()
412 }
413 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
414 self.inner.shutdown_with_epitaph(status)
415 }
416
417 fn is_closed(&self) -> bool {
418 self.inner.channel().is_closed()
419 }
420 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
421 self.inner.channel().on_closed()
422 }
423
424 #[cfg(target_os = "fuchsia")]
425 fn signal_peer(
426 &self,
427 clear_mask: zx::Signals,
428 set_mask: zx::Signals,
429 ) -> Result<(), zx_status::Status> {
430 use fidl::Peered;
431 self.inner.channel().signal_peer(clear_mask, set_mask)
432 }
433}
434
435impl TestControlHandle {}
436
437#[must_use = "FIDL methods require a response to be sent"]
438#[derive(Debug)]
439pub struct TestPingResponder {
440 control_handle: std::mem::ManuallyDrop<TestControlHandle>,
441 tx_id: u32,
442}
443
444impl std::ops::Drop for TestPingResponder {
448 fn drop(&mut self) {
449 self.control_handle.shutdown();
450 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
452 }
453}
454
455impl fidl::endpoints::Responder for TestPingResponder {
456 type ControlHandle = TestControlHandle;
457
458 fn control_handle(&self) -> &TestControlHandle {
459 &self.control_handle
460 }
461
462 fn drop_without_shutdown(mut self) {
463 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
465 std::mem::forget(self);
467 }
468}
469
470impl TestPingResponder {
471 pub fn send(self, mut generation: u32) -> Result<(), fidl::Error> {
475 let _result = self.send_raw(generation);
476 if _result.is_err() {
477 self.control_handle.shutdown();
478 }
479 self.drop_without_shutdown();
480 _result
481 }
482
483 pub fn send_no_shutdown_on_err(self, mut generation: u32) -> Result<(), fidl::Error> {
485 let _result = self.send_raw(generation);
486 self.drop_without_shutdown();
487 _result
488 }
489
490 fn send_raw(&self, mut generation: u32) -> Result<(), fidl::Error> {
491 self.control_handle.inner.send::<TestPingResponse>(
492 (generation,),
493 self.tx_id,
494 0x23aa1eb7d24346cf,
495 fidl::encoding::DynamicFlags::empty(),
496 )
497 }
498}
499
500#[must_use = "FIDL methods require a response to be sent"]
501#[derive(Debug)]
502pub struct TestDisconnectResponder {
503 control_handle: std::mem::ManuallyDrop<TestControlHandle>,
504 tx_id: u32,
505}
506
507impl std::ops::Drop for TestDisconnectResponder {
511 fn drop(&mut self) {
512 self.control_handle.shutdown();
513 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
515 }
516}
517
518impl fidl::endpoints::Responder for TestDisconnectResponder {
519 type ControlHandle = TestControlHandle;
520
521 fn control_handle(&self) -> &TestControlHandle {
522 &self.control_handle
523 }
524
525 fn drop_without_shutdown(mut self) {
526 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
528 std::mem::forget(self);
530 }
531}
532
533impl TestDisconnectResponder {
534 pub fn send(self) -> Result<(), fidl::Error> {
538 let _result = self.send_raw();
539 if _result.is_err() {
540 self.control_handle.shutdown();
541 }
542 self.drop_without_shutdown();
543 _result
544 }
545
546 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
548 let _result = self.send_raw();
549 self.drop_without_shutdown();
550 _result
551 }
552
553 fn send_raw(&self) -> Result<(), fidl::Error> {
554 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
555 (),
556 self.tx_id,
557 0x5a1b547382bf672e,
558 fidl::encoding::DynamicFlags::empty(),
559 )
560 }
561}
562
563mod internal {
564 use super::*;
565}