mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #11367 - szeged:included_services, r=jdm
Extend WebBluetooth with included services - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy --faster` does not report any errors - [X] These changes do not require tests because there are no webbluetooth tests yet <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11367) <!-- Reviewable:end -->
This commit is contained in:
commit
3bf96a7a31
8 changed files with 201 additions and 10 deletions
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||
use dom::bindings::error::Error::Type;
|
||||
|
@ -13,7 +14,7 @@ use dom::bindings::str::DOMString;
|
|||
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
||||
use dom::bluetoothdevice::BluetoothDevice;
|
||||
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
||||
use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothUUID};
|
||||
use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, BluetoothUUID};
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
|
||||
|
@ -155,4 +156,59 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservice
|
||||
fn GetIncludedService(&self,
|
||||
service: BluetoothServiceUUID)
|
||||
-> Fallible<Root<BluetoothRemoteGATTService>> {
|
||||
let uuid = try!(BluetoothUUID::GetService(self.global().r(), service)).to_string();
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GetIncludedService(self.get_instance_id(),
|
||||
uuid,
|
||||
sender)).unwrap();
|
||||
let service = receiver.recv().unwrap();
|
||||
match service {
|
||||
Ok(service) => {
|
||||
Ok(BluetoothRemoteGATTService::new(self.global().r(),
|
||||
&self.device.get(),
|
||||
DOMString::from(service.uuid),
|
||||
service.is_primary,
|
||||
service.instance_id))
|
||||
},
|
||||
Err(error) => {
|
||||
Err(Type(error))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservices
|
||||
fn GetIncludedServices(&self,
|
||||
service: Option<BluetoothServiceUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTService>>> {
|
||||
let mut uuid: Option<String> = None;
|
||||
if let Some(s) = service {
|
||||
uuid = Some(try!(BluetoothUUID::GetService(self.global().r(), s)).to_string())
|
||||
};
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GetIncludedServices(self.get_instance_id(),
|
||||
uuid,
|
||||
sender)).unwrap();
|
||||
let services_vec = receiver.recv().unwrap();
|
||||
match services_vec {
|
||||
Ok(service_vec) => {
|
||||
Ok(service_vec.into_iter()
|
||||
.map(|service| BluetoothRemoteGATTService::new(self.global().r(),
|
||||
&self.device.get(),
|
||||
DOMString::from(service.uuid),
|
||||
service.is_primary,
|
||||
service.instance_id))
|
||||
.collect())
|
||||
},
|
||||
Err(error) => {
|
||||
Err(Type(error))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ interface BluetoothRemoteGATTService {
|
|||
//Promise<BluetoothRemoteGATTCharacteristic>getCharacteristic(BluetoothCharacteristicUUID characteristic);
|
||||
//Promise<sequence<BluetoothRemoteGATTCharacteristic>>
|
||||
//getCharacteristics(optional BluetoothCharacteristicUUID characteristic);
|
||||
[Throws]
|
||||
BluetoothRemoteGATTService getIncludedService(BluetoothServiceUUID service);
|
||||
[Throws]
|
||||
sequence<BluetoothRemoteGATTService> getIncludedServices(optional BluetoothServiceUUID service);
|
||||
//Promise<BluetoothRemoteGATTService>getIncludedService(BluetoothServiceUUID service);
|
||||
//Promise<sequence<BluetoothRemoteGATTService>>getIncludedServices(optional BluetoothServiceUUID service);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue