Actor::handle_message should return an enum instad of a boolean #7110 r=jdm

This commit is contained in:
Fabrice Desré 2015-08-13 18:14:34 -07:00
parent f5e97ef1b5
commit c7b48240b0
12 changed files with 83 additions and 76 deletions

View file

@ -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
@ -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;
}
@ -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);
}