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