1 | // SPDX-License-Identifier: GPL-3.0-or-later |
2 | |
3 | #include "dm_common.hpp" |
4 | #include "dm_server.hpp" |
5 | |
6 | #include <argparse/libargparse.h> |
7 | #include <iostream> |
8 | #include <libconfig/libconfig.h> |
9 | #include <librpc/rpc_server.h> |
10 | #include <stdio.h> |
11 | #include <stdlib.h> |
12 | #include <string.h> |
13 | |
14 | static const argparse_arg_t dm_args[] = { |
15 | { .full: "help" , .abbr: 'h', .argtype: ARGPARSE_NONE, .help: "show this help message and exit" }, |
16 | { .full: "config" , .abbr: 'c', .argtype: ARGPARSE_REQUIRED, .help: "path to the config file" }, |
17 | {}, |
18 | }; |
19 | |
20 | int main(int argc, const char *argv[]) |
21 | { |
22 | MOS_UNUSED(argc); |
23 | argparse_state_t arg_state; |
24 | argparse_init(options: &arg_state, argv); |
25 | |
26 | const char *config_path = "/initrd/config/dm.conf" ; |
27 | while (true) |
28 | { |
29 | const int option = argparse_long(options: &arg_state, longopts: dm_args, NULL); |
30 | if (option == -1) |
31 | break; |
32 | |
33 | switch (option) |
34 | { |
35 | case 'c': config_path = arg_state.optarg; break; |
36 | case 'h': argparse_usage(options: &arg_state, args: dm_args, usage: "device manager" ); return 0; |
37 | default: break; |
38 | } |
39 | } |
40 | |
41 | if (const auto result = Config::from_file(file_path: config_path); result) |
42 | dm_config = *result; |
43 | else |
44 | { |
45 | std::cerr << "Failed to parse config file: " << config_path << std::endl; |
46 | return 1; |
47 | } |
48 | |
49 | DeviceManagerServer dm_server; |
50 | |
51 | if (!start_load_drivers()) |
52 | { |
53 | fputs(string: "Failed to start device drivers\n" , stream: stderr); |
54 | return 2; |
55 | } |
56 | dm_server.run(); |
57 | fputs(string: "device_manager: server exited\n" , stream: stderr); |
58 | |
59 | return 0; |
60 | } |
61 | |