1 |
use super::Config; |
2 |
use salaryman::service::{Service, ServiceConf}; |
3 |
use std::path::PathBuf; |
4 |
use std::sync::Arc; |
5 |
use tokio::sync::RwLock; |
6 |
|
7 |
pub struct SalarymanService { |
8 |
pub config: ServiceConf, |
9 |
pub service: Arc<RwLock<Service>>, |
10 |
} |
11 |
impl SalarymanService { |
12 |
pub fn new() -> Self { |
13 |
Self { |
14 |
config: ServiceConf::new(), |
15 |
service: Arc::new(RwLock::new(Service::new())), |
16 |
} |
17 |
} |
18 |
pub fn from_parts(config: ServiceConf, service: Arc<RwLock<Service>>) -> Self { |
19 |
Self { config, service } |
20 |
} |
21 |
} |
22 |
|
23 |
pub struct SalarymanDContext { |
24 |
pub services: RwLock<Vec<Arc<SalarymanService>>>, |
25 |
pub save_file: PathBuf, |
26 |
pub config: Arc<RwLock<Config>>, |
27 |
} |
28 |
impl SalarymanDContext { |
29 |
pub fn new() -> Self { |
30 |
Self { |
31 |
services: RwLock::new(Vec::new()), |
32 |
save_file: PathBuf::from(""), |
33 |
config: Arc::new(RwLock::new(Config::new())), |
34 |
} |
35 |
} |
36 |
pub fn from_parts( |
37 |
services: RwLock<Vec<Arc<SalarymanService>>>, |
38 |
save_file: PathBuf, |
39 |
config: Arc<RwLock<Config>>, |
40 |
) -> Self { |
41 |
Self { |
42 |
services, |
43 |
save_file, |
44 |
config, |
45 |
} |
46 |
} |
47 |
} |