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

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

Issue 1974633002: Implement DBus changes needed for notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 } // namespace 97 } // namespace
98 98
99 BluetoothGattApplicationServiceProvider:: 99 BluetoothGattApplicationServiceProvider::
100 BluetoothGattApplicationServiceProvider() {} 100 BluetoothGattApplicationServiceProvider() {}
101 101
102 BluetoothGattApplicationServiceProvider:: 102 BluetoothGattApplicationServiceProvider::
103 ~BluetoothGattApplicationServiceProvider() {} 103 ~BluetoothGattApplicationServiceProvider() {}
104 104
105 // static
106 void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders( 105 void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders(
107 dbus::Bus* bus, 106 dbus::Bus* bus,
108 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& services, 107 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>&
109 std::vector<std::unique_ptr<BluetoothGattServiceServiceProvider>>* 108 services) {
110 service_providers,
111 std::vector<std::unique_ptr<BluetoothGattCharacteristicServiceProvider>>*
112 characteristic_providers,
113 std::vector<std::unique_ptr<BluetoothGattDescriptorServiceProvider>>*
114 descriptor_providers) {
115 for (const auto& service : services) { 109 for (const auto& service : services) {
116 service_providers->push_back( 110 service_providers_.push_back(
117 base::WrapUnique(BluetoothGattServiceServiceProvider::Create( 111 base::WrapUnique(BluetoothGattServiceServiceProvider::Create(
118 bus, service.second->object_path(), 112 bus, service.second->object_path(),
119 service.second->GetUUID().value(), service.second->IsPrimary(), 113 service.second->GetUUID().value(), service.second->IsPrimary(),
120 std::vector<dbus::ObjectPath>()))); 114 std::vector<dbus::ObjectPath>())));
121 for (const auto& characteristic : service.second->GetCharacteristics()) { 115 for (const auto& characteristic : service.second->GetCharacteristics()) {
122 characteristic_providers->push_back( 116 characteristic_providers_.push_back(
123 base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create( 117 base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create(
124 bus, characteristic.second->object_path(), 118 bus, characteristic.second->object_path(),
125 base::WrapUnique(new BluetoothGattCharacteristicDelegateWrapper( 119 base::WrapUnique(new BluetoothGattCharacteristicDelegateWrapper(
126 service.second, characteristic.second.get())), 120 service.second, characteristic.second.get())),
127 characteristic.second->GetUUID().value(), 121 characteristic.second->GetUUID().value(),
128 FlagsFromProperties(characteristic.second->GetProperties()), 122 FlagsFromProperties(characteristic.second->GetProperties()),
129 service.second->object_path()))); 123 service.second->object_path())));
130 for (const auto& descriptor : characteristic.second->GetDescriptors()) { 124 for (const auto& descriptor : characteristic.second->GetDescriptors()) {
131 descriptor_providers->push_back( 125 descriptor_providers_.push_back(
132 base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create( 126 base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create(
133 bus, descriptor->object_path(), 127 bus, descriptor->object_path(),
134 base::WrapUnique(new BluetoothGattDescriptorDelegateWrapper( 128 base::WrapUnique(new BluetoothGattDescriptorDelegateWrapper(
135 service.second, descriptor.get())), 129 service.second, descriptor.get())),
136 descriptor->GetUUID().value(), 130 descriptor->GetUUID().value(),
137 FlagsFromPermissions(descriptor->GetPermissions()), 131 FlagsFromPermissions(descriptor->GetPermissions()),
138 characteristic.second->object_path()))); 132 characteristic.second->object_path())));
139 } 133 }
140 } 134 }
141 } 135 }
142 } 136 }
143 137
138 void BluetoothGattApplicationServiceProvider::SendValueChanged(
139 const dbus::ObjectPath& characteristic_path,
140 const std::vector<uint8_t>& value) {
141 auto characteristic = std::find_if(
142 characteristic_providers_.begin(), characteristic_providers_.end(),
143 [&](const std::unique_ptr<BluetoothGattCharacteristicServiceProvider>&
144 p) { return p->object_path() == characteristic_path; });
145 if (characteristic == characteristic_providers_.end()) {
146 LOG(ERROR) << "Couldn't find characteristic provider for: "
147 << characteristic_path.value();
148 return;
149 }
150 characteristic->get()->SendValueChanged(value);
151 }
152
144 // static 153 // static
145 std::unique_ptr<BluetoothGattApplicationServiceProvider> 154 std::unique_ptr<BluetoothGattApplicationServiceProvider>
146 BluetoothGattApplicationServiceProvider::Create( 155 BluetoothGattApplicationServiceProvider::Create(
147 dbus::Bus* bus, 156 dbus::Bus* bus,
148 const dbus::ObjectPath& object_path, 157 const dbus::ObjectPath& object_path,
149 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>& 158 const std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>&
150 services) { 159 services) {
151 if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) { 160 if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) {
152 return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl( 161 return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl(
153 bus, object_path, services)); 162 bus, object_path, services));
154 } 163 }
155 return base::WrapUnique( 164 return base::WrapUnique(
156 new FakeBluetoothGattApplicationServiceProvider(object_path, services)); 165 new FakeBluetoothGattApplicationServiceProvider(object_path, services));
157 } 166 }
158 167
159 } // namespace bluez 168 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698