objc2_foundation/generated/
NSOperation.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
7use crate::*;
8
9/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsoperationqueuepriority?language=objc)
10// NS_ENUM
11#[repr(transparent)]
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
13pub struct NSOperationQueuePriority(pub NSInteger);
14impl NSOperationQueuePriority {
15    #[doc(alias = "NSOperationQueuePriorityVeryLow")]
16    pub const VeryLow: Self = Self(-8);
17    #[doc(alias = "NSOperationQueuePriorityLow")]
18    pub const Low: Self = Self(-4);
19    #[doc(alias = "NSOperationQueuePriorityNormal")]
20    pub const Normal: Self = Self(0);
21    #[doc(alias = "NSOperationQueuePriorityHigh")]
22    pub const High: Self = Self(4);
23    #[doc(alias = "NSOperationQueuePriorityVeryHigh")]
24    pub const VeryHigh: Self = Self(8);
25}
26
27unsafe impl Encode for NSOperationQueuePriority {
28    const ENCODING: Encoding = NSInteger::ENCODING;
29}
30
31unsafe impl RefEncode for NSOperationQueuePriority {
32    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
33}
34
35extern_class!(
36    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsoperation?language=objc)
37    #[unsafe(super(NSObject))]
38    #[derive(Debug, PartialEq, Eq, Hash)]
39    pub struct NSOperation;
40);
41
42unsafe impl Send for NSOperation {}
43
44unsafe impl Sync for NSOperation {}
45
46extern_conformance!(
47    unsafe impl NSObjectProtocol for NSOperation {}
48);
49
50impl NSOperation {
51    extern_methods!(
52        #[unsafe(method(start))]
53        #[unsafe(method_family = none)]
54        pub fn start(&self);
55
56        #[unsafe(method(main))]
57        #[unsafe(method_family = none)]
58        pub fn main(&self);
59
60        #[unsafe(method(isCancelled))]
61        #[unsafe(method_family = none)]
62        pub fn isCancelled(&self) -> bool;
63
64        #[unsafe(method(cancel))]
65        #[unsafe(method_family = none)]
66        pub fn cancel(&self);
67
68        #[unsafe(method(isExecuting))]
69        #[unsafe(method_family = none)]
70        pub fn isExecuting(&self) -> bool;
71
72        #[unsafe(method(isFinished))]
73        #[unsafe(method_family = none)]
74        pub fn isFinished(&self) -> bool;
75
76        #[unsafe(method(isConcurrent))]
77        #[unsafe(method_family = none)]
78        pub fn isConcurrent(&self) -> bool;
79
80        #[unsafe(method(isAsynchronous))]
81        #[unsafe(method_family = none)]
82        pub fn isAsynchronous(&self) -> bool;
83
84        #[unsafe(method(isReady))]
85        #[unsafe(method_family = none)]
86        pub fn isReady(&self) -> bool;
87
88        #[unsafe(method(addDependency:))]
89        #[unsafe(method_family = none)]
90        pub fn addDependency(&self, op: &NSOperation);
91
92        #[unsafe(method(removeDependency:))]
93        #[unsafe(method_family = none)]
94        pub fn removeDependency(&self, op: &NSOperation);
95
96        #[cfg(feature = "NSArray")]
97        #[unsafe(method(dependencies))]
98        #[unsafe(method_family = none)]
99        pub fn dependencies(&self) -> Retained<NSArray<NSOperation>>;
100
101        #[unsafe(method(queuePriority))]
102        #[unsafe(method_family = none)]
103        pub fn queuePriority(&self) -> NSOperationQueuePriority;
104
105        /// Setter for [`queuePriority`][Self::queuePriority].
106        #[unsafe(method(setQueuePriority:))]
107        #[unsafe(method_family = none)]
108        pub fn setQueuePriority(&self, queue_priority: NSOperationQueuePriority);
109
110        #[cfg(feature = "block2")]
111        /// # Safety
112        ///
113        /// The returned block must be sendable.
114        #[unsafe(method(completionBlock))]
115        #[unsafe(method_family = none)]
116        pub unsafe fn completionBlock(&self) -> *mut block2::DynBlock<dyn Fn()>;
117
118        #[cfg(feature = "block2")]
119        /// Setter for [`completionBlock`][Self::completionBlock].
120        ///
121        /// This is [copied][crate::NSCopying::copy] when set.
122        ///
123        /// # Safety
124        ///
125        /// `completion_block` block must be sendable.
126        #[unsafe(method(setCompletionBlock:))]
127        #[unsafe(method_family = none)]
128        pub unsafe fn setCompletionBlock(
129            &self,
130            completion_block: Option<&block2::DynBlock<dyn Fn()>>,
131        );
132
133        #[unsafe(method(waitUntilFinished))]
134        #[unsafe(method_family = none)]
135        pub fn waitUntilFinished(&self);
136
137        #[deprecated = "Not supported"]
138        #[unsafe(method(threadPriority))]
139        #[unsafe(method_family = none)]
140        pub fn threadPriority(&self) -> c_double;
141
142        /// Setter for [`threadPriority`][Self::threadPriority].
143        #[deprecated = "Not supported"]
144        #[unsafe(method(setThreadPriority:))]
145        #[unsafe(method_family = none)]
146        pub fn setThreadPriority(&self, thread_priority: c_double);
147
148        #[cfg(feature = "NSObjCRuntime")]
149        #[unsafe(method(qualityOfService))]
150        #[unsafe(method_family = none)]
151        pub fn qualityOfService(&self) -> NSQualityOfService;
152
153        #[cfg(feature = "NSObjCRuntime")]
154        /// Setter for [`qualityOfService`][Self::qualityOfService].
155        #[unsafe(method(setQualityOfService:))]
156        #[unsafe(method_family = none)]
157        pub fn setQualityOfService(&self, quality_of_service: NSQualityOfService);
158
159        #[cfg(feature = "NSString")]
160        #[unsafe(method(name))]
161        #[unsafe(method_family = none)]
162        pub fn name(&self) -> Option<Retained<NSString>>;
163
164        #[cfg(feature = "NSString")]
165        /// Setter for [`name`][Self::name].
166        ///
167        /// This is [copied][crate::NSCopying::copy] when set.
168        #[unsafe(method(setName:))]
169        #[unsafe(method_family = none)]
170        pub fn setName(&self, name: Option<&NSString>);
171    );
172}
173
174/// Methods declared on superclass `NSObject`.
175impl NSOperation {
176    extern_methods!(
177        #[unsafe(method(init))]
178        #[unsafe(method_family = init)]
179        pub fn init(this: Allocated<Self>) -> Retained<Self>;
180
181        #[unsafe(method(new))]
182        #[unsafe(method_family = new)]
183        pub fn new() -> Retained<Self>;
184    );
185}
186
187impl DefaultRetained for NSOperation {
188    #[inline]
189    fn default_retained() -> Retained<Self> {
190        Self::new()
191    }
192}
193
194extern_class!(
195    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsblockoperation?language=objc)
196    #[unsafe(super(NSOperation, NSObject))]
197    #[derive(Debug, PartialEq, Eq, Hash)]
198    pub struct NSBlockOperation;
199);
200
201unsafe impl Send for NSBlockOperation {}
202
203unsafe impl Sync for NSBlockOperation {}
204
205extern_conformance!(
206    unsafe impl NSObjectProtocol for NSBlockOperation {}
207);
208
209impl NSBlockOperation {
210    extern_methods!(
211        #[cfg(feature = "block2")]
212        /// # Safety
213        ///
214        /// `block` block must be sendable.
215        #[unsafe(method(blockOperationWithBlock:))]
216        #[unsafe(method_family = none)]
217        pub unsafe fn blockOperationWithBlock(block: &block2::DynBlock<dyn Fn()>)
218            -> Retained<Self>;
219
220        #[cfg(feature = "block2")]
221        /// # Safety
222        ///
223        /// `block` block must be sendable.
224        #[unsafe(method(addExecutionBlock:))]
225        #[unsafe(method_family = none)]
226        pub unsafe fn addExecutionBlock(&self, block: &block2::DynBlock<dyn Fn()>);
227    );
228}
229
230/// Methods declared on superclass `NSObject`.
231impl NSBlockOperation {
232    extern_methods!(
233        #[unsafe(method(init))]
234        #[unsafe(method_family = init)]
235        pub fn init(this: Allocated<Self>) -> Retained<Self>;
236
237        #[unsafe(method(new))]
238        #[unsafe(method_family = new)]
239        pub fn new() -> Retained<Self>;
240    );
241}
242
243impl DefaultRetained for NSBlockOperation {
244    #[inline]
245    fn default_retained() -> Retained<Self> {
246        Self::new()
247    }
248}
249
250extern_class!(
251    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsinvocationoperation?language=objc)
252    #[unsafe(super(NSOperation, NSObject))]
253    #[derive(Debug, PartialEq, Eq, Hash)]
254    pub struct NSInvocationOperation;
255);
256
257extern_conformance!(
258    unsafe impl NSObjectProtocol for NSInvocationOperation {}
259);
260
261impl NSInvocationOperation {
262    extern_methods!(
263        /// # Safety
264        ///
265        /// - `target` should be of the correct type.
266        /// - `sel` must be a valid selector.
267        /// - `arg` should be of the correct type.
268        #[unsafe(method(initWithTarget:selector:object:))]
269        #[unsafe(method_family = init)]
270        pub unsafe fn initWithTarget_selector_object(
271            this: Allocated<Self>,
272            target: &AnyObject,
273            sel: Sel,
274            arg: Option<&AnyObject>,
275        ) -> Option<Retained<Self>>;
276
277        #[cfg(feature = "NSInvocation")]
278        #[unsafe(method(initWithInvocation:))]
279        #[unsafe(method_family = init)]
280        pub unsafe fn initWithInvocation(
281            this: Allocated<Self>,
282            inv: &NSInvocation,
283        ) -> Retained<Self>;
284
285        #[cfg(feature = "NSInvocation")]
286        #[unsafe(method(invocation))]
287        #[unsafe(method_family = none)]
288        pub unsafe fn invocation(&self) -> Retained<NSInvocation>;
289
290        #[unsafe(method(result))]
291        #[unsafe(method_family = none)]
292        pub fn result(&self) -> Option<Retained<AnyObject>>;
293    );
294}
295
296/// Methods declared on superclass `NSObject`.
297impl NSInvocationOperation {
298    extern_methods!(
299        #[unsafe(method(init))]
300        #[unsafe(method_family = init)]
301        pub fn init(this: Allocated<Self>) -> Retained<Self>;
302
303        #[unsafe(method(new))]
304        #[unsafe(method_family = new)]
305        pub fn new() -> Retained<Self>;
306    );
307}
308
309impl DefaultRetained for NSInvocationOperation {
310    #[inline]
311    fn default_retained() -> Retained<Self> {
312        Self::new()
313    }
314}
315
316extern "C" {
317    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsinvocationoperationvoidresultexception?language=objc)
318    #[cfg(all(feature = "NSObjCRuntime", feature = "NSString"))]
319    pub static NSInvocationOperationVoidResultException: &'static NSExceptionName;
320}
321
322extern "C" {
323    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsinvocationoperationcancelledexception?language=objc)
324    #[cfg(all(feature = "NSObjCRuntime", feature = "NSString"))]
325    pub static NSInvocationOperationCancelledException: &'static NSExceptionName;
326}
327
328/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsoperationqueuedefaultmaxconcurrentoperationcount?language=objc)
329pub static NSOperationQueueDefaultMaxConcurrentOperationCount: NSInteger = -1;
330
331extern_class!(
332    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsoperationqueue?language=objc)
333    #[unsafe(super(NSObject))]
334    #[derive(Debug, PartialEq, Eq, Hash)]
335    pub struct NSOperationQueue;
336);
337
338unsafe impl Send for NSOperationQueue {}
339
340unsafe impl Sync for NSOperationQueue {}
341
342extern_conformance!(
343    unsafe impl NSObjectProtocol for NSOperationQueue {}
344);
345
346#[cfg(feature = "NSProgress")]
347extern_conformance!(
348    unsafe impl NSProgressReporting for NSOperationQueue {}
349);
350
351impl NSOperationQueue {
352    extern_methods!(
353        #[cfg(feature = "NSProgress")]
354        /// The `progress` property represents a total progress of the operations executed in the queue. By default NSOperationQueue
355        /// does not report progress until the `totalUnitCount` of the progress is set. When the `totalUnitCount` property of the progress is set the
356        /// queue then opts into participating in progress reporting. When enabled, each operation will contribute 1 unit of completion to the
357        /// overall progress of the queue for operations that are finished by the end of main (operations that override start and do not invoke super
358        /// will not contribute to progress). Special attention to race conditions should be made when updating the `totalUnitCount` of the progress
359        /// as well as care should be taken to avoid 'backwards progress'. For example; when a NSOperationQueue's progress is 5/10, representing 50%
360        /// completed, and there are 90 more operations about to be added and the `totalUnitCount` that would then make the progress report as 5/100
361        /// which represents 5%. In this example it would mean that any progress bar would jump from displaying 50% back to 5%, which might not be
362        /// desirable. In the cases where the `totalUnitCount` needs to be adjusted it is suggested to do this for thread-safety in a barrier by
363        /// using the `addBarrierBlock:` API. This ensures that no un-expected execution state occurs adjusting into a potentially backwards moving
364        /// progress scenario.
365        ///
366        ///
367        /// NSOperationQueue *queue = [[NSOperationQueue alloc] init];
368        /// queue.progress.totalUnitCount = 10;
369        #[unsafe(method(progress))]
370        #[unsafe(method_family = none)]
371        pub fn progress(&self) -> Retained<NSProgress>;
372
373        #[unsafe(method(addOperation:))]
374        #[unsafe(method_family = none)]
375        pub fn addOperation(&self, op: &NSOperation);
376
377        #[cfg(feature = "NSArray")]
378        #[unsafe(method(addOperations:waitUntilFinished:))]
379        #[unsafe(method_family = none)]
380        pub fn addOperations_waitUntilFinished(&self, ops: &NSArray<NSOperation>, wait: bool);
381
382        #[cfg(feature = "block2")]
383        /// # Safety
384        ///
385        /// `block` block must be sendable.
386        #[unsafe(method(addOperationWithBlock:))]
387        #[unsafe(method_family = none)]
388        pub unsafe fn addOperationWithBlock(&self, block: &block2::DynBlock<dyn Fn()>);
389
390        #[cfg(feature = "block2")]
391        /// Parameter `barrier`: A block to execute
392        ///
393        /// The `addBarrierBlock:` method executes the block when the NSOperationQueue has finished all enqueued operations and
394        /// prevents any subsequent operations to be executed until the barrier has been completed. This acts similarly to the
395        /// `dispatch_barrier_async` function.
396        ///
397        /// # Safety
398        ///
399        /// `barrier` block must be sendable.
400        #[unsafe(method(addBarrierBlock:))]
401        #[unsafe(method_family = none)]
402        pub unsafe fn addBarrierBlock(&self, barrier: &block2::DynBlock<dyn Fn()>);
403
404        #[unsafe(method(maxConcurrentOperationCount))]
405        #[unsafe(method_family = none)]
406        pub fn maxConcurrentOperationCount(&self) -> NSInteger;
407
408        /// Setter for [`maxConcurrentOperationCount`][Self::maxConcurrentOperationCount].
409        #[unsafe(method(setMaxConcurrentOperationCount:))]
410        #[unsafe(method_family = none)]
411        pub fn setMaxConcurrentOperationCount(&self, max_concurrent_operation_count: NSInteger);
412
413        #[unsafe(method(isSuspended))]
414        #[unsafe(method_family = none)]
415        pub fn isSuspended(&self) -> bool;
416
417        /// Setter for [`isSuspended`][Self::isSuspended].
418        #[unsafe(method(setSuspended:))]
419        #[unsafe(method_family = none)]
420        pub fn setSuspended(&self, suspended: bool);
421
422        #[cfg(feature = "NSString")]
423        #[unsafe(method(name))]
424        #[unsafe(method_family = none)]
425        pub fn name(&self) -> Option<Retained<NSString>>;
426
427        #[cfg(feature = "NSString")]
428        /// Setter for [`name`][Self::name].
429        ///
430        /// This is [copied][crate::NSCopying::copy] when set.
431        #[unsafe(method(setName:))]
432        #[unsafe(method_family = none)]
433        pub fn setName(&self, name: Option<&NSString>);
434
435        #[cfg(feature = "NSObjCRuntime")]
436        #[unsafe(method(qualityOfService))]
437        #[unsafe(method_family = none)]
438        pub fn qualityOfService(&self) -> NSQualityOfService;
439
440        #[cfg(feature = "NSObjCRuntime")]
441        /// Setter for [`qualityOfService`][Self::qualityOfService].
442        #[unsafe(method(setQualityOfService:))]
443        #[unsafe(method_family = none)]
444        pub fn setQualityOfService(&self, quality_of_service: NSQualityOfService);
445
446        #[unsafe(method(cancelAllOperations))]
447        #[unsafe(method_family = none)]
448        pub fn cancelAllOperations(&self);
449
450        #[unsafe(method(waitUntilAllOperationsAreFinished))]
451        #[unsafe(method_family = none)]
452        pub fn waitUntilAllOperationsAreFinished(&self);
453
454        #[unsafe(method(currentQueue))]
455        #[unsafe(method_family = none)]
456        pub fn currentQueue() -> Option<Retained<NSOperationQueue>>;
457
458        #[unsafe(method(mainQueue))]
459        #[unsafe(method_family = none)]
460        pub fn mainQueue() -> Retained<NSOperationQueue>;
461    );
462}
463
464/// Methods declared on superclass `NSObject`.
465impl NSOperationQueue {
466    extern_methods!(
467        #[unsafe(method(init))]
468        #[unsafe(method_family = init)]
469        pub fn init(this: Allocated<Self>) -> Retained<Self>;
470
471        #[unsafe(method(new))]
472        #[unsafe(method_family = new)]
473        pub fn new() -> Retained<Self>;
474    );
475}
476
477impl DefaultRetained for NSOperationQueue {
478    #[inline]
479    fn default_retained() -> Retained<Self> {
480        Self::new()
481    }
482}
483
484/// NSDeprecated.
485impl NSOperationQueue {
486    extern_methods!(
487        #[cfg(feature = "NSArray")]
488        #[deprecated = "access to operations is inherently a race condition, it should not be used. For barrier style behaviors please use addBarrierBlock: instead"]
489        #[unsafe(method(operations))]
490        #[unsafe(method_family = none)]
491        pub fn operations(&self) -> Retained<NSArray<NSOperation>>;
492
493        #[deprecated]
494        #[unsafe(method(operationCount))]
495        #[unsafe(method_family = none)]
496        pub fn operationCount(&self) -> NSUInteger;
497    );
498}