Skip to content

Commit

Permalink
Actor::handle_message should return an enum instad of a boolean #7110
Browse files Browse the repository at this point in the history
…r=jdm
  • Loading branch information
fabricedesre committed Aug 14, 2015
1 parent f5e97ef commit c7b4824
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 76 deletions.
11 changes: 9 additions & 2 deletions components/devtools/actor.rs
Expand Up @@ -15,6 +15,12 @@ use std::net::TcpStream;
use std::raw::TraitObject;
use std::sync::{Arc, Mutex};

#[derive(PartialEq)]
pub enum ActorMessageStatus {
Processed,
Ignored,
}

/// A common trait for all devtools actors that encompasses an immutable name
/// and the ability to process messages that are directed to particular actors.
/// TODO: ensure the name is immutable
Expand All @@ -23,7 +29,7 @@ pub trait Actor: Any {
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
stream: &mut TcpStream) -> Result<bool, ()>;
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()>;
fn name(&self) -> String;
}

Expand Down Expand Up @@ -194,7 +200,8 @@ impl ActorRegistry {
None => println!("message received for unknown actor \"{}\"", to),
Some(actor) => {
let msg_type = msg.get("type").unwrap().as_string().unwrap();
if !try!(actor.handle_message(self, &msg_type.to_string(), msg, stream)) {
if try!(actor.handle_message(self, &msg_type.to_string(), msg, stream))
!= ActorMessageStatus::Processed {
println!("unexpected message type \"{}\" found for actor \"{}\"",
msg_type, to);
}
Expand Down
16 changes: 8 additions & 8 deletions components/devtools/actors/console.rs
Expand Up @@ -7,7 +7,7 @@
//! Mediates interaction between the remote web console and equivalent functionality (object
//! inspection, JS evaluation, autocompletion) in Servo.

use actor::{Actor, ActorRegistry};
use actor::{Actor, ActorRegistry, ActorMessageStatus};
use actors::object::ObjectActor;
use protocol::JsonPacketStream;

Expand Down Expand Up @@ -96,7 +96,7 @@ impl Actor for ConsoleActor {
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
stream: &mut TcpStream) -> Result<bool, ()> {
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getCachedMessages" => {
let str_types = msg.get("messageTypes").unwrap().as_array().unwrap().into_iter().map(|json_type| {
Expand Down Expand Up @@ -124,7 +124,7 @@ impl Actor for ConsoleActor {
messages: messages,
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"startListeners" => {
Expand All @@ -139,7 +139,7 @@ impl Actor for ConsoleActor {
}
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"stopListeners" => {
Expand All @@ -155,7 +155,7 @@ impl Actor for ConsoleActor {
.collect(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

//TODO: implement autocompletion like onAutocomplete in
Expand All @@ -167,7 +167,7 @@ impl Actor for ConsoleActor {
matchProp: "".to_string(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"evaluateJS" => {
Expand Down Expand Up @@ -237,10 +237,10 @@ impl Actor for ConsoleActor {
helperResult: Json::Object(BTreeMap::new()),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

_ => false
_ => ActorMessageStatus::Ignored
})
}
}
6 changes: 3 additions & 3 deletions components/devtools/actors/framerate.rs
Expand Up @@ -10,7 +10,7 @@ use std::sync::{Arc, Mutex};
use time::precise_time_ns;

use msg::constellation_msg::PipelineId;
use actor::{Actor, ActorRegistry};
use actor::{Actor, ActorRegistry, ActorMessageStatus};
use actors::timeline::HighResolutionStamp;
use devtools_traits::DevtoolScriptControlMsg;

Expand All @@ -33,8 +33,8 @@ impl Actor for FramerateActor {
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &json::Object,
_stream: &mut TcpStream) -> Result<bool, ()> {
Ok(false)
_stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}
}

Expand Down
48 changes: 24 additions & 24 deletions components/devtools/actors/inspector.rs
Expand Up @@ -9,7 +9,7 @@ use devtools_traits::{DevtoolScriptControlMsg, NodeInfo, ComputedNodeLayout};
use devtools_traits::DevtoolScriptControlMsg::{GetRootNode, GetDocumentElement, GetChildren};
use devtools_traits::DevtoolScriptControlMsg::{GetLayout, ModifyAttribute};

use actor::{Actor, ActorRegistry};
use actor::{Actor, ActorRegistry, ActorMessageStatus};
use protocol::JsonPacketStream;

use ipc_channel::ipc::{self, IpcSender};
Expand Down Expand Up @@ -69,25 +69,25 @@ impl Actor for HighlighterActor {
_registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
stream: &mut TcpStream) -> Result<bool, ()> {
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"showBoxModel" => {
let msg = ShowBoxModelReply {
from: self.name(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"hideBoxModel" => {
let msg = HideBoxModelReply {
from: self.name(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

_ => false,
_ => ActorMessageStatus::Ignored,
})
}
}
Expand All @@ -106,7 +106,7 @@ impl Actor for NodeActor {
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
stream: &mut TcpStream) -> Result<bool, ()> {
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"modifyAttributes" => {
let target = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
Expand All @@ -123,10 +123,10 @@ impl Actor for NodeActor {
from: self.name(),
};
stream.write_json_packet(&reply);
true
ActorMessageStatus::Processed
}

_ => false,
_ => ActorMessageStatus::Ignored,
})
}
}
Expand Down Expand Up @@ -280,14 +280,14 @@ impl Actor for WalkerActor {
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
stream: &mut TcpStream) -> Result<bool, ()> {
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"querySelector" => {
let msg = QuerySelectorReply {
from: self.name(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"documentElement" => {
Expand All @@ -301,15 +301,15 @@ impl Actor for WalkerActor {
node: node,
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"clearPseudoClassLocks" => {
let msg = ClearPseudoclassesReply {
from: self.name(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"children" => {
Expand All @@ -330,10 +330,10 @@ impl Actor for WalkerActor {
from: self.name(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

_ => false,
_ => ActorMessageStatus::Ignored,
})
}
}
Expand Down Expand Up @@ -426,7 +426,7 @@ impl Actor for PageStyleActor {
registry: &ActorRegistry,
msg_type: &str,
msg: &json::Object,
stream: &mut TcpStream) -> Result<bool, ()> {
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getApplied" => {
//TODO: query script for relevant applied styles to node (msg.node)
Expand All @@ -437,7 +437,7 @@ impl Actor for PageStyleActor {
from: self.name(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"getComputed" => {
Expand All @@ -447,7 +447,7 @@ impl Actor for PageStyleActor {
from: self.name(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

//TODO: query script for box layout properties of node (msg.node)
Expand Down Expand Up @@ -484,10 +484,10 @@ impl Actor for PageStyleActor {
from: self.name(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

_ => false,
_ => ActorMessageStatus::Ignored,
})
}
}
Expand All @@ -501,7 +501,7 @@ impl Actor for InspectorActor {
registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
stream: &mut TcpStream) -> Result<bool, ()> {
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getWalker" => {
if self.walker.borrow().is_none() {
Expand Down Expand Up @@ -529,7 +529,7 @@ impl Actor for InspectorActor {
}
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

"getPageStyle" => {
Expand All @@ -551,7 +551,7 @@ impl Actor for InspectorActor {
},
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

//TODO: this is an old message; try adding highlightable to the root traits instead
Expand All @@ -574,10 +574,10 @@ impl Actor for InspectorActor {
},
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}

_ => false,
_ => ActorMessageStatus::Ignored,
})
}
}
6 changes: 3 additions & 3 deletions components/devtools/actors/memory.rs
Expand Up @@ -5,7 +5,7 @@
use rustc_serialize::json;
use std::net::TcpStream;

use actor::{Actor, ActorRegistry};
use actor::{Actor, ActorRegistry, ActorMessageStatus};

#[derive(RustcEncodable)]
pub struct TimelineMemoryReply {
Expand Down Expand Up @@ -33,8 +33,8 @@ impl Actor for MemoryActor {
_registry: &ActorRegistry,
_msg_type: &str,
_msg: &json::Object,
_stream: &mut TcpStream) -> Result<bool, ()> {
Ok(false)
_stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}
}

Expand Down
18 changes: 9 additions & 9 deletions components/devtools/actors/network_event.rs
Expand Up @@ -8,7 +8,7 @@

extern crate hyper;

use actor::{Actor, ActorRegistry};
use actor::{Actor, ActorRegistry, ActorMessageStatus};
use protocol::JsonPacketStream;
use rustc_serialize::json;
use std::net::TcpStream;
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Actor for NetworkEventActor {
_registry: &ActorRegistry,
msg_type: &str,
_msg: &json::Object,
stream: &mut TcpStream) -> Result<bool, ()> {
stream: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"getRequestHeaders" => {
// TODO: Pass the correct values for headers, headerSize, rawHeaders
Expand All @@ -85,24 +85,24 @@ impl Actor for NetworkEventActor {
rawHeaders: "Raw headers".to_string(),
};
stream.write_json_packet(&msg);
true
ActorMessageStatus::Processed
}
"getRequestCookies" => {
false
ActorMessageStatus::Ignored
}
"getRequestPostData" => {
false
ActorMessageStatus::Ignored
}
"getResponseHeaders" => {
false
ActorMessageStatus::Ignored
}
"getResponseCookies" => {
false
ActorMessageStatus::Ignored
}
"getResponseContent" => {
false
ActorMessageStatus::Ignored
}
_ => false
_ => ActorMessageStatus::Ignored
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions components/devtools/actors/object.rs
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use actor::{Actor, ActorRegistry};
use actor::{Actor, ActorRegistry, ActorMessageStatus};
use rustc_serialize::json;
use std::net::TcpStream;

Expand All @@ -19,8 +19,8 @@ impl Actor for ObjectActor {
_: &ActorRegistry,
_: &str,
_: &json::Object,
_: &mut TcpStream) -> Result<bool, ()> {
Ok(false)
_: &mut TcpStream) -> Result<ActorMessageStatus, ()> {
Ok(ActorMessageStatus::Ignored)
}
}

Expand Down

0 comments on commit c7b4824

Please sign in to comment.