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