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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc

Issue 1951863004: API changes to support sending characteristic properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluez_changes_for_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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h" 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energ y_api.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <iterator> 9 #include <iterator>
10 #include <vector> 10 #include <vector>
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 std::unique_ptr<device::BluetoothAdvertisement::ServiceData> created_data( 164 std::unique_ptr<device::BluetoothAdvertisement::ServiceData> created_data(
165 new device::BluetoothAdvertisement::ServiceData()); 165 new device::BluetoothAdvertisement::ServiceData());
166 for (const auto& it : *service_data) { 166 for (const auto& it : *service_data) {
167 std::vector<uint8_t> data(it.data.size()); 167 std::vector<uint8_t> data(it.data.size());
168 std::copy(it.data.begin(), it.data.end(), data.begin()); 168 std::copy(it.data.begin(), it.data.end(), data.begin());
169 (*created_data)[it.uuid] = data; 169 (*created_data)[it.uuid] = data;
170 } 170 }
171 return created_data; 171 return created_data;
172 } 172 }
173 173
174 bool HasProperty(
175 const std::vector<apibtle::CharacteristicProperty>& api_properties,
176 apibtle::CharacteristicProperty property) {
177 if (find(api_properties.begin(), api_properties.end(), property) !=
178 api_properties.end())
179 return true;
180 return false;
181 }
182
183 device::BluetoothGattCharacteristic::Properties GetBluetoothProperties(
184 const std::vector<apibtle::CharacteristicProperty>& api_properties) {
185 device::BluetoothGattCharacteristic::Properties properties =
186 device::BluetoothGattCharacteristic::PROPERTY_NONE;
187
scheib 2016/05/07 01:15:06 Add a compile time check that all enum values are
rkc 2016/05/07 20:39:23 Done.
188 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_BROADCAST))
189 properties |= device::BluetoothGattCharacteristic::PROPERTY_BROADCAST;
190
191 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_READ))
192 properties |= device::BluetoothGattCharacteristic::PROPERTY_READ;
193 if (HasProperty(api_properties,
194 apibtle::CHARACTERISTIC_PROPERTY_WRITEWITHOUTRESPONSE))
195 properties |=
196 device::BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE;
197 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_WRITE))
198 properties |= device::BluetoothGattCharacteristic::PROPERTY_WRITE;
199
200 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_NOTIFY))
201 properties |= device::BluetoothGattCharacteristic::PROPERTY_NOTIFY;
202
203 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_INDICATE))
204 properties |= device::BluetoothGattCharacteristic::PROPERTY_INDICATE;
205
206 if (HasProperty(api_properties,
207 apibtle::CHARACTERISTIC_PROPERTY_AUTHENTICATEDSIGNEDWRITES))
208 properties |= device::BluetoothGattCharacteristic::
209 PROPERTY_AUTHENTICATED_SIGNED_WRITES;
210 if (HasProperty(api_properties,
211 apibtle::CHARACTERISTIC_PROPERTY_EXTENDEDPROPERTIES))
212 properties |=
213 device::BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES;
214 if (HasProperty(api_properties,
215 apibtle::CHARACTERISTIC_PROPERTY_RELIABLEWRITE))
216 properties |= device::BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE;
217 if (HasProperty(api_properties,
218 apibtle::CHARACTERISTIC_PROPERTY_WRITABLEAUXILIARIES))
219 properties |=
220 device::BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES;
221
222 return properties;
223 }
224
174 } // namespace 225 } // namespace
175 226
176 227
177 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> > 228 static base::LazyInstance<BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI> >
178 g_factory = LAZY_INSTANCE_INITIALIZER; 229 g_factory = LAZY_INSTANCE_INITIALIZER;
179 230
180 // static 231 // static
181 BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>* 232 BrowserContextKeyedAPIFactory<BluetoothLowEnergyAPI>*
182 BluetoothLowEnergyAPI::GetFactoryInstance() { 233 BluetoothLowEnergyAPI::GetFactoryInstance() {
183 return g_factory.Pointer(); 234 return g_factory.Pointer();
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 device::BluetoothLocalGattService* service = 1224 device::BluetoothLocalGattService* service =
1174 event_router_->adapter()->GetGattService(params_->service_id); 1225 event_router_->adapter()->GetGattService(params_->service_id);
1175 if (!service) { 1226 if (!service) {
1176 Respond(Error(kErrorInvalidServiceId)); 1227 Respond(Error(kErrorInvalidServiceId));
1177 return; 1228 return;
1178 } 1229 }
1179 1230
1180 base::WeakPtr<device::BluetoothLocalGattCharacteristic> characteristic = 1231 base::WeakPtr<device::BluetoothLocalGattCharacteristic> characteristic =
1181 device::BluetoothLocalGattCharacteristic::Create( 1232 device::BluetoothLocalGattCharacteristic::Create(
1182 device::BluetoothUUID(params_->characteristic.uuid), 1233 device::BluetoothUUID(params_->characteristic.uuid),
1183 device::BluetoothGattCharacteristic::Properties(), 1234 GetBluetoothProperties(params_->characteristic.properties),
1184 device::BluetoothGattCharacteristic::Permissions(), service); 1235 device::BluetoothGattCharacteristic::Permissions(), service);
1185 1236
1186 // Keep a track of this characteristic so we can look it up later if a 1237 // Keep a track of this characteristic so we can look it up later if a
1187 // descriptor lists it as its parent. 1238 // descriptor lists it as its parent.
1188 event_router_->AddLocalCharacteristic(characteristic->GetIdentifier(), 1239 event_router_->AddLocalCharacteristic(characteristic->GetIdentifier(),
1189 service->GetIdentifier()); 1240 service->GetIdentifier());
1190 1241
1191 Respond(ArgumentList(apibtle::CreateCharacteristic::Results::Create( 1242 Respond(ArgumentList(apibtle::CreateCharacteristic::Results::Create(
1192 characteristic->GetIdentifier()))); 1243 characteristic->GetIdentifier())));
1193 } 1244 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 std::vector<uint8_t> uint8_vector(params_->response.value->begin(), 1321 std::vector<uint8_t> uint8_vector(params_->response.value->begin(),
1271 params_->response.value->end()); 1322 params_->response.value->end());
1272 event_router_->HandleRequestResponse( 1323 event_router_->HandleRequestResponse(
1273 extension(), params_->response.request_id, params_->response.is_error, 1324 extension(), params_->response.request_id, params_->response.is_error,
1274 uint8_vector); 1325 uint8_vector);
1275 Respond(NoArguments()); 1326 Respond(NoArguments());
1276 } 1327 }
1277 1328
1278 } // namespace api 1329 } // namespace api
1279 } // namespace extensions 1330 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698