This commit is contained in:
azw 2024-05-12 18:51:45 +08:00
parent 73618b38d8
commit e8f05c5424
5 changed files with 43 additions and 0 deletions

View File

@ -3,9 +3,11 @@ use std::sync::Mutex;
use crate::listener::WsListener; use crate::listener::WsListener;
use crate::upstream::UpStreamMgr; use crate::upstream::UpStreamMgr;
use crate::common::types::DownStreamPack; use crate::common::types::DownStreamPack;
use crate::master::MasterMgr;
use std::sync::OnceLock; use std::sync::OnceLock;
pub struct UserApp { pub struct UserApp {
pub _masterMgr: MasterMgr,
down_stream_msg_queue: Arc::<std::sync::Mutex::<r9::QueueLock<DownStreamPack>>>, down_stream_msg_queue: Arc::<std::sync::Mutex::<r9::QueueLock<DownStreamPack>>>,
} }
@ -16,6 +18,7 @@ impl f9::app::UserApp for UserApp {
} }
fn init(&self) { fn init(&self) {
MasterMgr::instance().init();
WsListener::instance().init(); WsListener::instance().init();
UpStreamMgr::instance().borrow_mut().init(); UpStreamMgr::instance().borrow_mut().init();
} }
@ -49,6 +52,7 @@ impl f9::app::UserApp for UserApp {
fn uninit(&self) { fn uninit(&self) {
WsListener::instance().uninit(); WsListener::instance().uninit();
MasterMgr::instance().uninit();
} }
fn get_http_listen_port(&self) -> i32 { fn get_http_listen_port(&self) -> i32 {
@ -66,6 +70,7 @@ impl UserApp {
} }
pub fn new() -> Self { pub fn new() -> Self {
let p = UserApp{ let p = UserApp{
_masterMgr: MasterMgr::new(),
down_stream_msg_queue: r9::QueueLock::<DownStreamPack>::new(), down_stream_msg_queue: r9::QueueLock::<DownStreamPack>::new(),
}; };
return p; return p;

View File

@ -7,6 +7,7 @@ mod downstream;
mod ss; mod ss;
mod constant; mod constant;
mod common; mod common;
mod master;
use crate::app::UserApp; use crate::app::UserApp;

View File

@ -0,0 +1,4 @@
pub mod mastermgr;
pub use mastermgr::*;

View File

View File

@ -0,0 +1,33 @@
use std::collections::HashMap;
use crate::app::UserApp;
pub struct MasterMgr {
curr_context_id: i64,
mastersvr_hash: HashMap<i32, i32>,
}
impl MasterMgr {
pub fn instance() -> &'static Self {
return &UserApp::instance()._masterMgr;
}
pub fn new() -> Self {
let p = Self{
curr_context_id: 0,
mastersvr_hash: Default::default(),
};
return p;
}
pub fn init(&self) {
}
pub fn uninit(&self) {
}
}