Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M1453: Review for GetCachedMessages #4175

Closed
wants to merge 9 commits into from

M1453: Support for separated client & writing

  • Loading branch information
sam0rai9 committed Nov 26, 2014
commit ded845c83bce41b74a133204094b64863449036a
@@ -14,6 +14,7 @@ use devtools_traits::{ActorValue, DevtoolScriptControlMsg};
use servo_msg::constellation_msg::PipelineId;

use collections::TreeMap;
use core::cell::RefCell;
use serialize::json;
use serialize::json::ToJson;
use std::io::TcpStream;
@@ -101,6 +102,7 @@ pub struct ConsoleActor {
pub name: String,
pub pipeline: PipelineId,
pub script_chan: Sender<DevtoolScriptControlMsg>,
pub streams: RefCell<Vec<TcpStream>>,
}

impl Actor for ConsoleActor {
@@ -7,6 +7,7 @@
/// Supports dynamic attaching and detaching which control notifications of navigation, etc.

use actor::{Actor, ActorRegistry};
use actors::console::ConsoleActor;
use protocol::JsonPacketSender;

use serialize::json;
@@ -95,6 +96,8 @@ impl Actor for TabActor {
javascriptEnabled: true,
traits: TabTraits,
};
let console_actor = _registry.find::<ConsoleActor>(self.console.clone().as_slice());
console_actor.streams.borrow_mut().push((*stream).clone());
stream.write_json_packet(&msg);
true
}
@@ -104,6 +107,8 @@ impl Actor for TabActor {
from: self.name(),
__type__: "detached".to_string(),
};
let console_actor = _registry.find::<ConsoleActor>(self.console.clone().as_slice());
console_actor.streams.borrow_mut().pop( );
stream.write_json_packet(&msg);
true
}
@@ -41,6 +41,7 @@ use servo_msg::constellation_msg::PipelineId;
use servo_util::task::spawn_named;

use std::cell::RefCell;
use std::collections::HashMap;
use std::comm;
use std::comm::{Disconnected, Empty};
use std::io::{TcpListener, TcpStream};
@@ -90,6 +91,8 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {

let mut accepted_connections: Vec<TcpStream> = Vec::new();

let mut _actor_pipelines: HashMap<PipelineId, String> = HashMap::new();

/// Process the input from a single devtools client until EOF.
fn handle_client(actors: Arc<Mutex<ActorRegistry>>, mut stream: TcpStream) {
println!("connection established to {:?}", stream.peer_name().unwrap());
@@ -138,15 +141,16 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
// TODO: move this into the root or tab modules?
fn handle_new_global(actors: Arc<Mutex<ActorRegistry>>,
pipeline: PipelineId,
sender: Sender<DevtoolScriptControlMsg>) {
sender: Sender<DevtoolScriptControlMsg>,
mut actor_pipelines: HashMap<PipelineId, String>) {
let mut actors = actors.lock();

//TODO: move all this actor creation into a constructor method on TabActor
let (tab, console, inspector) = {
let console = ConsoleActor {
name: actors.new_name("console"),
script_chan: sender.clone(),
pipeline: pipeline,
streams: RefCell::new(Vec::new()),
};
let inspector = InspectorActor {
name: actors.new_name("inspector"),
@@ -170,6 +174,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
(tab, console, inspector)
};

actor_pipelines.insert(pipeline, tab.name.clone());
actors.register(box tab);
actors.register(box console);
actors.register(box inspector);
@@ -186,7 +191,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
Err(ref e) if e.kind == TimedOut => {
match receiver.try_recv() {
Ok(ServerExitMsg) | Err(Disconnected) => break,
Ok(NewGlobal(id, sender)) => handle_new_global(actors.clone(), id, sender),
Ok(NewGlobal(id, sender)) => handle_new_global(actors.clone(), id, sender, _actor_pipelines.clone()),
Err(Empty) => acceptor.set_timeout(Some(POLL_TIMEOUT)),
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.