Skip to main content

fidl_componentmanager_test/
fidl_componentmanager_test.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![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_componentmanager_test__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct TestOutcomeReportMarker;
16
17impl fidl::endpoints::ProtocolMarker for TestOutcomeReportMarker {
18    type Proxy = TestOutcomeReportProxy;
19    type RequestStream = TestOutcomeReportRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = TestOutcomeReportSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "componentmanager.test.TestOutcomeReport";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for TestOutcomeReportMarker {}
26
27pub trait TestOutcomeReportProxyInterface: Send + Sync {
28    type ReportResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29    fn r#report(&self, backstop: i64, current_time: i64) -> Self::ReportResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct TestOutcomeReportSynchronousProxy {
34    client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for TestOutcomeReportSynchronousProxy {
39    type Proxy = TestOutcomeReportProxy;
40    type Protocol = TestOutcomeReportMarker;
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 TestOutcomeReportSynchronousProxy {
57    pub fn new(channel: fidl::Channel) -> Self {
58        Self { client: fidl::client::sync::Client::new(channel) }
59    }
60
61    pub fn into_channel(self) -> fidl::Channel {
62        self.client.into_channel()
63    }
64
65    /// Waits until an event arrives and returns it. It is safe for other
66    /// threads to make concurrent requests while waiting for an event.
67    pub fn wait_for_event(
68        &self,
69        deadline: zx::MonotonicInstant,
70    ) -> Result<TestOutcomeReportEvent, fidl::Error> {
71        TestOutcomeReportEvent::decode(
72            self.client.wait_for_event::<TestOutcomeReportMarker>(deadline)?,
73        )
74    }
75
76    pub fn r#report(
77        &self,
78        mut backstop: i64,
79        mut current_time: i64,
80        ___deadline: zx::MonotonicInstant,
81    ) -> Result<(), fidl::Error> {
82        let _response = self.client.send_query::<
83            TestOutcomeReportReportRequest,
84            fidl::encoding::EmptyPayload,
85            TestOutcomeReportMarker,
86        >(
87            (backstop, current_time,),
88            0xeab49d3f96e4950,
89            fidl::encoding::DynamicFlags::empty(),
90            ___deadline,
91        )?;
92        Ok(_response)
93    }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl From<TestOutcomeReportSynchronousProxy> for zx::NullableHandle {
98    fn from(value: TestOutcomeReportSynchronousProxy) -> Self {
99        value.into_channel().into()
100    }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<fidl::Channel> for TestOutcomeReportSynchronousProxy {
105    fn from(value: fidl::Channel) -> Self {
106        Self::new(value)
107    }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl fidl::endpoints::FromClient for TestOutcomeReportSynchronousProxy {
112    type Protocol = TestOutcomeReportMarker;
113
114    fn from_client(value: fidl::endpoints::ClientEnd<TestOutcomeReportMarker>) -> Self {
115        Self::new(value.into_channel())
116    }
117}
118
119#[derive(Debug, Clone)]
120pub struct TestOutcomeReportProxy {
121    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
122}
123
124impl fidl::endpoints::Proxy for TestOutcomeReportProxy {
125    type Protocol = TestOutcomeReportMarker;
126
127    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
128        Self::new(inner)
129    }
130
131    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
132        self.client.into_channel().map_err(|client| Self { client })
133    }
134
135    fn as_channel(&self) -> &::fidl::AsyncChannel {
136        self.client.as_channel()
137    }
138}
139
140impl TestOutcomeReportProxy {
141    /// Create a new Proxy for componentmanager.test/TestOutcomeReport.
142    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
143        let protocol_name =
144            <TestOutcomeReportMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
145        Self { client: fidl::client::Client::new(channel, protocol_name) }
146    }
147
148    /// Get a Stream of events from the remote end of the protocol.
149    ///
150    /// # Panics
151    ///
152    /// Panics if the event stream was already taken.
153    pub fn take_event_stream(&self) -> TestOutcomeReportEventStream {
154        TestOutcomeReportEventStream { event_receiver: self.client.take_event_receiver() }
155    }
156
157    pub fn r#report(
158        &self,
159        mut backstop: i64,
160        mut current_time: i64,
161    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
162        TestOutcomeReportProxyInterface::r#report(self, backstop, current_time)
163    }
164}
165
166impl TestOutcomeReportProxyInterface for TestOutcomeReportProxy {
167    type ReportResponseFut =
168        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
169    fn r#report(&self, mut backstop: i64, mut current_time: i64) -> Self::ReportResponseFut {
170        fn _decode(
171            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
172        ) -> Result<(), fidl::Error> {
173            let _response = fidl::client::decode_transaction_body::<
174                fidl::encoding::EmptyPayload,
175                fidl::encoding::DefaultFuchsiaResourceDialect,
176                0xeab49d3f96e4950,
177            >(_buf?)?;
178            Ok(_response)
179        }
180        self.client.send_query_and_decode::<TestOutcomeReportReportRequest, ()>(
181            (backstop, current_time),
182            0xeab49d3f96e4950,
183            fidl::encoding::DynamicFlags::empty(),
184            _decode,
185        )
186    }
187}
188
189pub struct TestOutcomeReportEventStream {
190    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
191}
192
193impl std::marker::Unpin for TestOutcomeReportEventStream {}
194
195impl futures::stream::FusedStream for TestOutcomeReportEventStream {
196    fn is_terminated(&self) -> bool {
197        self.event_receiver.is_terminated()
198    }
199}
200
201impl futures::Stream for TestOutcomeReportEventStream {
202    type Item = Result<TestOutcomeReportEvent, fidl::Error>;
203
204    fn poll_next(
205        mut self: std::pin::Pin<&mut Self>,
206        cx: &mut std::task::Context<'_>,
207    ) -> std::task::Poll<Option<Self::Item>> {
208        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
209            &mut self.event_receiver,
210            cx
211        )?) {
212            Some(buf) => std::task::Poll::Ready(Some(TestOutcomeReportEvent::decode(buf))),
213            None => std::task::Poll::Ready(None),
214        }
215    }
216}
217
218#[derive(Debug)]
219pub enum TestOutcomeReportEvent {}
220
221impl TestOutcomeReportEvent {
222    /// Decodes a message buffer as a [`TestOutcomeReportEvent`].
223    fn decode(
224        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
225    ) -> Result<TestOutcomeReportEvent, fidl::Error> {
226        let (bytes, _handles) = buf.split_mut();
227        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
228        debug_assert_eq!(tx_header.tx_id, 0);
229        match tx_header.ordinal {
230            _ => Err(fidl::Error::UnknownOrdinal {
231                ordinal: tx_header.ordinal,
232                protocol_name:
233                    <TestOutcomeReportMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
234            }),
235        }
236    }
237}
238
239/// A Stream of incoming requests for componentmanager.test/TestOutcomeReport.
240pub struct TestOutcomeReportRequestStream {
241    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
242    is_terminated: bool,
243}
244
245impl std::marker::Unpin for TestOutcomeReportRequestStream {}
246
247impl futures::stream::FusedStream for TestOutcomeReportRequestStream {
248    fn is_terminated(&self) -> bool {
249        self.is_terminated
250    }
251}
252
253impl fidl::endpoints::RequestStream for TestOutcomeReportRequestStream {
254    type Protocol = TestOutcomeReportMarker;
255    type ControlHandle = TestOutcomeReportControlHandle;
256
257    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
258        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
259    }
260
261    fn control_handle(&self) -> Self::ControlHandle {
262        TestOutcomeReportControlHandle { inner: self.inner.clone() }
263    }
264
265    fn into_inner(
266        self,
267    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
268    {
269        (self.inner, self.is_terminated)
270    }
271
272    fn from_inner(
273        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
274        is_terminated: bool,
275    ) -> Self {
276        Self { inner, is_terminated }
277    }
278}
279
280impl futures::Stream for TestOutcomeReportRequestStream {
281    type Item = Result<TestOutcomeReportRequest, fidl::Error>;
282
283    fn poll_next(
284        mut self: std::pin::Pin<&mut Self>,
285        cx: &mut std::task::Context<'_>,
286    ) -> std::task::Poll<Option<Self::Item>> {
287        let this = &mut *self;
288        if this.inner.check_shutdown(cx) {
289            this.is_terminated = true;
290            return std::task::Poll::Ready(None);
291        }
292        if this.is_terminated {
293            panic!("polled TestOutcomeReportRequestStream after completion");
294        }
295        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
296            |bytes, handles| {
297                match this.inner.channel().read_etc(cx, bytes, handles) {
298                    std::task::Poll::Ready(Ok(())) => {}
299                    std::task::Poll::Pending => return std::task::Poll::Pending,
300                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
301                        this.is_terminated = true;
302                        return std::task::Poll::Ready(None);
303                    }
304                    std::task::Poll::Ready(Err(e)) => {
305                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
306                            e.into(),
307                        ))));
308                    }
309                }
310
311                // A message has been received from the channel
312                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
313
314                std::task::Poll::Ready(Some(match header.ordinal {
315                    0xeab49d3f96e4950 => {
316                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
317                        let mut req = fidl::new_empty!(
318                            TestOutcomeReportReportRequest,
319                            fidl::encoding::DefaultFuchsiaResourceDialect
320                        );
321                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<TestOutcomeReportReportRequest>(&header, _body_bytes, handles, &mut req)?;
322                        let control_handle =
323                            TestOutcomeReportControlHandle { inner: this.inner.clone() };
324                        Ok(TestOutcomeReportRequest::Report {
325                            backstop: req.backstop,
326                            current_time: req.current_time,
327
328                            responder: TestOutcomeReportReportResponder {
329                                control_handle: std::mem::ManuallyDrop::new(control_handle),
330                                tx_id: header.tx_id,
331                            },
332                        })
333                    }
334                    _ => Err(fidl::Error::UnknownOrdinal {
335                        ordinal: header.ordinal,
336                        protocol_name:
337                            <TestOutcomeReportMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
338                    }),
339                }))
340            },
341        )
342    }
343}
344
345#[derive(Debug)]
346pub enum TestOutcomeReportRequest {
347    Report { backstop: i64, current_time: i64, responder: TestOutcomeReportReportResponder },
348}
349
350impl TestOutcomeReportRequest {
351    #[allow(irrefutable_let_patterns)]
352    pub fn into_report(self) -> Option<(i64, i64, TestOutcomeReportReportResponder)> {
353        if let TestOutcomeReportRequest::Report { backstop, current_time, responder } = self {
354            Some((backstop, current_time, responder))
355        } else {
356            None
357        }
358    }
359
360    /// Name of the method defined in FIDL
361    pub fn method_name(&self) -> &'static str {
362        match *self {
363            TestOutcomeReportRequest::Report { .. } => "report",
364        }
365    }
366}
367
368#[derive(Debug, Clone)]
369pub struct TestOutcomeReportControlHandle {
370    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
371}
372
373impl fidl::endpoints::ControlHandle for TestOutcomeReportControlHandle {
374    fn shutdown(&self) {
375        self.inner.shutdown()
376    }
377
378    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
379        self.inner.shutdown_with_epitaph(status)
380    }
381
382    fn is_closed(&self) -> bool {
383        self.inner.channel().is_closed()
384    }
385    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
386        self.inner.channel().on_closed()
387    }
388
389    #[cfg(target_os = "fuchsia")]
390    fn signal_peer(
391        &self,
392        clear_mask: zx::Signals,
393        set_mask: zx::Signals,
394    ) -> Result<(), zx_status::Status> {
395        use fidl::Peered;
396        self.inner.channel().signal_peer(clear_mask, set_mask)
397    }
398}
399
400impl TestOutcomeReportControlHandle {}
401
402#[must_use = "FIDL methods require a response to be sent"]
403#[derive(Debug)]
404pub struct TestOutcomeReportReportResponder {
405    control_handle: std::mem::ManuallyDrop<TestOutcomeReportControlHandle>,
406    tx_id: u32,
407}
408
409/// Set the the channel to be shutdown (see [`TestOutcomeReportControlHandle::shutdown`])
410/// if the responder is dropped without sending a response, so that the client
411/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
412impl std::ops::Drop for TestOutcomeReportReportResponder {
413    fn drop(&mut self) {
414        self.control_handle.shutdown();
415        // Safety: drops once, never accessed again
416        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
417    }
418}
419
420impl fidl::endpoints::Responder for TestOutcomeReportReportResponder {
421    type ControlHandle = TestOutcomeReportControlHandle;
422
423    fn control_handle(&self) -> &TestOutcomeReportControlHandle {
424        &self.control_handle
425    }
426
427    fn drop_without_shutdown(mut self) {
428        // Safety: drops once, never accessed again due to mem::forget
429        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
430        // Prevent Drop from running (which would shut down the channel)
431        std::mem::forget(self);
432    }
433}
434
435impl TestOutcomeReportReportResponder {
436    /// Sends a response to the FIDL transaction.
437    ///
438    /// Sets the channel to shutdown if an error occurs.
439    pub fn send(self) -> Result<(), fidl::Error> {
440        let _result = self.send_raw();
441        if _result.is_err() {
442            self.control_handle.shutdown();
443        }
444        self.drop_without_shutdown();
445        _result
446    }
447
448    /// Similar to "send" but does not shutdown the channel if an error occurs.
449    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
450        let _result = self.send_raw();
451        self.drop_without_shutdown();
452        _result
453    }
454
455    fn send_raw(&self) -> Result<(), fidl::Error> {
456        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
457            (),
458            self.tx_id,
459            0xeab49d3f96e4950,
460            fidl::encoding::DynamicFlags::empty(),
461        )
462    }
463}
464
465mod internal {
466    use super::*;
467}