Skip to main content

cidre/vn/
request.rs

1use crate::{arc, blocks, cg, define_obj_type, ns, objc, vn};
2
3define_obj_type!(
4    #[doc(alias = "VNRequest")]
5    pub Request(ns::Id)
6);
7
8/// A block that is executed at the completion of a request.
9#[doc(alias = "VNRequestCompletionHandler")]
10pub type RequestCh<R = Request> = blocks::EscBlock<fn(request: &mut R, error: Option<&ns::Error>)>;
11
12impl Request {
13    /// The specific algorithm or implementation revision that is to be used to perform the request.
14    #[objc::msg_send(revision)]
15    pub fn revision(&self) -> usize;
16
17    #[objc::msg_send(setRevision:)]
18    pub fn set_revision(&mut self, value: usize);
19
20    #[objc::msg_send(usesCPUOnly)]
21    pub fn uses_cpu_only(&self) -> bool;
22
23    #[objc::msg_send(setUsesCPUOnly:)]
24    pub fn set_uses_cpu_only(&mut self, value: bool);
25
26    #[objc::msg_send(results)]
27    pub fn results(&self) -> Option<arc::R<ns::Array<vn::Observation>>>;
28
29    #[objc::msg_send(completionHandler)]
30    pub fn completion_handler(&self) -> Option<arc::R<RequestCh>>;
31
32    #[objc::msg_send(preferBackgroundProcessing)]
33    pub fn prefer_background_processing(&self) -> bool;
34
35    #[objc::msg_send(setPreferBackgroundProcessing:)]
36    pub fn set_prefer_background_processing(&mut self, val: bool);
37
38    #[objc::msg_send(cancel)]
39    pub fn cancel(&mut self);
40
41    pub const REVISION_UNSPECIFIED: usize = 0;
42}
43
44define_obj_type!(
45    #[doc(alias = "VNImageBasedRequest")]
46    pub ImageBasedRequest(Request)
47);
48
49impl ImageBasedRequest {
50    /// The region of the image in which the request will be performed.
51    /// The rectangle is normalized to the dimensions of the image being
52    /// processed and has its origin specified relative to the image's lower-left corner.
53    ///
54    /// The default value for this property is { { 0, 0 }, { 1, 1 } }.  Setting this
55    /// property to a rectangle that is outside of the normalized coordinate space will
56    /// be accepted but result in the request failing to be performed.
57    #[objc::msg_send(regionOfInterest)]
58    pub fn region_of_interest(&self) -> cg::Rect;
59
60    #[objc::msg_send(setRegionOfInterest:)]
61    pub fn set_region_of_interest(&mut self, value: cg::Rect);
62}
63
64define_obj_type!(
65    #[doc(alias = "VNDetectHorizonRequest")]
66    pub DetectHorizonRequest(ImageBasedRequest),
67    VN_DETECT_HORIZON_REQUEST
68);
69
70impl DetectHorizonRequest {
71    pub const REVISION_1: usize = 1;
72
73    #[objc::msg_send(results)]
74    pub fn results(&self) -> Option<arc::R<ns::Array<vn::HorizonObservation>>>;
75}
76
77#[doc(alias = "VNRequestProgressHandler")]
78pub type RequestProgressHandler =
79    blocks::EscBlock<fn(request: &Request, fraction_completed: f64, error: Option<&ns::Error>)>;
80
81#[objc::protocol(VNRequestProgressProviding)]
82pub trait RequestProgressProviding: objc::Obj {
83    #[objc::msg_send(progressHandler)]
84    fn progress_handler(&self) -> Option<arc::R<RequestProgressHandler>>;
85
86    #[objc::msg_send(setProgressHandler:)]
87    fn set_progress_handler(&mut self, handler: &mut RequestProgressHandler);
88
89    #[objc::msg_send(indeterminate)]
90    fn indeterminate(&self) -> bool;
91}
92
93unsafe extern "C" {
94    static VN_DETECT_HORIZON_REQUEST: &'static objc::Class<DetectHorizonRequest>;
95}