camera_get_twice/
camera_get_twice.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * SPDX-FileCopyrightText: 2023 Purism, SPC <https://puri.sm>
 *
 * SPDX-License-Identifier: MPL-2.0 OR LGPL-2.1-or-later
 */

/*! Try to acquire the same camera twice, but from two independent resources.
This needs a global lock to work.

TODO: this should be a test
*/

use vidi as camera;
use std::io;

fn main() -> io::Result<()> {
    let cameras_list = camera::actors::camera_list::spawn()?;
    
    let cameras = cameras_list.cameras();
    dbg!(&cameras);
    let camera = cameras_list.create(&cameras[0].info.id())
        .unwrap().unwrap();
    dbg!(camera.get_id());
    // FIXME: test, fail to acquire the same camera again.
    {
        let _q = camera.acquire();
        let cameras_list = camera::actors::camera_list::spawn()?;
        let camera2 = cameras_list.create(&cameras[0].info.id())
        .expect("No such camera").unwrap();
        assert!(camera2.acquire().is_err());
    }
    Ok(())
}