Skip to content

Commit

Permalink
Support for Separated Read Write
Browse files Browse the repository at this point in the history
  • Loading branch information
srm09 authored and jdm committed Dec 4, 2014
1 parent ad9aeda commit 75ffda9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions components/devtools/actors/console.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -105,6 +106,7 @@ pub struct ConsoleActor {
pub name: String,
pub pipeline: PipelineId,
pub script_chan: Sender<DevtoolScriptControlMsg>,
pub streams: RefCell<Vec<TcpStream>>,
}

impl Actor for ConsoleActor {
Expand Down
9 changes: 8 additions & 1 deletion components/devtools/actors/tab.rs
Expand Up @@ -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::JsonPacketStream;

use serialize::json;
Expand Down Expand Up @@ -74,7 +75,7 @@ impl Actor for TabActor {
}

fn handle_message(&self,
_registry: &ActorRegistry,
registry: &ActorRegistry,
msg_type: &String,
_msg: &json::JsonObject,
stream: &mut TcpStream) -> bool {
Expand All @@ -95,15 +96,21 @@ impl Actor for TabActor {
javascriptEnabled: true,
traits: TabTraits,
};
let console_actor = registry.find::<ConsoleActor>(self.console.as_slice());
console_actor.streams.borrow_mut().push(stream.clone());
stream.write_json_packet(&msg);
true
}

//FIXME: The current implementation won't work for multiple connections. Need to ensure 105
// that the correct stream is removed.
"detach" => {
let msg = TabDetachedReply {
from: self.name(),
__type__: "detached".to_string(),
};
let console_actor = registry.find::<ConsoleActor>(self.console.as_slice());
console_actor.streams.borrow_mut().pop();
stream.write_json_packet(&msg);
true
}
Expand Down
10 changes: 8 additions & 2 deletions components/devtools/lib.rs
Expand Up @@ -40,6 +40,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};
Expand Down Expand Up @@ -87,6 +88,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());
Expand Down Expand Up @@ -114,7 +117,8 @@ 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>,
actor_pipelines: &mut HashMap<PipelineId, String>) {
let mut actors = actors.lock();

//TODO: move all this actor creation into a constructor method on TabActor
Expand All @@ -123,6 +127,7 @@ fn run_server(receiver: Receiver<DevtoolsControlMsg>, port: u16) {
name: actors.new_name("console"),
script_chan: sender.clone(),
pipeline: pipeline,
streams: RefCell::new(Vec::new()),
};
let inspector = InspectorActor {
name: actors.new_name("inspector"),
Expand All @@ -146,6 +151,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);
Expand All @@ -162,7 +168,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, &mut actor_pipelines),
Err(Empty) => acceptor.set_timeout(Some(POLL_TIMEOUT)),
}
}
Expand Down

9 comments on commit 75ffda9

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at jdm@75ffda9

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jdm/servo/sepreadwrite = 75ffda9 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jdm/servo/sepreadwrite = 75ffda9 merged ok, testing candidate = 2ade696

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at jdm@75ffda9

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jdm/servo/sepreadwrite = 75ffda9 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jdm/servo/sepreadwrite = 75ffda9 merged ok, testing candidate = 28a132a

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 28a132a

Please sign in to comment.