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

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(
scheib 2016/05/07 01:12:45 Add a compile time check that all enum values are
rkc 2016/05/07 20:27:00 Done.
scheib 2016/05/08 03:29:56 Flags too please.
rkc 2016/05/08 22:15:30 I presume you mean permissions too? Done.
scheib 2016/05/08 23:43:51 Yep.
26 device::BluetoothGattCharacteristic::Properties properties) {
27 std::vector<std::string> flags;
28 if (properties & device::BluetoothGattCharacteristic::PROPERTY_BROADCAST)
29 flags.push_back(bluetooth_gatt_characteristic::kFlagBroadcast);
30 if (properties & device::BluetoothGattCharacteristic::PROPERTY_READ)
31 flags.push_back(bluetooth_gatt_characteristic::kFlagRead);
32 if (properties &
33 device::BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE)
34 flags.push_back(bluetooth_gatt_characteristic::kFlagWriteWithoutResponse);
35 if (properties & device::BluetoothGattCharacteristic::PROPERTY_WRITE)
36 flags.push_back(bluetooth_gatt_characteristic::kFlagWrite);
37 if (properties & device::BluetoothGattCharacteristic::PROPERTY_NOTIFY)
38 flags.push_back(bluetooth_gatt_characteristic::kFlagNotify);
39 if (properties & device::BluetoothGattCharacteristic::PROPERTY_INDICATE)
40 flags.push_back(bluetooth_gatt_characteristic::kFlagIndicate);
41 if (properties &
42 device::BluetoothGattCharacteristic::PROPERTY_AUTHENTICATED_SIGNED_WRITES)
43 flags.push_back(
44 bluetooth_gatt_characteristic::kFlagAuthenticatedSignedWrites);
45 if (properties &
46 device::BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES)
47 flags.push_back(bluetooth_gatt_characteristic::kFlagExtendedProperties);
48 if (properties & device::BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE)
49 flags.push_back(bluetooth_gatt_characteristic::kFlagReliableWrite);
50 if (properties &
51 device::BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES)
52 flags.push_back(bluetooth_gatt_characteristic::kFlagWritableAuxiliaries);
53 if (properties & device::BluetoothGattCharacteristic::PROPERTY_READ_ENCRYPTED)
54 flags.push_back(bluetooth_gatt_characteristic::kFlagEncryptRead);
55 if (properties &
56 device::BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED)
57 flags.push_back(bluetooth_gatt_characteristic::kFlagEncryptWrite);
58 if (properties & device::BluetoothGattCharacteristic::
59 PROPERTY_READ_ENCRYPTED_AUTHENTICATED)
60 flags.push_back(
61 bluetooth_gatt_characteristic::kFlagEncryptAuthenticatedRead);
62 if (properties & device::BluetoothGattCharacteristic::
63 PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED)
64 flags.push_back(
65 bluetooth_gatt_characteristic::kFlagEncryptAuthenticatedWrite);
66 return flags;
67 }
68
69 const std::vector<std::string> FlagsFromPermissions(
70 device::BluetoothGattCharacteristic::Permissions permissions) {
71 std::vector<std::string> flags;
72 if (permissions & device::BluetoothGattCharacteristic::PERMISSION_READ)
73 flags.push_back(bluetooth_gatt_descriptor::kFlagRead);
74 if (permissions & device::BluetoothGattCharacteristic::PERMISSION_WRITE)
75 flags.push_back(bluetooth_gatt_descriptor::kFlagWrite);
76 if (permissions &
77 device::BluetoothGattCharacteristic::PERMISSION_READ_ENCRYPTED)
78 flags.push_back(bluetooth_gatt_descriptor::kFlagEncryptRead);
79 if (permissions &
80 device::BluetoothGattCharacteristic::PERMISSION_WRITE_ENCRYPTED)
81 flags.push_back(bluetooth_gatt_descriptor::kFlagEncryptWrite);
82 if (permissions & device::BluetoothGattCharacteristic::
83 PERMISSION_READ_ENCRYPTED_AUTHENTICATED)
84 flags.push_back(bluetooth_gatt_descriptor::kFlagEncryptAuthenticatedRead);
85 if (permissions & device::BluetoothGattCharacteristic::
86 PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED)
87 flags.push_back(bluetooth_gatt_descriptor::kFlagEncryptAuthenticatedWrite);
88 return flags;
89 }
90
91 } // namespace
92
25 BluetoothGattApplicationServiceProvider:: 93 BluetoothGattApplicationServiceProvider::
26 BluetoothGattApplicationServiceProvider() {} 94 BluetoothGattApplicationServiceProvider() {}
27 95
28 BluetoothGattApplicationServiceProvider:: 96 BluetoothGattApplicationServiceProvider::
29 ~BluetoothGattApplicationServiceProvider() {} 97 ~BluetoothGattApplicationServiceProvider() {}
30 98
31 // static 99 // static
32 void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders( 100 void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders(
33 dbus::Bus* bus, 101 dbus::Bus* bus,
34 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& services, 102 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& services,
35 std::vector<std::unique_ptr<BluetoothGattServiceServiceProvider>>* 103 std::vector<std::unique_ptr<BluetoothGattServiceServiceProvider>>*
36 service_providers, 104 service_providers,
37 std::vector<std::unique_ptr<BluetoothGattCharacteristicServiceProvider>>* 105 std::vector<std::unique_ptr<BluetoothGattCharacteristicServiceProvider>>*
38 characteristic_providers, 106 characteristic_providers,
39 std::vector<std::unique_ptr<BluetoothGattDescriptorServiceProvider>>* 107 std::vector<std::unique_ptr<BluetoothGattDescriptorServiceProvider>>*
40 descriptor_providers) { 108 descriptor_providers) {
41 for (const auto& service : services) { 109 for (const auto& service : services) {
42 service_providers->push_back( 110 service_providers->push_back(
43 base::WrapUnique(BluetoothGattServiceServiceProvider::Create( 111 base::WrapUnique(BluetoothGattServiceServiceProvider::Create(
44 bus, service.second->object_path(), 112 bus, service.second->object_path(),
45 service.second->GetUUID().value(), service.second->IsPrimary(), 113 service.second->GetUUID().value(), service.second->IsPrimary(),
46 std::vector<dbus::ObjectPath>()))); 114 std::vector<dbus::ObjectPath>())));
47 for (const auto& characteristic : service.second->GetCharacteristics()) { 115 for (const auto& characteristic : service.second->GetCharacteristics()) {
48 characteristic_providers->push_back( 116 characteristic_providers->push_back(
49 base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create( 117 base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create(
50 bus, characteristic.second->object_path(), 118 bus, characteristic.second->object_path(),
51 base::WrapUnique(new BluetoothGattCharacteristicDelegateWrapper( 119 base::WrapUnique(new BluetoothGattCharacteristicDelegateWrapper(
52 service.second, characteristic.second.get())), 120 service.second, characteristic.second.get())),
53 characteristic.second->GetUUID().value(), 121 characteristic.second->GetUUID().value(),
54 std::vector<std::string>(), service.second->object_path()))); 122 FlagsFromProperties(characteristic.second->GetProperties()),
scheib 2016/05/07 01:12:45 It would be nice if this code was covered in bluet
rkc 2016/05/07 20:27:01 To use this method, we'd need to have a valid set
scheib 2016/05/08 03:29:56 Acknowledged.
123 service.second->object_path())));
55 for (const auto& descriptor : characteristic.second->GetDescriptors()) { 124 for (const auto& descriptor : characteristic.second->GetDescriptors()) {
56 descriptor_providers->push_back( 125 descriptor_providers->push_back(
57 base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create( 126 base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create(
58 bus, descriptor->object_path(), 127 bus, descriptor->object_path(),
59 base::WrapUnique(new BluetoothGattDescriptorDelegateWrapper( 128 base::WrapUnique(new BluetoothGattDescriptorDelegateWrapper(
60 service.second, descriptor.get())), 129 service.second, descriptor.get())),
61 descriptor->GetUUID().value(), std::vector<std::string>(), 130 descriptor->GetUUID().value(),
131 FlagsFromPermissions(descriptor->GetPermissions()),
62 characteristic.second->object_path()))); 132 characteristic.second->object_path())));
63 } 133 }
64 } 134 }
65 } 135 }
66 } 136 }
67 137
68 // static 138 // static
69 std::unique_ptr<BluetoothGattApplicationServiceProvider> 139 std::unique_ptr<BluetoothGattApplicationServiceProvider>
70 BluetoothGattApplicationServiceProvider::Create( 140 BluetoothGattApplicationServiceProvider::Create(
71 dbus::Bus* bus, 141 dbus::Bus* bus,
72 const dbus::ObjectPath& object_path, 142 const dbus::ObjectPath& object_path,
73 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& 143 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>&
74 services) { 144 services) {
75 if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) { 145 if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) {
76 return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl( 146 return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl(
77 bus, object_path, services)); 147 bus, object_path, services));
78 } 148 }
79 return base::WrapUnique( 149 return base::WrapUnique(
80 new FakeBluetoothGattApplicationServiceProvider(object_path, services)); 150 new FakeBluetoothGattApplicationServiceProvider(object_path, services));
81 } 151 }
82 152
83 } // namespace bluez 153 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698