objc2-thread-network 0.3.2

Bindings to the ThreadNetwork 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 supports safely sharing Thread credentials between multiple
    /// clients.
    ///
    /// Request credentials for either a specific Thread network or for the
    /// _preferred network_ using `THClient`. The preferred network is the default
    /// Thread network chosen by the framework for a home.
    ///
    /// The ThreadNetwork framework maintains a database of network credentials. The
    /// class allows clients to store, list, and delete credentials for a given
    /// network from the database.
    ///
    /// Some methods in `THClient` use the _team ID_, a string that you store in
    /// your application’s `Info.plist`. The ThreadNetwork framework uses the team
    /// ID to preserve the privacy of the Thread network credentials across
    /// different clients. For example, credentials stored by one client can’t be
    /// deleted or modified by another client.
    ///
    /// - Important: Thread credentials give you the ability to add any device into
    /// the Thread network. Use this information responsibly.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/threadnetwork/thclient?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct THClient;
);

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

impl THClient {
    extern_methods!(
        /// Creates the client object.
        ///
        /// - Returns: An instance of the client object.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(all(feature = "THCredentials", feature = "block2"))]
        /// Requests all Thread credentials from the framework.
        ///
        /// The framework identifies the developer by the team ID. When calling this
        /// method, you receive credentials for your team ID only.
        ///
        /// - Parameters:
        /// - completion: The completion handler the framework calls when the
        /// credentials become available.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func allCredentials() async throws -> Set
        /// <THCredentials
        /// >
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(retrieveAllCredentials:))]
        #[unsafe(method_family = none)]
        pub unsafe fn retrieveAllCredentials(
            &self,
            completion: &block2::DynBlock<dyn Fn(*mut NSSet<THCredentials>, *mut NSError)>,
        );

        #[cfg(all(feature = "THCredentials", feature = "block2"))]
        /// Requests all Thread credentials with active border routers around from the framework.
        ///
        /// The framework identifies the developer by the team ID. When calling this
        /// method, you will receive credentials for active border routers around.
        /// You receive credentials for your team ID only.
        ///
        /// - Parameters:
        /// - completion: The completion handler the framework calls when the
        /// credentials become available.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func allActiveCredentials() async throws -> Set
        /// <THCredentials
        /// >
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(retrieveAllActiveCredentials:))]
        #[unsafe(method_family = none)]
        pub unsafe fn retrieveAllActiveCredentials(
            &self,
            completion: &block2::DynBlock<dyn Fn(*mut NSSet<THCredentials>, *mut NSError)>,
        );

        #[cfg(feature = "block2")]
        /// Deletes Thread network credentials from the framework database for a Border
        /// Agent.
        ///
        /// The Border Agent is the software component running in the Border Router
        /// responsible for advertising itself in the Wi-Fi or Ethernet network.
        ///
        /// - Parameters:
        /// - borderAgentID: The identifer of a Thread network Border Agent.
        /// - completion: The completion handler the framework calls after deleting
        /// the credentials.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func deleteCredentials(forBorderAgent borderAgentID: Data) async throws
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(deleteCredentialsForBorderAgent:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn deleteCredentialsForBorderAgent_completion(
            &self,
            border_agent_id: &NSData,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "THCredentials", feature = "block2"))]
        /// Requests Thread credentials for a Border Agent.
        ///
        /// The framework identifies the developer by the team ID. When calling this
        /// method, you receive credentials for your team ID only.
        ///
        /// - Parameters:
        /// - borderAgentID: The identifer of a Thread network Border Agent.
        /// - completion: The completion handler the framework calls when the
        /// credentials become available.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func credentials(forBorderAgentID borderAgentID: Data) async throws -> THCredentials
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(retrieveCredentialsForBorderAgent:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn retrieveCredentialsForBorderAgent_completion(
            &self,
            border_agent_id: &NSData,
            completion: &block2::DynBlock<dyn Fn(*mut THCredentials, *mut NSError)>,
        );

        #[cfg(feature = "block2")]
        /// Stores Thread network credentials into the framework database
        /// that a Border Agent provides.
        ///
        /// The Border Agent is the software component running in the
        /// Border Router responsible for advertising itself in the Wi-Fi
        /// or Ethernet network.
        ///
        /// The framework only stores credentials if it can find an mDNS
        /// record for the Border Agent that contains the specified Border
        /// Agent identifier.
        ///
        /// - Parameters:
        /// - borderAgentID: The identifer of an active Thread network Border Agent.
        /// - activeOperationalDataSet: The essential operational parameters for the
        /// Thread network.
        /// - completion: The completion handler the framework calls after
        /// storing the credentials.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func storeCredentials(forBorderAgent borderAgentID: Data, activeOperationalDataSet: Data) async throws
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(storeCredentialsForBorderAgent:activeOperationalDataSet:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn storeCredentialsForBorderAgent_activeOperationalDataSet_completion(
            &self,
            border_agent_id: &NSData,
            active_operational_data_set: &NSData,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        #[cfg(all(feature = "THCredentials", feature = "block2"))]
        /// Requests Thread credentials for the preferred network.
        ///
        /// When you call this method, an alert appears asking for user permission to
        /// access credentials.
        ///
        /// - Parameters:
        /// - completion: The completion handler the framework calls when the
        /// credentials become available.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func preferredCredentials() async throws -> THCredentials
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(retrievePreferredCredentials:))]
        #[unsafe(method_family = none)]
        pub unsafe fn retrievePreferredCredentials(
            &self,
            completion: &block2::DynBlock<dyn Fn(*mut THCredentials, *mut NSError)>,
        );

        #[cfg(all(feature = "THCredentials", feature = "block2"))]
        /// Requests Thread credentials for an extended Personal Area Network (PAN) ID.
        ///
        /// When calling this method, an alert appears asking for user permission to
        /// access credentials.
        ///
        /// - Parameters:
        /// - extendedPANID: The extended PAN identifier.
        /// - completion: The completion handler the framework calls when the
        /// credentials become available.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func credentials(forExtendedPANID extendedPANID: Data) async throws -> THCredentials
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(retrieveCredentialsForExtendedPANID:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn retrieveCredentialsForExtendedPANID_completion(
            &self,
            extended_panid: &NSData,
            completion: &block2::DynBlock<dyn Fn(*mut THCredentials, *mut NSError)>,
        );

        #[cfg(feature = "block2")]
        /// Determines if the essential operating parameters match the preferred
        /// network’s parameters.
        ///
        /// - Parameters:
        /// - activeOperationalDataSet: The essential operating parameters to compare
        /// against the preferred network’s parameters.
        /// - completion: The completion handler that returns the result of the
        /// comparison.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func isPreferred(forActiveOperationalDataset activeOperationalDataSet: Data) async -> Bool
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(checkPreferredNetworkForActiveOperationalDataset:completion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn checkPreferredNetworkForActiveOperationalDataset_completion(
            &self,
            active_operational_data_set: &NSData,
            completion: &block2::DynBlock<dyn Fn(Bool)>,
        );

        #[cfg(feature = "block2")]
        /// Determines if the preferred network is available or not
        ///
        /// - Parameters:
        /// - completion: The completion handler that returns the result of the
        /// preferred network availability.
        ///
        /// > Concurrency Note: You can call this method from synchronous code using a completion handler,
        /// > as shown on this page, or you can call it as an asynchronous method that has the
        /// > following declaration:
        /// >
        /// > ```swift
        /// > func isPreferredAvailable() async -> Bool
        /// > ```
        /// >
        /// > For information about concurrency and asynchronous code in Swift, see
        /// <doc
        /// ://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.
        #[unsafe(method(isPreferredNetworkAvailableWithCompletion:))]
        #[unsafe(method_family = none)]
        pub unsafe fn isPreferredNetworkAvailableWithCompletion(
            &self,
            completion: &block2::DynBlock<dyn Fn(Bool)>,
        );
    );
}

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