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