Iterative progress

* Cleaned up MessageSession code a little bit, it's still pretty
  suboptimal
* Added stub `tests` folder
* Renamed rojo_core to librojo
This commit is contained in:
Lucien Greathouse 2018-06-04 23:10:42 -07:00
parent 1dc69d81dc
commit 8cd7d990e0
5 changed files with 21 additions and 18 deletions

View file

@ -7,7 +7,7 @@ license = "MIT"
repository = "https://github.com/LPGhatguy/rojo" repository = "https://github.com/LPGhatguy/rojo"
[lib] [lib]
name = "rojo_core" name = "librojo"
path = "src/lib.rs" path = "src/lib.rs"
[[bin]] [[bin]]

View file

@ -1,11 +1,11 @@
#[macro_use] extern crate clap; #[macro_use] extern crate clap;
extern crate rojo_core; extern crate librojo;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process; use std::process;
use rojo_core::pathext::canonicalish; use librojo::pathext::canonicalish;
fn main() { fn main() {
let matches = clap_app!(rojo => let matches = clap_app!(rojo =>
@ -32,7 +32,7 @@ fn main() {
let project_path = Path::new(sub_matches.value_of("PATH").unwrap_or(".")); let project_path = Path::new(sub_matches.value_of("PATH").unwrap_or("."));
let full_path = canonicalish(project_path); let full_path = canonicalish(project_path);
rojo_core::commands::init(&full_path); librojo::commands::init(&full_path);
}, },
("serve", sub_matches) => { ("serve", sub_matches) => {
let sub_matches = sub_matches.unwrap(); let sub_matches = sub_matches.unwrap();
@ -55,7 +55,7 @@ fn main() {
} }
}; };
rojo_core::commands::serve(&project_path, port); librojo::commands::serve(&project_path, port);
}, },
_ => { _ => {
eprintln!("Please specify a subcommand!"); eprintln!("Please specify a subcommand!");

View file

@ -26,14 +26,14 @@ impl MessageSession {
} }
pub fn push_messages(&self, new_messages: &[Message]) { pub fn push_messages(&self, new_messages: &[Message]) {
let message_listeners = self.message_listeners.lock().unwrap();
{ {
let mut messages = self.messages.write().unwrap(); let mut messages = self.messages.write().unwrap();
messages.extend_from_slice(new_messages); messages.extend_from_slice(new_messages);
} }
{ {
let message_listeners = self.message_listeners.lock().unwrap();
for listener in message_listeners.values() { for listener in message_listeners.values() {
listener.send(()).unwrap(); listener.send(()).unwrap();
} }
@ -57,4 +57,8 @@ impl MessageSession {
message_listeners.remove(&id); message_listeners.remove(&id);
} }
} }
pub fn get_message_cursor(&self) -> i32 {
self.messages.read().unwrap().len() as i32 - 1
}
} }

View file

@ -52,14 +52,14 @@ struct SubscribeResponse<'a> {
messages: &'a [Message], messages: &'a [Message],
} }
struct Server { pub struct Server {
config: WebConfig, config: WebConfig,
server_version: &'static str, server_version: &'static str,
server_id: String, server_id: String,
} }
impl Server { impl Server {
fn new(config: WebConfig) -> Server { pub fn new(config: WebConfig) -> Server {
Server { Server {
server_version: env!("CARGO_PKG_VERSION"), server_version: env!("CARGO_PKG_VERSION"),
server_id: config.server_id.to_string(), server_id: config.server_id.to_string(),
@ -67,7 +67,7 @@ impl Server {
} }
} }
fn handle_request(&self, request: &Request) -> Response { pub fn handle_request(&self, request: &Request) -> Response {
router!(request, router!(request,
(GET) (/) => { (GET) (/) => {
Response::text("Rojo up and running!") Response::text("Rojo up and running!")
@ -145,10 +145,7 @@ impl Server {
(GET) (/api/read_all) => { (GET) (/api/read_all) => {
let rbx_session = self.config.rbx_session.read().unwrap(); let rbx_session = self.config.rbx_session.read().unwrap();
let message_cursor = { let message_cursor = self.config.message_session.get_message_cursor();
let messages = self.config.message_session.messages.read().unwrap();
messages.len() as i32 - 1
};
Response::json(&ReadAllResponse { Response::json(&ReadAllResponse {
server_id: &self.server_id, server_id: &self.server_id,
@ -165,10 +162,7 @@ impl Server {
let rbx_session = self.config.rbx_session.read().unwrap(); let rbx_session = self.config.rbx_session.read().unwrap();
let message_cursor = { let message_cursor = self.config.message_session.get_message_cursor();
let messages = self.config.message_session.messages.read().unwrap();
messages.len() as i32 - 1
};
let mut instances = HashMap::new(); let mut instances = HashMap::new();

5
server/tests/web.rs Normal file
View file

@ -0,0 +1,5 @@
extern crate librojo;
fn main() {
println!("Hello, world!");
}