Skip to content

Commit

Permalink
add vn::RequestProgressProviding protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Dec 5, 2024
1 parent a74fe97 commit 999d83e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cidre/src/vn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub use request::DetectHorizonRequest;
pub use request::ImageBasedRequest;
pub use request::Request;
pub use request::RequestCh;
pub use request::RequestProgressHandler;
pub use request::RequestProgressProviding;
pub use request::RequestProgressProvidingImpl;

mod request_handler;
pub use request_handler::ImageRequestHandler;
Expand Down
7 changes: 6 additions & 1 deletion cidre/src/vn/recognize_text_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ define_obj_type!(
VN_RECOGNIZE_TEXT_REQUEST
);

impl vn::RequestProgressProviding for RecognizeTextRequest {}

impl RecognizeTextRequest {
/// only supports English
pub const REVISION_1: usize = 1;
Expand Down Expand Up @@ -117,7 +119,7 @@ extern "C" {

#[cfg(test)]
mod tests {
use crate::{ns, vn};
use crate::{ns, vn, vn::RequestProgressProviding};

#[test]
fn basics() {
Expand All @@ -135,6 +137,9 @@ mod tests {

assert!(request.custom_words().is_empty());

assert!(request.progress_handler().is_none());
assert!(!request.indeterminate());

// test if api throws...

request.set_min_text_height(-10.0);
Expand Down
16 changes: 16 additions & 0 deletions cidre/src/vn/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ impl DetectHorizonRequest {
pub fn results(&self) -> Option<arc::R<ns::Array<vn::HorizonObservation>>>;
}

#[doc(alias = "VNRequestProgressHandler")]
pub type RequestProgressHandler =
blocks::EscBlock<fn(request: &Request, fraction_completed: f64, error: Option<&ns::Error>)>;

#[objc::protocol(VNRequestProgressProviding)]
pub trait RequestProgressProviding: objc::Obj {
#[objc::msg_send(progressHandler)]
fn progress_handler(&self) -> Option<arc::R<RequestProgressHandler>>;

#[objc::msg_send(setProgressHandler:)]
fn set_progress_handler(&mut self, handler: &mut RequestProgressHandler);

#[objc::msg_send(indeterminate)]
fn indeterminate(&self) -> bool;
}

#[link(name = "vn", kind = "static")]
extern "C" {
static VN_DETECT_HORIZON_REQUEST: &'static objc::Class<DetectHorizonRequest>;
Expand Down

0 comments on commit 999d83e

Please # to comment.