objc2_vision/generated/VNRequest.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-ml")]
9use objc2_core_ml::*;
10use objc2_foundation::*;
11
12use crate::*;
13
14/// A block that is executed at the completion of a request.
15///
16/// The completion handler is called for each request when it is finished processing, before the performRequests call returns. When an array of multiple requests is executed with one performRequests call, each request's completion handler is invoked when that request has finished its processing. This invocation may therefore occur while other requests in the array are either still executing or waiting for execution. This allows, for example, UI to be updated while the first tasks are complete instead of having to wait that all requests have to finish. Note, however, that performRequests is not an asynchronous method, for which completion handlers are most typically used
17///
18/// Parameter `request`: The VNRequest that has been completed. The results of the request if no error was encountered are populated in the results array of the request.
19///
20/// Parameter `error`: The error that caused the request to fail, or nil if completed successfully.
21///
22/// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnrequestcompletionhandler?language=objc)
23#[cfg(feature = "block2")]
24pub type VNRequestCompletionHandler =
25 *mut block2::DynBlock<dyn Fn(NonNull<VNRequest>, *mut NSError)>;
26
27extern_class!(
28 /// VNRequest objects describe the operation to be performed as well as act as the recipient of the operation's resultant observations.
29 ///
30 /// VNRequest objects are instantiated in a pre-configured nominal state. Prior to sending a VNRequest to a request handler to perform a desired operation, the default configuration can be changed by modifying the values of VNRequest properties. The VNRequest class itself acts as a base class and is not meant to be directly instantiated.
31 ///
32 /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnrequest?language=objc)
33 #[unsafe(super(NSObject))]
34 #[derive(Debug, PartialEq, Eq, Hash)]
35 pub struct VNRequest;
36);
37
38extern_conformance!(
39 unsafe impl NSCopying for VNRequest {}
40);
41
42unsafe impl CopyingHelper for VNRequest {
43 type Result = Self;
44}
45
46extern_conformance!(
47 unsafe impl NSObjectProtocol for VNRequest {}
48);
49
50impl VNRequest {
51 extern_methods!(
52 /// Creates a new VNRequest with no completion handler.
53 #[unsafe(method(init))]
54 #[unsafe(method_family = init)]
55 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
56
57 #[cfg(feature = "block2")]
58 /// Creates a new VNRequest with an optional completion handler.
59 ///
60 ///
61 /// Parameter `completionHandler`: The block to be invoked after the request has completed its processing. The completion handler gets executed on the same dispatch queue as the request being executed.
62 #[unsafe(method(initWithCompletionHandler:))]
63 #[unsafe(method_family = init)]
64 pub unsafe fn initWithCompletionHandler(
65 this: Allocated<Self>,
66 completion_handler: VNRequestCompletionHandler,
67 ) -> Retained<Self>;
68
69 /// A hint used to minimize the resource burden of the request. Memory footprint, processing footprint and/or CPU/GPU contention will be reduced (depending on the request), at the potential cost of longer execution time. This can help, for example, with ensuring UI updates and rendering are not getting blocked by Vision processing.
70 #[unsafe(method(preferBackgroundProcessing))]
71 #[unsafe(method_family = none)]
72 pub unsafe fn preferBackgroundProcessing(&self) -> bool;
73
74 /// Setter for [`preferBackgroundProcessing`][Self::preferBackgroundProcessing].
75 #[unsafe(method(setPreferBackgroundProcessing:))]
76 #[unsafe(method_family = none)]
77 pub unsafe fn setPreferBackgroundProcessing(&self, prefer_background_processing: bool);
78
79 /// This property, if set to YES, signifies that the request should be performed exclusively on the CPU and not on the GPU. The default value is NO, which signifies that the request is free to leverage the GPU to accelerate any work the request may require.
80 #[deprecated]
81 #[unsafe(method(usesCPUOnly))]
82 #[unsafe(method_family = none)]
83 pub unsafe fn usesCPUOnly(&self) -> bool;
84
85 /// Setter for [`usesCPUOnly`][Self::usesCPUOnly].
86 #[deprecated]
87 #[unsafe(method(setUsesCPUOnly:))]
88 #[unsafe(method_family = none)]
89 pub unsafe fn setUsesCPUOnly(&self, uses_cpu_only: bool);
90
91 #[cfg(feature = "VNObservation")]
92 /// The collection of VNObservations generated by the processing of the request.
93 ///
94 /// The only valid time to access this property is after the request has been processed by a request handler. If the request failed, this property will be nil; otherwise, it will be an array of zero or more VNObservation subclasses specific to the VNRequest subclass.
95 #[unsafe(method(results))]
96 #[unsafe(method_family = none)]
97 pub unsafe fn results(&self) -> Option<Retained<NSArray<VNObservation>>>;
98
99 #[cfg(feature = "block2")]
100 /// The completion handler block that will be invoked after the request has completed processing.
101 #[unsafe(method(completionHandler))]
102 #[unsafe(method_family = none)]
103 pub unsafe fn completionHandler(&self) -> VNRequestCompletionHandler;
104
105 /// The specific algorithm or implementation revision that is to be used to perform the request.
106 #[unsafe(method(revision))]
107 #[unsafe(method_family = none)]
108 pub unsafe fn revision(&self) -> NSUInteger;
109
110 /// Setter for [`revision`][Self::revision].
111 #[unsafe(method(setRevision:))]
112 #[unsafe(method_family = none)]
113 pub unsafe fn setRevision(&self, revision: NSUInteger);
114
115 /// Provides the collection of currently-supported algorithm or implementation versions for the class of request.
116 ///
117 /// This method allows clients to introspect at runtime what capabilities are available for each class of VNRequest in the Vision framework.
118 #[unsafe(method(supportedRevisions))]
119 #[unsafe(method_family = none)]
120 pub unsafe fn supportedRevisions() -> Retained<NSIndexSet>;
121
122 /// Provides the revision of the request that was latest for the particular SDK that was linked with the client application.
123 #[unsafe(method(defaultRevision))]
124 #[unsafe(method_family = none)]
125 pub unsafe fn defaultRevision() -> NSUInteger;
126
127 /// Provides the current revision supported by the request.
128 #[unsafe(method(currentRevision))]
129 #[unsafe(method_family = none)]
130 pub unsafe fn currentRevision() -> NSUInteger;
131
132 /// Tries to abort the request as soon as possible. Results will be nil. The completionHandler (if present) will be called with an error of VNErrorRequestCancelled.
133 #[unsafe(method(cancel))]
134 #[unsafe(method_family = none)]
135 pub unsafe fn cancel(&self);
136 );
137}
138
139/// Methods declared on superclass `NSObject`.
140impl VNRequest {
141 extern_methods!(
142 #[unsafe(method(new))]
143 #[unsafe(method_family = new)]
144 pub unsafe fn new() -> Retained<Self>;
145 );
146}
147
148/// A value that indicates that the request revision is either unknown or not applicable.
149///
150/// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnrequestrevisionunspecified?language=objc)
151pub static VNRequestRevisionUnspecified: NSUInteger = 0;
152
153impl VNRequest {
154 extern_methods!(
155 #[cfg(all(feature = "VNTypes", feature = "objc2-core-ml"))]
156 /// Obtain the collection of compute device per stage that are supported by the request.
157 ///
158 /// This method's result is based on the current state of configuration of the target request at the time of the call.
159 ///
160 ///
161 /// Parameter `error`: The address of a variable that will be populated with the error that describes the failure. If the caller does not require this information, NULL can be passed.
162 ///
163 ///
164 /// Returns: A dictionary of per-stage supported compute devices, or `nil` if an error occurs.
165 #[unsafe(method(supportedComputeStageDevicesAndReturnError:_))]
166 #[unsafe(method_family = none)]
167 pub unsafe fn supportedComputeStageDevicesAndReturnError(
168 &self,
169 ) -> Result<
170 Retained<
171 NSDictionary<VNComputeStage, NSArray<ProtocolObject<dyn MLComputeDeviceProtocol>>>,
172 >,
173 Retained<NSError>,
174 >;
175
176 #[cfg(all(feature = "VNTypes", feature = "objc2-core-ml"))]
177 /// Determine what the currently configured compute device is for a specific compute stage.
178 ///
179 ///
180 /// Parameter `computeStage`: The compute stage to be introspected.
181 ///
182 ///
183 /// Returns: The currently assigned compute device, or `nil` if there is no explicit assignment.
184 #[unsafe(method(computeDeviceForComputeStage:))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn computeDeviceForComputeStage(
187 &self,
188 compute_stage: &VNComputeStage,
189 ) -> Option<Retained<ProtocolObject<dyn MLComputeDeviceProtocol>>>;
190
191 #[cfg(all(feature = "VNTypes", feature = "objc2-core-ml"))]
192 /// Assign a specific compute device for a compute stage.
193 ///
194 /// It is important to note that any compute device can be configured for a given compute stage. Only when the request is performed is the validity of the (compute device / compute stage) assignments checked. Valid compute devices for a request's compute stages can be obtained via `-supportedComputeStageDevicesAndReturnError:`.
195 ///
196 ///
197 /// Parameter `computeDevice`: The compute device to assign to the compute stage. Passing nil for this parameter will remove any explicit compute device assignment, allowing Vision to select which device to use.
198 ///
199 /// Parameter `computeStage`: The compute stage being configured.
200 #[unsafe(method(setComputeDevice:forComputeStage:))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn setComputeDevice_forComputeStage(
203 &self,
204 compute_device: Option<&ProtocolObject<dyn MLComputeDeviceProtocol>>,
205 compute_stage: &VNComputeStage,
206 );
207 );
208}
209
210extern_class!(
211 /// A request that will process the contents of a reference image.
212 ///
213 /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnimagebasedrequest?language=objc)
214 #[unsafe(super(VNRequest, NSObject))]
215 #[derive(Debug, PartialEq, Eq, Hash)]
216 pub struct VNImageBasedRequest;
217);
218
219extern_conformance!(
220 unsafe impl NSCopying for VNImageBasedRequest {}
221);
222
223unsafe impl CopyingHelper for VNImageBasedRequest {
224 type Result = Self;
225}
226
227extern_conformance!(
228 unsafe impl NSObjectProtocol for VNImageBasedRequest {}
229);
230
231impl VNImageBasedRequest {
232 extern_methods!(
233 #[cfg(feature = "objc2-core-foundation")]
234 /// The region of the image in which the request will be performed. The rectangle is normalized to the dimensions of the image being processed and has its origin specified relative to the image's lower-left corner.
235 ///
236 ///
237 /// The default value for this property is { { 0, 0 }, { 1, 1 } }. Setting this property to a rectangle that is outside of the normalized coordinate space will be accepted but result in the request failing to be performed.
238 #[unsafe(method(regionOfInterest))]
239 #[unsafe(method_family = none)]
240 pub unsafe fn regionOfInterest(&self) -> CGRect;
241
242 #[cfg(feature = "objc2-core-foundation")]
243 /// Setter for [`regionOfInterest`][Self::regionOfInterest].
244 #[unsafe(method(setRegionOfInterest:))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn setRegionOfInterest(&self, region_of_interest: CGRect);
247 );
248}
249
250/// Methods declared on superclass `VNRequest`.
251impl VNImageBasedRequest {
252 extern_methods!(
253 /// Creates a new VNRequest with no completion handler.
254 #[unsafe(method(init))]
255 #[unsafe(method_family = init)]
256 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
257
258 #[cfg(feature = "block2")]
259 /// Creates a new VNRequest with an optional completion handler.
260 ///
261 ///
262 /// Parameter `completionHandler`: The block to be invoked after the request has completed its processing. The completion handler gets executed on the same dispatch queue as the request being executed.
263 #[unsafe(method(initWithCompletionHandler:))]
264 #[unsafe(method_family = init)]
265 pub unsafe fn initWithCompletionHandler(
266 this: Allocated<Self>,
267 completion_handler: VNRequestCompletionHandler,
268 ) -> Retained<Self>;
269 );
270}
271
272/// Methods declared on superclass `NSObject`.
273impl VNImageBasedRequest {
274 extern_methods!(
275 #[unsafe(method(new))]
276 #[unsafe(method_family = new)]
277 pub unsafe fn new() -> Retained<Self>;
278 );
279}
280
281/// A block that is executed at intervals during the processing of a request.
282///
283/// Parameter `request`: The VNRequest that has been completed. The results of the request, if no error was encountered, are populated in the results array of the request.
284///
285/// Parameter `fractionCompleted`: When possible the request will report its progress between 0.0 and 1.0. If the requests indeterminate property is set, then this value is undefined.
286///
287/// Parameter `error`: The error that caused the request to fail, or nil if completed successfully.
288///
289/// The results in the request can be populated with partial results. The progressHandler can be called on a different dispatch queue than what the request was initiated from.
290///
291/// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnrequestprogresshandler?language=objc)
292#[cfg(feature = "block2")]
293pub type VNRequestProgressHandler =
294 *mut block2::DynBlock<dyn Fn(NonNull<VNRequest>, c_double, *mut NSError)>;
295
296extern_protocol!(
297 /// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrequestprogressproviding?language=objc)
298 pub unsafe trait VNRequestProgressProviding: NSObjectProtocol {
299 #[cfg(feature = "block2")]
300 /// Requests that support the VNRequestProgressProviding protocol would periodically call the progressHandler to report progress on longer running tasks.
301 ///
302 ///
303 /// The progessHandler is optional allowing clients of the request to report progress to the user and/or display or process partial results when they become available. Note that the progressHandler can be called on a different dispatch queue than what the request was initiated from.
304 #[unsafe(method(progressHandler))]
305 #[unsafe(method_family = none)]
306 unsafe fn progressHandler(&self) -> VNRequestProgressHandler;
307
308 #[cfg(feature = "block2")]
309 /// Setter for [`progressHandler`][Self::progressHandler].
310 #[unsafe(method(setProgressHandler:))]
311 #[unsafe(method_family = none)]
312 unsafe fn setProgressHandler(&self, progress_handler: VNRequestProgressHandler);
313
314 /// If a request cannot determine its progress in fractions completed, this property will be set.
315 ///
316 /// If this is set, it doesn't mean that the request will run forever just that the nature of the request is not broken down into identifiable fractions on which progress can be reported in increments. The progressHandler will nonetheless be called at suitable intervals.
317 #[unsafe(method(indeterminate))]
318 #[unsafe(method_family = none)]
319 unsafe fn indeterminate(&self) -> bool;
320 }
321);