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