diff --git a/src/main.cpp b/src/main.cpp index 7ce2b40..c1cbae4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "app_config.hpp" @@ -15,7 +16,7 @@ #include "tunnel_client.hpp" std::atomic g_running(true); -TunnelClient* g_tunnel_client = nullptr; +std::unique_ptr g_tunnel_client; static void signal_handler(int signum) { @@ -65,15 +66,19 @@ int main() RTMPManager::start_all(); { - std::string vid = g_app_config.vehicle_id; - int local_http_port = 2980; + // 从配置里拿 VID(确保 AppConfig 有 vehicle_id 字段) + const std::string vid = g_app_config.vehicle_id; + const int local_http_port = 2980; - std::string tunnel_server = "ws://36.153.162.171:2088/tunnel"; - - g_tunnel_client = new TunnelClient(vid, tunnel_server, local_http_port); + // 建议也从 config 里读;这里先保留你的固定值 + const std::string tunnel_server = "ws://36.153.162.171:2088/tunnel"; + // 用 unique_ptr 管理生命周期 + g_tunnel_client = std::make_unique(vid, tunnel_server, local_http_port); g_tunnel_client->start(); - LOG_INFO("[MAIN] TunnelClient started: %s", tunnel_server.c_str()); + + // 关键:LOG_INFO 只接收一个参数,所以拼接成一个字符串 + LOG_INFO(("[MAIN] TunnelClient started: " + tunnel_server).c_str()); } // 启动 MQTT 线程 @@ -101,8 +106,7 @@ int main() if (g_tunnel_client) { g_tunnel_client->stop(); - delete g_tunnel_client; - g_tunnel_client = nullptr; + g_tunnel_client.reset(); LOG_INFO("[MAIN] TunnelClient stopped."); }