fidl_test_persistence_factory/
fidl_test_persistence_factory.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_persistence_factory__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ControllerMarker;
16
17impl fidl::endpoints::ProtocolMarker for ControllerMarker {
18 type Proxy = ControllerProxy;
19 type RequestStream = ControllerRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = ControllerSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "test.persistence.factory.Controller";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for ControllerMarker {}
26
27pub trait ControllerProxyInterface: Send + Sync {
28 type SetUpdateCompletedResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29 fn r#set_update_completed(&self) -> Self::SetUpdateCompletedResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct ControllerSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for ControllerSynchronousProxy {
39 type Proxy = ControllerProxy;
40 type Protocol = ControllerMarker;
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 ControllerSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 let protocol_name = <ControllerMarker 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<ControllerEvent, fidl::Error> {
72 ControllerEvent::decode(self.client.wait_for_event(deadline)?)
73 }
74
75 pub fn r#set_update_completed(
77 &self,
78 ___deadline: zx::MonotonicInstant,
79 ) -> Result<(), fidl::Error> {
80 let _response = self.client.send_query::<
81 fidl::encoding::EmptyPayload,
82 fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
83 >(
84 (),
85 0x5484f071a04be31,
86 fidl::encoding::DynamicFlags::FLEXIBLE,
87 ___deadline,
88 )?
89 .into_result::<ControllerMarker>("set_update_completed")?;
90 Ok(_response)
91 }
92}
93
94#[cfg(target_os = "fuchsia")]
95impl From<ControllerSynchronousProxy> for zx::Handle {
96 fn from(value: ControllerSynchronousProxy) -> Self {
97 value.into_channel().into()
98 }
99}
100
101#[cfg(target_os = "fuchsia")]
102impl From<fidl::Channel> for ControllerSynchronousProxy {
103 fn from(value: fidl::Channel) -> Self {
104 Self::new(value)
105 }
106}
107
108#[cfg(target_os = "fuchsia")]
109impl fidl::endpoints::FromClient for ControllerSynchronousProxy {
110 type Protocol = ControllerMarker;
111
112 fn from_client(value: fidl::endpoints::ClientEnd<ControllerMarker>) -> Self {
113 Self::new(value.into_channel())
114 }
115}
116
117#[derive(Debug, Clone)]
118pub struct ControllerProxy {
119 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
120}
121
122impl fidl::endpoints::Proxy for ControllerProxy {
123 type Protocol = ControllerMarker;
124
125 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
126 Self::new(inner)
127 }
128
129 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
130 self.client.into_channel().map_err(|client| Self { client })
131 }
132
133 fn as_channel(&self) -> &::fidl::AsyncChannel {
134 self.client.as_channel()
135 }
136}
137
138impl ControllerProxy {
139 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
141 let protocol_name = <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
142 Self { client: fidl::client::Client::new(channel, protocol_name) }
143 }
144
145 pub fn take_event_stream(&self) -> ControllerEventStream {
151 ControllerEventStream { event_receiver: self.client.take_event_receiver() }
152 }
153
154 pub fn r#set_update_completed(
156 &self,
157 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
158 ControllerProxyInterface::r#set_update_completed(self)
159 }
160}
161
162impl ControllerProxyInterface for ControllerProxy {
163 type SetUpdateCompletedResponseFut =
164 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
165 fn r#set_update_completed(&self) -> Self::SetUpdateCompletedResponseFut {
166 fn _decode(
167 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
168 ) -> Result<(), fidl::Error> {
169 let _response = fidl::client::decode_transaction_body::<
170 fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
171 fidl::encoding::DefaultFuchsiaResourceDialect,
172 0x5484f071a04be31,
173 >(_buf?)?
174 .into_result::<ControllerMarker>("set_update_completed")?;
175 Ok(_response)
176 }
177 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
178 (),
179 0x5484f071a04be31,
180 fidl::encoding::DynamicFlags::FLEXIBLE,
181 _decode,
182 )
183 }
184}
185
186pub struct ControllerEventStream {
187 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
188}
189
190impl std::marker::Unpin for ControllerEventStream {}
191
192impl futures::stream::FusedStream for ControllerEventStream {
193 fn is_terminated(&self) -> bool {
194 self.event_receiver.is_terminated()
195 }
196}
197
198impl futures::Stream for ControllerEventStream {
199 type Item = Result<ControllerEvent, fidl::Error>;
200
201 fn poll_next(
202 mut self: std::pin::Pin<&mut Self>,
203 cx: &mut std::task::Context<'_>,
204 ) -> std::task::Poll<Option<Self::Item>> {
205 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
206 &mut self.event_receiver,
207 cx
208 )?) {
209 Some(buf) => std::task::Poll::Ready(Some(ControllerEvent::decode(buf))),
210 None => std::task::Poll::Ready(None),
211 }
212 }
213}
214
215#[derive(Debug)]
216pub enum ControllerEvent {
217 #[non_exhaustive]
218 _UnknownEvent {
219 ordinal: u64,
221 },
222}
223
224impl ControllerEvent {
225 fn decode(
227 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
228 ) -> Result<ControllerEvent, fidl::Error> {
229 let (bytes, _handles) = buf.split_mut();
230 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
231 debug_assert_eq!(tx_header.tx_id, 0);
232 match tx_header.ordinal {
233 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
234 Ok(ControllerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
235 }
236 _ => Err(fidl::Error::UnknownOrdinal {
237 ordinal: tx_header.ordinal,
238 protocol_name: <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
239 }),
240 }
241 }
242}
243
244pub struct ControllerRequestStream {
246 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
247 is_terminated: bool,
248}
249
250impl std::marker::Unpin for ControllerRequestStream {}
251
252impl futures::stream::FusedStream for ControllerRequestStream {
253 fn is_terminated(&self) -> bool {
254 self.is_terminated
255 }
256}
257
258impl fidl::endpoints::RequestStream for ControllerRequestStream {
259 type Protocol = ControllerMarker;
260 type ControlHandle = ControllerControlHandle;
261
262 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
263 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
264 }
265
266 fn control_handle(&self) -> Self::ControlHandle {
267 ControllerControlHandle { inner: self.inner.clone() }
268 }
269
270 fn into_inner(
271 self,
272 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
273 {
274 (self.inner, self.is_terminated)
275 }
276
277 fn from_inner(
278 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
279 is_terminated: bool,
280 ) -> Self {
281 Self { inner, is_terminated }
282 }
283}
284
285impl futures::Stream for ControllerRequestStream {
286 type Item = Result<ControllerRequest, fidl::Error>;
287
288 fn poll_next(
289 mut self: std::pin::Pin<&mut Self>,
290 cx: &mut std::task::Context<'_>,
291 ) -> std::task::Poll<Option<Self::Item>> {
292 let this = &mut *self;
293 if this.inner.check_shutdown(cx) {
294 this.is_terminated = true;
295 return std::task::Poll::Ready(None);
296 }
297 if this.is_terminated {
298 panic!("polled ControllerRequestStream after completion");
299 }
300 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
301 |bytes, handles| {
302 match this.inner.channel().read_etc(cx, bytes, handles) {
303 std::task::Poll::Ready(Ok(())) => {}
304 std::task::Poll::Pending => return std::task::Poll::Pending,
305 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
306 this.is_terminated = true;
307 return std::task::Poll::Ready(None);
308 }
309 std::task::Poll::Ready(Err(e)) => {
310 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
311 e.into(),
312 ))))
313 }
314 }
315
316 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
318
319 std::task::Poll::Ready(Some(match header.ordinal {
320 0x5484f071a04be31 => {
321 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
322 let mut req = fidl::new_empty!(
323 fidl::encoding::EmptyPayload,
324 fidl::encoding::DefaultFuchsiaResourceDialect
325 );
326 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
327 let control_handle = ControllerControlHandle { inner: this.inner.clone() };
328 Ok(ControllerRequest::SetUpdateCompleted {
329 responder: ControllerSetUpdateCompletedResponder {
330 control_handle: std::mem::ManuallyDrop::new(control_handle),
331 tx_id: header.tx_id,
332 },
333 })
334 }
335 _ if header.tx_id == 0
336 && header
337 .dynamic_flags()
338 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
339 {
340 Ok(ControllerRequest::_UnknownMethod {
341 ordinal: header.ordinal,
342 control_handle: ControllerControlHandle { inner: this.inner.clone() },
343 method_type: fidl::MethodType::OneWay,
344 })
345 }
346 _ if header
347 .dynamic_flags()
348 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
349 {
350 this.inner.send_framework_err(
351 fidl::encoding::FrameworkErr::UnknownMethod,
352 header.tx_id,
353 header.ordinal,
354 header.dynamic_flags(),
355 (bytes, handles),
356 )?;
357 Ok(ControllerRequest::_UnknownMethod {
358 ordinal: header.ordinal,
359 control_handle: ControllerControlHandle { inner: this.inner.clone() },
360 method_type: fidl::MethodType::TwoWay,
361 })
362 }
363 _ => Err(fidl::Error::UnknownOrdinal {
364 ordinal: header.ordinal,
365 protocol_name:
366 <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
367 }),
368 }))
369 },
370 )
371 }
372}
373
374#[derive(Debug)]
376pub enum ControllerRequest {
377 SetUpdateCompleted { responder: ControllerSetUpdateCompletedResponder },
379 #[non_exhaustive]
381 _UnknownMethod {
382 ordinal: u64,
384 control_handle: ControllerControlHandle,
385 method_type: fidl::MethodType,
386 },
387}
388
389impl ControllerRequest {
390 #[allow(irrefutable_let_patterns)]
391 pub fn into_set_update_completed(self) -> Option<(ControllerSetUpdateCompletedResponder)> {
392 if let ControllerRequest::SetUpdateCompleted { responder } = self {
393 Some((responder))
394 } else {
395 None
396 }
397 }
398
399 pub fn method_name(&self) -> &'static str {
401 match *self {
402 ControllerRequest::SetUpdateCompleted { .. } => "set_update_completed",
403 ControllerRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
404 "unknown one-way method"
405 }
406 ControllerRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
407 "unknown two-way method"
408 }
409 }
410 }
411}
412
413#[derive(Debug, Clone)]
414pub struct ControllerControlHandle {
415 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
416}
417
418impl fidl::endpoints::ControlHandle for ControllerControlHandle {
419 fn shutdown(&self) {
420 self.inner.shutdown()
421 }
422 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
423 self.inner.shutdown_with_epitaph(status)
424 }
425
426 fn is_closed(&self) -> bool {
427 self.inner.channel().is_closed()
428 }
429 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
430 self.inner.channel().on_closed()
431 }
432
433 #[cfg(target_os = "fuchsia")]
434 fn signal_peer(
435 &self,
436 clear_mask: zx::Signals,
437 set_mask: zx::Signals,
438 ) -> Result<(), zx_status::Status> {
439 use fidl::Peered;
440 self.inner.channel().signal_peer(clear_mask, set_mask)
441 }
442}
443
444impl ControllerControlHandle {}
445
446#[must_use = "FIDL methods require a response to be sent"]
447#[derive(Debug)]
448pub struct ControllerSetUpdateCompletedResponder {
449 control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
450 tx_id: u32,
451}
452
453impl std::ops::Drop for ControllerSetUpdateCompletedResponder {
457 fn drop(&mut self) {
458 self.control_handle.shutdown();
459 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
461 }
462}
463
464impl fidl::endpoints::Responder for ControllerSetUpdateCompletedResponder {
465 type ControlHandle = ControllerControlHandle;
466
467 fn control_handle(&self) -> &ControllerControlHandle {
468 &self.control_handle
469 }
470
471 fn drop_without_shutdown(mut self) {
472 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
474 std::mem::forget(self);
476 }
477}
478
479impl ControllerSetUpdateCompletedResponder {
480 pub fn send(self) -> Result<(), fidl::Error> {
484 let _result = self.send_raw();
485 if _result.is_err() {
486 self.control_handle.shutdown();
487 }
488 self.drop_without_shutdown();
489 _result
490 }
491
492 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
494 let _result = self.send_raw();
495 self.drop_without_shutdown();
496 _result
497 }
498
499 fn send_raw(&self) -> Result<(), fidl::Error> {
500 self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
501 fidl::encoding::Flexible::new(()),
502 self.tx_id,
503 0x5484f071a04be31,
504 fidl::encoding::DynamicFlags::FLEXIBLE,
505 )
506 }
507}
508
509mod internal {
510 use super::*;
511}