objc2_foundation/generated/
NSTask.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/nstaskterminationreason?language=objc)
10// NS_ENUM
11#[repr(transparent)]
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
13pub struct NSTaskTerminationReason(pub NSInteger);
14impl NSTaskTerminationReason {
15    #[doc(alias = "NSTaskTerminationReasonExit")]
16    pub const Exit: Self = Self(1);
17    #[doc(alias = "NSTaskTerminationReasonUncaughtSignal")]
18    pub const UncaughtSignal: Self = Self(2);
19}
20
21unsafe impl Encode for NSTaskTerminationReason {
22    const ENCODING: Encoding = NSInteger::ENCODING;
23}
24
25unsafe impl RefEncode for NSTaskTerminationReason {
26    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
27}
28
29extern_class!(
30    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nstask?language=objc)
31    #[unsafe(super(NSObject))]
32    #[derive(Debug, PartialEq, Eq, Hash)]
33    pub struct NSTask;
34);
35
36unsafe impl Send for NSTask {}
37
38unsafe impl Sync for NSTask {}
39
40extern_conformance!(
41    unsafe impl NSObjectProtocol for NSTask {}
42);
43
44impl NSTask {
45    extern_methods!(
46        #[unsafe(method(init))]
47        #[unsafe(method_family = init)]
48        pub fn init(this: Allocated<Self>) -> Retained<Self>;
49
50        #[cfg(feature = "NSURL")]
51        #[unsafe(method(executableURL))]
52        #[unsafe(method_family = none)]
53        pub fn executableURL(&self) -> Option<Retained<NSURL>>;
54
55        #[cfg(feature = "NSURL")]
56        /// Setter for [`executableURL`][Self::executableURL].
57        ///
58        /// This is [copied][crate::NSCopying::copy] when set.
59        #[unsafe(method(setExecutableURL:))]
60        #[unsafe(method_family = none)]
61        pub fn setExecutableURL(&self, executable_url: Option<&NSURL>);
62
63        #[cfg(all(feature = "NSArray", feature = "NSString"))]
64        #[unsafe(method(arguments))]
65        #[unsafe(method_family = none)]
66        pub fn arguments(&self) -> Option<Retained<NSArray<NSString>>>;
67
68        #[cfg(all(feature = "NSArray", feature = "NSString"))]
69        /// Setter for [`arguments`][Self::arguments].
70        ///
71        /// This is [copied][crate::NSCopying::copy] when set.
72        #[unsafe(method(setArguments:))]
73        #[unsafe(method_family = none)]
74        pub fn setArguments(&self, arguments: Option<&NSArray<NSString>>);
75
76        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
77        #[unsafe(method(environment))]
78        #[unsafe(method_family = none)]
79        pub fn environment(&self) -> Option<Retained<NSDictionary<NSString, NSString>>>;
80
81        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
82        /// Setter for [`environment`][Self::environment].
83        ///
84        /// This is [copied][crate::NSCopying::copy] when set.
85        #[unsafe(method(setEnvironment:))]
86        #[unsafe(method_family = none)]
87        pub fn setEnvironment(&self, environment: Option<&NSDictionary<NSString, NSString>>);
88
89        #[cfg(feature = "NSURL")]
90        #[unsafe(method(currentDirectoryURL))]
91        #[unsafe(method_family = none)]
92        pub fn currentDirectoryURL(&self) -> Option<Retained<NSURL>>;
93
94        #[cfg(feature = "NSURL")]
95        /// Setter for [`currentDirectoryURL`][Self::currentDirectoryURL].
96        ///
97        /// This is [copied][crate::NSCopying::copy] when set.
98        #[unsafe(method(setCurrentDirectoryURL:))]
99        #[unsafe(method_family = none)]
100        pub fn setCurrentDirectoryURL(&self, current_directory_url: Option<&NSURL>);
101
102        #[cfg(feature = "NSData")]
103        #[unsafe(method(launchRequirementData))]
104        #[unsafe(method_family = none)]
105        pub fn launchRequirementData(&self) -> Option<Retained<NSData>>;
106
107        #[cfg(feature = "NSData")]
108        /// Setter for [`launchRequirementData`][Self::launchRequirementData].
109        ///
110        /// This is [copied][crate::NSCopying::copy] when set.
111        #[unsafe(method(setLaunchRequirementData:))]
112        #[unsafe(method_family = none)]
113        pub fn setLaunchRequirementData(&self, launch_requirement_data: Option<&NSData>);
114
115        #[unsafe(method(standardInput))]
116        #[unsafe(method_family = none)]
117        pub fn standardInput(&self) -> Option<Retained<AnyObject>>;
118
119        /// Setter for [`standardInput`][Self::standardInput].
120        ///
121        /// # Safety
122        ///
123        /// `standard_input` should be of the correct type.
124        #[unsafe(method(setStandardInput:))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn setStandardInput(&self, standard_input: Option<&AnyObject>);
127
128        #[unsafe(method(standardOutput))]
129        #[unsafe(method_family = none)]
130        pub fn standardOutput(&self) -> Option<Retained<AnyObject>>;
131
132        /// Setter for [`standardOutput`][Self::standardOutput].
133        ///
134        /// # Safety
135        ///
136        /// `standard_output` should be of the correct type.
137        #[unsafe(method(setStandardOutput:))]
138        #[unsafe(method_family = none)]
139        pub unsafe fn setStandardOutput(&self, standard_output: Option<&AnyObject>);
140
141        #[unsafe(method(standardError))]
142        #[unsafe(method_family = none)]
143        pub fn standardError(&self) -> Option<Retained<AnyObject>>;
144
145        /// Setter for [`standardError`][Self::standardError].
146        ///
147        /// # Safety
148        ///
149        /// `standard_error` should be of the correct type.
150        #[unsafe(method(setStandardError:))]
151        #[unsafe(method_family = none)]
152        pub unsafe fn setStandardError(&self, standard_error: Option<&AnyObject>);
153
154        #[cfg(feature = "NSError")]
155        #[unsafe(method(launchAndReturnError:_))]
156        #[unsafe(method_family = none)]
157        pub fn launchAndReturnError(&self) -> Result<(), Retained<NSError>>;
158
159        #[unsafe(method(interrupt))]
160        #[unsafe(method_family = none)]
161        pub fn interrupt(&self);
162
163        #[unsafe(method(terminate))]
164        #[unsafe(method_family = none)]
165        pub fn terminate(&self);
166
167        #[unsafe(method(suspend))]
168        #[unsafe(method_family = none)]
169        pub fn suspend(&self) -> bool;
170
171        #[unsafe(method(resume))]
172        #[unsafe(method_family = none)]
173        pub fn resume(&self) -> bool;
174
175        #[unsafe(method(processIdentifier))]
176        #[unsafe(method_family = none)]
177        pub fn processIdentifier(&self) -> c_int;
178
179        #[unsafe(method(isRunning))]
180        #[unsafe(method_family = none)]
181        pub fn isRunning(&self) -> bool;
182
183        #[unsafe(method(terminationStatus))]
184        #[unsafe(method_family = none)]
185        pub fn terminationStatus(&self) -> c_int;
186
187        #[unsafe(method(terminationReason))]
188        #[unsafe(method_family = none)]
189        pub fn terminationReason(&self) -> NSTaskTerminationReason;
190
191        #[cfg(feature = "block2")]
192        /// # Safety
193        ///
194        /// The returned block must be sendable.
195        #[unsafe(method(terminationHandler))]
196        #[unsafe(method_family = none)]
197        pub unsafe fn terminationHandler(&self) -> *mut block2::DynBlock<dyn Fn(NonNull<NSTask>)>;
198
199        #[cfg(feature = "block2")]
200        /// Setter for [`terminationHandler`][Self::terminationHandler].
201        ///
202        /// This is [copied][crate::NSCopying::copy] when set.
203        ///
204        /// # Safety
205        ///
206        /// `termination_handler` block must be sendable.
207        #[unsafe(method(setTerminationHandler:))]
208        #[unsafe(method_family = none)]
209        pub unsafe fn setTerminationHandler(
210            &self,
211            termination_handler: Option<&block2::DynBlock<dyn Fn(NonNull<NSTask>)>>,
212        );
213
214        #[cfg(feature = "NSObjCRuntime")]
215        #[unsafe(method(qualityOfService))]
216        #[unsafe(method_family = none)]
217        pub fn qualityOfService(&self) -> NSQualityOfService;
218
219        #[cfg(feature = "NSObjCRuntime")]
220        /// Setter for [`qualityOfService`][Self::qualityOfService].
221        #[unsafe(method(setQualityOfService:))]
222        #[unsafe(method_family = none)]
223        pub fn setQualityOfService(&self, quality_of_service: NSQualityOfService);
224    );
225}
226
227/// Methods declared on superclass `NSObject`.
228impl NSTask {
229    extern_methods!(
230        #[unsafe(method(new))]
231        #[unsafe(method_family = new)]
232        pub fn new() -> Retained<Self>;
233    );
234}
235
236impl DefaultRetained for NSTask {
237    #[inline]
238    fn default_retained() -> Retained<Self> {
239        Self::new()
240    }
241}
242
243/// NSTaskConveniences.
244impl NSTask {
245    extern_methods!(
246        #[cfg(all(
247            feature = "NSArray",
248            feature = "NSError",
249            feature = "NSString",
250            feature = "NSURL",
251            feature = "block2"
252        ))]
253        /// # Safety
254        ///
255        /// `termination_handler` block must be sendable.
256        #[unsafe(method(launchedTaskWithExecutableURL:arguments:error:terminationHandler:))]
257        #[unsafe(method_family = none)]
258        pub unsafe fn launchedTaskWithExecutableURL_arguments_error_terminationHandler(
259            url: &NSURL,
260            arguments: &NSArray<NSString>,
261            error: Option<&mut Option<Retained<NSError>>>,
262            termination_handler: Option<&block2::DynBlock<dyn Fn(NonNull<NSTask>)>>,
263        ) -> Option<Retained<NSTask>>;
264
265        #[unsafe(method(waitUntilExit))]
266        #[unsafe(method_family = none)]
267        pub fn waitUntilExit(&self);
268    );
269}
270
271/// NSDeprecated.
272impl NSTask {
273    extern_methods!(
274        #[cfg(feature = "NSString")]
275        #[deprecated]
276        #[unsafe(method(launchPath))]
277        #[unsafe(method_family = none)]
278        pub fn launchPath(&self) -> Option<Retained<NSString>>;
279
280        #[cfg(feature = "NSString")]
281        /// Setter for [`launchPath`][Self::launchPath].
282        ///
283        /// This is [copied][crate::NSCopying::copy] when set.
284        #[deprecated]
285        #[unsafe(method(setLaunchPath:))]
286        #[unsafe(method_family = none)]
287        pub fn setLaunchPath(&self, launch_path: Option<&NSString>);
288
289        #[cfg(feature = "NSString")]
290        #[deprecated]
291        #[unsafe(method(currentDirectoryPath))]
292        #[unsafe(method_family = none)]
293        pub fn currentDirectoryPath(&self) -> Retained<NSString>;
294
295        #[cfg(feature = "NSString")]
296        /// Setter for [`currentDirectoryPath`][Self::currentDirectoryPath].
297        ///
298        /// This is [copied][crate::NSCopying::copy] when set.
299        #[deprecated]
300        #[unsafe(method(setCurrentDirectoryPath:))]
301        #[unsafe(method_family = none)]
302        pub fn setCurrentDirectoryPath(&self, current_directory_path: &NSString);
303
304        #[deprecated]
305        #[unsafe(method(launch))]
306        #[unsafe(method_family = none)]
307        pub fn launch(&self);
308
309        #[cfg(all(feature = "NSArray", feature = "NSString"))]
310        #[deprecated]
311        #[unsafe(method(launchedTaskWithLaunchPath:arguments:))]
312        #[unsafe(method_family = none)]
313        pub fn launchedTaskWithLaunchPath_arguments(
314            path: &NSString,
315            arguments: &NSArray<NSString>,
316        ) -> Retained<NSTask>;
317    );
318}
319
320extern "C" {
321    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nstaskdidterminatenotification?language=objc)
322    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
323    pub static NSTaskDidTerminateNotification: &'static NSNotificationName;
324}