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 Self { client: fidl::client::sync::Client::new(channel) }
58 }
59
60 pub fn into_channel(self) -> fidl::Channel {
61 self.client.into_channel()
62 }
63
64 pub fn wait_for_event(
67 &self,
68 deadline: zx::MonotonicInstant,
69 ) -> Result<ShutdownerEvent, fidl::Error> {
70 ShutdownerEvent::decode(self.client.wait_for_event::<ShutdownerMarker>(deadline)?)
71 }
72
73 pub fn r#shutdown(&self) -> Result<(), fidl::Error> {
74 self.client.send::<fidl::encoding::EmptyPayload>(
75 (),
76 0x4da8a4e818bef187,
77 fidl::encoding::DynamicFlags::empty(),
78 )
79 }
80}
81
82#[cfg(target_os = "fuchsia")]
83impl From<ShutdownerSynchronousProxy> for zx::NullableHandle {
84 fn from(value: ShutdownerSynchronousProxy) -> Self {
85 value.into_channel().into()
86 }
87}
88
89#[cfg(target_os = "fuchsia")]
90impl From<fidl::Channel> for ShutdownerSynchronousProxy {
91 fn from(value: fidl::Channel) -> Self {
92 Self::new(value)
93 }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl fidl::endpoints::FromClient for ShutdownerSynchronousProxy {
98 type Protocol = ShutdownerMarker;
99
100 fn from_client(value: fidl::endpoints::ClientEnd<ShutdownerMarker>) -> Self {
101 Self::new(value.into_channel())
102 }
103}
104
105#[derive(Debug, Clone)]
106pub struct ShutdownerProxy {
107 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
108}
109
110impl fidl::endpoints::Proxy for ShutdownerProxy {
111 type Protocol = ShutdownerMarker;
112
113 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
114 Self::new(inner)
115 }
116
117 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
118 self.client.into_channel().map_err(|client| Self { client })
119 }
120
121 fn as_channel(&self) -> &::fidl::AsyncChannel {
122 self.client.as_channel()
123 }
124}
125
126impl ShutdownerProxy {
127 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
129 let protocol_name = <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
130 Self { client: fidl::client::Client::new(channel, protocol_name) }
131 }
132
133 pub fn take_event_stream(&self) -> ShutdownerEventStream {
139 ShutdownerEventStream { event_receiver: self.client.take_event_receiver() }
140 }
141
142 pub fn r#shutdown(&self) -> Result<(), fidl::Error> {
143 ShutdownerProxyInterface::r#shutdown(self)
144 }
145}
146
147impl ShutdownerProxyInterface for ShutdownerProxy {
148 fn r#shutdown(&self) -> Result<(), fidl::Error> {
149 self.client.send::<fidl::encoding::EmptyPayload>(
150 (),
151 0x4da8a4e818bef187,
152 fidl::encoding::DynamicFlags::empty(),
153 )
154 }
155}
156
157pub struct ShutdownerEventStream {
158 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
159}
160
161impl std::marker::Unpin for ShutdownerEventStream {}
162
163impl futures::stream::FusedStream for ShutdownerEventStream {
164 fn is_terminated(&self) -> bool {
165 self.event_receiver.is_terminated()
166 }
167}
168
169impl futures::Stream for ShutdownerEventStream {
170 type Item = Result<ShutdownerEvent, fidl::Error>;
171
172 fn poll_next(
173 mut self: std::pin::Pin<&mut Self>,
174 cx: &mut std::task::Context<'_>,
175 ) -> std::task::Poll<Option<Self::Item>> {
176 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
177 &mut self.event_receiver,
178 cx
179 )?) {
180 Some(buf) => std::task::Poll::Ready(Some(ShutdownerEvent::decode(buf))),
181 None => std::task::Poll::Ready(None),
182 }
183 }
184}
185
186#[derive(Debug)]
187pub enum ShutdownerEvent {}
188
189impl ShutdownerEvent {
190 fn decode(
192 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
193 ) -> Result<ShutdownerEvent, fidl::Error> {
194 let (bytes, _handles) = buf.split_mut();
195 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
196 debug_assert_eq!(tx_header.tx_id, 0);
197 match tx_header.ordinal {
198 _ => Err(fidl::Error::UnknownOrdinal {
199 ordinal: tx_header.ordinal,
200 protocol_name: <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
201 }),
202 }
203 }
204}
205
206pub struct ShutdownerRequestStream {
208 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
209 is_terminated: bool,
210}
211
212impl std::marker::Unpin for ShutdownerRequestStream {}
213
214impl futures::stream::FusedStream for ShutdownerRequestStream {
215 fn is_terminated(&self) -> bool {
216 self.is_terminated
217 }
218}
219
220impl fidl::endpoints::RequestStream for ShutdownerRequestStream {
221 type Protocol = ShutdownerMarker;
222 type ControlHandle = ShutdownerControlHandle;
223
224 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
225 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
226 }
227
228 fn control_handle(&self) -> Self::ControlHandle {
229 ShutdownerControlHandle { inner: self.inner.clone() }
230 }
231
232 fn into_inner(
233 self,
234 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
235 {
236 (self.inner, self.is_terminated)
237 }
238
239 fn from_inner(
240 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
241 is_terminated: bool,
242 ) -> Self {
243 Self { inner, is_terminated }
244 }
245}
246
247impl futures::Stream for ShutdownerRequestStream {
248 type Item = Result<ShutdownerRequest, fidl::Error>;
249
250 fn poll_next(
251 mut self: std::pin::Pin<&mut Self>,
252 cx: &mut std::task::Context<'_>,
253 ) -> std::task::Poll<Option<Self::Item>> {
254 let this = &mut *self;
255 if this.inner.check_shutdown(cx) {
256 this.is_terminated = true;
257 return std::task::Poll::Ready(None);
258 }
259 if this.is_terminated {
260 panic!("polled ShutdownerRequestStream after completion");
261 }
262 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
263 |bytes, handles| {
264 match this.inner.channel().read_etc(cx, bytes, handles) {
265 std::task::Poll::Ready(Ok(())) => {}
266 std::task::Poll::Pending => return std::task::Poll::Pending,
267 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
268 this.is_terminated = true;
269 return std::task::Poll::Ready(None);
270 }
271 std::task::Poll::Ready(Err(e)) => {
272 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
273 e.into(),
274 ))));
275 }
276 }
277
278 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
280
281 std::task::Poll::Ready(Some(match header.ordinal {
282 0x4da8a4e818bef187 => {
283 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
284 let mut req = fidl::new_empty!(
285 fidl::encoding::EmptyPayload,
286 fidl::encoding::DefaultFuchsiaResourceDialect
287 );
288 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
289 let control_handle = ShutdownerControlHandle { inner: this.inner.clone() };
290 Ok(ShutdownerRequest::Shutdown { control_handle })
291 }
292 _ => Err(fidl::Error::UnknownOrdinal {
293 ordinal: header.ordinal,
294 protocol_name:
295 <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
296 }),
297 }))
298 },
299 )
300 }
301}
302
303#[derive(Debug)]
305pub enum ShutdownerRequest {
306 Shutdown { control_handle: ShutdownerControlHandle },
307}
308
309impl ShutdownerRequest {
310 #[allow(irrefutable_let_patterns)]
311 pub fn into_shutdown(self) -> Option<(ShutdownerControlHandle)> {
312 if let ShutdownerRequest::Shutdown { control_handle } = self {
313 Some((control_handle))
314 } else {
315 None
316 }
317 }
318
319 pub fn method_name(&self) -> &'static str {
321 match *self {
322 ShutdownerRequest::Shutdown { .. } => "shutdown",
323 }
324 }
325}
326
327#[derive(Debug, Clone)]
328pub struct ShutdownerControlHandle {
329 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
330}
331
332impl fidl::endpoints::ControlHandle for ShutdownerControlHandle {
333 fn shutdown(&self) {
334 self.inner.shutdown()
335 }
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}