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

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

Issue 1966893003: IDL changes for BLE GATT server support. (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 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return true; 179 return true;
180 return false; 180 return false;
181 } 181 }
182 182
183 device::BluetoothGattCharacteristic::Properties GetBluetoothProperties( 183 device::BluetoothGattCharacteristic::Properties GetBluetoothProperties(
184 const std::vector<apibtle::CharacteristicProperty>& api_properties) { 184 const std::vector<apibtle::CharacteristicProperty>& api_properties) {
185 device::BluetoothGattCharacteristic::Properties properties = 185 device::BluetoothGattCharacteristic::Properties properties =
186 device::BluetoothGattCharacteristic::PROPERTY_NONE; 186 device::BluetoothGattCharacteristic::PROPERTY_NONE;
187 187
188 static_assert( 188 static_assert(
189 apibtle::CHARACTERISTIC_PROPERTY_LAST == 10, 189 apibtle::CHARACTERISTIC_PROPERTY_LAST == 14,
190 "Update required if the number of characteristic properties changes."); 190 "Update required if the number of characteristic properties changes.");
191 191
192 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_BROADCAST)) 192 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_BROADCAST))
193 properties |= device::BluetoothGattCharacteristic::PROPERTY_BROADCAST; 193 properties |= device::BluetoothGattCharacteristic::PROPERTY_BROADCAST;
194 194
195 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_READ)) 195 if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_READ))
196 properties |= device::BluetoothGattCharacteristic::PROPERTY_READ; 196 properties |= device::BluetoothGattCharacteristic::PROPERTY_READ;
197 if (HasProperty(api_properties, 197 if (HasProperty(api_properties,
198 apibtle::CHARACTERISTIC_PROPERTY_WRITEWITHOUTRESPONSE)) 198 apibtle::CHARACTERISTIC_PROPERTY_WRITEWITHOUTRESPONSE))
199 properties |= 199 properties |=
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 void BluetoothLowEnergyRegisterServiceFunction::DoWork() { 1277 void BluetoothLowEnergyRegisterServiceFunction::DoWork() {
1278 event_router_->RegisterGattService( 1278 event_router_->RegisterGattService(
1279 extension(), params_->service_id, 1279 extension(), params_->service_id,
1280 base::Bind(&BluetoothLowEnergyRegisterServiceFunction::SuccessCallback, 1280 base::Bind(&BluetoothLowEnergyRegisterServiceFunction::SuccessCallback,
1281 this), 1281 this),
1282 base::Bind(&BluetoothLowEnergyRegisterServiceFunction::ErrorCallback, 1282 base::Bind(&BluetoothLowEnergyRegisterServiceFunction::ErrorCallback,
1283 this)); 1283 this));
1284 } 1284 }
1285 1285
1286 void BluetoothLowEnergyRegisterServiceFunction::SuccessCallback() { 1286 void BluetoothLowEnergyRegisterServiceFunction::SuccessCallback() {
1287 Respond(ArgumentList(apibtle::RegisterService::Results::Create( 1287 Respond(NoArguments());
1288 apibtle::SERVICE_RESULT_SUCCESS)));
1289 } 1288 }
1290 1289
1291 void BluetoothLowEnergyRegisterServiceFunction::ErrorCallback( 1290 void BluetoothLowEnergyRegisterServiceFunction::ErrorCallback(
1292 BluetoothLowEnergyEventRouter::Status status) { 1291 BluetoothLowEnergyEventRouter::Status status) {
1293 Respond(Error(StatusToString(status))); 1292 Respond(Error(StatusToString(status)));
1294 } 1293 }
1295 1294
1296 // unregisterService: 1295 // unregisterService:
1297 1296
1298 template class BLEPeripheralExtensionFunction< 1297 template class BLEPeripheralExtensionFunction<
1299 apibtle::UnregisterService::Params>; 1298 apibtle::UnregisterService::Params>;
1300 1299
1301 void BluetoothLowEnergyUnregisterServiceFunction::DoWork() { 1300 void BluetoothLowEnergyUnregisterServiceFunction::DoWork() {
1302 event_router_->UnregisterGattService( 1301 event_router_->UnregisterGattService(
1303 extension(), params_->service_id, 1302 extension(), params_->service_id,
1304 base::Bind(&BluetoothLowEnergyUnregisterServiceFunction::SuccessCallback, 1303 base::Bind(&BluetoothLowEnergyUnregisterServiceFunction::SuccessCallback,
1305 this), 1304 this),
1306 base::Bind(&BluetoothLowEnergyUnregisterServiceFunction::ErrorCallback, 1305 base::Bind(&BluetoothLowEnergyUnregisterServiceFunction::ErrorCallback,
1307 this)); 1306 this));
1308 } 1307 }
1309 1308
1310 void BluetoothLowEnergyUnregisterServiceFunction::SuccessCallback() { 1309 void BluetoothLowEnergyUnregisterServiceFunction::SuccessCallback() {
1311 Respond(ArgumentList(apibtle::UnregisterService::Results::Create( 1310 Respond(NoArguments());
1312 apibtle::SERVICE_RESULT_SUCCESS)));
1313 } 1311 }
1314 1312
1315 void BluetoothLowEnergyUnregisterServiceFunction::ErrorCallback( 1313 void BluetoothLowEnergyUnregisterServiceFunction::ErrorCallback(
1316 BluetoothLowEnergyEventRouter::Status status) { 1314 BluetoothLowEnergyEventRouter::Status status) {
1317 Respond(Error(StatusToString(status))); 1315 Respond(Error(StatusToString(status)));
1318 } 1316 }
1319 1317
1318 // notifyCharacteristicValueChanged:
1319
1320 template class BLEPeripheralExtensionFunction<
1321 apibtle::NotifyCharacteristicValueChanged::Params>;
1322
1323 void BluetoothLowEnergyNotifyCharacteristicValueChangedFunction::DoWork() {
1324 Respond(Error(kErrorPermissionDenied));
1325 }
1326
1327 // removeService:
1328
1329 template class BLEPeripheralExtensionFunction<apibtle::RemoveService::Params>;
1330
1331 void BluetoothLowEnergyRemoveServiceFunction::DoWork() {
1332 Respond(Error(kErrorPermissionDenied));
1333 }
1334
1320 // sendRequestResponse: 1335 // sendRequestResponse:
1321 1336
1322 template class BLEPeripheralExtensionFunction< 1337 template class BLEPeripheralExtensionFunction<
1323 apibtle::SendRequestResponse::Params>; 1338 apibtle::SendRequestResponse::Params>;
1324 1339
1325 void BluetoothLowEnergySendRequestResponseFunction::DoWork() { 1340 void BluetoothLowEnergySendRequestResponseFunction::DoWork() {
1326 std::vector<uint8_t> uint8_vector; 1341 std::vector<uint8_t> uint8_vector;
1327 if (params_->response.value) { 1342 if (params_->response.value) {
1328 uint8_vector.assign(params_->response.value->begin(), 1343 uint8_vector.assign(params_->response.value->begin(),
1329 params_->response.value->end()); 1344 params_->response.value->end());
1330 } 1345 }
1331 event_router_->HandleRequestResponse( 1346 event_router_->HandleRequestResponse(
1332 extension(), params_->response.request_id, params_->response.is_error, 1347 extension(), params_->response.request_id, params_->response.is_error,
1333 uint8_vector); 1348 uint8_vector);
1334 Respond(NoArguments()); 1349 Respond(NoArguments());
1335 } 1350 }
1336 1351
1337 } // namespace api 1352 } // namespace api
1338 } // namespace extensions 1353 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698