aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bluetoothremotegattservice.rs
diff options
context:
space:
mode:
authorAttila Dusnoki <dati91@users.noreply.github.com>2016-05-24 15:50:33 +0200
committerAttila Dusnoki <dati91@users.noreply.github.com>2016-05-24 15:50:33 +0200
commit39c99af4c87ef7eb6965842436b23d9364c341ca (patch)
tree748e7bbdc7b3e3693993edea9eb38736384f162b /components/script/dom/bluetoothremotegattservice.rs
parent03465ad8c77f03ae2f538d046ae1e1dc86f04723 (diff)
downloadservo-39c99af4c87ef7eb6965842436b23d9364c341ca.tar.gz
servo-39c99af4c87ef7eb6965842436b23d9364c341ca.zip
Add included services
Diffstat (limited to 'components/script/dom/bluetoothremotegattservice.rs')
-rw-r--r--components/script/dom/bluetoothremotegattservice.rs58
1 files changed, 57 insertions, 1 deletions
diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs
index 92a5edc2f28..bff15493428 100644
--- a/components/script/dom/bluetoothremotegattservice.rs
+++ b/components/script/dom/bluetoothremotegattservice.rs
@@ -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;
@@ -12,7 +13,7 @@ use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
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;
use util::str::DOMString;
@@ -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))
+ },
+ }
+ }
}