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

Unified Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc

Issue 1972353002: Implement the notifyCharacteristicValueChanged API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notifications_bluez
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest_chromeos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc
diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc
index 297405b0832f5a6fc46897df1146df6cec7c94a8..32754f60621336257669c2e2e5154dd05ffb2789 100644
--- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc
+++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc
@@ -73,6 +73,15 @@ const char kErrorUnsupportedDevice[] =
const char kErrorInvalidServiceId[] = "The service ID doesn't exist.";
const char kErrorInvalidCharacteristicId[] =
"The characteristic ID doesn't exist.";
+const char kErrorNotifyPropertyNotSet[] =
+ "The characteristic does not have the notify property set.";
+const char kErrorIndicatePropertyNotSet[] =
+ "The characteristic does not have the indicate property set.";
+const char kErrorServiceNotRegistered[] =
+ "The characteristic is not owned by a service that is registered.";
+const char kErrorUnknownNotificationError[] =
+ "An unknown notification error occured.";
+
const char kStatusAdvertisementAlreadyExists[] =
"An advertisement is already advertising";
const char kStatusAdvertisementDoesNotExist[] =
@@ -1410,7 +1419,39 @@ template class BLEPeripheralExtensionFunction<
apibtle::NotifyCharacteristicValueChanged::Params>;
void BluetoothLowEnergyNotifyCharacteristicValueChangedFunction::DoWork() {
- Respond(Error(kErrorPermissionDenied));
+ device::BluetoothLocalGattCharacteristic* characteristic =
+ event_router_->GetLocalCharacteristic(params_->characteristic_id);
+ if (!characteristic) {
+ Respond(Error(kErrorInvalidCharacteristicId));
+ return;
+ }
+ std::vector<uint8_t> uint8_vector;
+ uint8_vector.assign(params_->notification.value.begin(),
+ params_->notification.value.end());
+
+ bool indicate = params_->notification.should_indicate.get()
+ ? *params_->notification.should_indicate
+ : false;
+ device::BluetoothLocalGattCharacteristic::NotificationStatus status =
+ characteristic->NotifyValueChanged(uint8_vector, indicate);
+
+ switch (status) {
+ case device::BluetoothLocalGattCharacteristic::NOTIFICATION_SUCCESS:
+ Respond(NoArguments());
+ break;
+ case device::BluetoothLocalGattCharacteristic::NOTIFY_PROPERTY_NOT_SET:
+ Respond(Error(kErrorNotifyPropertyNotSet));
+ break;
+ case device::BluetoothLocalGattCharacteristic::INDICATE_PROPERTY_NOT_SET:
+ Respond(Error(kErrorIndicatePropertyNotSet));
+ break;
+ case device::BluetoothLocalGattCharacteristic::SERVICE_NOT_REGISTERED:
+ Respond(Error(kErrorServiceNotRegistered));
+ break;
+ default:
+ LOG(ERROR) << "Unknown notification error!";
+ Respond(Error(kErrorUnknownNotificationError));
+ }
}
// removeService:
« no previous file with comments | « no previous file | chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_apitest_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698