ENH: CLI: add warning message

send the warning message back to caller

Change-Id: Id36edc9537721fb890f2bd4eb8db4fc0670eb97d
This commit is contained in:
lane.wei 2022-11-10 22:54:08 +08:00 committed by Lane.Wei
parent 79c644d1da
commit 8340e1ceec
1 changed files with 22 additions and 13 deletions

View File

@ -137,7 +137,7 @@ std::map<int, std::string> cli_errors = {
}; };
#if defined(__linux__) || defined(__LINUX__) #if defined(__linux__) || defined(__LINUX__)
#define PIPE_BUFFER_SIZE 128 #define PIPE_BUFFER_SIZE 512
typedef struct _cli_callback_mgr { typedef struct _cli_callback_mgr {
int m_plate_count {0}; int m_plate_count {0};
@ -188,6 +188,9 @@ typedef struct _cli_callback_mgr {
j["plate_count"] = m_plate_count; j["plate_count"] = m_plate_count;
j["plate_percent"] = m_progress; j["plate_percent"] = m_progress;
j["total_percent"] = m_total_progress; j["total_percent"] = m_total_progress;
if (m_warning_step >= 0)
j["warning"] = m_message;
else
j["message"] = m_message; j["message"] = m_message;
std::string notify_message = j.dump(); std::string notify_message = j.dump();
@ -231,18 +234,19 @@ typedef struct _cli_callback_mgr {
void update(int percent, std::string message, int warning_step) void update(int percent, std::string message, int warning_step)
{ {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": percent="<<percent<< ", plate_index = "<< m_plate_index<<", plate_count="<< m_plate_count<<", message="<<message;
std::unique_lock<std::mutex> lck(m_mutex); std::unique_lock<std::mutex> lck(m_mutex);
if (!m_started) { if (!m_started) {
lck.unlock(); lck.unlock();
return; return;
} }
if (m_progress >= percent) { if ((m_progress >= percent)&&(warning_step == -1)) {
//already update before //already update before
lck.unlock(); lck.unlock();
return; return;
} }
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": percent="<<percent<< ", warning_step=" << warning_step << ", plate_index = "<< m_plate_index<<", plate_count="<< m_plate_count<<", message="<<message;
if (warning_step == -1) {
m_progress = percent; m_progress = percent;
if ((m_plate_index >= 1)&&(m_plate_index <= m_plate_count)) { if ((m_plate_index >= 1)&&(m_plate_index <= m_plate_count)) {
if (m_plate_count <= 1) if (m_plate_count <= 1)
@ -253,6 +257,7 @@ typedef struct _cli_callback_mgr {
} }
else else
m_total_progress = m_progress; m_total_progress = m_progress;
}
m_message = message; m_message = message;
m_warning_step = warning_step; m_warning_step = warning_step;
m_data_ready = true; m_data_ready = true;
@ -1410,6 +1415,10 @@ int CLI::run(int argc, char **argv)
BOOST_LOG_TRIVIAL(info) << "set print's callback to cli_status_callback."; BOOST_LOG_TRIVIAL(info) << "set print's callback to cli_status_callback.";
print->set_status_callback(cli_status_callback); print->set_status_callback(cli_status_callback);
g_cli_callback_mgr.set_plate_info(index+1, (plate_to_slice== 0)?partplate_list.get_plate_count():1); g_cli_callback_mgr.set_plate_info(index+1, (plate_to_slice== 0)?partplate_list.get_plate_count():1);
if (!warning.string.empty()) {
PrintBase::SlicingStatus slicing_status{2, warning.string, 0, 0};
cli_status_callback(slicing_status);
}
} }
#endif #endif
print->process(); print->process();