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