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

@ -1,11 +1,11 @@
#[macro_use] extern crate clap;
extern crate rojo_core;
extern crate librojo;
use std::path::{Path, PathBuf};
use std::process;
use rojo_core::pathext::canonicalish;
use librojo::pathext::canonicalish;
fn main() {
let matches = clap_app!(rojo =>
@ -32,7 +32,7 @@ fn main() {
let project_path = Path::new(sub_matches.value_of("PATH").unwrap_or("."));
let full_path = canonicalish(project_path);
rojo_core::commands::init(&full_path);
librojo::commands::init(&full_path);
},
("serve", sub_matches) => {
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!");

View file

@ -26,14 +26,14 @@ impl MessageSession {
}
pub fn push_messages(&self, new_messages: &[Message]) {
let message_listeners = self.message_listeners.lock().unwrap();
{
let mut messages = self.messages.write().unwrap();
messages.extend_from_slice(new_messages);
}
{
let message_listeners = self.message_listeners.lock().unwrap();
for listener in message_listeners.values() {
listener.send(()).unwrap();
}
@ -57,4 +57,8 @@ impl MessageSession {
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],
}
struct Server {
pub struct Server {
config: WebConfig,
server_version: &'static str,
server_id: String,
}
impl Server {
fn new(config: WebConfig) -> Server {
pub fn new(config: WebConfig) -> Server {
Server {
server_version: env!("CARGO_PKG_VERSION"),
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,
(GET) (/) => {
Response::text("Rojo up and running!")
@ -145,10 +145,7 @@ impl Server {
(GET) (/api/read_all) => {
let rbx_session = self.config.rbx_session.read().unwrap();
let message_cursor = {
let messages = self.config.message_session.messages.read().unwrap();
messages.len() as i32 - 1
};
let message_cursor = self.config.message_session.get_message_cursor();
Response::json(&ReadAllResponse {
server_id: &self.server_id,
@ -165,10 +162,7 @@ impl Server {
let rbx_session = self.config.rbx_session.read().unwrap();
let message_cursor = {
let messages = self.config.message_session.messages.read().unwrap();
messages.len() as i32 - 1
};
let message_cursor = self.config.message_session.get_message_cursor();
let mut instances = HashMap::new();