-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (40 loc) · 1.34 KB
/
main.cpp
File metadata and controls
48 lines (40 loc) · 1.34 KB
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
48
#include <iostream>
#include <web/src/dao/UserDao.hpp>
#include <web/src/dao/TransactionDao.hpp>
#include <web/src/dao/BaseDao.hpp>
#include <web/src/controller/BaseController.hpp>
#include <server/include/EpollServer.hpp>
void init(const std::string& databaseRoot) {
// 加载数据
try {
web::BaseDao::databaseRoot = databaseRoot;
web::UserDao::loadDatabase(web::UserDao::userDatabase_);
web::TransactionDao::loadDatabase(web::TransactionDao::transDatabase_);
} catch (std::exception& e) {
std::cerr << "load database Error! Please check your Database. (or rm -r <your database>)" << std::endl;
exit(1);
}
// 加载控制器
try {
web::BaseController::handle();
} catch (std::exception& e) {
std::cerr << "load Web Controller Error! Sorry about that, please try to debug. " << std::endl;
exit(1);
}
}
void epoll_http(int argc, char* argv[]) {
try {
if (argc != 5) {
std::cerr << "Usage:: <address> <port> <doc_root> <database_root>" << std::endl;
return;
}
init(argv[4]);
payhttp::EpollServer server(argv[1], argv[2], argv[3]);
} catch (std::exception& e) {
std::cerr << "exception: " << e.what() << std::endl;
}
}
int main(int argc, char* argv[]) {
epoll_http(argc, argv);
return 0;
}