mirror of
https://github.com/kunkundi/crossdesk-server.git
synced 2026-10-25 17:21:59 +08:00
[feat] use argv to set database path
This commit is contained in:
1 parent
94cee80cc6
commit
2155e823ca
5 files changed
+20
-9
No files matched your search
+7
-2
@@ -16,6 +16,7 @@ int main(int argc, char* argv[]) {
|
||||
std::string port = "9090";
|
||||
std::string log_dir = "./logs";
|
||||
std::string certs_dir = "./cert";
|
||||
std::string db_path = "devices.db";
|
||||
|
||||
if (argc > 1) {
|
||||
port = argv[1];
|
||||
@@ -26,13 +27,17 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
if (argc > 3) {
|
||||
log_dir = argv[3];
|
||||
db_path = argv[3];
|
||||
}
|
||||
|
||||
if (argc > 4) {
|
||||
log_dir = argv[4];
|
||||
}
|
||||
|
||||
InitLogger(log_dir);
|
||||
|
||||
SignalServer s;
|
||||
s.Run(std::stoi(port), certs_dir);
|
||||
s.Run(std::stoi(port), certs_dir, db_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
#include "log.h"
|
||||
|
||||
SignalNegotiation::SignalNegotiation(
|
||||
std::shared_ptr<TransmissionManager> transmission_manager)
|
||||
std::shared_ptr<TransmissionManager> transmission_manager,
|
||||
std::string db_path)
|
||||
: transmission_manager_(transmission_manager) {
|
||||
device_db_manager_ = std::make_unique<DeviceDBManager>("devices.db");
|
||||
device_db_manager_ = std::make_unique<DeviceDBManager>(db_path);
|
||||
}
|
||||
|
||||
SignalNegotiation::~SignalNegotiation() {}
|
||||
|
||||
@@ -16,7 +16,8 @@ using nlohmann::json;
|
||||
|
||||
class SignalNegotiation {
|
||||
public:
|
||||
SignalNegotiation(std::shared_ptr<TransmissionManager> transmission_manager);
|
||||
SignalNegotiation(std::shared_ptr<TransmissionManager> transmission_manager,
|
||||
std::string db_path);
|
||||
~SignalNegotiation();
|
||||
|
||||
void SetSendMsgCallback(
|
||||
|
||||
@@ -31,7 +31,7 @@ SignalServer::SignalServer() {
|
||||
|
||||
transmission_manager_ = std::make_shared<TransmissionManager>();
|
||||
signal_negotiation_ =
|
||||
std::make_unique<SignalNegotiation>(transmission_manager_);
|
||||
std::make_unique<SignalNegotiation>(transmission_manager_, db_path_);
|
||||
signal_negotiation_->SetSendMsgCallback(std::bind(&SignalServer::SendMsg,
|
||||
this, std::placeholders::_1,
|
||||
std::placeholders::_2));
|
||||
@@ -73,7 +73,7 @@ context_ptr SignalServer::OnTlsInit(websocketpp::connection_hdl hdl) {
|
||||
asio::ssl::context::default_workarounds | asio::ssl::context::no_sslv2 |
|
||||
asio::ssl::context::no_sslv3 | asio::ssl::context::single_dh_use);
|
||||
|
||||
std::string cert_file = certs_dir_ + "/crossdesk.cn.crt";
|
||||
std::string cert_file = certs_dir_ + "crossdesk.cn_bundle.crt";
|
||||
std::string key_file = certs_dir_ + "/crossdesk.cn.key";
|
||||
ctx->use_certificate_chain_file(cert_file);
|
||||
ctx->use_private_key_file(key_file, asio::ssl::context::pem);
|
||||
@@ -98,8 +98,11 @@ bool SignalServer::OnPong(websocketpp::connection_hdl hdl, std::string s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SignalServer::Run(uint16_t port, std::string certs_dir) {
|
||||
void SignalServer::Run(uint16_t port, std::string certs_dir,
|
||||
std::string db_path) {
|
||||
certs_dir_ = certs_dir;
|
||||
db_path_ = db_path;
|
||||
|
||||
if (!std::filesystem::exists(certs_dir_)) {
|
||||
LOG_ERROR("Certs dir [{}] not exist", certs_dir_);
|
||||
return;
|
||||
|
||||
+2
-1
@@ -35,13 +35,14 @@ class SignalServer {
|
||||
bool OnPing(websocketpp::connection_hdl hdl, std::string s);
|
||||
bool OnPong(websocketpp::connection_hdl hdl, std::string s);
|
||||
|
||||
void Run(uint16_t port, std::string certs_dir);
|
||||
void Run(uint16_t port, std::string certs_dir, std::string db_path);
|
||||
void SendMsg(websocketpp::connection_hdl hdl, json message);
|
||||
void OnMessage(websocketpp::connection_hdl hdl, server::message_ptr msg);
|
||||
|
||||
private:
|
||||
server server_;
|
||||
std::string certs_dir_;
|
||||
std::string db_path_;
|
||||
std::map<websocketpp::connection_hdl, connection_id,
|
||||
std::owner_less<websocketpp::connection_hdl>>
|
||||
ws_connections_;
|
||||
|
||||
Reference in new issue
Block a user