This commit is contained in:
azw 2023-11-11 07:58:35 +00:00
parent 486d7c038a
commit f90b03aebb
2 changed files with 18 additions and 1 deletions

View File

@ -6,6 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = "*"
serde_derive = "*"
serde_json = "*"
tokio = { version = "1", features = ["full"] }
actix-web = "4"
r9 = { path = "../r9" }

View File

@ -8,13 +8,15 @@ use actix_web::{
web,
App as WebApp,
web::Data,
web::Query,
HttpRequest,
HttpResponse,
HttpServer,
Responder};
use std::sync::{Arc, Mutex};
//use std::collections::HashMap;
use std::collections::HashMap;
use std::any::Any;
use serde_derive::Deserialize;
use r9_macro::SharedFromSelf;
use r9_macro_derive::SharedFromSelf;
@ -38,9 +40,16 @@ pub struct App {
im_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
im_work_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
im_mutex: Mutex<i32>,
http_handlers: HashMap<String, Box::<dyn FnMut (&Option<Vec<Rc::<dyn Any>>>)>>,
webapp_state: Arc::<AppState>,
}
#[derive(Deserialize)]
struct Ca {
c: String,
a: String
}
struct AppState {
request: Arc<Mutex<Vec<Arc<Mutex<HttpContext>>>>>,
}
@ -58,6 +67,7 @@ struct HttpContext {
query_str: String,
add_tick: i64,
handled: bool,
//not_found: bool,
rsp: String
}
@ -121,6 +131,7 @@ impl App {
im_msgs: r9::ListHead::<IMMsgNode>::new_head(),
im_work_msgs: r9::ListHead::<IMMsgNode>::new_head(),
im_mutex: Mutex::new(1),
http_handlers: Default::default(),
webapp_state: Arc::new(
AppState{
request: Default::default()
@ -237,6 +248,9 @@ impl App {
let c = v.pop();
match c {
Some(v) => {
let query = web::Query::<Ca>::from_query(&v.lock().unwrap().query_str).unwrap();
println!("c={}&a={}", query.c, query.a);
v.lock().unwrap().rsp = "dsafsf".to_string();
v.lock().unwrap().handled = true;
}