Add Start/Stop notifications

This commit is contained in:
Attila Dusnoki 2016-11-14 17:51:41 +01:00 committed by Keith Yeung
parent a89ba50180
commit fd7cdbf19f
18 changed files with 364 additions and 4 deletions

View file

@ -238,6 +238,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)
}
@ -940,4 +943,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))),
}
}
}