ENH:try again after subscription failure

jira:[Try again after subscription failure]

Change-Id: Ibfb1e8e26eb166d786a372632a86ef98030db034
This commit is contained in:
tao wang 2023-11-01 12:33:16 +08:00 committed by Lane.Wei
parent 55b27a0e30
commit 1d41b0a7a7
6 changed files with 33 additions and 1 deletions

View File

@ -2468,6 +2468,7 @@ void MachineObject::reset_update_time()
{
BOOST_LOG_TRIVIAL(trace) << "reset reset_update_time, dev_id =" << dev_id;
last_update_time = std::chrono::system_clock::now();
subscribe_counter = 3;
}
void MachineObject::reset()
@ -2491,6 +2492,7 @@ void MachineObject::reset()
nozzle_diameter = 0.0f;
network_wired = false;
dev_connection_name = "";
subscribe_counter = 3;
job_id_ = "";
// reset print_json
@ -5201,6 +5203,10 @@ bool DeviceManager::set_selected_machine(std::string dev_id, bool need_disconnec
if (it->second->connection_type() != "lan") {
// only reset update time
it->second->reset_update_time();
// check subscribe state
Slic3r::GUI::wxGetApp().on_start_subscribe_again(dev_id);
return true;
} else {
// lan mode printer reconnect printer

View File

@ -405,6 +405,7 @@ public:
bool local_use_ssl_for_mqtt { true };
bool local_use_ssl_for_ftp { true };
float nozzle_diameter { 0.0f };
int subscribe_counter{3};
std::string nozzle_type;
std::string dev_connection_type; /* lan | cloud */
std::string connection_type() { return dev_connection_type; }

View File

@ -1884,6 +1884,12 @@ void GUI_App::init_networking_callbacks()
}
);
m_agent->set_on_subscribe_failure_fn([this](std::string dev_id) {
CallAfter([this, dev_id] {
on_start_subscribe_again(dev_id);
});
});
m_agent->set_on_local_connect_fn(
[this](int state, std::string dev_id, std::string msg) {
if (m_is_closing) {
@ -2230,7 +2236,8 @@ void GUI_App::on_start_subscribe_again(std::string dev_id)
MachineObject* obj = dev->get_selected_machine();
if (!obj) return;
if ( (dev_id == obj->dev_id) && obj->is_connecting() ) {
if ( (dev_id == obj->dev_id) && obj->is_connecting() && obj->subscribe_counter > 0) {
obj->subscribe_counter--;
if(wxGetApp().getAgent()) wxGetApp().getAgent()->set_user_selected_machine(dev_id);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": dev_id=" << obj->dev_id;
}

View File

@ -42,6 +42,7 @@ func_set_on_printer_connected_fn NetworkAgent::set_on_printer_connected_fn_pt
func_set_on_server_connected_fn NetworkAgent::set_on_server_connected_fn_ptr = nullptr;
func_set_on_http_error_fn NetworkAgent::set_on_http_error_fn_ptr = nullptr;
func_set_get_country_code_fn NetworkAgent::set_get_country_code_fn_ptr = nullptr;
func_set_on_subscribe_failure_fn NetworkAgent::set_on_subscribe_failure_fn_ptr = nullptr;
func_set_on_message_fn NetworkAgent::set_on_message_fn_ptr = nullptr;
func_set_on_local_connect_fn NetworkAgent::set_on_local_connect_fn_ptr = nullptr;
func_set_on_local_message_fn NetworkAgent::set_on_local_message_fn_ptr = nullptr;
@ -200,6 +201,7 @@ int NetworkAgent::initialize_network_module(bool using_backup)
set_on_server_connected_fn_ptr = reinterpret_cast<func_set_on_server_connected_fn>(get_network_function("bambu_network_set_on_server_connected_fn"));
set_on_http_error_fn_ptr = reinterpret_cast<func_set_on_http_error_fn>(get_network_function("bambu_network_set_on_http_error_fn"));
set_get_country_code_fn_ptr = reinterpret_cast<func_set_get_country_code_fn>(get_network_function("bambu_network_set_get_country_code_fn"));
set_on_subscribe_failure_fn_ptr = reinterpret_cast<func_set_on_subscribe_failure_fn>(get_network_function("bambu_network_set_on_subscribe_failure_fn"));
set_on_message_fn_ptr = reinterpret_cast<func_set_on_message_fn>(get_network_function("bambu_network_set_on_message_fn"));
set_on_local_connect_fn_ptr = reinterpret_cast<func_set_on_local_connect_fn>(get_network_function("bambu_network_set_on_local_connect_fn"));
set_on_local_message_fn_ptr = reinterpret_cast<func_set_on_local_message_fn>(get_network_function("bambu_network_set_on_local_message_fn"));
@ -312,6 +314,7 @@ int NetworkAgent::unload_network_module()
set_on_server_connected_fn_ptr = nullptr;
set_on_http_error_fn_ptr = nullptr;
set_get_country_code_fn_ptr = nullptr;
set_on_subscribe_failure_fn_ptr = nullptr;
set_on_message_fn_ptr = nullptr;
set_on_local_connect_fn_ptr = nullptr;
set_on_local_message_fn_ptr = nullptr;
@ -595,6 +598,17 @@ int NetworkAgent::set_get_country_code_fn(GetCountryCodeFn fn)
return ret;
}
int NetworkAgent::set_on_subscribe_failure_fn(GetSubscribeFailureFn fn)
{
int ret = 0;
if (network_agent && set_on_subscribe_failure_fn_ptr) {
ret = set_on_subscribe_failure_fn_ptr(network_agent, fn);
if (ret)
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%") % network_agent % ret;
}
return ret;
}
int NetworkAgent::set_on_message_fn(OnMessageFn fn)
{
int ret = 0;

View File

@ -22,6 +22,7 @@ typedef int (*func_set_on_printer_connected_fn)(void *agent, OnPrinterConnectedF
typedef int (*func_set_on_server_connected_fn)(void *agent, OnServerConnectedFn fn);
typedef int (*func_set_on_http_error_fn)(void *agent, OnHttpErrorFn fn);
typedef int (*func_set_get_country_code_fn)(void *agent, GetCountryCodeFn fn);
typedef int (*func_set_on_subscribe_failure_fn)(void *agent, GetSubscribeFailureFn fn);
typedef int (*func_set_on_message_fn)(void *agent, OnMessageFn fn);
typedef int (*func_set_on_local_connect_fn)(void *agent, OnLocalConnectedFn fn);
typedef int (*func_set_on_local_message_fn)(void *agent, OnMessageFn fn);
@ -124,6 +125,7 @@ public:
int set_on_server_connected_fn(OnServerConnectedFn fn);
int set_on_http_error_fn(OnHttpErrorFn fn);
int set_get_country_code_fn(GetCountryCodeFn fn);
int set_on_subscribe_failure_fn(GetSubscribeFailureFn fn);
int set_on_message_fn(OnMessageFn fn);
int set_on_local_connect_fn(OnLocalConnectedFn fn);
int set_on_local_message_fn(OnMessageFn fn);
@ -214,6 +216,7 @@ private:
static func_set_on_server_connected_fn set_on_server_connected_fn_ptr;
static func_set_on_http_error_fn set_on_http_error_fn_ptr;
static func_set_get_country_code_fn set_get_country_code_fn_ptr;
static func_set_on_subscribe_failure_fn set_on_subscribe_failure_fn_ptr;
static func_set_on_message_fn set_on_message_fn_ptr;
static func_set_on_local_connect_fn set_on_local_connect_fn_ptr;
static func_set_on_local_message_fn set_on_local_message_fn_ptr;

View File

@ -135,6 +135,7 @@ typedef std::function<void(std::string dev_id, std::string msg)> OnMessageFn;
// http callbacks
typedef std::function<void(unsigned http_code, std::string http_body)> OnHttpErrorFn;
typedef std::function<std::string()> GetCountryCodeFn;
typedef std::function<void(std::string topic)> GetSubscribeFailureFn;
// print callbacks
typedef std::function<void(int status, int code, std::string msg)> OnUpdateStatusFn;
typedef std::function<bool()> WasCancelledFn;