| OLD | NEW |
| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 const char kErrorPermissionDenied[] = "Permission denied"; | 66 const char kErrorPermissionDenied[] = "Permission denied"; |
| 67 const char kErrorPlatformNotSupported[] = | 67 const char kErrorPlatformNotSupported[] = |
| 68 "This operation is not supported on the current platform"; | 68 "This operation is not supported on the current platform"; |
| 69 const char kErrorRequestNotSupported[] = "Request not supported"; | 69 const char kErrorRequestNotSupported[] = "Request not supported"; |
| 70 const char kErrorTimeout[] = "Operation timed out"; | 70 const char kErrorTimeout[] = "Operation timed out"; |
| 71 const char kErrorUnsupportedDevice[] = | 71 const char kErrorUnsupportedDevice[] = |
| 72 "This device is not supported on the current platform"; | 72 "This device is not supported on the current platform"; |
| 73 const char kErrorInvalidServiceId[] = "The service ID doesn't exist."; | 73 const char kErrorInvalidServiceId[] = "The service ID doesn't exist."; |
| 74 const char kErrorInvalidCharacteristicId[] = | 74 const char kErrorInvalidCharacteristicId[] = |
| 75 "The characteristic ID doesn't exist."; | 75 "The characteristic ID doesn't exist."; |
| 76 const char kErrorNotifyPropertyNotSet[] = |
| 77 "The characteristic does not have the notify property set."; |
| 78 const char kErrorIndicatePropertyNotSet[] = |
| 79 "The characteristic does not have the indicate property set."; |
| 80 const char kErrorServiceNotRegistered[] = |
| 81 "The characteristic is not owned by a service that is registered."; |
| 82 const char kErrorUnknownNotificationError[] = |
| 83 "An unknown notification error occured."; |
| 84 |
| 76 const char kStatusAdvertisementAlreadyExists[] = | 85 const char kStatusAdvertisementAlreadyExists[] = |
| 77 "An advertisement is already advertising"; | 86 "An advertisement is already advertising"; |
| 78 const char kStatusAdvertisementDoesNotExist[] = | 87 const char kStatusAdvertisementDoesNotExist[] = |
| 79 "This advertisement does not exist"; | 88 "This advertisement does not exist"; |
| 80 | 89 |
| 81 // Returns the correct error string based on error status |status|. This is used | 90 // Returns the correct error string based on error status |status|. This is used |
| 82 // to set the value of |chrome.runtime.lastError.message| and should not be | 91 // to set the value of |chrome.runtime.lastError.message| and should not be |
| 83 // passed |BluetoothLowEnergyEventRouter::kStatusSuccess|. | 92 // passed |BluetoothLowEnergyEventRouter::kStatusSuccess|. |
| 84 std::string StatusToString(BluetoothLowEnergyEventRouter::Status status) { | 93 std::string StatusToString(BluetoothLowEnergyEventRouter::Status status) { |
| 85 switch (status) { | 94 switch (status) { |
| (...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 BluetoothLowEnergyEventRouter::Status status) { | 1412 BluetoothLowEnergyEventRouter::Status status) { |
| 1404 Respond(Error(StatusToString(status))); | 1413 Respond(Error(StatusToString(status))); |
| 1405 } | 1414 } |
| 1406 | 1415 |
| 1407 // notifyCharacteristicValueChanged: | 1416 // notifyCharacteristicValueChanged: |
| 1408 | 1417 |
| 1409 template class BLEPeripheralExtensionFunction< | 1418 template class BLEPeripheralExtensionFunction< |
| 1410 apibtle::NotifyCharacteristicValueChanged::Params>; | 1419 apibtle::NotifyCharacteristicValueChanged::Params>; |
| 1411 | 1420 |
| 1412 void BluetoothLowEnergyNotifyCharacteristicValueChangedFunction::DoWork() { | 1421 void BluetoothLowEnergyNotifyCharacteristicValueChangedFunction::DoWork() { |
| 1413 Respond(Error(kErrorPermissionDenied)); | 1422 device::BluetoothLocalGattCharacteristic* characteristic = |
| 1423 event_router_->GetLocalCharacteristic(params_->characteristic_id); |
| 1424 if (!characteristic) { |
| 1425 Respond(Error(kErrorInvalidCharacteristicId)); |
| 1426 return; |
| 1427 } |
| 1428 std::vector<uint8_t> uint8_vector; |
| 1429 uint8_vector.assign(params_->notification.value.begin(), |
| 1430 params_->notification.value.end()); |
| 1431 |
| 1432 bool indicate = params_->notification.should_indicate.get() |
| 1433 ? *params_->notification.should_indicate |
| 1434 : false; |
| 1435 device::BluetoothLocalGattCharacteristic::NotificationStatus status = |
| 1436 characteristic->NotifyValueChanged(uint8_vector, indicate); |
| 1437 |
| 1438 switch (status) { |
| 1439 case device::BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS: |
| 1440 Respond(NoArguments()); |
| 1441 break; |
| 1442 case device::BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET: |
| 1443 Respond(Error(kErrorNotifyPropertyNotSet)); |
| 1444 break; |
| 1445 case device::BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET: |
| 1446 Respond(Error(kErrorIndicatePropertyNotSet)); |
| 1447 break; |
| 1448 case device::BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED: |
| 1449 Respond(Error(kErrorServiceNotRegistered)); |
| 1450 break; |
| 1451 default: |
| 1452 LOG(ERROR) << "Unknown notification error!"; |
| 1453 Respond(Error(kErrorUnknownNotificationError)); |
| 1454 } |
| 1414 } | 1455 } |
| 1415 | 1456 |
| 1416 // removeService: | 1457 // removeService: |
| 1417 | 1458 |
| 1418 template class BLEPeripheralExtensionFunction<apibtle::RemoveService::Params>; | 1459 template class BLEPeripheralExtensionFunction<apibtle::RemoveService::Params>; |
| 1419 | 1460 |
| 1420 void BluetoothLowEnergyRemoveServiceFunction::DoWork() { | 1461 void BluetoothLowEnergyRemoveServiceFunction::DoWork() { |
| 1421 device::BluetoothLocalGattService* service = | 1462 device::BluetoothLocalGattService* service = |
| 1422 event_router_->adapter()->GetGattService(params_->service_id); | 1463 event_router_->adapter()->GetGattService(params_->service_id); |
| 1423 if (!service) { | 1464 if (!service) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1441 params_->response.value->end()); | 1482 params_->response.value->end()); |
| 1442 } | 1483 } |
| 1443 event_router_->HandleRequestResponse( | 1484 event_router_->HandleRequestResponse( |
| 1444 extension(), params_->response.request_id, params_->response.is_error, | 1485 extension(), params_->response.request_id, params_->response.is_error, |
| 1445 uint8_vector); | 1486 uint8_vector); |
| 1446 Respond(NoArguments()); | 1487 Respond(NoArguments()); |
| 1447 } | 1488 } |
| 1448 | 1489 |
| 1449 } // namespace api | 1490 } // namespace api |
| 1450 } // namespace extensions | 1491 } // namespace extensions |
| OLD | NEW |