Skip to main content

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