Rename Session to LiveSession, a better name

This commit is contained in:
Lucien Greathouse
2019-01-17 18:24:49 -08:00
parent e301116e87
commit 779d462932
4 changed files with 25 additions and 24 deletions

View File

@@ -9,7 +9,7 @@ use failure::Fail;
use crate::{ use crate::{
project::{Project, ProjectLoadFuzzyError}, project::{Project, ProjectLoadFuzzyError},
web::Server, web::Server,
session::Session, live_session::LiveSession,
}; };
const DEFAULT_PORT: u16 = 34872; const DEFAULT_PORT: u16 = 34872;
@@ -38,8 +38,8 @@ pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
info!("Found project at {}", project.file_location.display()); info!("Found project at {}", project.file_location.display());
info!("Using project {:#?}", project); info!("Using project {:#?}", project);
let session = Arc::new(Session::new(Arc::clone(&project)).unwrap()); let live_session = Arc::new(LiveSession::new(Arc::clone(&project)).unwrap());
let server = Server::new(Arc::clone(&session)); let server = Server::new(Arc::clone(&live_session));
let port = options.port let port = options.port
.or(project.serve_port) .or(project.serve_port)

View File

@@ -11,7 +11,7 @@ pub mod path_map;
pub mod project; pub mod project;
pub mod rbx_session; pub mod rbx_session;
pub mod rbx_snapshot; pub mod rbx_snapshot;
pub mod session; pub mod live_session;
pub mod session_id; pub mod session_id;
pub mod snapshot_reconciler; pub mod snapshot_reconciler;
pub mod visualize; pub mod visualize;

View File

