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