mirror of
https://github.com/servo/servo.git
synced 2025-07-04 14:03:39 +01:00
refactor(bluetooth): factory fn returns constellation channel
This commit is contained in:
parent
c2161da3ca
commit
410cf63a8e
4 changed files with 26 additions and 21 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -181,6 +181,7 @@ dependencies = [
|
||||||
"bluetooth_traits 0.0.1",
|
"bluetooth_traits 0.0.1",
|
||||||
"device 0.0.1 (git+https://github.com/servo/devices)",
|
"device 0.0.1 (git+https://github.com/servo/devices)",
|
||||||
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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_config 0.0.1",
|
||||||
"servo_rand 0.0.1",
|
"servo_rand 0.0.1",
|
||||||
"tinyfiledialogs 3.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"tinyfiledialogs 3.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -14,6 +14,7 @@ bitflags = "1.0"
|
||||||
bluetooth_traits = {path = "../bluetooth_traits"}
|
bluetooth_traits = {path = "../bluetooth_traits"}
|
||||||
device = {git = "https://github.com/servo/devices", features = ["bluetooth-test"]}
|
device = {git = "https://github.com/servo/devices", features = ["bluetooth-test"]}
|
||||||
ipc-channel = "0.10"
|
ipc-channel = "0.10"
|
||||||
|
script_traits = {path = "../script_traits"}
|
||||||
servo_config = {path = "../config"}
|
servo_config = {path = "../config"}
|
||||||
servo_rand = {path = "../rand"}
|
servo_rand = {path = "../rand"}
|
||||||
uuid = {version = "0.6", features = ["v4"]}
|
uuid = {version = "0.6", features = ["v4"]}
|
||||||
|
|
|
@ -7,6 +7,7 @@ extern crate bitflags;
|
||||||
extern crate bluetooth_traits;
|
extern crate bluetooth_traits;
|
||||||
extern crate device;
|
extern crate device;
|
||||||
extern crate ipc_channel;
|
extern crate ipc_channel;
|
||||||
|
extern crate script_traits;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
extern crate servo_rand;
|
extern crate servo_rand;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
@ -23,6 +24,7 @@ use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSeque
|
||||||
use device::bluetooth::{BluetoothAdapter, BluetoothDevice, BluetoothGATTCharacteristic};
|
use device::bluetooth::{BluetoothAdapter, BluetoothDevice, BluetoothGATTCharacteristic};
|
||||||
use device::bluetooth::{BluetoothGATTDescriptor, BluetoothGATTService};
|
use device::bluetooth::{BluetoothGATTDescriptor, BluetoothGATTService};
|
||||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||||
|
use script_traits::BluetoothManagerMsg;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_config::prefs::PREFS;
|
use servo_config::prefs::PREFS;
|
||||||
|
@ -68,23 +70,19 @@ macro_rules! return_if_cached(
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
pub trait BluetoothThreadFactory {
|
pub fn new_bluetooth_thread() -> (IpcSender<BluetoothRequest>, IpcSender<IpcSender<BluetoothManagerMsg>>) {
|
||||||
fn new() -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BluetoothThreadFactory for IpcSender<BluetoothRequest> {
|
|
||||||
fn new() -> IpcSender<BluetoothRequest> {
|
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
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() {
|
let adapter = if Some(true) == PREFS.get("dom.bluetooth.enabled").as_boolean() {
|
||||||
BluetoothAdapter::init()
|
BluetoothAdapter::init()
|
||||||
} else {
|
} else {
|
||||||
BluetoothAdapter::init_mock()
|
BluetoothAdapter::init_mock()
|
||||||
}.ok();
|
}.ok();
|
||||||
thread::Builder::new().name("BluetoothThread".to_owned()).spawn(move || {
|
thread::Builder::new().name("BluetoothThread".to_owned()).spawn(move || {
|
||||||
BluetoothManager::new(receiver, adapter).start();
|
let constellation_chan = constellation_receiver.recv().unwrap();
|
||||||
|
BluetoothManager::new(receiver, adapter, constellation_chan).start();
|
||||||
}).expect("Thread spawning failed");
|
}).expect("Thread spawning failed");
|
||||||
sender
|
(sender, constellation_sender)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#matches-a-filter
|
// https://webbluetoothcg.github.io/web-bluetooth/#matches-a-filter
|
||||||
|
@ -206,10 +204,13 @@ pub struct BluetoothManager {
|
||||||
cached_characteristics: HashMap<String, BluetoothGATTCharacteristic>,
|
cached_characteristics: HashMap<String, BluetoothGATTCharacteristic>,
|
||||||
cached_descriptors: HashMap<String, BluetoothGATTDescriptor>,
|
cached_descriptors: HashMap<String, BluetoothGATTDescriptor>,
|
||||||
allowed_services: HashMap<String, HashSet<String>>,
|
allowed_services: HashMap<String, HashSet<String>>,
|
||||||
|
constellation_chan: IpcSender<BluetoothManagerMsg>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BluetoothManager {
|
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 {
|
BluetoothManager {
|
||||||
receiver: receiver,
|
receiver: receiver,
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
|
@ -222,6 +223,7 @@ impl BluetoothManager {
|
||||||
cached_characteristics: HashMap::new(),
|
cached_characteristics: HashMap::new(),
|
||||||
cached_descriptors: HashMap::new(),
|
cached_descriptors: HashMap::new(),
|
||||||
allowed_services: HashMap::new(),
|
allowed_services: HashMap::new(),
|
||||||
|
constellation_chan: constellation_chan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,7 @@ fn webdriver(port: u16, constellation: Sender<ConstellationMsg>) {
|
||||||
#[cfg(not(feature = "webdriver"))]
|
#[cfg(not(feature = "webdriver"))]
|
||||||
fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) { }
|
fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) { }
|
||||||
|
|
||||||
use bluetooth::BluetoothThreadFactory;
|
use bluetooth::new_bluetooth_thread;
|
||||||
use bluetooth_traits::BluetoothRequest;
|
|
||||||
use canvas::gl_context::GLContextFactory;
|
use canvas::gl_context::GLContextFactory;
|
||||||
use canvas::webgl_thread::WebGLThreads;
|
use canvas::webgl_thread::WebGLThreads;
|
||||||
use compositing::{IOCompositor, ShutdownState, RenderNotifier};
|
use compositing::{IOCompositor, ShutdownState, RenderNotifier};
|
||||||
|
@ -458,7 +457,7 @@ fn create_constellation(user_agent: Cow<'static, str>,
|
||||||
webrender_api_sender: webrender_api::RenderApiSender,
|
webrender_api_sender: webrender_api::RenderApiSender,
|
||||||
window_gl: Rc<gl::Gl>)
|
window_gl: Rc<gl::Gl>)
|
||||||
-> (Sender<ConstellationMsg>, SWManagerSenders) {
|
-> (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) =
|
let (public_resource_threads, private_resource_threads) =
|
||||||
new_resource_threads(user_agent,
|
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();
|
webvr_constellation_sender.send(constellation_chan.clone()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bluetooth_constellation_sender.send(from_bluetoothmanager_sender.clone()).unwrap();
|
||||||
|
|
||||||
// channels to communicate with Service Worker Manager
|
// channels to communicate with Service Worker Manager
|
||||||
let sw_senders = SWManagerSenders {
|
let sw_senders = SWManagerSenders {
|
||||||
swmanager_sender: from_swmanager_sender,
|
swmanager_sender: from_swmanager_sender,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue