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