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