1
This commit is contained in:
parent
0e4b8daa34
commit
eb8316b98b
@ -33,9 +33,9 @@ pub struct HttpContext {
|
|||||||
id: u64,
|
id: u64,
|
||||||
query_str: String,
|
query_str: String,
|
||||||
add_tick: i64,
|
add_tick: i64,
|
||||||
handled: bool,
|
pub handled: bool,
|
||||||
//not_found: bool,
|
//not_found: bool,
|
||||||
rsp: String
|
pub rsp: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SharedFromSelf)]
|
#[derive(SharedFromSelf)]
|
||||||
@ -49,7 +49,7 @@ pub struct App {
|
|||||||
im_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
|
im_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
|
||||||
im_work_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
|
im_work_msgs: Rc::<RefCell::<r9::ListHead::<IMMsgNode>>>,
|
||||||
im_mutex: Mutex<i32>,
|
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)>>,
|
//http_handlers: HashMap<String, Box::<dyn Fn (&HttpContext)>>,
|
||||||
webapp_state: Arc::<AppState>,
|
webapp_state: Arc::<AppState>,
|
||||||
}
|
}
|
||||||
@ -143,26 +143,25 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&mut self, user_app: Rc::<RefCell::<dyn UserApp>>) {
|
pub fn init(user_app: Rc::<RefCell::<dyn UserApp>>) {
|
||||||
println!("main.thread.id {:?}", std::thread::current().id());
|
App::instance().borrow_mut().user_app = Some(user_app.clone());
|
||||||
self.user_app = Some(user_app);
|
App::instance().borrow_mut().tokio_rt.enter();
|
||||||
self.tokio_rt.enter();
|
App::instance().borrow_mut().init_http_server();
|
||||||
self.init_http_server();
|
|
||||||
crate::Timer::instance().borrow_mut().init();
|
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) {
|
pub fn uninit() {
|
||||||
self.user_app.as_ref().unwrap().borrow_mut().uninit();
|
//.user_app.as_ref().unwrap().borrow_mut().uninit();
|
||||||
crate::Timer::instance().borrow_mut().uninit();
|
crate::Timer::instance().borrow_mut().uninit();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self) {
|
pub fn run() {
|
||||||
loop {
|
loop {
|
||||||
crate::Timer::instance().borrow_mut().update();
|
crate::Timer::instance().borrow_mut().update();
|
||||||
std::thread::sleep(Duration::from_millis(1));
|
std::thread::sleep(Duration::from_millis(1));
|
||||||
self.dispatch_immsg();
|
//self.dispatch_immsg();
|
||||||
self.dispatch_httprequest();
|
//self.dispatch_httprequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +251,7 @@ impl App {
|
|||||||
let key = format!("{}${}", &req.c, &req.a);
|
let key = format!("{}${}", &req.c, &req.a);
|
||||||
match self.http_handlers.get_mut(&key) {
|
match self.http_handlers.get_mut(&key) {
|
||||||
Some(v1) => {
|
Some(v1) => {
|
||||||
(v1)(&ctx);
|
(v1)(ctx);
|
||||||
ctx.handled = true;
|
ctx.handled = true;
|
||||||
}
|
}
|
||||||
None => {
|
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);
|
self.http_handlers.insert(key, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user