objc2-fs-kit 0.3.2

Bindings to the FSKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// A class that enables a file system module to pass log messages and completion notifications to clients.
    ///
    /// FSKit creates an instance of this class for each long-running operations.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/fskit/fstask?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct FSTask;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for FSTask {}
);

impl FSTask {
    extern_methods!(
        /// Logs the given string to the initiating client.
        ///
        /// - Parameter str: The string to log.
        #[unsafe(method(logMessage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn logMessage(&self, str: &NSString);

        /// Informs the client that the task completed.
        ///
        /// - Parameter error: `nil` if the task completed successfully; otherwise, an error that caused the task to fail.
        #[unsafe(method(didCompleteWithError:))]
        #[unsafe(method_family = none)]
        pub unsafe fn didCompleteWithError(&self, error: Option<&NSError>);

        #[cfg(feature = "block2")]
        /// ```obj-c
        /// {
        /// NSProgress *progress = [[NSProgress alloc] init];
        /// yourFileSystemChecker *checker= [[yourFileSystemChecker alloc] init];
        /// checker.work_group = dispatch_group_create();
        /// dispatch_group_enter(checker.work_group);
        /// [task setCancellationHandler:^NSError * _Nullable{
        /// checker.terminate = TRUE;
        /// dispatch_group_wait(checker.work_group);
        /// return nil;
        /// }];
        /// dispatch_async(someQueue, ^{[self performCheck:task progress:progress];});
        /// return progress;
        /// }
        /// ```
        ///
        /// > Note: this example did not account for errors while delivered code must. finally, the `performCheck`
        /// code should perform the check operation. It should periodically update the progress object and check
        /// its `interrupted` variable. The check can either complete successfully, complete with an error, or
        /// be interrupted. It should then call `[task didCompleteWithError:...]` wtih the appropriate
        /// error value or nil. Finally it should `dispatch_group_leave(self.work_group);`
        ///
        /// - Returns: An error if the cancellation did not complete successfully. Any returned error will be logged, and FSKit will then terminate all activity in the container.
        ///
        /// # Safety
        ///
        /// The returned block must be sendable.
        #[unsafe(method(cancellationHandler))]
        #[unsafe(method_family = none)]
        pub unsafe fn cancellationHandler(&self)
            -> *mut block2::DynBlock<dyn Fn() -> *mut NSError>;

        #[cfg(feature = "block2")]
        /// Setter for [`cancellationHandler`][Self::cancellationHandler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `cancellation_handler` block must be sendable.
        #[unsafe(method(setCancellationHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCancellationHandler(
            &self,
            cancellation_handler: Option<&block2::DynBlock<dyn Fn() -> *mut NSError>>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl FSTask {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}