objc2_core_bluetooth/generated/
CBCharacteristic.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Characteristic properties determine how the characteristic value can be    used, or how the descriptor(s) can be accessed. Can be combined. Unless
11/// otherwise specified, properties are valid for local characteristics published via
12///
13/// ```text
14///  CBPeripheralManager
15/// ```
16///
17/// .
18///
19/// See also [Apple's documentation](https://developer.apple.com/documentation/corebluetooth/cbcharacteristicproperties?language=objc)
20// NS_OPTIONS
21#[repr(transparent)]
22#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
23pub struct CBCharacteristicProperties(pub NSUInteger);
24bitflags::bitflags! {
25    impl CBCharacteristicProperties: NSUInteger {
26        #[doc(alias = "CBCharacteristicPropertyBroadcast")]
27        const Broadcast = 0x01;
28        #[doc(alias = "CBCharacteristicPropertyRead")]
29        const Read = 0x02;
30        #[doc(alias = "CBCharacteristicPropertyWriteWithoutResponse")]
31        const WriteWithoutResponse = 0x04;
32        #[doc(alias = "CBCharacteristicPropertyWrite")]
33        const Write = 0x08;
34        #[doc(alias = "CBCharacteristicPropertyNotify")]
35        const Notify = 0x10;
36        #[doc(alias = "CBCharacteristicPropertyIndicate")]
37        const Indicate = 0x20;
38        #[doc(alias = "CBCharacteristicPropertyAuthenticatedSignedWrites")]
39        const AuthenticatedSignedWrites = 0x40;
40        #[doc(alias = "CBCharacteristicPropertyExtendedProperties")]
41        const ExtendedProperties = 0x80;
42        #[doc(alias = "CBCharacteristicPropertyNotifyEncryptionRequired")]
43        const NotifyEncryptionRequired = 0x100;
44        #[doc(alias = "CBCharacteristicPropertyIndicateEncryptionRequired")]
45        const IndicateEncryptionRequired = 0x200;
46    }
47}
48
49unsafe impl Encode for CBCharacteristicProperties {
50    const ENCODING: Encoding = NSUInteger::ENCODING;
51}
52
53unsafe impl RefEncode for CBCharacteristicProperties {
54    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
55}
56
57extern_class!(
58    /// Represents a service's characteristic.
59    ///
60    /// See also [Apple's documentation](https://developer.apple.com/documentation/corebluetooth/cbcharacteristic?language=objc)
61    #[unsafe(super(CBAttribute, NSObject))]
62    #[derive(Debug, PartialEq, Eq, Hash)]
63    #[cfg(feature = "CBAttribute")]
64    pub struct CBCharacteristic;
65);
66
67#[cfg(feature = "CBAttribute")]
68extern_conformance!(
69    unsafe impl NSObjectProtocol for CBCharacteristic {}
70);
71
72#[cfg(feature = "CBAttribute")]
73impl CBCharacteristic {
74    extern_methods!(
75        #[cfg(feature = "CBService")]
76        /// A back-pointer to the service this characteristic belongs to.
77        #[unsafe(method(service))]
78        #[unsafe(method_family = none)]
79        pub unsafe fn service(&self) -> Option<Retained<CBService>>;
80
81        /// The properties of the characteristic.
82        #[unsafe(method(properties))]
83        #[unsafe(method_family = none)]
84        pub unsafe fn properties(&self) -> CBCharacteristicProperties;
85
86        /// The value of the characteristic.
87        #[unsafe(method(value))]
88        #[unsafe(method_family = none)]
89        pub unsafe fn value(&self) -> Option<Retained<NSData>>;
90
91        #[cfg(feature = "CBDescriptor")]
92        /// A list of the CBDescriptors that have so far been discovered in this characteristic.
93        #[unsafe(method(descriptors))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn descriptors(&self) -> Option<Retained<NSArray<CBDescriptor>>>;
96
97        /// Whether the characteristic is currently broadcasted or not.
98        #[deprecated]
99        #[unsafe(method(isBroadcasted))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn isBroadcasted(&self) -> bool;
102
103        /// Whether the characteristic is currently notifying or not.
104        #[unsafe(method(isNotifying))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn isNotifying(&self) -> bool;
107    );
108}
109
110/// Methods declared on superclass `CBAttribute`.
111#[cfg(feature = "CBAttribute")]
112impl CBCharacteristic {
113    extern_methods!(
114        #[unsafe(method(init))]
115        #[unsafe(method_family = init)]
116        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
117    );
118}
119
120/// Methods declared on superclass `NSObject`.
121#[cfg(feature = "CBAttribute")]
122impl CBCharacteristic {
123    extern_methods!(
124        #[unsafe(method(new))]
125        #[unsafe(method_family = new)]
126        pub unsafe fn new() -> Retained<Self>;
127    );
128}
129
130/// Read, write, and encryption permissions for an ATT attribute. Can be combined.
131///
132/// See also [Apple's documentation](https://developer.apple.com/documentation/corebluetooth/cbattributepermissions?language=objc)
133// NS_OPTIONS
134#[repr(transparent)]
135#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
136pub struct CBAttributePermissions(pub NSUInteger);
137bitflags::bitflags! {
138    impl CBAttributePermissions: NSUInteger {
139        #[doc(alias = "CBAttributePermissionsReadable")]
140        const Readable = 0x01;
141        #[doc(alias = "CBAttributePermissionsWriteable")]
142        const Writeable = 0x02;
143        #[doc(alias = "CBAttributePermissionsReadEncryptionRequired")]
144        const ReadEncryptionRequired = 0x04;
145        #[doc(alias = "CBAttributePermissionsWriteEncryptionRequired")]
146        const WriteEncryptionRequired = 0x08;
147    }
148}
149
150unsafe impl Encode for CBAttributePermissions {
151    const ENCODING: Encoding = NSUInteger::ENCODING;
152}
153
154unsafe impl RefEncode for CBAttributePermissions {
155    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
156}
157
158extern_class!(
159    /// Used to create a local characteristic, which can be added to the local database via
160    /// <code>
161    /// CBPeripheralManager
162    /// </code>
163    /// . Once a characteristic
164    /// is published, it is cached and can no longer be changed.
165    /// If a characteristic value is specified, it will be cached and marked
166    /// <code>
167    /// CBCharacteristicPropertyRead
168    /// </code>
169    /// and
170    /// <code>
171    /// CBAttributePermissionsReadable
172    /// </code>
173    /// . If a characteristic value needs to be writeable, or may change during the lifetime of the
174    /// published
175    /// <code>
176    /// CBService
177    /// </code>
178    /// , it is considered a dynamic value and will be requested on-demand. Dynamic values are identified by a
179    /// <i>
180    /// value
181    /// </i>
182    /// of
183    /// <i>
184    /// nil
185    /// </i>
186    /// .
187    ///
188    /// See also [Apple's documentation](https://developer.apple.com/documentation/corebluetooth/cbmutablecharacteristic?language=objc)
189    #[unsafe(super(CBCharacteristic, CBAttribute, NSObject))]
190    #[derive(Debug, PartialEq, Eq, Hash)]
191    #[cfg(feature = "CBAttribute")]
192    pub struct CBMutableCharacteristic;
193);
194
195#[cfg(feature = "CBAttribute")]
196extern_conformance!(
197    unsafe impl NSObjectProtocol for CBMutableCharacteristic {}
198);
199
200#[cfg(feature = "CBAttribute")]
201impl CBMutableCharacteristic {
202    extern_methods!(
203        /// The permissions of the characteristic value.
204        ///
205        ///
206        /// See: CBAttributePermissions
207        #[unsafe(method(permissions))]
208        #[unsafe(method_family = none)]
209        pub unsafe fn permissions(&self) -> CBAttributePermissions;
210
211        /// Setter for [`permissions`][Self::permissions].
212        #[unsafe(method(setPermissions:))]
213        #[unsafe(method_family = none)]
214        pub unsafe fn setPermissions(&self, permissions: CBAttributePermissions);
215
216        #[cfg(all(feature = "CBCentral", feature = "CBPeer"))]
217        /// For notifying characteristics, the set of currently subscribed centrals.
218        #[unsafe(method(subscribedCentrals))]
219        #[unsafe(method_family = none)]
220        pub unsafe fn subscribedCentrals(&self) -> Option<Retained<NSArray<CBCentral>>>;
221
222        #[unsafe(method(properties))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn properties(&self) -> CBCharacteristicProperties;
225
226        /// Setter for [`properties`][Self::properties].
227        #[unsafe(method(setProperties:))]
228        #[unsafe(method_family = none)]
229        pub unsafe fn setProperties(&self, properties: CBCharacteristicProperties);
230
231        #[unsafe(method(value))]
232        #[unsafe(method_family = none)]
233        pub unsafe fn value(&self) -> Option<Retained<NSData>>;
234
235        /// Setter for [`value`][Self::value].
236        #[unsafe(method(setValue:))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn setValue(&self, value: Option<&NSData>);
239
240        #[cfg(feature = "CBDescriptor")]
241        #[unsafe(method(descriptors))]
242        #[unsafe(method_family = none)]
243        pub unsafe fn descriptors(&self) -> Option<Retained<NSArray<CBDescriptor>>>;
244
245        #[cfg(feature = "CBDescriptor")]
246        /// Setter for [`descriptors`][Self::descriptors].
247        #[unsafe(method(setDescriptors:))]
248        #[unsafe(method_family = none)]
249        pub unsafe fn setDescriptors(&self, descriptors: Option<&NSArray<CBDescriptor>>);
250
251        #[cfg(feature = "CBUUID")]
252        /// Parameter `UUID`: The Bluetooth UUID of the characteristic.
253        ///
254        /// Parameter `properties`: The properties of the characteristic.
255        ///
256        /// Parameter `value`: The characteristic value to be cached. If
257        /// <i>
258        /// nil
259        /// </i>
260        /// , the value will be dynamic and requested on-demand.
261        ///
262        /// Parameter `permissions`: The permissions of the characteristic value.
263        ///
264        ///
265        /// Returns an initialized characteristic.
266        #[unsafe(method(initWithType:properties:value:permissions:))]
267        #[unsafe(method_family = init)]
268        pub unsafe fn initWithType_properties_value_permissions(
269            this: Allocated<Self>,
270            uuid: &CBUUID,
271            properties: CBCharacteristicProperties,
272            value: Option<&NSData>,
273            permissions: CBAttributePermissions,
274        ) -> Retained<Self>;
275    );
276}
277
278/// Methods declared on superclass `CBAttribute`.
279#[cfg(feature = "CBAttribute")]
280impl CBMutableCharacteristic {
281    extern_methods!(
282        #[unsafe(method(init))]
283        #[unsafe(method_family = init)]
284        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
285    );
286}
287
288/// Methods declared on superclass `NSObject`.
289#[cfg(feature = "CBAttribute")]
290impl CBMutableCharacteristic {
291    extern_methods!(
292        #[unsafe(method(new))]
293        #[unsafe(method_family = new)]
294        pub unsafe fn new() -> Retained<Self>;
295    );
296}