This commit is contained in:
azw 2023-11-11 08:56:35 +00:00
parent 0e4b8daa34
commit eb8316b98b

View File

@ -33,9 +33,9 @@ pub struct HttpContext {
id: u64,
query_str: String,
add_tick: i64,
handled: bool,
pub handled: bool,
//not_found: bool,
rsp: String
pub rsp: String
}
#[derive(SharedFromSelf)]
@ -49,7 +49,7 @@ 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 (&HttpContext)>>,
http_handlers: HashMap<String, Box::<dyn FnMut (&mut HttpContext)>>,
//http_handlers: HashMap<String, Box::<dyn Fn (&HttpContext)>>,
webapp_state: Arc::<AppState>,
}
@ -143,26 +143,25 @@ impl App {
}
}
pub fn init(&mut self, user_app: Rc::<RefCell::<dyn UserApp>>) {
println!("main.thread.id {:?}", std::thread::current().id());
self.user_app = Some(user_app);
self.tokio_rt.enter();
self.init_http_server();
pub fn init(user_app: Rc::<RefCell::<dyn UserApp>>) {
App::instance().borrow_mut().user_app = Some(user_app.clone());
App::instance().borrow_mut().tokio_rt.enter();
App::instance().borrow_mut().init_http_server();
crate::Timer::instance().borrow_mut().init();
self.user_app.as_ref().unwrap().borrow_mut().init();
user_app.borrow_mut().init();
}
pub fn uninit(&mut self) {
self.user_app.as_ref().unwrap().borrow_mut().uninit();
pub fn uninit() {
//.user_app.as_ref().unwrap().borrow_mut().uninit();
crate::Timer::instance().borrow_mut().uninit();
}
pub fn run(&mut self) {
pub fn run() {
loop {
crate::Timer::instance().borrow_mut().update();
std::thread::sleep(Duration::from_millis(1));
self.dispatch_immsg();
self.dispatch_httprequest();
//self.dispatch_immsg();
//self.dispatch_httprequest();
}
}
@ -252,7 +251,7 @@ impl App {
let key = format!("{}${}", &req.c, &req.a);
match self.http_handlers.get_mut(&key) {
Some(v1) => {
(v1)(&ctx);
(v1)(ctx);
ctx.handled = true;
}
None => {
@ -279,7 +278,7 @@ impl App {
});
}
pub fn add_http_handler(&mut self, key: String, cb: Box::<dyn FnMut (&HttpContext)>) {
pub fn add_http_handler(&mut self, key: String, cb: Box::<dyn FnMut (&mut HttpContext)>) {
self.http_handlers.insert(key, cb);
}