aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorOJ Kwon <kwon.ohjoong@gmail.com>2018-04-06 12:25:03 -0700
committerOJ Kwon <kwon.ohjoong@gmail.com>2018-04-18 11:39:32 -0700
commit410cf63a8e24e9acc7ea1ecbb953ec686b758aa6 (patch)
tree2fbe3ac96a33ac03d7bc797be4e5c2163b82e0f4 /components
parentc2161da3cab8f4dd8ea244307b7f8a4d3f4044c3 (diff)
downloadservo-410cf63a8e24e9acc7ea1ecbb953ec686b758aa6.tar.gz
servo-410cf63a8e24e9acc7ea1ecbb953ec686b758aa6.zip
refactor(bluetooth): factory fn returns constellation channel
Diffstat (limited to 'components')
-rw-r--r--components/bluetooth/Cargo.toml1
-rw-r--r--components/bluetooth/lib.rs38
-rw-r--r--components/servo/lib.rs7
3 files changed, 25 insertions, 21 deletions
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,