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

Side by Side Diff: device/bluetooth/dbus/bluetooth_gatt_application_service_provider.cc

Issue 1947353002: //device/bluetooth support for attribute properties and permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@properties
Patch Set: Created 4 years, 7 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h" 5 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector>
10 9
11 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
12 #include "device/bluetooth/bluetooth_uuid.h" 12 #include "device/bluetooth/bluetooth_uuid.h"
13 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h" 13 #include "device/bluetooth/bluez/bluetooth_gatt_service_bluez.h"
14 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider_impl .h" 14 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider_impl .h"
15 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_delegate_wrapper.h " 15 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_delegate_wrapper.h "
16 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider.h "
17 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_delegate_wrapper.h" 16 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_delegate_wrapper.h"
18 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider.h"
19 #include "device/bluetooth/dbus/bluetooth_gatt_service_service_provider.h"
20 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_application_service_provider .h" 18 #include "device/bluetooth/dbus/fake_bluetooth_gatt_application_service_provider .h"
19 #include "third_party/cros_system_api/dbus/service_constants.h"
22 20
23 namespace bluez { 21 namespace bluez {
24 22
23 namespace {
24
25 const std::vector<std::string> FlagsFromProperties(
26 device::BluetoothGattCharacteristic::Properties properties) {
27 static_assert(
28 device::BluetoothGattCharacteristic::NUM_PROPERTY == 1 << 14,
29 "Update required if the number of characteristic properties changes.");
30 std::vector<std::string> flags;
31 if (properties & device::BluetoothGattCharacteristic::PROPERTY_BROADCAST)
32 flags.push_back(bluetooth_gatt_characteristic::kFlagBroadcast);
33 if (properties & device::BluetoothGattCharacteristic::PROPERTY_READ)
34 flags.push_back(bluetooth_gatt_characteristic::kFlagRead);
35 if (properties &
36 device::BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE)
37 flags.push_back(bluetooth_gatt_characteristic::kFlagWriteWithoutResponse);
38 if (properties & device::BluetoothGattCharacteristic::PROPERTY_WRITE)
39 flags.push_back(bluetooth_gatt_characteristic::kFlagWrite);
40 if (properties & device::BluetoothGattCharacteristic::PROPERTY_NOTIFY)
41 flags.push_back(bluetooth_gatt_characteristic::kFlagNotify);
42 if (properties & device::BluetoothGattCharacteristic::PROPERTY_INDICATE)
43 flags.push_back(bluetooth_gatt_characteristic::kFlagIndicate);
44 if (properties &
45 device::BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES)
46 flags.push_back(
47 bluetooth_gatt_characteristic::kFlagAuthenticatedSignedWrites);
48 if (properties &
49 device::BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES)
50 flags.push_back(bluetooth_gatt_characteristic::kFlagExtendedProperties);
51 if (properties & device::BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE)
52 flags.push_back(bluetooth_gatt_characteristic::kFlagReliableWrite);
53 if (properties &
54 device::BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES)
55 flags.push_back(bluetooth_gatt_characteristic::kFlagWritableAuxiliaries);
56 if (properties & device::BluetoothGattCharacteristic::PROPERTY_READ_ENCRYPTED)
57 flags.push_back(bluetooth_gatt_characteristic::kFlagEncryptRead);
58 if (properties &
59 device::BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED)
60 flags.push_back(bluetooth_gatt_characteristic::kFlagEncryptWrite);
61 if (properties & device::BluetoothGattCharacteristic::
62 PROPERTY_READ_ENCRYPTED_AUTHENTICATED)
63 flags.push_back(
64 bluetooth_gatt_characteristic::kFlagEncryptAuthenticatedRead);
65 if (properties & device::BluetoothGattCharacteristic::
66 PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED)
67 flags.push_back(
68 bluetooth_gatt_characteristic::kFlagEncryptAuthenticatedWrite);
69 return flags;
70 }
71
72 const std::vector<std::string> FlagsFromPermissions(
73 device::BluetoothGattCharacteristic::Permissions permissions) {
74 static_assert(
75 device::BluetoothGattCharacteristic::NUM_PERMISSION == 1 << 6,
76 "Update required if the number of attribute permissions changes.");
77 std::vector<std::string> flags;
78 if (permissions & device::BluetoothGattCharacteristic::PERMISSION_READ)
79 flags.push_back(bluetooth_gatt_descriptor::kFlagRead);
80 if (permissions & device::BluetoothGattCharacteristic::PERMISSION_WRITE)
81 flags.push_back(bluetooth_gatt_descriptor::kFlagWrite);
82 if (permissions &
83 device::BluetoothGattCharacteristic::PERMISSION_READ_ENCRYPTED)
84 flags.push_back(bluetooth_gatt_descriptor::kFlagEncryptRead);
85 if (permissions &
86 device::BluetoothGattCharacteristic::PERMISSION_WRITE_ENCRYPTED)
87 flags.push_back(bluetooth_gatt_descriptor::kFlagEncryptWrite);
88 if (permissions & device::BluetoothGattCharacteristic::
89 PERMISSION_READ_ENCRYPTED_AUTHENTICATED)
90 flags.push_back(bluetooth_gatt_descriptor::kFlagEncryptAuthenticatedRead);
91 if (permissions & device::BluetoothGattCharacteristic::
92 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED)
93 flags.push_back(bluetooth_gatt_descriptor::kFlagEncryptAuthenticatedWrite);
94 return flags;
95 }
96
97 } // namespace
98
25 BluetoothGattApplicationServiceProvider:: 99 BluetoothGattApplicationServiceProvider::
26 BluetoothGattApplicationServiceProvider() {} 100 BluetoothGattApplicationServiceProvider() {}
27 101
28 BluetoothGattApplicationServiceProvider:: 102 BluetoothGattApplicationServiceProvider::
29 ~BluetoothGattApplicationServiceProvider() {} 103 ~BluetoothGattApplicationServiceProvider() {}
30 104
31 // static 105 // static
32 void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders( 106 void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders(
33 dbus::Bus* bus, 107 dbus::Bus* bus,
34 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& services, 108 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& services,
35 std::vector<std::unique_ptr<BluetoothGattServiceServiceProvider>>* 109 std::vector<std::unique_ptr<BluetoothGattServiceServiceProvider>>*
36 service_providers, 110 service_providers,
37 std::vector<std::unique_ptr<BluetoothGattCharacteristicServiceProvider>>* 111 std::vector<std::unique_ptr<BluetoothGattCharacteristicServiceProvider>>*
38 characteristic_providers, 112 characteristic_providers,
39 std::vector<std::unique_ptr<BluetoothGattDescriptorServiceProvider>>* 113 std::vector<std::unique_ptr<BluetoothGattDescriptorServiceProvider>>*
40 descriptor_providers) { 114 descriptor_providers) {
41 for (const auto& service : services) { 115 for (const auto& service : services) {
42 service_providers->push_back( 116 service_providers->push_back(
43 base::WrapUnique(BluetoothGattServiceServiceProvider::Create( 117 base::WrapUnique(BluetoothGattServiceServiceProvider::Create(
44 bus, service.second->object_path(), 118 bus, service.second->object_path(),
45 service.second->GetUUID().value(), service.second->IsPrimary(), 119 service.second->GetUUID().value(), service.second->IsPrimary(),
46 std::vector<dbus::ObjectPath>()))); 120 std::vector<dbus::ObjectPath>())));
47 for (const auto& characteristic : service.second->GetCharacteristics()) { 121 for (const auto& characteristic : service.second->GetCharacteristics()) {
48 characteristic_providers->push_back( 122 characteristic_providers->push_back(
49 base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create( 123 base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create(
50 bus, characteristic.second->object_path(), 124 bus, characteristic.second->object_path(),
51 base::WrapUnique(new BluetoothGattCharacteristicDelegateWrapper( 125 base::WrapUnique(new BluetoothGattCharacteristicDelegateWrapper(
52 service.second, characteristic.second.get())), 126 service.second, characteristic.second.get())),
53 characteristic.second->GetUUID().value(), 127 characteristic.second->GetUUID().value(),
54 std::vector<std::string>(), service.second->object_path()))); 128 FlagsFromProperties(characteristic.second->GetProperties()),
129 service.second->object_path())));
55 for (const auto& descriptor : characteristic.second->GetDescriptors()) { 130 for (const auto& descriptor : characteristic.second->GetDescriptors()) {
56 descriptor_providers->push_back( 131 descriptor_providers->push_back(
57 base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create( 132 base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create(
58 bus, descriptor->object_path(), 133 bus, descriptor->object_path(),
59 base::WrapUnique(new BluetoothGattDescriptorDelegateWrapper( 134 base::WrapUnique(new BluetoothGattDescriptorDelegateWrapper(
60 service.second, descriptor.get())), 135 service.second, descriptor.get())),
61 descriptor->GetUUID().value(), std::vector<std::string>(), 136 descriptor->GetUUID().value(),
137 FlagsFromPermissions(descriptor->GetPermissions()),
62 characteristic.second->object_path()))); 138 characteristic.second->object_path())));
63 } 139 }
64 } 140 }
65 } 141 }
66 } 142 }
67 143
68 // static 144 // static
69 std::unique_ptr<BluetoothGattApplicationServiceProvider> 145 std::unique_ptr<BluetoothGattApplicationServiceProvider>
70 BluetoothGattApplicationServiceProvider::Create( 146 BluetoothGattApplicationServiceProvider::Create(
71 dbus::Bus* bus, 147 dbus::Bus* bus,
72 const dbus::ObjectPath& object_path, 148 const dbus::ObjectPath& object_path,
73 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& 149 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>&
74 services) { 150 services) {
75 if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) { 151 if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) {
76 return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl( 152 return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl(
77 bus, object_path, services)); 153 bus, object_path, services));
78 } 154 }
79 return base::WrapUnique( 155 return base::WrapUnique(
80 new FakeBluetoothGattApplicationServiceProvider(object_path, services)); 156 new FakeBluetoothGattApplicationServiceProvider(object_path, services));
81 } 157 }
82 158
83 } // namespace bluez 159 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698