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