fix: snapmakerprinteragent use moonraker's lifecycle-owned command worker

This commit is contained in:
Ian Chua
2026-09-22 16:06:18 +08:00
parent 9a7e925790
commit ce0c759ded
2 changed files with 6 additions and 3 deletions
+4 -1
View File
@@ -136,6 +136,10 @@ protected:
virtual void on_status_loop_tick(const std::string& dev_id) {}
// Queue work that may use agent state. The command worker is joined during
// destruction, so queued commands cannot outlive the agent.
void enqueue_command(std::function<void()> fn);
private:
int handle_request(const std::string& dev_id, const std::string& json_str);
int send_version_info(const std::string& dev_id);
@@ -254,7 +258,6 @@ private:
std::thread connect_thread;
mutable std::recursive_mutex connect_mutex;
void enqueue_command(std::function<void()> fn);
void run_command_worker();
std::thread cmd_thread;
std::deque<std::function<void()>> cmd_queue;
+2 -2
View File
@@ -82,10 +82,10 @@ SnapmakerPrinterAgent::SnapmakerPrinterAgent(std::string log_dir) : MoonrakerPri
void SnapmakerPrinterAgent::start_camera_monitor()
{
std::thread([this] {
enqueue_command([this] {
send_ws_rpc("camera.start_monitor",
{{"domain", "lan"}, {"interval", 0}, {"expect_pw", false}});
}).detach();
});
m_camera_last_fire_ms.store(now_ms());
}