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