mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 04:02:02 +08:00
Improvement of Printer status polling.
Define polling action that changes when uuid->printer_model map is filled. Also serves to turn off polling.
This commit is contained in:
parent
fd8a580dee
commit
5e171ccfe7
@ -152,10 +152,6 @@ void UserAccount::on_communication_fail()
|
|||||||
m_communication->enqueue_test_connection();
|
m_communication->enqueue_test_connection();
|
||||||
m_fail_counter = 0;
|
m_fail_counter = 0;
|
||||||
}
|
}
|
||||||
// Printer models are called only after login, if it fails, it should repeat
|
|
||||||
if (m_printer_uuid_map.empty()) {
|
|
||||||
enqueue_connect_printer_models_action();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -299,6 +295,7 @@ bool UserAccount::on_connect_uiid_map_success(const std::string& data, AppConfig
|
|||||||
}
|
}
|
||||||
m_printer_uuid_map[*printer_uuid] = *printer_model;
|
m_printer_uuid_map[*printer_uuid] = *printer_model;
|
||||||
}
|
}
|
||||||
|
m_communication->on_uuid_map_success();
|
||||||
return on_connect_printers_success(data, app_config, out_printers_changed);
|
return on_connect_printers_success(data, app_config, out_printers_changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +214,15 @@ void UserAccountCommunication::set_polling_enabled(bool enabled)
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_session_mutex);
|
std::lock_guard<std::mutex> lock(m_session_mutex);
|
||||||
return m_session->set_polling_enabled(enabled);
|
return m_session->set_polling_action(enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserAccountCommunication::on_uuid_map_success()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_session_mutex);
|
||||||
|
return m_session->set_polling_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,8 @@ public:
|
|||||||
std::string get_shared_session_key();
|
std::string get_shared_session_key();
|
||||||
|
|
||||||
void set_polling_enabled(bool enabled);
|
void set_polling_enabled(bool enabled);
|
||||||
|
// we have map of uuids and printer_models - set polling action to lightweight STATUS action
|
||||||
|
void on_uuid_map_success();
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<UserAccountSession> m_session;
|
std::unique_ptr<UserAccountSession> m_session;
|
||||||
std::thread m_thread;
|
std::thread m_thread;
|
||||||
|
@ -75,11 +75,7 @@ void UserAccountSession::process_action_queue()
|
|||||||
return;
|
return;
|
||||||
if (m_priority_action_queue.empty() && m_action_queue.empty()) {
|
if (m_priority_action_queue.empty() && m_action_queue.empty()) {
|
||||||
// update printers periodically
|
// update printers periodically
|
||||||
if (m_polling_enabled) {
|
enqueue_action(m_polling_action, nullptr, nullptr, {});
|
||||||
enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS, nullptr, nullptr, {});
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// priority queue works even when tokens are empty or broken
|
// priority queue works even when tokens are empty or broken
|
||||||
while (!m_priority_action_queue.empty()) {
|
while (!m_priority_action_queue.empty()) {
|
||||||
|
@ -38,8 +38,8 @@ enum class UserAccountActionID {
|
|||||||
USER_ACCOUNT_ACTION_USER_ID,
|
USER_ACCOUNT_ACTION_USER_ID,
|
||||||
USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN,
|
USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN,
|
||||||
USER_ACCOUNT_ACTION_TEST_CONNECTION,
|
USER_ACCOUNT_ACTION_TEST_CONNECTION,
|
||||||
USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers
|
USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers by UUID
|
||||||
USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS,
|
USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS, // status of all printers by UUID with printer_model. Should be called once to save printer models.
|
||||||
USER_ACCOUNT_ACTION_AVATAR,
|
USER_ACCOUNT_ACTION_AVATAR,
|
||||||
};
|
};
|
||||||
class UserAction
|
class UserAction
|
||||||
@ -101,7 +101,7 @@ public:
|
|||||||
, m_access_token(access_token)
|
, m_access_token(access_token)
|
||||||
, m_refresh_token(refresh_token)
|
, m_refresh_token(refresh_token)
|
||||||
, m_shared_session_key(shared_session_key)
|
, m_shared_session_key(shared_session_key)
|
||||||
, m_polling_enabled(polling_enabled)
|
, m_polling_action(polling_enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -146,7 +146,8 @@ public:
|
|||||||
std::string get_refresh_token() const { return m_refresh_token; }
|
std::string get_refresh_token() const { return m_refresh_token; }
|
||||||
std::string get_shared_session_key() const { return m_shared_session_key; }
|
std::string get_shared_session_key() const { return m_shared_session_key; }
|
||||||
|
|
||||||
void set_polling_enabled(bool enabled) {m_polling_enabled = enabled; }
|
//void set_polling_enabled(bool enabled) {m_polling_action = enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY; }
|
||||||
|
void set_polling_action(UserAccountActionID action) { m_polling_action = action; }
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void enqueue_refresh(const std::string& body);
|
void enqueue_refresh(const std::string& body);
|
||||||
@ -159,8 +160,9 @@ private:
|
|||||||
// false prevents action queu to be processed - no communication is done
|
// false prevents action queu to be processed - no communication is done
|
||||||
// sets to true by init_with_code or enqueue_action call
|
// sets to true by init_with_code or enqueue_action call
|
||||||
bool m_proccessing_enabled {false};
|
bool m_proccessing_enabled {false};
|
||||||
// triggers CONNECT_PRINTERS action when woken up on idle
|
// action when woken up on idle - switches between USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS and USER_ACCOUNT_ACTION_CONNECT_STATUS
|
||||||
bool m_polling_enabled;
|
// set to USER_ACCOUNT_ACTION_DUMMY to switch off polling
|
||||||
|
UserAccountActionID m_polling_action;
|
||||||
|
|
||||||
std::string m_access_token;
|
std::string m_access_token;
|
||||||
std::string m_refresh_token;
|
std::string m_refresh_token;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user