@@ -13,7 +13,8 @@ use crate::{
fs_watcher::FsWatcher, fs_watcher::FsWatcher,
}; };
pub struct Session { /// Contains all of the state for a Rojo live-sync session.
pub struct LiveSession {
pub project: Arc<Project>, pub project: Arc<Project>,
pub session_id: SessionId, pub session_id: SessionId,
pub message_queue: Arc<MessageQueue<InstanceChanges>>, pub message_queue: Arc<MessageQueue<InstanceChanges>>,
@@ -22,8 +23,8 @@ pub struct Session {
_fs_watcher: FsWatcher, _fs_watcher: FsWatcher,
} }
impl Session { impl LiveSession {
pub fn new(project: Arc<Project>) -> io::Result<Session> { pub fn new(project: Arc<Project>) -> io::Result<LiveSession> {
let imfs = { let imfs = {
let mut imfs = Imfs::new(); let mut imfs = Imfs::new();
imfs.add_roots_from_project(&project)?; imfs.add_roots_from_project(&project)?;
@@ -45,7 +46,7 @@ impl Session {
let session_id = SessionId::new(); let session_id = SessionId::new();
Ok(Session { Ok(LiveSession {
project, project,
session_id, session_id,
message_queue, message_queue,

View File

@@ -15,7 +15,7 @@ use rouille::{
use rbx_tree::{RbxId, RbxInstance}; use rbx_tree::{RbxId, RbxInstance};
use crate::{ use crate::{
session::Session, live_session::LiveSession,
session_id::SessionId, session_id::SessionId,
snapshot_reconciler::InstanceChanges, snapshot_reconciler::InstanceChanges,
visualize::{VisualizeRbxSession, VisualizeImfs, graphviz_to_svg}, visualize::{VisualizeRbxSession, VisualizeImfs, graphviz_to_svg},
@@ -77,14 +77,14 @@ pub struct SubscribeResponse<'a> {
} }
pub struct Server { pub struct Server {
session: Arc<Session>, live_session: Arc<LiveSession>,
server_version: &'static str, server_version: &'static str,
} }
impl Server { impl Server {
pub fn new(session: Arc<Session>) -> Server { pub fn new(live_session: Arc<LiveSession>) -> Server {
Server { Server {
session, live_session,
server_version: env!("CARGO_PKG_VERSION"), server_version: env!("CARGO_PKG_VERSION"),
} }
} }
@@ -101,14 +101,14 @@ impl Server {
(GET) (/api/rojo) => { (GET) (/api/rojo) => {
// Get a summary of information about the server. // Get a summary of information about the server.
let rbx_session = self.session.rbx_session.lock().unwrap(); let rbx_session = self.live_session.rbx_session.lock().unwrap();
let tree = rbx_session.get_tree(); let tree = rbx_session.get_tree();
Response::json(&ServerInfoResponse { Response::json(&ServerInfoResponse {
server_version: self.server_version, server_version: self.server_version,
protocol_version: 2, protocol_version: 2,
session_id: self.session.session_id, session_id: self.live_session.session_id,
expected_place_ids: self.session.project.serve_place_ids.clone(), expected_place_ids: self.live_session.project.serve_place_ids.clone(),
root_instance_id: tree.get_root_id(), root_instance_id: tree.get_root_id(),
}) })
}, },
@@ -117,7 +117,7 @@ impl Server {
// Retrieve any messages past the given cursor index, and if // Retrieve any messages past the given cursor index, and if
// there weren't any, subscribe to receive any new messages. // there weren't any, subscribe to receive any new messages.
let message_queue = Arc::clone(&self.session.message_queue); let message_queue = Arc::clone(&self.live_session.message_queue);
// Did the client miss any messages since the last subscribe? // Did the client miss any messages since the last subscribe?
{ {
@@ -125,7 +125,7 @@ impl Server {
if !new_messages.is_empty() { if !new_messages.is_empty() {
return Response::json(&SubscribeResponse { return Response::json(&SubscribeResponse {
session_id: self.session.session_id, session_id: self.live_session.session_id,
messages: Cow::Borrowed(&new_messages), messages: Cow::Borrowed(&new_messages),
message_cursor: new_cursor, message_cursor: new_cursor,
}) })
@@ -147,7 +147,7 @@ impl Server {
let (new_cursor, new_messages) = message_queue.get_messages_since(cursor); let (new_cursor, new_messages) = message_queue.get_messages_since(cursor);
return Response::json(&SubscribeResponse { return Response::json(&SubscribeResponse {
session_id: self.session.session_id, session_id: self.live_session.session_id,
messages: Cow::Owned(new_messages), messages: Cow::Owned(new_messages),
message_cursor: new_cursor, message_cursor: new_cursor,
}) })
@@ -155,7 +155,7 @@ impl Server {
}, },
(GET) (/api/read/{ id_list: String }) => { (GET) (/api/read/{ id_list: String }) => {
let message_queue = Arc::clone(&self.session.message_queue); let message_queue = Arc::clone(&self.live_session.message_queue);
let requested_ids: Option<Vec<RbxId>> = id_list let requested_ids: Option<Vec<RbxId>> = id_list
.split(',') .split(',')
@@ -167,7 +167,7 @@ impl Server {
None => return rouille::Response::text("Malformed ID list").with_status_code(400), None => return rouille::Response::text("Malformed ID list").with_status_code(400),
}; };
let rbx_session = self.session.rbx_session.lock().unwrap(); let rbx_session = self.live_session.rbx_session.lock().unwrap();
let tree = rbx_session.get_tree(); let tree = rbx_session.get_tree();
let message_cursor = message_queue.get_message_cursor(); let message_cursor = message_queue.get_message_cursor();
@@ -197,14 +197,14 @@ impl Server {
} }
Response::json(&ReadResponse { Response::json(&ReadResponse {
session_id: self.session.session_id, session_id: self.live_session.session_id,
message_cursor, message_cursor,
instances, instances,
}) })
}, },
(GET) (/visualize/rbx) => { (GET) (/visualize/rbx) => {
let rbx_session = self.session.rbx_session.lock().unwrap(); let rbx_session = self.live_session.rbx_session.lock().unwrap();
let dot_source = format!("{}", VisualizeRbxSession(&rbx_session)); let dot_source = format!("{}", VisualizeRbxSession(&rbx_session));
@@ -212,7 +212,7 @@ impl Server {
}, },
(GET) (/visualize/imfs) => { (GET) (/visualize/imfs) => {
let imfs = self.session.imfs.lock().unwrap(); let imfs = self.live_session.imfs.lock().unwrap();
let dot_source = format!("{}", VisualizeImfs(&imfs)); let dot_source = format!("{}", VisualizeImfs(&imfs));
@@ -220,7 +220,7 @@ impl Server {
}, },
(GET) (/visualize/path_metadata) => { (GET) (/visualize/path_metadata) => {
let rbx_session = self.session.rbx_session.lock().unwrap(); let rbx_session = self.live_session.rbx_session.lock().unwrap();
Response::json(&rbx_session.debug_get_metadata_per_path()) Response::json(&rbx_session.debug_get_metadata_per_path())
}, },