|
|
|
@ -5,6 +5,7 @@ use parking_lot::Mutex; |
|
|
|
use solstice_proto::ServerRequest;
|
|
|
|
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
|
|
|
|
|
|
|
use crate::control::Response as ControlResponse;
|
|
|
|
use crate::room::RoomMap;
|
|
|
|
use crate::user::UserMap;
|
|
|
|
|
|
|
|
@ -23,7 +24,9 @@ pub struct Context { |
|
|
|
|
|
|
|
/// Sender half of a channel used to send requests to the server.
|
|
|
|
pub server_request_tx: Sender<ServerRequest>,
|
|
|
|
// TODO: Add control response sender.
|
|
|
|
|
|
|
|
/// Sender half of a channel used to send responses to the controller.
|
|
|
|
pub control_response_tx: Sender<ControlResponse>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Convenience bundle for creating new `Context` structs.
|
|
|
|
@ -34,6 +37,9 @@ pub struct ContextBundle { |
|
|
|
|
|
|
|
/// The receiver corresponding to `context.server_request_tx`.
|
|
|
|
pub server_request_rx: Receiver<ServerRequest>,
|
|
|
|
|
|
|
|
/// The receiver corresponsing to `context.control_response_tx`.
|
|
|
|
pub control_response_rx: Receiver<ControlResponse>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Specifies options for new `ContextBundle` structs.
|
|
|
|
@ -44,13 +50,17 @@ pub struct ContextOptions { |
|
|
|
|
|
|
|
/// The buffer size of the server request channel.
|
|
|
|
pub server_request_buffer: usize,
|
|
|
|
|
|
|
|
/// The buffer size of the control response channel.
|
|
|
|
pub control_response_buffer: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ContextOptions {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
server_request_buffer: 100,
|
|
|
|
initial_state: State::default(),
|
|
|
|
server_request_buffer: 100,
|
|
|
|
control_response_buffer: 100,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -60,12 +70,16 @@ impl ContextBundle { |
|
|
|
fn new(options: ContextOptions) -> Self {
|
|
|
|
let (server_request_tx, server_request_rx) =
|
|
|
|
channel(options.server_request_buffer);
|
|
|
|
let (control_response_tx, control_response_rx) =
|
|
|
|
channel(options.control_response_buffer);
|
|
|
|
Self {
|
|
|
|
context: Context {
|
|
|
|
state: Mutex::new(options.initial_state),
|
|
|
|
server_request_tx,
|
|
|
|
control_response_tx,
|
|
|
|
},
|
|
|
|
server_request_rx,
|
|
|
|
control_response_rx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|