fidl_fuchsia_component_tests/
fidl_fuchsia_component_tests.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_fuchsia_component_tests__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ShutdownerMarker;
16
17impl fidl::endpoints::ProtocolMarker for ShutdownerMarker {
18 type Proxy = ShutdownerProxy;
19 type RequestStream = ShutdownerRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = ShutdownerSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.component.tests.Shutdowner";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for ShutdownerMarker {}
26
27pub trait ShutdownerProxyInterface: Send + Sync {
28 fn r#shutdown(&self) -> Result<(), fidl::Error>;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct ShutdownerSynchronousProxy {
33 client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for ShutdownerSynchronousProxy {
38 type Proxy = ShutdownerProxy;
39 type Protocol = ShutdownerMarker;
40
41 fn from_channel(inner: fidl::Channel) -> Self {
42 Self::new(inner)
43 }
44
45 fn into_channel(self) -> fidl::Channel {
46 self.client.into_channel()
47 }
48
49 fn as_channel(&self) -> &fidl::Channel {
50 self.client.as_channel()
51 }
52}
53
54#[cfg(target_os = "fuchsia")]
55impl ShutdownerSynchronousProxy {
56 pub fn new(channel: fidl::Channel) -> Self {
57 let protocol_name = <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
58 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
59 }
60
61 pub fn into_channel(self) -> fidl::Channel {
62 self.client.into_channel()
63 }
64
65 pub fn wait_for_event(
68 &self,
69 deadline: zx::MonotonicInstant,
70 ) -> Result<ShutdownerEvent, fidl::Error> {
71 ShutdownerEvent::decode(self.client.wait_for_event(deadline)?)
72 }
73
74 pub fn r#shutdown(&self) -> Result<(), fidl::Error> {
75 self.client.send::<fidl::encoding::EmptyPayload>(
76 (),
77 0x4da8a4e818bef187,
78 fidl::encoding::DynamicFlags::empty(),
79 )
80 }
81}
82
83#[cfg(target_os = "fuchsia")]
84impl From<ShutdownerSynchronousProxy> for zx::Handle {
85 fn from(value: ShutdownerSynchronousProxy) -> Self {
86 value.into_channel().into()
87 }
88}
89
90#[cfg(target_os = "fuchsia")]
91impl From<fidl::Channel> for ShutdownerSynchronousProxy {
92 fn from(value: fidl::Channel) -> Self {
93 Self::new(value)
94 }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl fidl::endpoints::FromClient for ShutdownerSynchronousProxy {
99 type Protocol = ShutdownerMarker;
100
101 fn from_client(value: fidl::endpoints::ClientEnd<ShutdownerMarker>) -> Self {
102 Self::new(value.into_channel())
103 }
104}
105
106#[derive(Debug, Clone)]
107pub struct ShutdownerProxy {
108 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
109}
110
111impl fidl::endpoints::Proxy for ShutdownerProxy {
112 type Protocol = ShutdownerMarker;
113
114 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
115 Self::new(inner)
116 }
117
118 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
119 self.client.into_channel().map_err(|client| Self { client })
120 }
121
122 fn as_channel(&self) -> &::fidl::AsyncChannel {
123 self.client.as_channel()
124 }
125}
126
127impl ShutdownerProxy {
128 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
130 let protocol_name = <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
131 Self { client: fidl::client::Client::new(channel, protocol_name) }
132 }
133
134 pub fn take_event_stream(&self) -> ShutdownerEventStream {
140 ShutdownerEventStream { event_receiver: self.client.take_event_receiver() }
141 }
142
143 pub fn r#shutdown(&self) -> Result<(), fidl::Error> {
144 ShutdownerProxyInterface::r#shutdown(self)
145 }
146}
147
148impl ShutdownerProxyInterface for ShutdownerProxy {
149 fn r#shutdown(&self) -> Result<(), fidl::Error> {
150 self.client.send::<fidl::encoding::EmptyPayload>(
151 (),
152 0x4da8a4e818bef187,
153 fidl::encoding::DynamicFlags::empty(),
154 )
155 }
156}
157
158pub struct ShutdownerEventStream {
159 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
160}
161
162impl std::marker::Unpin for ShutdownerEventStream {}
163
164impl futures::stream::FusedStream for ShutdownerEventStream {
165 fn is_terminated(&self) -> bool {
166 self.event_receiver.is_terminated()
167 }
168}
169
170impl futures::Stream for ShutdownerEventStream {
171 type Item = Result<ShutdownerEvent, fidl::Error>;
172
173 fn poll_next(
174 mut self: std::pin::Pin<&mut Self>,
175 cx: &mut std::task::Context<'_>,
176 ) -> std::task::Poll<Option<Self::Item>> {
177 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
178 &mut self.event_receiver,
179 cx
180 )?) {
181 Some(buf) => std::task::Poll::Ready(Some(ShutdownerEvent::decode(buf))),
182 None => std::task::Poll::Ready(None),
183 }
184 }
185}
186
187#[derive(Debug)]
188pub enum ShutdownerEvent {}
189
190impl ShutdownerEvent {
191 fn decode(
193 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
194 ) -> Result<ShutdownerEvent, fidl::Error> {
195 let (bytes, _handles) = buf.split_mut();
196 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
197 debug_assert_eq!(tx_header.tx_id, 0);
198 match tx_header.ordinal {
199 _ => Err(fidl::Error::UnknownOrdinal {
200 ordinal: tx_header.ordinal,
201 protocol_name: <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
202 }),
203 }
204 }
205}
206
207pub struct ShutdownerRequestStream {
209 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
210 is_terminated: bool,
211}
212
213impl std::marker::Unpin for ShutdownerRequestStream {}
214
215impl futures::stream::FusedStream for ShutdownerRequestStream {
216 fn is_terminated(&self) -> bool {
217 self.is_terminated
218 }
219}
220
221impl fidl::endpoints::RequestStream for ShutdownerRequestStream {
222 type Protocol = ShutdownerMarker;
223 type ControlHandle = ShutdownerControlHandle;
224
225 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
226 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
227 }
228
229 fn control_handle(&self) -> Self::ControlHandle {
230 ShutdownerControlHandle { inner: self.inner.clone() }
231 }
232
233 fn into_inner(
234 self,
235 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
236 {
237 (self.inner, self.is_terminated)
238 }
239
240 fn from_inner(
241 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
242 is_terminated: bool,
243 ) -> Self {
244 Self { inner, is_terminated }
245 }
246}
247
248impl futures::Stream for ShutdownerRequestStream {
249 type Item = Result<ShutdownerRequest, fidl::Error>;
250
251 fn poll_next(
252 mut self: std::pin::Pin<&mut Self>,
253 cx: &mut std::task::Context<'_>,
254 ) -> std::task::Poll<Option<Self::Item>> {
255 let this = &mut *self;
256 if this.inner.check_shutdown(cx) {
257 this.is_terminated = true;
258 return std::task::Poll::Ready(None);
259 }
260 if this.is_terminated {
261 panic!("polled ShutdownerRequestStream after completion");
262 }
263 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
264 |bytes, handles| {
265 match this.inner.channel().read_etc(cx, bytes, handles) {
266 std::task::Poll::Ready(Ok(())) => {}
267 std::task::Poll::Pending => return std::task::Poll::Pending,
268 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
269 this.is_terminated = true;
270 return std::task::Poll::Ready(None);
271 }
272 std::task::Poll::Ready(Err(e)) => {
273 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
274 e.into(),
275 ))))
276 }
277 }
278
279 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
281
282 std::task::Poll::Ready(Some(match header.ordinal {
283 0x4da8a4e818bef187 => {
284 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
285 let mut req = fidl::new_empty!(
286 fidl::encoding::EmptyPayload,
287 fidl::encoding::DefaultFuchsiaResourceDialect
288 );
289 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
290 let control_handle = ShutdownerControlHandle { inner: this.inner.clone() };
291 Ok(ShutdownerRequest::Shutdown { control_handle })
292 }
293 _ => Err(fidl::Error::UnknownOrdinal {
294 ordinal: header.ordinal,
295 protocol_name:
296 <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
297 }),
298 }))
299 },
300 )
301 }
302}
303
304#[derive(Debug)]
306pub enum ShutdownerRequest {
307 Shutdown { control_handle: ShutdownerControlHandle },
308}
309
310impl ShutdownerRequest {
311 #[allow(irrefutable_let_patterns)]
312 pub fn into_shutdown(self) -> Option<(ShutdownerControlHandle)> {
313 if let ShutdownerRequest::Shutdown { control_handle } = self {
314 Some((control_handle))
315 } else {
316 None
317 }
318 }
319
320 pub fn method_name(&self) -> &'static str {
322 match *self {
323 ShutdownerRequest::Shutdown { .. } => "shutdown",
324 }
325 }
326}
327
328#[derive(Debug, Clone)]
329pub struct ShutdownerControlHandle {
330 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
331}
332
333impl fidl::endpoints::ControlHandle for ShutdownerControlHandle {
334 fn shutdown(&self) {
335 self.inner.shutdown()
336 }
337 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
338 self.inner.shutdown_with_epitaph(status)
339 }
340
341 fn is_closed(&self) -> bool {
342 self.inner.channel().is_closed()
343 }
344 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
345 self.inner.channel().on_closed()
346 }
347
348 #[cfg(target_os = "fuchsia")]
349 fn signal_peer(
350 &self,
351 clear_mask: zx::Signals,
352 set_mask: zx::Signals,
353 ) -> Result<(), zx_status::Status> {
354 use fidl::Peered;
355 self.inner.channel().signal_peer(clear_mask, set_mask)
356 }
357}
358
359impl ShutdownerControlHandle {}
360
361mod internal {
362 use super::*;
363}