diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | components/bluetooth/Cargo.toml | 1 | ||||
-rw-r--r-- | components/bluetooth/lib.rs | 38 | ||||
-rw-r--r-- | components/servo/lib.rs | 7 |
4 files changed, 26 insertions, 21 deletions
diff --git a/Cargo.lock b/Cargo.lock index 69c7b234e16..b9334986b08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,6 +181,7 @@ dependencies = [ "bluetooth_traits 0.0.1", "device 0.0.1 (git+https://github.com/servo/devices)", "ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "script_traits 0.0.1", "servo_config 0.0.1", "servo_rand 0.0.1", "tinyfiledialogs 3.3.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/bluetooth/Cargo.toml b/components/bluetooth/Cargo.toml index 53784d13e9c..eb7ffcf5fc7 100644 --- a/components/bluetooth/Cargo.toml +++ b/components/bluetooth/Cargo.toml @@ -14,6 +14,7 @@ bitflags = "1.0" bluetooth_traits = {path = "../bluetooth_traits"} device = {git = "https://github.com/servo/devices", features = ["bluetooth-test"]} ipc-channel = "0.10" +script_traits = {path = "../script_traits"} servo_config = {path = "../config"} servo_rand = {path = "../rand"} uuid = {version = "0.6", features = ["v4"]} diff --git a/components/bluetooth/lib.rs b/components/bluetooth/lib.rs index a68b701d883..5d45772cd52 100644 --- a/components/bluetooth/lib.rs +++ b/components/bluetooth/lib.rs @@ -7,6 +7,7 @@ extern crate bitflags; extern crate bluetooth_traits; extern crate device; extern crate ipc_channel; +extern crate script_traits; extern crate servo_config; extern crate servo_rand; #[cfg(target_os = "linux")] @@ -23,6 +24,7 @@ use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSeque use device::bluetooth::{BluetoothAdapter, BluetoothDevice, BluetoothGATTCharacteristic}; use device::bluetooth::{BluetoothGATTDescriptor, BluetoothGATTService}; use ipc_channel::ipc::{self, IpcReceiver, IpcSender}; +use script_traits::BluetoothManagerMsg; #[cfg(target_os = "linux")] use servo_config::opts; use servo_config::prefs::PREFS; @@ -68,23 +70,19 @@ macro_rules! return_if_cached( ); ); -pub trait BluetoothThreadFactory { - fn new() -> Self; -} - -impl BluetoothThreadFactory for IpcSender<BluetoothRequest> { - fn new() -> IpcSender<BluetoothRequest> { - let (sender, receiver) = ipc::channel().unwrap(); - let adapter = if Some(true) == PREFS.get("dom.bluetooth.enabled").as_boolean() { - BluetoothAdapter::init() - } else { - BluetoothAdapter::init_mock() - }.ok(); - thread::Builder::new().name("BluetoothThread".to_owned()).spawn(move || { - BluetoothManager::new(receiver, adapter).start(); - }).expect("Thread spawning failed"); - sender - } +pub fn new_bluetooth_thread() -> (IpcSender<BluetoothRequest>, IpcSender<IpcSender<BluetoothManagerMsg>>) { + let (sender, receiver) = ipc::channel().unwrap(); + let (constellation_sender, constellation_receiver) = ipc::channel().unwrap(); + let adapter = if Some(true) == PREFS.get("dom.bluetooth.enabled").as_boolean() { + BluetoothAdapter::init() + } else { + BluetoothAdapter::init_mock() + }.ok(); + thread::Builder::new().name("BluetoothThread".to_owned()).spawn(move || { + let constellation_chan = constellation_receiver.recv().unwrap(); + BluetoothManager::new(receiver, adapter, constellation_chan).start(); + }).expect("Thread spawning failed"); + (sender, constellation_sender) } // https://webbluetoothcg.github.io/web-bluetooth/#matches-a-filter @@ -206,10 +204,13 @@ pub struct BluetoothManager { cached_characteristics: HashMap<String, BluetoothGATTCharacteristic>, cached_descriptors: HashMap<String, BluetoothGATTDescriptor>, allowed_services: HashMap<String, HashSet<String>>, + constellation_chan: IpcSender<BluetoothManagerMsg>, } impl BluetoothManager { - pub fn new(receiver: IpcReceiver<BluetoothRequest>, adapter: Option<BluetoothAdapter>) -> BluetoothManager { + pub fn new(receiver: IpcReceiver<BluetoothRequest>, + adapter: Option<BluetoothAdapter>, + constellation_chan: IpcSender<BluetoothManagerMsg>) -> BluetoothManager { BluetoothManager { receiver: receiver, adapter: adapter, @@ -222,6 +223,7 @@ impl BluetoothManager { cached_characteristics: HashMap::new(), cached_descriptors: HashMap::new(), allowed_services: HashMap::new(), + constellation_chan: constellation_chan, } } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 9b17735b8ba..b6f95e28a52 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -67,8 +67,7 @@ fn webdriver(port: u16, constellation: Sender<ConstellationMsg>) { #[cfg(not(feature = "webdriver"))] fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) { } -use bluetooth::BluetoothThreadFactory; -use bluetooth_traits::BluetoothRequest; +use bluetooth::new_bluetooth_thread; use canvas::gl_context::GLContextFactory; use canvas::webgl_thread::WebGLThreads; use compositing::{IOCompositor, ShutdownState, RenderNotifier}; @@ -458,7 +457,7 @@ fn create_constellation(user_agent: Cow<'static, str>, webrender_api_sender: webrender_api::RenderApiSender, window_gl: Rc<gl::Gl>) -> (Sender<ConstellationMsg>, SWManagerSenders) { - let bluetooth_thread: IpcSender<BluetoothRequest> = BluetoothThreadFactory::new(); + let (bluetooth_thread, bluetooth_constellation_sender) = new_bluetooth_thread(); let (public_resource_threads, private_resource_threads) = new_resource_threads(user_agent, @@ -538,6 +537,8 @@ fn create_constellation(user_agent: Cow<'static, str>, webvr_constellation_sender.send(constellation_chan.clone()).unwrap(); } + bluetooth_constellation_sender.send(from_bluetoothmanager_sender.clone()).unwrap(); + // channels to communicate with Service Worker Manager let sw_senders = SWManagerSenders { swmanager_sender: from_swmanager_sender, |