Covalent Bond
0.0.1-alpha
'covalent bond' is a data middle office. As a 2022-2023 Fall SWE final project.
src
core
server
main.cpp
Go to the documentation of this file.
1
#include "
argparse.hpp
"
2
#include "
pipeline.hpp
"
3
4
#define HELP_STR \
5
"\
6
Licensed under the Apache License, Version 2.0 (the \" License \")\n\
7
You may obtain a copy of the License at\n\
8
\n\
9
http://www.apache.org/licenses/LICENSE-2.0\n\
10
\n\
11
Unless required by applicable law or agreed to in writing, software\n\
12
distributed under the License is distributed on an \" AS IS \" BASIS,\n\
13
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\
14
See the License for the specific language governing permissions and\n\
15
limitations under the License.\n"
16
17
#define WELCOME_STR "Welcome to CovalentBond."
18
19
static
WFFacilities::WaitGroup
wait_group
(1);
20
static
WFFacilities::WaitGroup
wait_group_end
(1);
21
22
void
sig_handler
(
int
signo) {
wait_group
.done(); }
23
24
int
main
(
int
argc,
char
* argv[]) {
25
argp::parser
args;
26
args.
add_arg
(
"--help"
,
"-H"
,
false
);
27
args.
add_arg
<std::string>(
"--webRoot"
,
"-R"
,
argp::arg_type::t_string
,
"."
,
true
);
28
args.
add_arg
<
int
>(
"--webPort"
,
"-Wp"
,
argp::arg_type::t_int
, 8888,
true
);
29
args.
add_arg
<
int
>(
"--httpPort"
,
"-Hp"
,
argp::arg_type::t_int
, 8080,
true
);
30
args.
add_arg
<
int
>(
"--execSec"
,
"-S"
,
argp::arg_type::t_int
, 10,
false
);
31
args.
add_arg
<std::string>(
"--redisHost"
,
"-Rh"
,
argp::arg_type::t_string
,
true
);
32
args.
add_arg
<std::string>(
"--redisPassword"
,
"-Rpa"
,
argp::arg_type::t_string
,
true
);
33
args.
add_arg
<std::string>(
"--redisPort"
,
"-Rpo"
,
argp::arg_type::t_string
,
true
);
34
args.
add_arg
<
int
>(
"--redisDBNum"
,
"-RDBNum"
,
argp::arg_type::t_int
, 1,
false
);
35
args.
add_arg
<
int
>(
"--redisSSL"
,
"-Rs"
,
argp::arg_type::t_int
, 0,
false
);
36
37
args.
parse
(argc, argv);
38
39
if
(args.
has_item
(
"help"
)) {
40
std::cout <<
HELP_STR
<< std::endl;
41
args.
show_all_defined
();
42
exit(0);
43
}
44
45
if
(!(args.
has_item
(
"redisHost"
) && args.
has_item
(
"redisPassword"
)
46
&& args.
has_item
(
"redisPort"
))) {
47
std::cout <<
HELP_STR
<< std::endl;
48
args.
show_all_defined
();
49
exit(1);
50
}
51
52
cb::pipeline::appCfg
cfg;
53
54
cfg.
webPort
= args.
get_item
<
int
>(
"webPort"
);
55
cfg.
webRoot
= args.
get_item
<std::string>(
"webRoot"
).c_str();
56
cfg.
rHttpPort
= args.
get_item
<
int
>(
"httpPort"
);
57
cfg.
graphExecSec
= args.
get_item
<
int
>(
"execSec"
);
58
cfg.
redisHost
= args.
get_item
<std::string>(
"redisHost"
).c_str();
59
cfg.
redisPassword
= args.
get_item
<std::string>(
"redisPassword"
).c_str();
60
cfg.
redisPort
= args.
get_item
<std::string>(
"redisPort"
).c_str();
61
cfg.
redisDBNum
= args.
get_item
<
int
>(
"redisDBNum"
);
62
cfg.
redisSSL
= args.
get_item
<
int
>(
"redisSSL"
) == 0 ?
false
:
true
;
63
64
signal(SIGINT,
sig_handler
);
65
signal(SIGTERM,
sig_handler
);
66
signal(SIGKILL,
sig_handler
);
67
68
std::cout <<
HELP_STR
<< std::endl;
69
std::cout <<
WELCOME_STR
<< std::endl;
70
71
auto
App =
cb::pipeline::app
(cfg);
72
App.execMain();
73
wait_group
.wait();
74
App.stopMain();
75
// Waiting for 10 sec for graph tasks in queue done.
76
fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
77
"Waiting about {} sec for graph tasks in queue done.\n"
, cfg.
graphExecSec
);
78
WFTimerTask* timerToEnd =
79
WFTaskFactory::create_timer_task(cfg.
graphExecSec
* 2, 0, [=](WFTimerTask* task) {
80
fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
"All tasks were done.\n"
);
81
wait_group_end.done();
82
});
83
timerToEnd->start();
84
wait_group_end
.wait();
85
fmt::print(
"\nBye.\n"
);
86
return
0;
87
}
cb::pipeline::appCfg::redisPort
const char * redisPort
Definition:
pipeline.hpp:92
argp::parser::show_all_defined
virtual void show_all_defined()
Definition:
argparse.hpp:178
argp::parser::parse
virtual bool parse(int argc, char **args)
Definition:
argparse.hpp:112
cb::pipeline::appCfg::rHttpPort
unsigned short rHttpPort
Definition:
pipeline.hpp:88
pipeline.hpp
The main pipeline, manage all resources.
argp::parser::has_item
bool has_item(const string &key)
Definition:
argparse.hpp:107
cb::pipeline::app
Definition:
pipeline.hpp:97
HELP_STR
#define HELP_STR
Definition:
main.cpp:4
cb::pipeline::appCfg
Definition:
pipeline.hpp:85
sig_handler
void sig_handler(int signo)
Definition:
main.cpp:22
cb::pipeline::appCfg::redisDBNum
int32_t redisDBNum
Definition:
pipeline.hpp:93
argparse.hpp
cb::pipeline::appCfg::webRoot
const char * webRoot
Definition:
pipeline.hpp:87
cb::pipeline::appCfg::redisHost
const char * redisHost
Definition:
pipeline.hpp:90
cb::pipeline::appCfg::redisPassword
const char * redisPassword
Definition:
pipeline.hpp:91
argp::parser::add_arg
void add_arg(const string &name, const string &s_name, arg_type type, T default_v, bool is_necessary)
Definition:
argparse.hpp:62
argp::parser::get_item
T & get_item(const string &key)
Definition:
argparse.hpp:98
cb::pipeline::appCfg::webPort
unsigned short webPort
Definition:
pipeline.hpp:86
wait_group_end
static WFFacilities::WaitGroup wait_group_end(1)
cb::pipeline::appCfg::graphExecSec
int32_t graphExecSec
Definition:
pipeline.hpp:89
argp::parser
Definition:
argparse.hpp:53
argp::arg_type::t_int
@ t_int
argp::arg_type::t_string
@ t_string
wait_group
static WFFacilities::WaitGroup wait_group(1)
cb::pipeline::appCfg::redisSSL
bool redisSSL
Definition:
pipeline.hpp:94
main
int main(int argc, char *argv[])
Definition:
main.cpp:24
WELCOME_STR
#define WELCOME_STR
Definition:
main.cpp:17
Generated by
1.8.17