From b44f3ae3e6329281508fd791d821f22f8b953c83 Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Mon, 7 Nov 2022 19:40:48 +0800 Subject: [PATCH] ENH: CLI: use json insteadof string for progress pipe Change-Id: I1fdecfa6198d06d0c9745f3cbeb02dece9d8e20f --- src/BambuStudio.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index aad4d8a307..010455a9bf 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -27,6 +27,10 @@ #include #include #include +//add json logic +#include "nlohmann/json.hpp" + +using namespace nlohmann; #endif #include @@ -132,7 +136,7 @@ std::map cli_errors = { }; #if defined(__linux__) || defined(__LINUX__) -#define PIPE_BUFFER_SIZE 64 +#define PIPE_BUFFER_SIZE 128 typedef struct _cli_callback_mgr { int m_plate_count {0}; @@ -174,8 +178,15 @@ typedef struct _cli_callback_mgr { if (m_pipe_fd < 0) return; - std::string notify_message; - notify_message = "Plate "+ std::to_string(m_plate_index) + "/" +std::to_string(m_plate_count)+ ": Percent " + std::to_string(m_progress) + ": "+m_message; + json j; + //record the headers + j["plate_index"] = m_plate_index; + j["plate_count"] = m_plate_count; + j["percent"] = m_progress; + j["message"] = m_message; + + std::string notify_message = j.dump(); + //notify_message = "Plate "+ std::to_string(m_plate_index) + "/" +std::to_string(m_plate_count)+ ": Percent " + std::to_string(m_progress) + ": "+m_message; char pipe_message[PIPE_BUFFER_SIZE] = {0}; strncpy(pipe_message, notify_message.c_str(), PIPE_BUFFER_SIZE); @@ -239,7 +250,7 @@ typedef struct _cli_callback_mgr { BOOST_LOG_TRIVIAL(info) << "cli_callback_mgr_t::start enter."; m_pipe_fd = open(pipe_name.c_str(),O_WRONLY|O_NONBLOCK); if (m_pipe_fd < 0) { - BOOST_LOG_TRIVIAL(error) << "could not create pipe for "< lck(m_mutex); @@ -261,6 +272,7 @@ typedef struct _cli_callback_mgr { } if (!m_started) { lck.unlock(); + BOOST_LOG_TRIVIAL(info) << "cli_callback_mgr_t::stop not started before, return directly."; return; } m_exit = true;