Created
January 27, 2016 10:38
-
-
Save zakorgy/069ed550da7469f401d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/components/script/dom/bluetoothdevice.rs b/components/script/dom/bluetoothdevice.rs | |
index 732b206..49a314f 100644 | |
--- a/components/script/dom/bluetoothdevice.rs | |
+++ b/components/script/dom/bluetoothdevice.rs | |
@@ -6,12 +6,15 @@ use dom::bluetoothadvertisingdata::BluetoothAdvertisingData; | |
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding; | |
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::{BluetoothDeviceMethods, VendorIDSource}; | |
use dom::bindings::global::GlobalRef; | |
+use dom::bluetoothgattremoteserver::BluetoothGATTRemoteServer; | |
use dom::bindings::js::{JS, Root}; | |
use dom::bindings::reflector::{Reflector, reflect_dom_object}; | |
use util::str::DOMString; | |
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice | |
+pub type Uuid = DOMString; | |
+ | |
#[dom_struct] | |
pub struct BluetoothDevice { | |
reflector_: Reflector, | |
@@ -23,8 +26,8 @@ pub struct BluetoothDevice { | |
vendorID: u32, | |
productID: u32, | |
productVersion: u32, | |
- // gattServer: BluetoothGATTRemoteServer, | |
- // uuids: UUID[], | |
+ gattServer: JS<BluetoothGATTRemoteServer>, | |
+ //Fixme : uuids: Vec<Uuid>, | |
} | |
impl BluetoothDevice { | |
@@ -35,7 +38,8 @@ impl BluetoothDevice { | |
vendorIDSource: VendorIDSource, | |
vendorID: u32, | |
productID: u32, | |
- productVersion: u32) | |
+ productVersion: u32, | |
+ gattServer: &BluetoothGATTRemoteServer) | |
-> BluetoothDevice { | |
BluetoothDevice { | |
reflector_: Reflector::new(), | |
@@ -47,6 +51,7 @@ impl BluetoothDevice { | |
vendorID: vendorID, | |
productID: productID, | |
productVersion: productVersion, | |
+ gattServer: JS::from_ref(gattServer), | |
} | |
} | |
@@ -58,7 +63,8 @@ impl BluetoothDevice { | |
vendorIDSource: VendorIDSource, | |
vendorID: u32, | |
productID: u32, | |
- productVersion: u32) | |
+ productVersion: u32, | |
+ gattServer: &BluetoothGATTRemoteServer) | |
-> Root<BluetoothDevice> { | |
reflect_dom_object(box BluetoothDevice::new_inherited(id, | |
name, | |
@@ -67,7 +73,8 @@ impl BluetoothDevice { | |
vendorIDSource, | |
vendorID, | |
productID, | |
- productVersion), | |
+ productVersion, | |
+ gattServer), | |
global, | |
BluetoothDeviceBinding::Wrap) | |
} | |
@@ -105,4 +112,8 @@ impl BluetoothDeviceMethods for BluetoothDevice { | |
fn GetProductVersion(&self) -> Option<u32> { | |
Some(self.productVersion) | |
} | |
+ | |
+ fn GetGattServer(&self) -> Option<Root<BluetoothGATTRemoteServer>> { | |
+ Some(Root::from_ref(&*self.gattServer)) | |
+ } | |
} | |
diff --git a/components/script/dom/bluetoothgattremoteserver.rs b/components/script/dom/bluetoothgattremoteserver.rs | |
new file mode 100644 | |
index 0000000..4dca97a | |
--- /dev/null | |
+++ b/components/script/dom/bluetoothgattremoteserver.rs | |
@@ -0,0 +1,48 @@ | |
+/* This Source Code Form is subject to the terms of the Mozilla Public | |
+ * 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::BluetoothGATTRemoteServerBinding; | |
+use dom::bindings::codegen::Bindings::BluetoothGATTRemoteServerBinding::BluetoothGATTRemoteServerMethods; | |
+use dom::bluetoothdevice::BluetoothDevice; | |
+use dom::bindings::global::GlobalRef; | |
+use dom::bindings::js::{JS, Root}; | |
+use dom::bindings::reflector::{Reflector, reflect_dom_object}; | |
+ | |
+#[dom_struct] | |
+pub struct BluetoothGATTRemoteServer { | |
+ reflector_: Reflector, | |
+ device: JS<BluetoothDevice>, | |
+ connected: bool, | |
+} | |
+ | |
+impl BluetoothGATTRemoteServer { | |
+ pub fn new_inherited(device: &BluetoothDevice, connected: bool) -> BluetoothGATTRemoteServer { | |
+ BluetoothGATTRemoteServer { | |
+ reflector_: Reflector::new(), | |
+ device: JS::from_ref(device), | |
+ connected: connected, | |
+ } | |
+ } | |
+ | |
+ pub fn new(global: GlobalRef, device: &BluetoothDevice, connected: bool) -> Root<BluetoothGATTRemoteServer> { | |
+ reflect_dom_object(box BluetoothGATTRemoteServer::new_inherited( | |
+ device, | |
+ connected), | |
+ global, | |
+ BluetoothGATTRemoteServerBinding::Wrap) | |
+ } | |
+} | |
+ | |
+impl BluetoothGATTRemoteServerMethods for BluetoothGATTRemoteServer { | |
+ fn Device(&self) -> Root<BluetoothDevice> { | |
+ Root::from_ref(&*self.device) | |
+ } | |
+ | |
+ fn Connected(&self) -> bool { | |
+ self.connected | |
+ } | |
+ | |
+ fn Disconnect(&self) -> (){ | |
+ ()//TODO | |
+ } | |
+} | |
\ No newline at end of file | |
diff --git a/components/script/dom/bluetoothgattservice.rs b/components/script/dom/bluetoothgattservice.rs | |
new file mode 100644 | |
index 0000000..2a0cb39 | |
--- /dev/null | |
+++ b/components/script/dom/bluetoothgattservice.rs | |
@@ -0,0 +1,55 @@ | |
+/* This Source Code Form is subject to the terms of the Mozilla Public | |
+ * 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/. */ | |
+extern crate uuid; | |
+use dom::bindings::codegen::Bindings::BluetoothGATTServiceBinding; | |
+use dom::bindings::codegen::Bindings::BluetoothGATTServiceBinding::BluetoothGATTServiceMethods; | |
+use dom::bluetoothdevice::BluetoothDevice; | |
+use dom::bindings::global::GlobalRef; | |
+use dom::bindings::js::{JS, Root}; | |
+use dom::bindings::reflector::{Reflector, reflect_dom_object}; | |
+use util::str::DOMString; | |
+use uuid::Uuid; | |
+ | |
+//pub type Uuid = DOMString; | |
+ | |
+#[dom_struct] | |
+pub struct BluetoothGATTService { | |
+ reflector_: Reflector, | |
+ device: JS<BluetoothDevice>, | |
+ isPrimary: bool, | |
+ uuid: Uuid, | |
+} | |
+ | |
+impl BluetoothGATTService { | |
+ pub fn new_inherited(device: &BluetoothDevice, isPrimary: bool, uuid: Uuid) -> BluetoothGATTService { | |
+ BluetoothGATTService { | |
+ reflector_: Reflector::new(), | |
+ device: JS::from_ref(device), | |
+ isPrimary: isPrimary, | |
+ uuid: uuid, | |
+ } | |
+ } | |
+ | |
+ pub fn new(global: GlobalRef, device: &BluetoothDevice, isPrimary: bool, uuid: Uuid) -> Root<BluetoothGATTService> { | |
+ reflect_dom_object(box BluetoothGATTService::new_inherited( | |
+ device, | |
+ isPrimary, | |
+ uuid), | |
+ global, | |
+ BluetoothGATTServiceBinding::Wrap) | |
+ } | |
+} | |
+ | |
+impl BluetoothGATTServiceMethods for BluetoothGATTService { | |
+ fn Device(&self) -> Root<BluetoothDevice> { | |
+ Root::from_ref(&*self.device) | |
+ } | |
+ | |
+ fn IsPrimary(&self) -> bool { | |
+ self.isPrimary | |
+ } | |
+ fn Uuid(&self) -> DOMString { | |
+ DOMString::from_string(self.uuid.to_simple_string().clone()) | |
+ } | |
+} | |
\ No newline at end of file | |
diff --git a/components/script/dom/bluetoothuuid.rs b/components/script/dom/bluetoothuuid.rs | |
index 65a64f5..6756c40 100644 | |
--- a/components/script/dom/bluetoothuuid.rs | |
+++ b/components/script/dom/bluetoothuuid.rs | |
@@ -13,6 +13,7 @@ pub struct BluetoothUUID { | |
reflector_: Reflector, | |
} | |
+ | |
impl BluetoothUUID { | |
pub fn CanonicalUUID(_: GlobalRef, _alias: u32) -> DOMString { | |
DOMString::new() | |
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs | |
index a91e2d1..3423c3a 100644 | |
--- a/components/script/dom/mod.rs | |
+++ b/components/script/dom/mod.rs | |
@@ -221,6 +221,8 @@ pub mod bluetooth; | |
pub mod bluetoothadvertisingdata; | |
pub mod bluetoothcharacteristicproperties; | |
pub mod bluetoothdevice; | |
+pub mod bluetoothgattremoteserver; | |
+pub mod bluetoothgattservice; | |
pub mod bluetoothuuid; | |
pub mod browsingcontext; | |
pub mod canvasgradient; | |
diff --git a/components/script/dom/webidls/BluetoothDevice.webidl b/components/script/dom/webidls/BluetoothDevice.webidl | |
index ab6a804..38115a8 100644 | |
--- a/components/script/dom/webidls/BluetoothDevice.webidl | |
+++ b/components/script/dom/webidls/BluetoothDevice.webidl | |
@@ -20,7 +20,7 @@ interface BluetoothDevice { | |
readonly attribute unsigned long? vendorID; | |
readonly attribute unsigned long? productID; | |
readonly attribute unsigned long? productVersion; | |
- // readonly attribute BluetoothGATTRemoteServer? gattServer; | |
- // readonly attribute UUID[] uuids; | |
+ readonly attribute BluetoothGATTRemoteServer? gattServer; | |
+ //Fixme: readonly attribute UUID[] uuids; | |
//Promise<BluetoothGATTRemoteServer> connectGATT(); | |
}; | |
diff --git a/components/script/dom/webidls/BluetoothGATTRemoteServer.webidl b/components/script/dom/webidls/BluetoothGATTRemoteServer.webidl | |
new file mode 100644 | |
index 0000000..b513163 | |
--- /dev/null | |
+++ b/components/script/dom/webidls/BluetoothGATTRemoteServer.webidl | |
@@ -0,0 +1,21 @@ | |
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
+/* This Source Code Form is subject to the terms of the Mozilla Public | |
+ * 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/. */ | |
+ | |
+// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothgattremoteserver | |
+ | |
+interface BluetoothGATTRemoteServer { | |
+ readonly attribute BluetoothDevice device; | |
+ readonly attribute boolean connected; | |
+ void disconnect(); | |
+ // TODO (zakorgy) | |
+ // Set this.connected to false. | |
+ // In parallel: if, for all BluetoothDevices device in the whole UA with device@[[representedDevice]] | |
+ // the same device as this.device@[[representedDevice]], device.gattServer === null or !device.gattServer.connected, | |
+ // the UA MAY destroy device@[[representedDevice]]’s ATT Bearer. | |
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattremoteserver-disconnect | |
+ // https://webbluetoothcg.github.io/web-bluetooth/#same-device | |
+ //Promise<BluetoothGATTService> getPrimaryService(BluetoothServiceUUID service); | |
+ //Promise<sequence<BluetoothGATTService>>getPrimaryServices(optional BluetoothServiceUUID service); | |
+ }; | |
\ No newline at end of file | |
diff --git a/components/script/dom/webidls/BluetoothGATTService.webidl b/components/script/dom/webidls/BluetoothGATTService.webidl | |
new file mode 100644 | |
index 0000000..8a21f78 | |
--- /dev/null | |
+++ b/components/script/dom/webidls/BluetoothGATTService.webidl | |
@@ -0,0 +1,22 @@ | |
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
+/* This Source Code Form is subject to the terms of the Mozilla Public | |
+ * 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/. */ | |
+ | |
+// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothgattservice | |
+ | |
+interface BluetoothGATTService { | |
+ readonly attribute BluetoothDevice device; | |
+ | |
+ readonly attribute boolean isPrimary; | |
+ | |
+ readonly attribute UUID uuid; | |
+ | |
+ //Promise<BluetoothGATTCharacteristic>getCharacteristic(BluetoothCharacteristicUUID characteristic); | |
+ | |
+ //Promise<sequence<BluetoothGATTCharacteristic>>getCharacteristics(optional BluetoothCharacteristicUUID characteristic); | |
+ | |
+ //Promise<BluetoothGATTService>getIncludedService(BluetoothServiceUUID service); | |
+ | |
+ //Promise<sequence<BluetoothGATTService>>getIncludedServices(optional BluetoothServiceUUID service); | |
+}; | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment