Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.mm

Issue 2071323002: bluetooth: mac: Initial BluetoothRemoteGattCharacteristicMac implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Skip reconnect-during-disconnected-event test Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h"
6
7 #include "base/mac/foundation_util.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
10
11 using base::mac::ObjCCast;
12 using base::scoped_nsobject;
13
14 namespace device {
15
16 namespace {
17
18 CBCharacteristicProperties AddCBCharacteristicProperties(
19 CBCharacteristicProperties value1,
20 CBCharacteristicProperties value2) {
21 return static_cast<CBCharacteristicProperties>(value1 | value2);
22 }
23
24 CBCharacteristicProperties GattCharacteristicPropertyToCBCharacteristicProperty(
25 BluetoothGattCharacteristic::Properties gatt_property) {
26 CBCharacteristicProperties result =
27 static_cast<CBCharacteristicProperties>(0);
28 if (gatt_property & BluetoothGattCharacteristic::PROPERTY_BROADCAST) {
29 result = AddCBCharacteristicProperties(result,
30 CBCharacteristicPropertyBroadcast);
31 }
32 if (gatt_property & BluetoothGattCharacteristic::PROPERTY_READ) {
33 result =
34 AddCBCharacteristicProperties(result, CBCharacteristicPropertyRead);
35 }
36 if (gatt_property &
37 BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE) {
38 result = AddCBCharacteristicProperties(
39 result, CBCharacteristicPropertyWriteWithoutResponse);
40 }
41 if (gatt_property & BluetoothGattCharacteristic::PROPERTY_WRITE) {
42 result =
43 AddCBCharacteristicProperties(result, CBCharacteristicPropertyWrite);
44 }
45 if (gatt_property & BluetoothGattCharacteristic::PROPERTY_NOTIFY) {
46 result =
47 AddCBCharacteristicProperties(result, CBCharacteristicPropertyNotify);
48 }
49 if (gatt_property & BluetoothGattCharacteristic::PROPERTY_INDICATE) {
50 result =
51 AddCBCharacteristicProperties(result, CBCharacteristicPropertyIndicate);
52 }
53 if (gatt_property &
54 BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES) {
55 result = AddCBCharacteristicProperties(
56 result, CBCharacteristicPropertyAuthenticatedSignedWrites);
57 }
58 if (gatt_property &
59 BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES) {
60 result = AddCBCharacteristicProperties(
61 result, CBCharacteristicPropertyExtendedProperties);
62 }
63 if (gatt_property & BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE) {
64 }
65 if (gatt_property &
66 BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES) {
67 }
68 if (gatt_property & BluetoothGattCharacteristic::PROPERTY_READ_ENCRYPTED) {
69 result =
70 AddCBCharacteristicProperties(result, CBCharacteristicPropertyRead);
71 }
72 if (gatt_property & BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED) {
73 result =
74 AddCBCharacteristicProperties(result, CBCharacteristicPropertyWrite);
75 }
76 if (gatt_property &
77 BluetoothGattCharacteristic::PROPERTY_READ_ENCRYPTED_AUTHENTICATED) {
78 result =
79 AddCBCharacteristicProperties(result, CBCharacteristicPropertyRead);
80 }
81 if (gatt_property &
82 BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED) {
83 result =
84 AddCBCharacteristicProperties(result, CBCharacteristicPropertyWrite);
85 }
86 return result;
87 }
88 } // namespace
89 } // device
90
91 @interface MockCBCharacteristic () {
92 scoped_nsobject<CBUUID> _UUID;
93 CBCharacteristicProperties _cb_properties;
94 }
95 @end
96
97 @implementation MockCBCharacteristic
98
99 - (instancetype)initWithCBUUID:(CBUUID*)uuid properties:(int)properties {
100 self = [super init];
101 if (self) {
102 _UUID.reset([uuid retain]);
103 _cb_properties =
104 device::GattCharacteristicPropertyToCBCharacteristicProperty(
105 properties);
106 }
107 return self;
108 }
109
110 - (BOOL)isKindOfClass:(Class)aClass {
111 if (aClass == [CBCharacteristic class] ||
112 [aClass isSubclassOfClass:[CBCharacteristic class]]) {
113 return YES;
114 }
115 return [super isKindOfClass:aClass];
116 }
117
118 - (BOOL)isMemberOfClass:(Class)aClass {
119 if (aClass == [CBCharacteristic class] ||
120 [aClass isSubclassOfClass:[CBCharacteristic class]]) {
121 return YES;
122 }
123 return [super isKindOfClass:aClass];
124 }
125
126 - (CBUUID*)UUID {
127 return _UUID.get();
128 }
129
130 - (CBCharacteristic*)characteristic {
131 return ObjCCast<CBCharacteristic>(self);
132 }
133
134 - (CBCharacteristicProperties)properties {
135 return _cb_properties;
136 }
137
138 @end
OLDNEW
« no previous file with comments | « device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h ('k') | device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698