objc2-home-kit 0.3.2

Bindings to the HomeKit 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::*;

/// The home data authorization status of the client process.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmhomemanagerauthorizationstatus?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct HMHomeManagerAuthorizationStatus(pub NSUInteger);
bitflags::bitflags! {
    impl HMHomeManagerAuthorizationStatus: NSUInteger {
        #[doc(alias = "HMHomeManagerAuthorizationStatusDetermined")]
        const Determined = 1<<0;
        #[doc(alias = "HMHomeManagerAuthorizationStatusRestricted")]
        const Restricted = 1<<1;
        #[doc(alias = "HMHomeManagerAuthorizationStatusAuthorized")]
        const Authorized = 1<<2;
    }
}

unsafe impl Encode for HMHomeManagerAuthorizationStatus {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for HMHomeManagerAuthorizationStatus {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Manages collection of one or more homes.
    ///
    ///
    /// This class is responsible for managing a collection of homes.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmhomemanager?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct HMHomeManager;
);

unsafe impl Send for HMHomeManager {}

unsafe impl Sync for HMHomeManager {}

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

impl HMHomeManager {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Delegate that receives updates on the collection of homes.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn HMHomeManagerDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn HMHomeManagerDelegate>>,
        );

        /// The current authorization status of the application.
        ///
        /// The authorization is managed by the system, there is no need to explicitly request authorization.
        #[unsafe(method(authorizationStatus))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorizationStatus(&self) -> HMHomeManagerAuthorizationStatus;

        #[cfg(feature = "HMHome")]
        /// The primary home for this collection.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[deprecated = "No longer supported."]
        #[unsafe(method(primaryHome))]
        #[unsafe(method_family = none)]
        pub unsafe fn primaryHome(&self) -> Option<Retained<HMHome>>;

        #[cfg(feature = "HMHome")]
        /// Array of HMHome objects that represents the homes associated with the home manager.
        ///
        ///
        /// When a new home manager is created, this array is initialized as an empty array. It is
        /// not guaranteed to be filled with the list of homes, represented as HMHome objects,
        /// until the homeManagerDidUpdateHomes: delegate method has been invoked.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(homes))]
        #[unsafe(method_family = none)]
        pub unsafe fn homes(&self) -> Retained<NSArray<HMHome>>;

        #[cfg(all(feature = "HMHome", feature = "block2"))]
        /// This method is used to change the primary home.
        ///
        ///
        /// Parameter `home`: New primary home.
        ///
        ///
        /// Parameter `completion`: Block that is invoked once the request is processed.
        /// The NSError provides more information on the status of the request, error
        /// will be nil on success.
        #[deprecated = "No longer supported."]
        #[unsafe(method(updatePrimaryHome:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn updatePrimaryHome_completionHandler(
            &self,
            home: &HMHome,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "HMHome", feature = "block2"))]
        /// Adds a new home to the collection.
        ///
        ///
        /// Parameter `homeName`: Name of the  home to create and add to the collection.
        ///
        ///
        /// Parameter `completion`: Block that is invoked once the request is processed.
        /// The NSError provides more information on the status of the request, error
        /// will be nil on success.
        #[unsafe(method(addHomeWithName:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addHomeWithName_completionHandler(
            &self,
            home_name: &NSString,
            completion: &block2::DynBlock<dyn Fn(*mut HMHome, *mut NSError)>,
        );

        #[cfg(all(feature = "HMHome", feature = "block2"))]
        /// Removes an existing home from the collection.
        ///
        ///
        /// Parameter `home`: Home object that needs to be removed from the collection.
        ///
        ///
        /// Parameter `completion`: Block that is invoked once the request is processed.
        /// The NSError provides more information on the status of the request, error
        /// will be nil on success.
        #[unsafe(method(removeHome:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeHome_completionHandler(
            &self,
            home: &HMHome,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl HMHomeManager {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_protocol!(
    /// This delegate receives updates on homes being managed via the home manager.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/homekit/hmhomemanagerdelegate?language=objc)
    pub unsafe trait HMHomeManagerDelegate: NSObjectProtocol {
        /// Informs the delegate a change in authorization status has occurred.
        ///
        ///
        /// Parameter `manager`: Sender of this message.
        ///
        /// Parameter `status`: The updated authorization status.
        #[optional]
        #[unsafe(method(homeManager:didUpdateAuthorizationStatus:))]
        #[unsafe(method_family = none)]
        unsafe fn homeManager_didUpdateAuthorizationStatus(
            &self,
            manager: &HMHomeManager,
            status: HMHomeManagerAuthorizationStatus,
        );

        /// Informs the delegate when homes configured by the user have been detected by the system.
        ///
        ///
        /// This delegate method is also invoked to inform an application of significant changes
        /// to the home configuration. Applications should use this as a cue to invalidate their
        /// current references to HomeKit objects and refresh their views with the new list of homes.
        ///
        ///
        /// Parameter `manager`: Sender of this message.
        #[optional]
        #[unsafe(method(homeManagerDidUpdateHomes:))]
        #[unsafe(method_family = none)]
        unsafe fn homeManagerDidUpdateHomes(&self, manager: &HMHomeManager);

        /// Informs the delegate when the primary home is modified.
        ///
        ///
        /// Parameter `manager`: Sender of this message.
        #[optional]
        #[unsafe(method(homeManagerDidUpdatePrimaryHome:))]
        #[unsafe(method_family = none)]
        unsafe fn homeManagerDidUpdatePrimaryHome(&self, manager: &HMHomeManager);

        #[cfg(feature = "HMHome")]
        /// Informs the delegate when a new home is added.
        ///
        ///
        /// Parameter `manager`: Sender of this message.
        ///
        ///
        /// Parameter `home`: New home that was added.
        #[optional]
        #[unsafe(method(homeManager:didAddHome:))]
        #[unsafe(method_family = none)]
        unsafe fn homeManager_didAddHome(&self, manager: &HMHomeManager, home: &HMHome);

        #[cfg(feature = "HMHome")]
        /// Informs the delegate when an existing home is removed.
        ///
        ///
        /// Parameter `manager`: Sender of this message.
        ///
        ///
        /// Parameter `home`: Home that was removed.
        #[optional]
        #[unsafe(method(homeManager:didRemoveHome:))]
        #[unsafe(method_family = none)]
        unsafe fn homeManager_didRemoveHome(&self, manager: &HMHomeManager, home: &HMHome);

        #[cfg(feature = "HMAddAccessoryRequest")]
        /// Informs the delegate an accessory needs to be added to the home by using one of the
        /// HMAccessorySetupPayload factory methods on the request parameter.
        ///
        ///
        /// Parameter `manager`: Sender of this message.
        ///
        ///
        /// Parameter `request`: Information for the add accessory request.
        #[optional]
        #[unsafe(method(homeManager:didReceiveAddAccessoryRequest:))]
        #[unsafe(method_family = none)]
        unsafe fn homeManager_didReceiveAddAccessoryRequest(
            &self,
            manager: &HMHomeManager,
            request: &HMAddAccessoryRequest,
        );
    }
);