Rename AppServer to AppState
This commit is contained in:
		
							parent
							
								
									6f8d63e7be
								
							
						
					
					
						commit
						8dc9072fe8
					
				
					 6 changed files with 19 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -27,25 +27,25 @@ pub struct Action {
 | 
			
		|||
	pub action: ControllerWsAction,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub struct AppServer {
 | 
			
		||||
pub struct AppState {
 | 
			
		||||
	pub pool: Pool<Sqlite>,
 | 
			
		||||
	pub connected_controllers: HashMap<ControllerUid, (Controller, Recipient<ControllerWsAction>)>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl AppServer {
 | 
			
		||||
	pub fn new(pool: Pool<Sqlite>) -> AppServer {
 | 
			
		||||
		AppServer {
 | 
			
		||||
impl AppState {
 | 
			
		||||
	pub fn new(pool: Pool<Sqlite>) -> AppState {
 | 
			
		||||
		AppState {
 | 
			
		||||
			pool,
 | 
			
		||||
			connected_controllers: HashMap::new(),
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Actor for AppServer {
 | 
			
		||||
impl Actor for AppState {
 | 
			
		||||
	type Context = Context<Self>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Handler<DisconnectController> for AppServer {
 | 
			
		||||
impl Handler<DisconnectController> for AppState {
 | 
			
		||||
	type Result = Result<(), EmgauwaError>;
 | 
			
		||||
 | 
			
		||||
	fn handle(&mut self, msg: DisconnectController, _ctx: &mut Self::Context) -> Self::Result {
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +66,7 @@ impl Handler<DisconnectController> for AppServer {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Handler<ConnectController> for AppServer {
 | 
			
		||||
impl Handler<ConnectController> for AppState {
 | 
			
		||||
	type Result = Result<(), EmgauwaError>;
 | 
			
		||||
 | 
			
		||||
	fn handle(&mut self, msg: ConnectController, _ctx: &mut Self::Context) -> Self::Result {
 | 
			
		||||
| 
						 | 
				
			
			@ -77,7 +77,7 @@ impl Handler<ConnectController> for AppServer {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Handler<Action> for AppServer {
 | 
			
		||||
impl Handler<Action> for AppState {
 | 
			
		||||
	type Result = Result<(), EmgauwaError>;
 | 
			
		||||
 | 
			
		||||
	fn handle(&mut self, msg: Action, _ctx: &mut Self::Context) -> Self::Result {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ use emgauwa_lib::types::{ControllerUid, ControllerWsAction, RequestUpdateControl
 | 
			
		|||
use sqlx::{Pool, Sqlite};
 | 
			
		||||
 | 
			
		||||
use crate::app_state;
 | 
			
		||||
use crate::app_state::AppServer;
 | 
			
		||||
use crate::app_state::AppState;
 | 
			
		||||
 | 
			
		||||
#[get("/api/v1/controllers")]
 | 
			
		||||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, EmgauwaError> {
 | 
			
		||||
| 
						 | 
				
			
			@ -41,7 +41,7 @@ pub async fn show(
 | 
			
		|||
#[put("/api/v1/controllers/{controller_id}")]
 | 
			
		||||
pub async fn update(
 | 
			
		||||
	pool: web::Data<Pool<Sqlite>>,
 | 
			
		||||
	app_server: web::Data<Addr<AppServer>>,
 | 
			
		||||
	app_server: web::Data<Addr<AppState>>,
 | 
			
		||||
	path: web::Path<(String,)>,
 | 
			
		||||
	data: web::Json<RequestUpdateController>,
 | 
			
		||||
) -> Result<HttpResponse, EmgauwaError> {
 | 
			
		||||
| 
						 | 
				
			
			@ -73,7 +73,7 @@ pub async fn update(
 | 
			
		|||
#[delete("/api/v1/controllers/{controller_id}")]
 | 
			
		||||
pub async fn delete(
 | 
			
		||||
	pool: web::Data<Pool<Sqlite>>,
 | 
			
		||||
	app_server: web::Data<Addr<AppServer>>,
 | 
			
		||||
	app_server: web::Data<Addr<AppState>>,
 | 
			
		||||
	path: web::Path<(String,)>,
 | 
			
		||||
) -> Result<HttpResponse, EmgauwaError> {
 | 
			
		||||
	let mut pool_conn = pool.acquire().await?;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ use emgauwa_lib::utils;
 | 
			
		|||
use sqlx::{Pool, Sqlite};
 | 
			
		||||
 | 
			
		||||
use crate::app_state;
 | 
			
		||||
use crate::app_state::AppServer;
 | 
			
		||||
use crate::app_state::AppState;
 | 
			
		||||
 | 
			
		||||
#[get("/api/v1/relays")]
 | 
			
		||||
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, EmgauwaError> {
 | 
			
		||||
| 
						 | 
				
			
			@ -84,7 +84,7 @@ pub async fn show_for_controller(
 | 
			
		|||
#[put("/api/v1/controllers/{controller_id}/relays/{relay_num}")]
 | 
			
		||||
pub async fn update_for_controller(
 | 
			
		||||
	pool: web::Data<Pool<Sqlite>>,
 | 
			
		||||
	app_server: web::Data<Addr<AppServer>>,
 | 
			
		||||
	app_server: web::Data<Addr<AppState>>,
 | 
			
		||||
	path: web::Path<(String, i64)>,
 | 
			
		||||
	data: web::Json<RequestUpdateRelay>,
 | 
			
		||||
) -> Result<HttpResponse, EmgauwaError> {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,13 +13,13 @@ use sqlx::pool::PoolConnection;
 | 
			
		|||
use sqlx::{Pool, Sqlite};
 | 
			
		||||
use ws::Message;
 | 
			
		||||
 | 
			
		||||
use crate::app_state::{AppServer, DisconnectController};
 | 
			
		||||
use crate::app_state::{AppState, DisconnectController};
 | 
			
		||||
use crate::utils::flatten_result;
 | 
			
		||||
 | 
			
		||||
pub struct ControllerWs {
 | 
			
		||||
	pub pool: Pool<Sqlite>,
 | 
			
		||||
	pub controller_uid: Option<ControllerUid>,
 | 
			
		||||
	pub app_server: Addr<AppServer>,
 | 
			
		||||
	pub app_server: Addr<AppState>,
 | 
			
		||||
	pub hb: Instant,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@ use actix_web_actors::ws;
 | 
			
		|||
use emgauwa_lib::errors::EmgauwaError;
 | 
			
		||||
use sqlx::{Pool, Sqlite};
 | 
			
		||||
 | 
			
		||||
use crate::app_state::AppServer;
 | 
			
		||||
use crate::app_state::AppState;
 | 
			
		||||
use crate::handlers::v1::ws::controllers::ControllerWs;
 | 
			
		||||
 | 
			
		||||
pub mod controllers;
 | 
			
		||||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ pub mod controllers;
 | 
			
		|||
#[get("/api/v1/ws/controllers")]
 | 
			
		||||
pub async fn ws_controllers(
 | 
			
		||||
	pool: web::Data<Pool<Sqlite>>,
 | 
			
		||||
	app_server: web::Data<Addr<AppServer>>,
 | 
			
		||||
	app_server: web::Data<Addr<AppState>>,
 | 
			
		||||
	req: HttpRequest,
 | 
			
		||||
	stream: web::Payload,
 | 
			
		||||
) -> Result<HttpResponse, EmgauwaError> {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ use emgauwa_lib::db::DbController;
 | 
			
		|||
use emgauwa_lib::errors::EmgauwaError;
 | 
			
		||||
use emgauwa_lib::utils::init_logging;
 | 
			
		||||
 | 
			
		||||
use crate::app_state::AppServer;
 | 
			
		||||
use crate::app_state::AppState;
 | 
			
		||||
use crate::utils::drop_privileges;
 | 
			
		||||
 | 
			
		||||
mod app_state;
 | 
			
		||||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ async fn main() -> Result<(), std::io::Error> {
 | 
			
		|||
		.map_err(EmgauwaError::from)?;
 | 
			
		||||
	conn.close().await.map_err(EmgauwaError::from)?;
 | 
			
		||||
 | 
			
		||||
	let app_server = AppServer::new(pool.clone()).start();
 | 
			
		||||
	let app_server = AppState::new(pool.clone()).start();
 | 
			
		||||
 | 
			
		||||
	log::info!("Starting server on {}:{}", settings.host, settings.port);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue