Auto merge of #14276 - szeged:notify, r=jdm

Add Start/Stop notifications

Add support for Start and Stop Notifications for WebBluetooth

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14276)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-23 03:22:43 -08:00 committed by GitHub
commit c4b7cc863e
18 changed files with 364 additions and 4 deletions

View file

@ -275,6 +275,9 @@ impl BluetoothManager {
BluetoothRequest::WriteValue(id, value, sender) => {
self.write_value(id, value, sender)
},
BluetoothRequest::EnableNotification(id, enable, sender) => {
self.enable_notification(id, enable, sender)
},
BluetoothRequest::Test(data_set_name, sender) => {
self.test(data_set_name, sender)
}
@ -977,4 +980,25 @@ impl BluetoothManager {
None => return drop(sender.send(Err(BluetoothError::InvalidState))),
}
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications
fn enable_notification(&mut self, id: String, enable: bool, sender: IpcSender<BluetoothResponseResult>) {
let mut adapter = get_adapter_or_return_error!(self, sender);
match self.get_gatt_characteristic(&mut adapter, &id) {
Some(c) => {
let result = match enable {
true => c.start_notify(),
false => c.stop_notify(),
};
match result {
// Step 11.
Ok(_) => return drop(sender.send(Ok(BluetoothResponse::EnableNotification(())))),
// Step 4.
Err(_) => return drop(sender.send(Err(BluetoothError::NotSupported))),
}
},
// Step 3.
None => return drop(sender.send(Err(BluetoothError::InvalidState))),
}
}
}