FIX: query hms crash while there is updating hms in other thread
jira: [STUDIO-9380] Change-Id: I1b3d94008d4d03d3d41c10e1240fe832755ef9da
This commit is contained in:
parent
2b1f8887ef
commit
0d367638b5
|
@ -242,6 +242,7 @@ wxString HMSQuery::_query_hms_msg(std::string long_error_code, std::string lang_
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_lock unique_lock(m_hms_mutex);
|
||||||
if (!m_hms_info_json.is_object())
|
if (!m_hms_info_json.is_object())
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(error) << "the hms info is not a valid json object";
|
BOOST_LOG_TRIVIAL(error) << "the hms info is not a valid json object";
|
||||||
|
@ -299,6 +300,8 @@ wxString HMSQuery::_query_hms_msg(std::string long_error_code, std::string lang_
|
||||||
|
|
||||||
bool HMSQuery::_query_error_msg(wxString &error_msg, std::string error_code, std::string lang_code)
|
bool HMSQuery::_query_error_msg(wxString &error_msg, std::string error_code, std::string lang_code)
|
||||||
{
|
{
|
||||||
|
std::unique_lock unique_lock(m_hms_mutex);
|
||||||
|
|
||||||
if (m_hms_info_json.contains("device_error")) {
|
if (m_hms_info_json.contains("device_error")) {
|
||||||
if (m_hms_info_json["device_error"].contains(lang_code)) {
|
if (m_hms_info_json["device_error"].contains(lang_code)) {
|
||||||
for (auto item = m_hms_info_json["device_error"][lang_code].begin(); item != m_hms_info_json["device_error"][lang_code].end(); item++) {
|
for (auto item = m_hms_info_json["device_error"][lang_code].begin(); item != m_hms_info_json["device_error"][lang_code].end(); item++) {
|
||||||
|
@ -338,6 +341,8 @@ bool HMSQuery::_query_error_msg(wxString &error_msg, std::string error_code, std
|
||||||
|
|
||||||
wxString HMSQuery::_query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action)
|
wxString HMSQuery::_query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action)
|
||||||
{
|
{
|
||||||
|
std::unique_lock unique_lock(m_hms_mutex);
|
||||||
|
|
||||||
if (m_hms_action_json.contains("data")) {
|
if (m_hms_action_json.contains("data")) {
|
||||||
for (auto item = m_hms_action_json["data"].begin(); item != m_hms_action_json["data"].end(); item++) {
|
for (auto item = m_hms_action_json["data"].begin(); item != m_hms_action_json["data"].end(); item++) {
|
||||||
if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == long_error_code) {
|
if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == long_error_code) {
|
||||||
|
@ -394,6 +399,8 @@ int HMSQuery::check_hms_info(std::string dev_type)
|
||||||
dev_sn.push_back("094");
|
dev_sn.push_back("094");
|
||||||
|
|
||||||
boost::thread check_thread = boost::thread([this, dev_type, dev_sn] {
|
boost::thread check_thread = boost::thread([this, dev_type, dev_sn] {
|
||||||
|
|
||||||
|
std::unique_lock unique_lock(m_hms_mutex);
|
||||||
for (auto sn : dev_sn) {
|
for (auto sn : dev_sn) {
|
||||||
download_hms_related(QUERY_HMS_INFO, &m_hms_info_json, sn);
|
download_hms_related(QUERY_HMS_INFO, &m_hms_info_json, sn);
|
||||||
download_hms_related(QUERY_HMS_ACTION, &m_hms_action_json, sn);
|
download_hms_related(QUERY_HMS_ACTION, &m_hms_action_json, sn);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "slic3r/Utils/Http.hpp"
|
#include "slic3r/Utils/Http.hpp"
|
||||||
#include "libslic3r/Thread.hpp"
|
#include "libslic3r/Thread.hpp"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
@ -20,9 +21,12 @@ namespace GUI {
|
||||||
#define QUERY_HMS_ACTION "query_hms_action"
|
#define QUERY_HMS_ACTION "query_hms_action"
|
||||||
|
|
||||||
class HMSQuery {
|
class HMSQuery {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
json m_hms_info_json;
|
json m_hms_info_json;
|
||||||
json m_hms_action_json;
|
json m_hms_action_json;
|
||||||
|
mutable std::mutex m_hms_mutex;
|
||||||
|
|
||||||
int download_hms_related(std::string hms_type, json *receive_json, std::string dev_type);
|
int download_hms_related(std::string hms_type, json *receive_json, std::string dev_type);
|
||||||
int load_from_local(std::string &version_info, std::string hms_type, json *load_json, std::string dev_type);
|
int load_from_local(std::string &version_info, std::string hms_type, json *load_json, std::string dev_type);
|
||||||
int save_to_local(std::string lang, std::string hms_type, std::string dev_type, json save_json);
|
int save_to_local(std::string lang, std::string hms_type, std::string dev_type, json save_json);
|
||||||
|
@ -30,6 +34,7 @@ protected:
|
||||||
wxString _query_hms_msg(std::string long_error_code, std::string lang_code = std::string("en")) const;
|
wxString _query_hms_msg(std::string long_error_code, std::string lang_code = std::string("en")) const;
|
||||||
bool _query_error_msg(wxString &error_msg, std::string long_error_code, std::string lang_code = std::string("en"));
|
bool _query_error_msg(wxString &error_msg, std::string long_error_code, std::string lang_code = std::string("en"));
|
||||||
wxString _query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action);
|
wxString _query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HMSQuery() {}
|
HMSQuery() {}
|
||||||
int check_hms_info(std::string dev_type = "00M");
|
int check_hms_info(std::string dev_type = "00M");
|
||||||
|
|
Loading…
Reference in New Issue