1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 mod auth;
16 mod client;
17 mod host_app;
18 mod logger;
19 mod parser;
20 mod server;
21 mod task;
22 mod translate;
23 mod unittest;
24
25 use std::io::ErrorKind;
26
27 use hdc::config;
28
29 #[macro_use]
30 extern crate lazy_static;
31
32 // static LOGGER: SimpleHostLogger = SimpleHostLogger;
33
34 // fn logger_init(log_level: log::LevelFilter) {
35 // let log_file: std::path::PathBuf = Path::new(&std::env::temp_dir()).join(config::LOG_FILE_NAME);
36 // let _ = std::fs::File::create(log_file);
37 // let logger: &'static SimpleHostLogger = &SimpleHostLogger { background_mode: false, flushed_size: 100 };
38 // log::set_logger(logger).unwrap();
39 // log::set_max_level(log_level);
40 // }
41
main()42 fn main() {
43 let _ = ylong_runtime::builder::RuntimeBuilder::new_multi_thread()
44 .worker_stack_size(16 * 1024 * 1024)
45 .worker_num(64)
46 .keep_alive_time(std::time::Duration::from_secs(10))
47 .build_global();
48
49 let parsed_cmd = match parser::parse_command(std::env::args()) {
50 Ok(parsed_cmd) => parsed_cmd,
51 Err(e) => {
52 println!("{}", e.to_string());
53 return;
54 }
55 };
56
57 logger::logger_init(
58 config::LOG_LEVEL_ORDER[parsed_cmd.log_level],
59 parsed_cmd.run_in_server,
60 parsed_cmd.spawned_server,
61 );
62
63 hdc::debug!("parsed cmd: {:#?}", parsed_cmd);
64
65 if parsed_cmd.run_in_server {
66 ylong_runtime::block_on(async {
67 let _ = server::run_server_mode(parsed_cmd.server_addr).await;
68 });
69 } else {
70 hdc::debug!(
71 "in client mode, cmd: {:#?}, parameter:{:#?}",
72 parsed_cmd.command.unwrap(),
73 parsed_cmd.parameters
74 );
75 ylong_runtime::block_on(async {
76 if parsed_cmd.command.is_none() {
77 println!("Unknown operation command...");
78 println!("{}", translate::usage());
79 return;
80 }
81
82 if let Err(e) = client::run_client_mode(parsed_cmd).await {
83 match e.kind() {
84 ErrorKind::Other => println!("[Fail]{}", e.to_string()),
85 _ => hdc::trace!("client exit with err: {e:?}"),
86 }
87 }
88 })
89 }
90 }
91